BornAgain  1.19.79
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/View/Mask/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 
16 #include "Device/Mask/DetectorMask.h"
17 #include "Device/Mask/IShape2D.h"
21 #include <QVBoxLayout>
22 
24  : QObject(parent)
25  , m_interpolation_flag_backup(false)
26 {
27 }
28 
30  const QModelIndex& maskContainerIndex,
31  IntensityDataItem* intensityItem)
32 {
33  m_maskModel = maskModel;
34  m_maskContainerIndex = maskContainerIndex;
35  m_intensityDataItem = intensityItem;
36 }
37 
39 {
40  setMaskContext(nullptr, QModelIndex(), nullptr);
41 }
42 
43 void MaskResultsPresenter::updatePresenter(MaskEditorFlags::PresentationType presentationType)
44 {
45  if (!m_maskContainerIndex.isValid())
46  return;
47 
48  if (presentationType == MaskEditorFlags::MASK_PRESENTER)
50  else if (presentationType == MaskEditorFlags::MASK_EDITOR)
52 }
53 
54 //! Update IntensityDataItem in SessionModel to represent masked areas. Corresponding
55 //! bins of Datafield will be put to zero.
56 
58 {
59  if (Datafield* maskedData = createMaskPresentation()) {
60  backup_data();
61  m_intensityDataItem->setDatafield(maskedData);
63  } else {
64  m_dataBackup.reset();
65  }
66 }
67 
68 //! Restores original state of IntensityDataItem
69 
71 {
72  if (m_dataBackup) {
75  }
76 }
77 
79 {
82 }
83 
84 //! Constructs Datafield which contains original intensity data except masked areas,
85 //! and areas outside of ROI, where bin content is set to zero.
86 
88 {
89  // Requesting mask information
90  std::unique_ptr<IShape2D> roi;
91  Datafield* result = m_intensityDataItem->getDatafield()->clone();
92  DetectorMask detectorMask(result->axis(0), result->axis(1));
93  const double scale = 1.0;
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 (auto* maskItem = dynamic_cast<MaskItem*>(m_maskModel->itemForIndex(itemIndex))) {
97  if (auto* roiItem = dynamic_cast<RegionOfInterestItem*>(maskItem))
98  roi = roiItem->createShape(scale);
99  else {
100  std::unique_ptr<IShape2D> shape(maskItem->createShape(scale));
101  detectorMask.addMask(*shape, maskItem->maskValue());
102  }
103  }
104  }
105 
106  // ROI mask has to be the last one, it can not be "unmasked" by other shapes
107  if (roi)
108  detectorMask.addMask(*roi, true);
109 
110  if (!detectorMask.hasMasks())
111  return nullptr;
112 
113  for (size_t i = 0; i < result->size(); ++i)
114  if (detectorMask.isMasked(i))
115  (*result)[i] = 0.0;
116 
117  return result;
118 }
Defines class IntensityDataItem.
Defines MaskItems classes.
Defines class MaskResultsPresenter.
Defines class SessionModel.
Datafield * getDatafield()
Definition: DataItem.h:41
void setDatafield(Datafield *data) override
The given pointer becomes owned by this class!!
void setInterpolated(bool interp)
bool isInterpolated() const
A base class for all mask items.
Definition: MaskItems.h:27
std::unique_ptr< Datafield > m_dataBackup
void setMaskContext(SessionModel *maskModel, const QModelIndex &maskContainerIndex, IntensityDataItem *intensityItem)
void updatePresenter(MaskEditorFlags::PresentationType presentationType)
void setShowMaskMode()
Update IntensityDataItem in SessionModel to represent masked areas. Corresponding bins of Datafield w...
Datafield * createMaskPresentation() const
Constructs Datafield which contains original intensity data except masked areas, and areas outside of...
IntensityDataItem * m_intensityDataItem
MaskResultsPresenter(QWidget *parent=nullptr)
void setOriginalMode()
Restores original state of IntensityDataItem.
Base class for a GUI data collection. A collection is e.g. all real data (RealDataModel)....
Definition: SessionModel.h:42
SessionItem * itemForIndex(const QModelIndex &index) const
QModelIndex index(int row, int column, const QModelIndex &parent) const override
int rowCount(const QModelIndex &parent) const override