BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
MaskResultsPresenter.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file GUI/coregui/Views/MaskWidgets/MaskResultsPresenter.cpp
6 //! @brief Implements class MaskResultsPresenter
7 //!
8 //! @homepage http://www.bornagainproject.org
9 //! @license GNU General Public License v3 or higher (see COPYING)
10 //! @copyright Forschungszentrum Jülich GmbH 2018
11 //! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
12 //
13 // ************************************************************************************************
14 
21 #include <QVBoxLayout>
22 
24  : QObject(parent), m_interpolation_flag_backup(false)
25 {
26 }
27 
29  const QModelIndex& maskContainerIndex,
30  IntensityDataItem* intensityItem)
31 {
32  m_maskModel = maskModel;
33  m_maskContainerIndex = maskContainerIndex;
34  m_intensityDataItem = intensityItem;
35 }
36 
38 {
39  setMaskContext(nullptr, QModelIndex(), nullptr);
40 }
41 
42 void MaskResultsPresenter::updatePresenter(MaskEditorFlags::PresentationType presentationType)
43 {
44  if (!m_maskContainerIndex.isValid())
45  return;
46 
47  if (presentationType == MaskEditorFlags::MASK_PRESENTER) {
49  } else if (presentationType == MaskEditorFlags::MASK_EDITOR) {
51  }
52 }
53 
54 //! Update IntensityDataItem in SessionModel to represent masked areas. Corresponding
55 //! bins of OutputData will be put to zero.
56 
58 {
59  if (OutputData<double>* maskedData = createMaskPresentation()) {
60  backup_data();
63  } else {
64  m_dataBackup.reset();
65  }
66 }
67 
68 //! Restores original state of IntensityDataItem
69 
71 {
72  if (m_dataBackup) {
76  }
77 }
78 
80 {
84 }
85 
86 //! Constructs OutputData which contains original intensity data except masked areas,
87 //! and areas outside of ROI, where bin content is set to zero.
88 
90 {
91  // Requesting mask information
92  std::unique_ptr<RegionOfInterest> roi;
93  DetectorMask detectorMask;
94  for (int i_row = m_maskModel->rowCount(m_maskContainerIndex); i_row > 0; --i_row) {
95  QModelIndex itemIndex = m_maskModel->index(i_row - 1, 0, m_maskContainerIndex);
96  if (MaskItem* maskItem = dynamic_cast<MaskItem*>(m_maskModel->itemForIndex(itemIndex))) {
97  if (maskItem->modelType() == "RegionOfInterest") {
98  double xlow = maskItem->getItemValue(RectangleItem::P_XLOW).toDouble();
99  double ylow = maskItem->getItemValue(RectangleItem::P_YLOW).toDouble();
100  double xup = maskItem->getItemValue(RectangleItem::P_XUP).toDouble();
101  double yup = maskItem->getItemValue(RectangleItem::P_YUP).toDouble();
102  roi.reset(new RegionOfInterest(*m_intensityDataItem->getOutputData(), xlow, ylow,
103  xup, yup));
104  } else {
105  std::unique_ptr<IShape2D> shape(maskItem->createShape());
106  bool mask_value = maskItem->getItemValue(MaskItem::P_MASK_VALUE).toBool();
107  detectorMask.addMask(*shape.get(), mask_value);
108  }
109  }
110  }
111 
112  if (!detectorMask.hasMasks() && !roi)
113  return 0;
114 
116  detectorMask.initMaskData(*result);
117 
118  for (size_t i = 0; i < result->getAllocatedSize(); ++i) {
119  if (detectorMask.isMasked(i))
120  (*result)[i] = 0.0;
121  if (roi && !roi->isInROI(i))
122  (*result)[i] = 0.0;
123  }
124 
125  return result;
126 }
Defines class DetectorMask.
Defines class IntensityDataItem.
Defines MaskItems classes.
Defines class MaskResultsPresenter.
Defines class RegionOfInterest.
Defines class SessionModel.
OutputData< double > * getOutputData()
Definition: DataItem.h:36
Collection of detector masks.
Definition: DetectorMask.h:28
bool isMasked(size_t index) const
bool hasMasks() const
returns true if has masks
Definition: DetectorMask.h:52
void addMask(const IShape2D &shape, bool mask_value)
Add mask to the stack of detector masks.
void initMaskData(const IDetector2D &detector)
Init the map of masks for the given detector plane.
void setOutputData(OutputData< double > *data) override
The given pointer becomes owned by this class!!
static const QString P_IS_INTERPOLATED
A base class for all mask items.
Definition: MaskItems.h:31
static const QString P_MASK_VALUE
Definition: MaskItems.h:33
std::unique_ptr< OutputData< double > > m_dataBackup
void updatePresenter(MaskEditorFlags::PresentationType mode)
void setMaskContext(SessionModel *maskModel, const QModelIndex &maskContainerIndex, IntensityDataItem *intensityItem)
void setShowMaskMode()
Update IntensityDataItem in SessionModel to represent masked areas.
IntensityDataItem * m_intensityDataItem
OutputData< double > * createMaskPresentation() const
Constructs OutputData which contains original intensity data except masked areas, and areas outside o...
MaskResultsPresenter(QWidget *parent=0)
void setOriginalMode()
Restores original state of IntensityDataItem.
size_t getAllocatedSize() const
Returns total size of data buffer (product of bin number in every dimension).
Definition: OutputData.h:59
OutputData * clone() const
Definition: OutputData.h:259
static const QString P_XUP
Definition: MaskItems.h:43
static const QString P_YLOW
Definition: MaskItems.h:42
static const QString P_YUP
Definition: MaskItems.h:44
static const QString P_XLOW
Definition: MaskItems.h:41
Defines rectangular area for the detector which will be simulated/fitted.
QVariant getItemValue(const QString &tag) const
Directly access value of item under given tag.
void setItemValue(const QString &tag, const QVariant &variant)
Directly set value of item under given tag.
SessionItem * itemForIndex(const QModelIndex &index) const
virtual QModelIndex index(int row, int column, const QModelIndex &parent) const
virtual int rowCount(const QModelIndex &parent) const