Skip to content
Snippets Groups Projects
Commit 310ac8b5 authored by Pospelov, Gennady's avatar Pospelov, Gennady
Browse files

Possibility to iterate over ROI _without_ skipping masked areas.

parent 95bf068b
No related branches found
No related tags found
No related merge requests found
......@@ -54,8 +54,9 @@ void FitObject::init_dataset(const OutputData<double >& real_data)
check_realdata(real_data);
m_chi2_data.reset(m_simulation->getInstrument().createDetectorMap());
m_real_data = DetectorFunctions::createDataSet(m_simulation->getInstrument(), real_data);
bool put_masked_areas_to_zero(false);
m_real_data = DetectorFunctions::createDataSet(m_simulation->getInstrument(), real_data,
put_masked_areas_to_zero);
}
//! Checks if real data and the detector have same dimensions. If not, exception will be thrown.
......
......@@ -85,26 +85,10 @@ std::unique_ptr<OutputData<double>> DetectorFunctions::createDataSet(const Instr
}
} else {
// if(const Geometry::Rectangle *roi = regionOfInterest()) {
// size_t roi_x = getAxis(BornAgain::X_AXIS_INDEX).findClosestIndex(roi->getXlow());
// size_t roi_y = getAxis(BornAgain::Y_AXIS_INDEX).findClosestIndex(roi->getYlow());
// size_t index0 = getGlobalIndex(roi_x, roi_y);
// const IAxis &yAxisOfDetector = getAxis(BornAgain::Y_AXIS_INDEX);
// const IAxis &xAxisOfMap = *detectorMap.getAxis(BornAgain::X_AXIS_INDEX);
// const IAxis &yAxisOfMap = *detectorMap.getAxis(BornAgain::Y_AXIS_INDEX);
// for(size_t ix=0; ix<xAxisOfMap.getSize(); ++ix) {
// for(size_t iy=0; iy<yAxisOfMap.getSize(); ++iy) {
// size_t mapIndex = iy + ix*yAxisOfMap.getSize();
// size_t globalIndex = index0 + iy + ix*yAxisOfDetector.getSize();
// detectorMap[mapIndex] = data[globalIndex];
// }
// }
// }
throw Exceptions::RuntimeErrorException("DetectorFunctions::createDataSet() -> Error. "
"Not implemented");
SimulationRoiArea area(instrument.getDetector());
for(SimulationRoiArea::iterator it = area.begin(); it!=area.end(); ++it) {
(*result)[it.roiIndex()] = data[it.index()];
}
}
return result;
......
......@@ -94,3 +94,22 @@ size_t SimulationArea::roiIndex(size_t globalIndex) const
return nyGlob - m_roi_y1 + (nxGlob - m_roi_x1)*(m_roi_y2-m_roi_y1+1);
}
// --------------------------------------------------------------------------------------
SimulationRoiArea::SimulationRoiArea(const IDetector2D *detector)
: SimulationArea(detector)
{
}
bool SimulationRoiArea::isMasked(size_t index) const
{
if(m_detector->regionOfInterest()) {
size_t nx = m_detector->getAxisBinIndex(index, BornAgain::X_AXIS_INDEX);
if(nx<m_roi_x1 || nx>m_roi_x2) return true;
size_t ny = m_detector->getAxisBinIndex(index, BornAgain::Y_AXIS_INDEX);
if(ny<m_roi_y1 || ny>m_roi_y2) return true;
}
return false;
}
......@@ -41,10 +41,22 @@ public:
//! Return index in ROO map from global index
size_t roiIndex(size_t globalIndex) const;
private:
protected:
const IDetector2D *m_detector;
size_t m_roi_x1, m_roi_x2, m_roi_y1, m_roi_y2;
};
//! Holds iteration logic over active detector channels in the presence of ROI. On the contrary
//! to SimulationArea class, iterates also over masked areas.
//! @ingroup simulation
class BA_CORE_API_ SimulationRoiArea : public SimulationArea
{
public:
explicit SimulationRoiArea(const IDetector2D *detector);
virtual bool isMasked(size_t index) const;
};
#endif
......@@ -20,9 +20,8 @@
#include <cstdlib>
class SimulationArea;
//! @class SimulationAreaIterator
//! An iterator for SimulationArea.
//! @ingroup simulation
//! @brief The SimulationAreaIterator class is an iterator for SimulationArea.
class BA_CORE_API_ SimulationAreaIterator
{
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment