Commit 64269e05 authored by Roberto Arturo Homs-Regojo's avatar Roberto Arturo Homs-Regojo
Browse files

commit local chages (pco_sinogram)

parent 76d831cd
Subproject commit ff1507690123b9f07f890123aa1df491c2f4bba5
Subproject commit f50a6f0c98faecd8b919e8641ffdb913e1d8caea
Subproject commit 3cb54a3cd5621c71df2460e203da7dd13547245d
Subproject commit 789a18a6dd165665c0e1b6706bd4c29016ec4947
......@@ -144,7 +144,7 @@ namespace lima
SoftOpFlatfieldCorrection();
virtual ~SoftOpFlatfieldCorrection();
void setFlatFieldImage(Data &aData,bool normalize = true);
void setFlatFieldImage(Data &aData);
protected:
virtual bool addTo(TaskMgr&,int stage);
......@@ -185,6 +185,168 @@ namespace lima
Tasks::Mask *m_opt;
};
template <class Manager, class Task>
class NameTaskMap
{
public:
typedef std::string Name;
typedef std::pair<Name, Task *> NameAndTask;
typedef std::list<Name> NameList;
typedef std::list<NameAndTask> NameAndTaskList;
typedef std::pair<Manager *, Task *> ManagerAndTask;
typedef std::map<Name, ManagerAndTask> Name2ManagerAndTask;
typedef typename Name2ManagerAndTask::iterator NameMapIterator;
typedef typename Name2ManagerAndTask::const_iterator NameMapConstIterator;
NameTaskMap()
{
clearCounterStatus();
m_compat_format = "%d";
}
~NameTaskMap()
{
for(NameMapIterator i = begin(); i != end(); ++i) {
i->second.second->unref();
i->second.first->unref();
}
}
void setCompatFormat(std::string compat_format)
{
m_compat_format = compat_format;
}
Name getCompatName(int id) const
{
char buffer[256];
snprintf(buffer, sizeof(buffer), m_compat_format.c_str(), id);
return Name(buffer);
}
bool getCompatId(Name name, int& id) const
{
if (sscanf(name.c_str(), m_compat_format.c_str(), &id) != 1)
return false;
return true;
}
int size() const
{
return m_manager_tasks.size();
}
NameMapIterator begin()
{
return m_manager_tasks.begin();
}
NameMapConstIterator begin() const
{
return m_manager_tasks.begin();
}
NameMapIterator end()
{
return m_manager_tasks.end();
}
NameMapConstIterator end() const
{
return m_manager_tasks.end();
}
NameMapIterator find(const Name& name)
{
return m_manager_tasks.find(name);
}
NameMapConstIterator find(const Name& name) const
{
return m_manager_tasks.find(name);
}
NameMapIterator findCompat(int id)
{
return m_manager_tasks.find(getCompatName(id));
}
NameMapConstIterator findCompat(int id) const
{
return m_manager_tasks.find(getCompatName(id));
}
void insert(const Name& name, ManagerAndTask man_task)
{
m_manager_tasks[name] = man_task;
}
void getTasks(NameAndTaskList& l) const
{
for (NameMapConstIterator i = begin(); i != end(); ++i) {
const Name& name = i->first;
Task *task = i->second.second;
l.push_back(NameAndTask(name, task));
}
}
void getNames(NameList& l) const
{
for (NameMapConstIterator i = begin(); i != end(); ++i)
l.push_back(i->first);
}
void remove(const NameList& l)
{
for (NameList::const_iterator i = l.begin(); i != l.end(); ++i) {
NameMapIterator named_roi = m_manager_tasks.find(*i);
if (named_roi != end()) {
named_roi->second.second->unref();
named_roi->second.first->unref();
m_manager_tasks.erase(named_roi);
}
}
}
void clearAll()
{
for (NameMapIterator i = begin(); i != end(); ++i) {
i->second.second->unref();
i->second.first->unref();
}
m_manager_tasks.clear();
}
bool addTo(TaskMgr& aMgr, int stage)
{
for (NameMapIterator i = begin(); i != end(); ++i)
aMgr.addSinkTask(stage, i->second.second);
++m_counter_status;
return !m_manager_tasks.empty();
}
int getCounterStatus() const
{
return m_counter_status;
}
void prepareCounterStatus()
{
m_counter_status = -1;
}
void clearCounterStatus()
{
m_counter_status = -2;
}
private:
Name2ManagerAndTask m_manager_tasks;
int m_counter_status;
std::string m_compat_format;
};
class LIMACORE_API SoftOpRoiCounter : public SoftOpBaseClass
{
DEB_CLASS_NAMESPC(DebModControl,"SoftwareOperation","SoftOpRoiCounter");
......@@ -194,6 +356,7 @@ namespace lima
typedef std::pair<std::string,std::list<Tasks::RoiCounterResult> > RoiNameAndResults;
typedef std::pair<std::string,Roi> RoiNameAndRoi;
typedef std::pair<std::string,ArcRoi> RoiNameAndArcRoi;
typedef std::pair<std::string,int> RoiNameAndType;
typedef std::pair<std::string,Tasks::RoiCounterTask*> RoiNameAndTask;
typedef std::list<RoiNameAndTask> RoiNameAndTaskList;
......@@ -210,20 +373,28 @@ namespace lima
void get(std::list<Roi>&) const;
void del(const std::list<int> &roiIds);
void readCounters(int from,std::list<RoiIdAndResults> &result) const;
/** New methods set */
void update(const std::list<RoiNameAndRoi>&);
void update(const std::list<RoiNameAndArcRoi>&);
void updateRois(const std::list<RoiNameAndRoi>&);
void updateArcRois(const std::list<RoiNameAndArcRoi>&);
void getRois(std::list<RoiNameAndRoi>& names_rois) const;
void getArcRois(std::list<RoiNameAndArcRoi>& names_rois) const;
void setLut(const std::string& name,
const Point& origin,Data &lut);
void setLutMask(const std::string& name,
const Point& origin,Data &lut);
void getNames(std::list<std::string>& roi_names) const;
void getTypes(std::list<RoiNameAndType>& names_types) const;
void getTasks(RoiNameAndTaskList&);
// end of new set
void names(std::list<std::string>& roi_names) const;
void remove(const std::list<std::string>& names);
void clearAllRoi(); /* clear all roi */
void readCounters(int from,std::list<RoiNameAndResults> &result) const;
void removeRois(const std::list<std::string>& names);
void clearAllRois(); /* clear all roi */
/** end of new set */
void clearCounterStatus();
int getCounterStatus() const;
......@@ -233,23 +404,62 @@ namespace lima
void setBufferSize(int size);
void getBufferSize(int &size) const;
void readCounters(int from,std::list<RoiNameAndResults> &result) const;
protected:
virtual bool addTo(TaskMgr&,int stage);
virtual void prepare();
private:
typedef std::pair<Tasks::RoiCounterManager*,Tasks::RoiCounterTask*> ManagerNCounter;
typedef std::map<std::string,ManagerNCounter> Name2ManagerNCounter;
typedef Tasks::RoiCounterTask SoftTask;
typedef Tasks::RoiCounterManager SoftManager;
typedef NameTaskMap<SoftManager, SoftTask> TaskMap;
typedef TaskMap::NameMapIterator NameMapIterator;
typedef TaskMap::NameMapConstIterator NameMapConstIterator;
void _get_or_create(const std::string& roi_name,
SoftManager *&, SoftTask *&);
inline void _get_or_create(const std::string& roi_name,
Tasks::RoiCounterManager*&,Tasks::RoiCounterTask*&);
template <SoftTask::type roi_type, class R>
void _get_rois_of_type(std::list<std::pair<std::string, R> >& names_rois) const;
template <class R>
void _get_task_roi(SoftTask *task, R& roi) const;
Name2ManagerNCounter m_manager_tasks;
TaskMap m_task_manager;
int m_history_size;
int m_counter_status;
Data m_mask;
mutable Cond m_cond;
};
template <SoftOpRoiCounter::SoftTask::type type, class R>
void SoftOpRoiCounter::_get_rois_of_type(std::list<std::pair<std::string, R> >& names_rois) const
{
for(NameMapConstIterator i = m_task_manager.begin();
i != m_task_manager.end();++i) {
SoftTask *task = i->second.second;
SoftTask::type roi_type;
task->getType(roi_type);
if (roi_type != type)
continue;
R roi;
_get_task_roi(task, roi);
names_rois.push_back(std::pair<std::string, R>(i->first, roi));
}
}
template <>
inline void SoftOpRoiCounter::_get_task_roi(SoftTask *task, Roi& roi) const
{
int x,y,width,height;
task->getRoi(x,y,width,height);
roi = Roi(x,y,width,height);
}
template <>
inline void SoftOpRoiCounter::_get_task_roi(SoftTask *task, ArcRoi& roi) const
{
double x,y,r1,r2,a1,a2;
task->getArcMask(x,y,r1,r2,a1,a2);
roi = ArcRoi(x,y,r1,r2,a1,a2);
}
#define ROI_WARNING
#ifdef WIN32
#pragma message ("deprecated use new methods set")
......@@ -259,38 +469,41 @@ namespace lima
inline void SoftOpRoiCounter::add(const std::list<Roi> &rois)
{
ROI_WARNING;
int nb_rois = m_manager_tasks.size();
int nb_rois = m_task_manager.size();
std::list<RoiNameAndRoi> local_rois;
for(std::list<Roi>::const_iterator i = rois.begin();
i != rois.end();++i,++nb_rois)
std::list<Roi>::const_iterator i, end = rois.end();
for (i = rois.begin(); i != end; ++i, ++nb_rois)
{
char buffer[256];
snprintf(buffer,sizeof(buffer),"roi_%d",nb_rois);
RoiNameAndRoi roiname_roi(buffer,*i);
RoiNameAndRoi roiname_roi(m_task_manager.getCompatName(nb_rois), *i);
local_rois.push_back(roiname_roi);
}
update(local_rois);
updateRois(local_rois);
}
inline void SoftOpRoiCounter::set(const std::list<Roi> &rois)
{
clearAllRoi();
clearAllRois();
add(rois);
}
inline void SoftOpRoiCounter::get(std::list<Roi> &rois) const
{
ROI_WARNING;
DEB_MEMBER_FUNCT();
AutoMutex aLock(m_cond.mutex());
std::list<RoiNameAndRoi> names_rois;
getRois(names_rois);
if (int(names_rois.size()) != int(m_task_manager.size()))
THROW_CTL_ERROR(InvalidValue) << "You can't mixed old and new methods set";
std::vector<Roi> v_rois;
v_rois.resize(m_manager_tasks.size());
for(Name2ManagerNCounter::const_iterator i = m_manager_tasks.begin();
i != m_manager_tasks.end();++i)
v_rois.resize(names_rois.size());
for(std::list<RoiNameAndRoi>::iterator i = names_rois.begin();
i != names_rois.end(); ++i)
{
int roi_id;
if(sscanf(i->first.c_str(),"roi_%d",&roi_id) != 1)
if(!m_task_manager.getCompatId(i->first, roi_id))
THROW_CTL_ERROR(InvalidValue) << "You can't mixed old and new methods set";
int x,y,width,height;
i->second.second->getRoi(x,y,width,height);
v_rois[roi_id] = Roi(x,y,width,height);
v_rois[roi_id] = i->second;
}
for(std::vector<Roi>::iterator i = v_rois.begin();
i != v_rois.end();++i)
......@@ -299,15 +512,12 @@ namespace lima
inline void SoftOpRoiCounter::del(const std::list<int> &roiIds)
{
ROI_WARNING;
AutoMutex aLock(m_cond.mutex());
std::list<std::string> rois_names;
for(std::list<int>::const_iterator i = roiIds.begin();
i != roiIds.end();++i)
{
char buffer[256];
snprintf(buffer,sizeof(buffer),"roi_%d",*i);
rois_names.push_back(buffer);
}
remove(rois_names);
rois_names.push_back(m_task_manager.getCompatName(*i));
removeRois(rois_names);
}
inline void SoftOpRoiCounter::readCounters(int from,
std::list<RoiIdAndResults> &result) const
......@@ -320,7 +530,7 @@ namespace lima
i != tmp_result.end();++i)
{
int roi_id;
if(sscanf(i->first.c_str(),"roi_%d",&roi_id) != 1)
if(!m_task_manager.getCompatId(i->first, roi_id))
THROW_CTL_ERROR(InvalidValue) << "You can't mixed old and new methods set";
result.push_back(RoiIdAndResults(roi_id,i->second));
}
......@@ -329,21 +539,51 @@ namespace lima
class LIMACORE_API SoftOpRoi2Spectrum : public SoftOpBaseClass
{
DEB_CLASS_NAMESPC(DebModControl,"SoftwareOperation","SoftOpRoi2Spectrum");
public:
typedef std::pair<int,std::list<Tasks::Roi2SpectrumResult> > RoiIdAndResults;
typedef std::pair<int,Roi> RoiIdAndRoi;
typedef std::pair<std::string,std::list<Tasks::Roi2SpectrumResult> > RoiNameAndResults;
typedef std::pair<std::string,Roi> RoiNameAndRoi;
typedef std::pair<std::string,Tasks::Roi2SpectrumTask*> RoiNameAndTask;
typedef std::pair<std::string,int> RoiNameAndMode;
typedef std::list<RoiNameAndTask> RoiNameAndTaskList;
SoftOpRoi2Spectrum();
virtual ~SoftOpRoi2Spectrum();
/** Old way to manage roi2spectrum counters
* they are now deprecated,
* please use the new set of methods.
* will be removed in version 2.
*/
void add(const std::list<Roi> &rois);
void set(const std::list<Roi> &rois);
void get(std::list<Roi>&) const;
void del(const std::list<int> &roiIds);
void clearAllRoi(); /* clear all roi */
void readCounters(int from,std::list<RoiIdAndResults> &result) const;
void createImage(int roiId,int &from,Data &aData) const;
void getRoiMode(std::list<int>&) const;
void setRoiMode(int roiId,int mode);
/** New methods set */
void updateRois(const std::list<RoiNameAndRoi>&);
void getRois(std::list<RoiNameAndRoi>&) const;
void setRoiModes(const std::list<RoiNameAndMode>& names_modes);
void getRoiModes(std::list<RoiNameAndMode>& roi_modes) const;
void getNames(std::list<std::string>& roi_names) const;
void getTasks(RoiNameAndTaskList&);
void readCounters(int from,std::list<RoiNameAndResults> &result) const;
void createImage(std::string roi_name,int &from,Data &aData) const;
void removeRois(const std::list<std::string>& names);
void clearAllRois(); /* clear all roi */
// end of new set
void clearCounterStatus();
int getCounterStatus() const;
......@@ -353,21 +593,125 @@ namespace lima
void setBufferSize(int size);
void getBufferSize(int &size) const;
void readCounters(int from,std::list<RoiIdAndResults> &result) const;
void createImage(int roiId,int &from,Data &aData) const;
protected:
virtual bool addTo(TaskMgr&,int stage);
virtual void prepare();
private:
typedef std::pair<Tasks::Roi2SpectrumManager*,Tasks::Roi2SpectrumTask*> ManagerNCounter;
typedef Tasks::Roi2SpectrumTask SoftTask;
typedef Tasks::Roi2SpectrumManager SoftManager;
typedef NameTaskMap<SoftManager, SoftTask> TaskMap;
typedef TaskMap::NameMapIterator NameMapIterator;
typedef TaskMap::NameMapConstIterator NameMapConstIterator;
void _get_or_create(const std::string& roi_name,
SoftManager *&, SoftTask *&);
std::list<ManagerNCounter> m_manager_tasks;
TaskMap m_task_manager;
int m_history_size;
int m_counter_status;
//Data m_mask;
mutable Cond m_cond;
};
inline void SoftOpRoi2Spectrum::add(const std::list<Roi> &rois)
{
ROI_WARNING;
int nb_rois = m_task_manager.size();
std::list<RoiNameAndRoi> local_rois;
for(std::list<Roi>::const_iterator i = rois.begin();
i != rois.end();++i,++nb_rois)
{
RoiNameAndRoi roiname_roi(m_task_manager.getCompatName(nb_rois), *i);
local_rois.push_back(roiname_roi);
}
updateRois(local_rois);
}
inline void SoftOpRoi2Spectrum::set(const std::list<Roi> &rois)
{
clearAllRois();
add(rois);
}
inline void SoftOpRoi2Spectrum::get(std::list<Roi> &rois) const
{
ROI_WARNING;
DEB_MEMBER_FUNCT();
std::vector<Roi> v_rois;
v_rois.resize(m_task_manager.size());
for(NameMapConstIterator i = m_task_manager.begin();
i != m_task_manager.end();++i)
{
int roi_id;
if(!m_task_manager.getCompatId(i->first, roi_id))
THROW_CTL_ERROR(InvalidValue) << "You can't mixed old and new methods set";
int x,y,width,height;
i->second.second->getRoi(x,y,width,height);
v_rois[roi_id] = Roi(x,y,width,height);
}
for(std::vector<Roi>::iterator i = v_rois.begin();
i != v_rois.end();++i)
rois.push_back(*i);
}
inline void SoftOpRoi2Spectrum::del(const std::list<int> &roiIds)
{
ROI_WARNING;
std::list<std::string> rois_names;
for(std::list<int>::const_iterator i = roiIds.begin();
i != roiIds.end();++i)
rois_names.push_back(m_task_manager.getCompatName(*i));
removeRois(rois_names);
}
inline void SoftOpRoi2Spectrum::readCounters(int from,
std::list<RoiIdAndResults> &result) const
{
ROI_WARNING;
DEB_MEMBER_FUNCT();
std::list<RoiNameAndResults> tmp_result;
readCounters(from,tmp_result);
for(std::list<RoiNameAndResults>::iterator i = tmp_result.begin();
i != tmp_result.end();++i)
{
int roi_id;
if(!m_task_manager.getCompatId(i->first, roi_id))
THROW_CTL_ERROR(InvalidValue) << "You can't mixed old and new methods set";
result.push_back(RoiIdAndResults(roi_id,i->second));
}
}
inline void SoftOpRoi2Spectrum::createImage(int roiId, int& from,
Data& aData) const
{
ROI_WARNING;
createImage(m_task_manager.getCompatName(roiId), from, aData);
}
inline void SoftOpRoi2Spectrum::getRoiMode(std::list<int>& modes) const
{
ROI_WARNING;
DEB_MEMBER_FUNCT();
std::vector<int> v_modes;
v_modes.resize(m_task_manager.size());
for(NameMapConstIterator i = m_task_manager.begin();
i != m_task_manager.end();++i)
{
int roi_id;
if(!m_task_manager.getCompatId(i->first, roi_id))
THROW_CTL_ERROR(InvalidValue) << "You can't mixed old and new methods set";
v_modes.push_back(i->second.second->getMode());
}
for(std::vector<int>::iterator i = v_modes.begin();
i != v_modes.end();++i)
modes.push_back(*i);
}
inline void SoftOpRoi2Spectrum::setRoiMode(int roiId, int mode)
{
ROI_WARNING;
RoiNameAndMode name_mode(m_task_manager.getCompatName(roiId), mode);
std::list<RoiNameAndMode> rois_modes(&name_mode, &name_mode + 1);
setRoiModes(rois_modes);
}
class LIMACORE_API SoftOpSoftRoi : public SoftOpBaseClass
{
public:
......
......@@ -49,7 +49,7 @@ if(sipIsErr == NULL)
return aReturnFlag;
}
std::list<SoftOpRoiCounter::RoiNameAndResults> *roiNameNResultPt =
std::list<SoftOpRoiCounter::RoiNameAndResults> *roiNameNResultPt =
new std::list<SoftOpRoiCounter::RoiNameAndResults>();
for(int i = 0;i < PyList_Size(sipPy);++i)
......@@ -154,7 +154,7 @@ if(sipIsErr == NULL)
}
return aReturnFlag;
}
std::list<SoftOpRoiCounter::RoiNameAndRoi> *named_roisPt =
std::list<SoftOpRoiCounter::RoiNameAndRoi> *named_roisPt =
new std::list<SoftOpRoiCounter::RoiNameAndRoi>();
for(int i = 0;i < PyList_Size(sipPy);++i)
......@@ -162,7 +162,7 @@ if(sipIsErr == NULL)
PyObject *p = PyList_GET_ITEM(sipPy,i);
char *name = PyString_AsString(PySequence_Fast_GET_ITEM(p,0));
int state;
lima::Roi *roi =
lima::Roi *roi =
reinterpret_cast<lima::Roi*>(sipConvertToType(PySequence_Fast_GET_ITEM(p,1),
sipType_Roi,0,
SIP_NOT_NONE,
......@@ -280,6 +280,59 @@ if(sipIsErr == NULL)