BornAgain  1.19.79
Simulate and fit neutron and x-ray scattering at grazing incidence
MaskResultsPresenter Class Reference

Description

Updates bin values inside IntensityData to display current mask state. Returns IntensityData to original state when requested.

Definition at line 30 of file MaskResultsPresenter.h.

Inheritance diagram for MaskResultsPresenter:
[legend]
Collaboration diagram for MaskResultsPresenter:
[legend]

Public Member Functions

 MaskResultsPresenter (QWidget *parent=nullptr)
 
void resetContext ()
 
void setMaskContext (SessionModel *maskModel, const QModelIndex &maskContainerIndex, IntensityDataItem *intensityItem)
 
void updatePresenter (MaskEditorFlags::PresentationType presentationType)
 

Private Member Functions

void backup_data ()
 
Datafield * createMaskPresentation () const
 Constructs Datafield which contains original intensity data except masked areas, and areas outside of ROI, where bin content is set to zero. More...
 
void setOriginalMode ()
 Restores original state of IntensityDataItem. More...
 
void setShowMaskMode ()
 Update IntensityDataItem in SessionModel to represent masked areas. Corresponding bins of Datafield will be put to zero. More...
 

Private Attributes

std::unique_ptr< Datafield > m_dataBackup
 
IntensityDataItemm_intensityDataItem
 
bool m_interpolation_flag_backup
 
QModelIndex m_maskContainerIndex
 
SessionModelm_maskModel
 

Constructor & Destructor Documentation

◆ MaskResultsPresenter()

MaskResultsPresenter::MaskResultsPresenter ( QWidget *  parent = nullptr)

Definition at line 23 of file MaskResultsPresenter.cpp.

24  : QObject(parent)
26 {
27 }

Member Function Documentation

◆ backup_data()

void MaskResultsPresenter::backup_data ( )
private

Definition at line 78 of file MaskResultsPresenter.cpp.

79 {
82 }
Datafield * getDatafield()
Definition: DataItem.h:41
bool isInterpolated() const
std::unique_ptr< Datafield > m_dataBackup
IntensityDataItem * m_intensityDataItem

References DataItem::getDatafield(), IntensityDataItem::isInterpolated(), m_dataBackup, m_intensityDataItem, and m_interpolation_flag_backup.

Referenced by setShowMaskMode().

Here is the call graph for this function:

◆ createMaskPresentation()

Datafield * MaskResultsPresenter::createMaskPresentation ( ) const
private

Constructs Datafield which contains original intensity data except masked areas, and areas outside of ROI, where bin content is set to zero.

Definition at line 87 of file MaskResultsPresenter.cpp.

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 }
A base class for all mask items.
Definition: MaskItems.h:27
SessionItem * itemForIndex(const QModelIndex &index) const
QModelIndex index(int row, int column, const QModelIndex &parent) const override
int rowCount(const QModelIndex &parent) const override

References DataItem::getDatafield(), SessionModel::index(), SessionModel::itemForIndex(), m_intensityDataItem, m_maskContainerIndex, m_maskModel, and SessionModel::rowCount().

Referenced by setShowMaskMode().

Here is the call graph for this function:

◆ resetContext()

void MaskResultsPresenter::resetContext ( )

Definition at line 38 of file MaskResultsPresenter.cpp.

39 {
40  setMaskContext(nullptr, QModelIndex(), nullptr);
41 }
void setMaskContext(SessionModel *maskModel, const QModelIndex &maskContainerIndex, IntensityDataItem *intensityItem)

References setMaskContext().

Here is the call graph for this function:

◆ setMaskContext()

void MaskResultsPresenter::setMaskContext ( SessionModel maskModel,
const QModelIndex &  maskContainerIndex,
IntensityDataItem intensityItem 
)

Definition at line 29 of file MaskResultsPresenter.cpp.

32 {
33  m_maskModel = maskModel;
34  m_maskContainerIndex = maskContainerIndex;
35  m_intensityDataItem = intensityItem;
36 }

References m_intensityDataItem, m_maskContainerIndex, and m_maskModel.

Referenced by resetContext(), and MaskEditorCanvas::setMaskContext().

◆ setOriginalMode()

void MaskResultsPresenter::setOriginalMode ( )
private

Restores original state of IntensityDataItem.

Definition at line 70 of file MaskResultsPresenter.cpp.

71 {
72  if (m_dataBackup) {
75  }
76 }
void setDatafield(Datafield *data) override
The given pointer becomes owned by this class!!
void setInterpolated(bool interp)

References m_dataBackup, m_intensityDataItem, m_interpolation_flag_backup, IntensityDataItem::setDatafield(), and IntensityDataItem::setInterpolated().

Referenced by updatePresenter().

Here is the call graph for this function:

◆ setShowMaskMode()

void MaskResultsPresenter::setShowMaskMode ( )
private

Update IntensityDataItem in SessionModel to represent masked areas. Corresponding bins of Datafield will be put to zero.

Definition at line 57 of file MaskResultsPresenter.cpp.

58 {
59  if (Datafield* maskedData = createMaskPresentation()) {
60  backup_data();
61  m_intensityDataItem->setDatafield(maskedData);
63  } else {
64  m_dataBackup.reset();
65  }
66 }
Datafield * createMaskPresentation() const
Constructs Datafield which contains original intensity data except masked areas, and areas outside of...

References backup_data(), createMaskPresentation(), m_dataBackup, m_intensityDataItem, IntensityDataItem::setDatafield(), and IntensityDataItem::setInterpolated().

Referenced by updatePresenter().

Here is the call graph for this function:

◆ updatePresenter()

void MaskResultsPresenter::updatePresenter ( MaskEditorFlags::PresentationType  presentationType)

Definition at line 43 of file MaskResultsPresenter.cpp.

44 {
45  if (!m_maskContainerIndex.isValid())
46  return;
47 
48  if (presentationType == MaskEditorFlags::MASK_PRESENTER)
50  else if (presentationType == MaskEditorFlags::MASK_EDITOR)
52 }
void setShowMaskMode()
Update IntensityDataItem in SessionModel to represent masked areas. Corresponding bins of Datafield w...
void setOriginalMode()
Restores original state of IntensityDataItem.

References m_maskContainerIndex, MaskEditorFlags::MASK_EDITOR, MaskEditorFlags::MASK_PRESENTER, setOriginalMode(), and setShowMaskMode().

Referenced by MaskEditorCanvas::onPresentationTypeRequest().

Here is the call graph for this function:

Member Data Documentation

◆ m_dataBackup

std::unique_ptr<Datafield> MaskResultsPresenter::m_dataBackup
private

Definition at line 50 of file MaskResultsPresenter.h.

Referenced by backup_data(), setOriginalMode(), and setShowMaskMode().

◆ m_intensityDataItem

IntensityDataItem* MaskResultsPresenter::m_intensityDataItem
private

◆ m_interpolation_flag_backup

bool MaskResultsPresenter::m_interpolation_flag_backup
private

Definition at line 51 of file MaskResultsPresenter.h.

Referenced by backup_data(), and setOriginalMode().

◆ m_maskContainerIndex

QModelIndex MaskResultsPresenter::m_maskContainerIndex
private

Definition at line 48 of file MaskResultsPresenter.h.

Referenced by createMaskPresentation(), setMaskContext(), and updatePresenter().

◆ m_maskModel

SessionModel* MaskResultsPresenter::m_maskModel
private

Definition at line 47 of file MaskResultsPresenter.h.

Referenced by createMaskPresentation(), and setMaskContext().


The documentation for this class was generated from the following files: