...
 
Commits (1)
//###########################################################################
// This file is part of LImA, a Library for Image Acquisition
//
// Copyright (C) : 2009-2011
// European Synchrotron Radiation Facility
// BP 220, Grenoble 38043
// FRANCE
//
// This is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 3 of the License, or
// (at your option) any later version.
//
// This software is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, see <http://www.gnu.org/licenses/>.
//###########################################################################
#ifndef CTBACKGROUND_H
#define CTBACKGROUND_H
#include "LimaCompatibility.h"
#include "CtControl.h"
namespace lima {
class LIMACORE_API CtBackground
{
friend class CtControl;
DEB_CLASS_NAMESPC(DebModControl,"Background","Control");
public:
enum OpMode
{
Hard,
Soft,
HardOrSoft
};
CtBackground(HwInterface *hw,CtControl&);
~CtBackground();
// --- background task management
void setActive(bool flag);
bool isActive() const;
void setRunLevel(int);
void getRunLevel(int&) const;
void setMode(OpMode mode);
void getMode(OpMode &mode) const;
// --- Background image management
void takeBackgroundImage(int nbFrames,double acqTime);
void usePreviousAcqImageAsBackgroundImage();
void setBackgroundImage(const Data&);
private:
void apply();
CtControl& m_ct;
OpMode m_mode;
bool m_active_flag;
int m_runlevel;
bool m_send_background_2_hw;
Data m_background_image;
bool m_has_background;
HwBackgroundCtrlObj* m_hw_background;
};
}
#endif
......@@ -23,6 +23,7 @@
#define CTCONTROL_H
#include <set>
#include <list>
#include "LimaCompatibility.h"
#include "ThreadUtils.h"
......@@ -48,6 +49,7 @@ namespace lima
class CtAccumulation;
class CtVideo;
class CtEvent;
class CtBackground;
class SoftOpInternalMgr;
class SoftOpExternalMgr;
......@@ -149,6 +151,7 @@ namespace lima
CtVideo* video();
CtShutter* shutter();
CtEvent* event();
CtBackground* background();
SoftOpExternalMgr* externalOperation();
......@@ -165,6 +168,7 @@ namespace lima
CtVideo* video() { return m_ct_video;}
CtShutter* shutter() { return m_ct_shutter; }
CtEvent* event() { return m_ct_event; }
CtBackground* background() { return m_ct_background; }
SoftOpExternalMgr* externalOperation() {return m_op_ext;}
......@@ -232,6 +236,7 @@ namespace lima
CtAccumulation *m_ct_accumulation;
CtVideo *m_ct_video;
CtEvent *m_ct_event;
CtBackground *m_ct_background;
SoftOpInternalMgr *m_op_int;
SoftOpExternalMgr *m_op_ext;
......@@ -253,10 +258,14 @@ namespace lima
#ifdef WITH_SPS_IMAGE
bool m_display_active_flag;
#endif
ImageStatusCallback *m_img_status_cb;
typedef std::list<ImageStatusCallback*> ImageStatusCallbackList
ImageStatusCallbackList m_img_status_cbs;
Mutex m_img_status_cbs_lock;
inline bool _checkOverrun(Data&);
inline void _calcAcqStatus();
inline ImageStatusCallbackList::iterator _find(ImageStatusCallback&);
inline void _imageStatusChanged(ImageStatus);
};
inline std::ostream& operator<<(std::ostream &os,
......
//###########################################################################
// This file is part of LImA, a Library for Image Acquisition
//
// Copyright (C) : 2009-2011
// European Synchrotron Radiation Facility
// BP 220, Grenoble 38043
// FRANCE
//
// This is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 3 of the License, or
// (at your option) any later version.
//
// This software is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, see <http://www.gnu.org/licenses/>.
//###########################################################################
#include "HwBackgroundCtrlObj.h"
#include "CtBackground.h"
using namespace lima;
CtBackground::CtBackground(HwInterface *hw,CtControl &aControl) :
m_ct(aControl),
m_mode(CtBackground::HardOrSoft)
m_active_flag(false),
m_runlevel(0),
m_send_background_2_hw(false)
{
DEB_CONSTRUCTOR();
m_has_background = hw->getHwCtrlObj(m_hw_background);
}
CtBackground::~CtBackground()
{
DEB_DESTRUCTOR();
}
void CtBackground::setActive(bool flag)
{
DEB_MEMBER_FUNCT();
if(flag)
{
if(m_has_background &&
(m_mode != CtBackground::Software) &&
!m_send_background_2_hw && // no new background image
!m_has_background->hasBackgroundImage()) // hw don't have it in memory
THROW_CTL_ERROR(Error) << "Take a background image first";
else if(m_background_image.empty())
THROW_CTL_ERROR(Error) << "Take a background image first";
}
m_active_flag = flag;
}
bool CtBackground::isActive() const
{
return m_active_flag;
}
void CtBackground::setRunLevel(int runlevel)
{
DEB_MEMBER_FUNCT();
if(m_has_background &&
(m_mode != CtBackground::Software))
THROW_CTL_ERROR(Error) << "Can't change runlevel for Hardware background";
}
void CtBackground::getRunLevel(int &runlevel) const
{
runlevel = m_runlevel;
}
void CtBackground::setMode(CtBackground::OpMode mode)
{
DEB_MEMBER_FUNCT();
DEB_PARAM() << DEB_VAR1(mode);
if(mode == CtBackground::Hard &&
!m_has_background)
THROW_CTL_ERROR(Error) <<
"Your hardware is not capable for a background substraction";
m_mode = mode;
}
void CtBackground::getMode(CtBackground::OpMode &mode) const
{
mode = m_mode;
}
void CtBackground::takeBackgroundImage(int nbFrames,double acqTime)
{
DEB_MEMBER_FUNCT();
DEB_PARAM() << DEB_VAR2(nbFrames,acqTime);
//Check first is Acquisition is finnished
CtControl::Status aStatus;
m_ct.getStatus(aStatus);
if(aStatus.AcquisitionStatus != AcqReady)
THROW_CTL_ERROR(Error) << "Can't take background image, Acquisition not ready";
if(m_has_background)
m_hw_background->takeBackgroundImage(nbFrames,acqTime);
else
{
CtSaving *saving = m_ct.saving();
CtSaving::Parameters savingPar;
saving->getParameters(savingPar);
CtAcquisition *acquisition = m_ct.acquisition();
CtAcquisition::Parameters acqPar;
acquisition->getParameters(acqPar);
//@todo should be also done for accumulation
try
{
saving->setSavingMode(CtSaving::Manual);
acquisition->setAcqMode(nbFrames > 1 ? Accumulation : Single);
acquisition->setAcqNbFrames(1);
acquisition->setAcqExpoTime(acqTime * nbFrames);
acquisition->setAccMaxExpoTime(acqTime);
m_ct.prepareAcq();
//Rollback parameters
saving->setSavingMode(savingPar.savingMode);
acquisition->setParameters(acqPar);
}
catch(Exception &exc)
{
//Rollback parameters
saving->setSavingMode(savingPar.savingMode);
acquisition->setParameters(acqPar);
THROW_CTL_ERROR(Error) << exc;
}
m_ct.startAcq();
}
}
......@@ -123,8 +123,7 @@ CtControl::CtControl(HwInterface *hw) :
m_images_ready(CtControl::ltData()),
m_images_buffer_size(16),
m_policy(All), m_ready(false),
m_autosave(false), m_running(false),
m_img_status_cb(NULL)
m_autosave(false), m_running(false)
{
DEB_CONSTRUCTOR();
......@@ -135,6 +134,7 @@ CtControl::CtControl(HwInterface *hw) :
m_ct_accumulation = new CtAccumulation(*this);
m_ct_video = new CtVideo(*this);
m_ct_event = new CtEvent(*this);
m_ct_background = new CtBackground(hw,*this);
//Saving
m_ct_saving= new CtSaving(*this);
......@@ -158,9 +158,10 @@ CtControl::~CtControl()
PoolThreadMgr& pool_thread_mgr = PoolThreadMgr::get();
pool_thread_mgr.wait();
if (m_img_status_cb)
unregisterImageStatusCallback(*m_img_status_cb);
for(ImageStatusCallbackList::iterator i = m_img_status_cbs.begin();
i != m_img_status_cbs.end();++i)
unregisterImageStatusCallback(*i);
delete m_ct_saving;
#ifdef WITH_SPS_IMAGE
delete m_ct_sps_image;
......@@ -171,6 +172,8 @@ CtControl::~CtControl()
delete m_ct_shutter;
delete m_ct_accumulation;
delete m_ct_video;
delete m_ct_event;
delete m_ct_background;
delete m_op_int;
delete m_op_ext;
......@@ -223,6 +226,9 @@ void CtControl::prepareAcq()
DEB_TRACE() << "Prepare Accumulation if needed";
m_ct_accumulation->prepare();
DEB_TRACE() << "Prepare background if needed";
m_ct_background->apply();
DEB_TRACE() << "Prepare Hardware for Acquisition";
m_hw->prepareAcq();
......@@ -584,8 +590,7 @@ bool CtControl::newFrameReady(Data& fdata)
if (!internal_stage)
newBaseImageReady(fdata);
if (m_img_status_cb)
m_img_status_cb->imageStatusChanged(m_status.ImageCounters);
_imageStatusChanged(m_status.ImageCounters);
_calcAcqStatus();
}
......@@ -636,9 +641,8 @@ void CtControl::newBaseImageReady(Data &aData)
m_ct_video->frameReady(aData);
if(m_img_status_cb && img_status_changed)
m_img_status_cb->imageStatusChanged(m_status.ImageCounters);
if(img_status_changed)
_imageStatusChanged(m_status.ImageCounters);
_calcAcqStatus();
}
......@@ -681,8 +685,8 @@ void CtControl::newImageReady(Data &aData)
if(m_autosave)
newFrameToSave(aData);
if (m_img_status_cb && img_status_changed)
m_img_status_cb->imageStatusChanged(m_status.ImageCounters);
if (img_status_changed)
_imageStatusChanged(m_status.ImageCounters);
_calcAcqStatus();
}
......@@ -711,8 +715,7 @@ void CtControl::newImageSaved(Data&)
}
aLock.unlock();
if (m_img_status_cb)
m_img_status_cb->imageStatusChanged(m_status.ImageCounters);
_imageStatusChanged(m_status.ImageCounters);
_calcAcqStatus();
}
......@@ -729,31 +732,51 @@ void CtControl::newFrameToSave(Data& fdata)
void CtControl::registerImageStatusCallback(ImageStatusCallback& cb)
{
DEB_MEMBER_FUNCT();
DEB_PARAM() << DEB_VAR2(&cb, m_img_status_cb);
if (m_img_status_cb) {
DEB_ERROR() << "ImageStatusCallback already registered";
throw LIMA_CTL_EXC(InvalidValue, "ImageStatusCallback already registered");
}
AutoMutex aLock(m_img_status_cbs_lock);
ImageStatusCallbackList::iterator i = _find(cb);
if(i != m_img_status_cbs.end())
THROW_CTL_ERROR(Error) <<"ImageStatusCallback already registered";
cb.setImageStatusCallbackGen(this);
m_img_status_cb = &cb;
m_img_status_cbs.append(&cb);
}
void CtControl::unregisterImageStatusCallback(ImageStatusCallback& cb)
{
DEB_MEMBER_FUNCT();
DEB_PARAM() << DEB_VAR2(&cb, m_img_status_cb);
if (m_img_status_cb != &cb) {
DEB_ERROR() << "ImageStatusCallback not registered";
throw LIMA_CTL_EXC(InvalidValue, "ImageStatusCallback not registered");
}
AutoMutex aLock(m_img_status_cbs_lock);
ImageStatusCallbackList::iterator i = _find(cb);
if (i == m_img_status_cbs.end())
THROW_CTL_ERROR(Error) << "ImageStatusCallback not registered";
m_img_status_cb = NULL;
cb.setImageStatusCallbackGen(NULL);
i->setImageStatusCallbackGen(NULL);
m_img_status_cbs.erase(i);
}
ImageStatusCallbackList::iterator CtControl::_find(ImageStatusCallback &cbk)
{
ImageStatusCallbackList::iterator i;
for(i = m_img_status_cbs.begin();
i != m_img_status_cbs.end();
++i)
{
if(*i == &cbk)
break;
}
return i;
}
void CtControl::_imageStatusChanged(ImageStatus img_status)
{
AutoMutex aLock(m_img_status_cbs_lock);
for(ImageStatusCallbackList::iterator i = m_img_status_cbs.begin();
i != m_img_status_cbs.end();++i)
i->imageStatusChanged(img_status);
}
/** @brief this methode check if an overrun
* @warning this methode is call under lock
*/
......@@ -883,6 +906,7 @@ CtAccumulation* CtControl::accumulation() { return m_ct_accumulation; }
CtVideo* CtControl::video() { return m_ct_video;}
CtShutter* CtControl::shutter() { return m_ct_shutter; }
CtEvent* CtControl::event() { return m_ct_event; }
CtBackground* CtControl::background() { return m_ct_background; }
SoftOpExternalMgr* CtControl::externalOperation() {return m_op_ext;}
......
//###########################################################################
// This file is part of LImA, a Library for Image Acquisition
//
// Copyright (C) : 2009-2011
// European Synchrotron Radiation Facility
// BP 220, Grenoble 38043
// FRANCE
//
// This is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 3 of the License, or
// (at your option) any later version.
//
// This software is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, see <http://www.gnu.org/licenses/>.
//###########################################################################
#ifndef HWBACKGROUNDCTRLOBJ_H
#define HWBACKGROUNDCTRLOBJ_H
#include "LimaCompatibility.h"
namespace lima
{
class LIMACORE_API HwBackgroundCtrlObj
{
public:
virtual ~HwBackgroundCtrlObj() {};
virtual void setActive(bool) = 0;
virtual bool isActive() const = 0;
virtual bool hasBackgroundImage() const = 0;
virtual void takeBackgroundImage(int nbframes,double acqTime) = 0;
virtual void setBackgroundImage(const Data&) = 0;
};
}
#endif
//###########################################################################
// This file is part of LImA, a Library for Image Acquisition
//
// Copyright (C) : 2009-2011
// European Synchrotron Radiation Facility
// BP 220, Grenoble 38043
// FRANCE
//
// This is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 3 of the License, or
// (at your option) any later version.
//
// This software is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, see <http://www.gnu.org/licenses/>.
//###########################################################################
#ifndef HWVIDEOCTRLOBJ_H
#define HWVIDEOCTRLOBJ_H
#include <list>
......