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

Description

The MaskUnitsConverter converts coordinates of all masks from one units to anoter. I.e. masks in 'mm' into masks in 'deg'. This is done in two steps. On first step masks are converted from native coordinates (as given by axes of Datafield) into bin-fraction coordinates. On second step masks are converted from bin-fraction coordinates into current axes of Datafield.

Definition at line 32 of file MaskUnitsConverter.h.

Public Types

enum  EConvertionDirection { TO_NBINS , FROM_NBINS , UNDEFINED }
 

Public Member Functions

 MaskUnitsConverter ()
 
void convertFromNbins (IntensityDataItem *intensityData)
 Converts all masks on board of IntensityDataItem from bin-fraction coordinates to coordinates of axes currently defined in Datafield. More...
 
void convertToNbins (IntensityDataItem *intensityData)
 Converts all masks on board of IntensityDataItem into bin-fraction coordinates. More...
 

Private Types

enum class  Axis { X , Y }
 

Private Member Functions

double convert (double value, Axis axis)
 Convert value of axis from/to bin-fraction coordinates. More...
 
void convertCoordinate (SessionItem *maskItem, const QString &xname, const QString &yname)
 Convert (x,y) coordinates registered as property (i.e. under P_XPOS, P_YPOS) from/to bin-fraction coordinates. Result of operation are new values for registered properties. More...
 
void convertIntensityDataItem (IntensityDataItem *intensityData)
 Converts all masks on board of IntensityDataItem from/to bin-fraction coordinates. More...
 
void convertMask (MaskItem *maskItem)
 Converts single mask from/to bin-fraction coordinates. More...
 

Private Attributes

const Datafield * m_data
 
EConvertionDirection m_direction
 

Member Enumeration Documentation

◆ Axis

enum MaskUnitsConverter::Axis
strongprivate
Enumerator

Definition at line 42 of file MaskUnitsConverter.h.

42 { X, Y };

◆ EConvertionDirection

Enumerator
TO_NBINS 
FROM_NBINS 
UNDEFINED 

Definition at line 34 of file MaskUnitsConverter.h.

Constructor & Destructor Documentation

◆ MaskUnitsConverter()

MaskUnitsConverter::MaskUnitsConverter ( )

Definition at line 21 of file MaskUnitsConverter.cpp.

22  : m_data(nullptr)
24 {
25 }
EConvertionDirection m_direction
const Datafield * m_data

Member Function Documentation

◆ convert()

double MaskUnitsConverter::convert ( double  value,
Axis  axis 
)
private

Convert value of axis from/to bin-fraction coordinates.

Definition at line 122 of file MaskUnitsConverter.cpp.

123 {
124  auto axis_index = static_cast<size_t>(axis);
125 
126  ASSERT(m_data);
127  ASSERT(axis_index == 0 || axis_index == 1);
128 
129  if (m_direction == TO_NBINS)
130  return FramUtil::coordinateToBinf(value, m_data->axis(axis_index));
131  if (m_direction == FROM_NBINS)
132  return FramUtil::coordinateFromBinf(value, m_data->axis(axis_index));
133  ASSERT(0);
134 }

References FROM_NBINS, m_data, m_direction, and TO_NBINS.

Referenced by convertCoordinate(), and convertMask().

◆ convertCoordinate()

void MaskUnitsConverter::convertCoordinate ( SessionItem maskItem,
const QString &  xname,
const QString &  yname 
)
private

Convert (x,y) coordinates registered as property (i.e. under P_XPOS, P_YPOS) from/to bin-fraction coordinates. Result of operation are new values for registered properties.

Definition at line 107 of file MaskUnitsConverter.cpp.

109 {
110  if (maskItem->isTag(xname)) {
111  double x = convert(maskItem->getItemValue(xname).toDouble(), Axis::X);
112  maskItem->setItemValue(xname, x);
113  }
114  if (maskItem->isTag(yname)) {
115  double y = convert(maskItem->getItemValue(yname).toDouble(), Axis::Y);
116  maskItem->setItemValue(yname, y);
117  }
118 }
double convert(double value, Axis axis)
Convert value of axis from/to bin-fraction coordinates.
bool isTag(const QString &name) const
Returns true if tag is available.
QVariant getItemValue(const QString &tag) const
Directly access value of item under given tag.
void setItemValue(const QString &tag, const QVariant &variant) const
Directly set value of item under given tag.

References convert(), SessionItem::getItemValue(), SessionItem::isTag(), SessionItem::setItemValue(), X, and Y.

Here is the call graph for this function:

◆ convertFromNbins()

void MaskUnitsConverter::convertFromNbins ( IntensityDataItem intensityData)

Converts all masks on board of IntensityDataItem from bin-fraction coordinates to coordinates of axes currently defined in Datafield.

Definition at line 38 of file MaskUnitsConverter.cpp.

39 {
41  convertIntensityDataItem(intensityData);
42 }
void convertIntensityDataItem(IntensityDataItem *intensityData)
Converts all masks on board of IntensityDataItem from/to bin-fraction coordinates.

References convertIntensityDataItem(), FROM_NBINS, and m_direction.

Referenced by IntensityDataItem::reset(), and IntensityDataItem::updateCoords().

Here is the call graph for this function:

◆ convertIntensityDataItem()

void MaskUnitsConverter::convertIntensityDataItem ( IntensityDataItem intensityData)
private

Converts all masks on board of IntensityDataItem from/to bin-fraction coordinates.

Definition at line 46 of file MaskUnitsConverter.cpp.

47 {
48  if (!intensityData || !intensityData->getDatafield())
49  return;
50 
51  m_data = intensityData->getDatafield();
52 
53  if (intensityData->maskContainerItem())
54  for (auto* maskItem : intensityData->maskContainerItem()->maskItems())
55  convertMask(maskItem);
56 
57  if (intensityData->projectionContainerItem())
58  for (SessionItem* item : intensityData->projectionContainerItem()->getItems())
59  if (auto* maskItem = dynamic_cast<MaskItem*>(item))
60  convertMask(maskItem);
61 }
Datafield * getDatafield()
Definition: DataItem.h:41
MaskContainerItem * maskContainerItem()
ProjectionContainerItem * projectionContainerItem()
QVector< MaskItem * > maskItems() const
Definition: MaskItems.cpp:38
A base class for all mask items.
Definition: MaskItems.h:27
void convertMask(MaskItem *maskItem)
Converts single mask from/to bin-fraction coordinates.
Base class for a GUI data item.
Definition: SessionItem.h:204
QVector< SessionItem * > getItems(const QString &tag="") const
Returns vector of all items of given tag.

References convertMask(), DataItem::getDatafield(), SessionItem::getItems(), m_data, IntensityDataItem::maskContainerItem(), MaskContainerItem::maskItems(), and IntensityDataItem::projectionContainerItem().

Referenced by convertFromNbins(), and convertToNbins().

Here is the call graph for this function:

◆ convertMask()

void MaskUnitsConverter::convertMask ( MaskItem maskItem)
private

Converts single mask from/to bin-fraction coordinates.

Definition at line 65 of file MaskUnitsConverter.cpp.

66 {
67  if (auto* rectItem = dynamic_cast<RectangleItem*>(maskItem)) {
68  rectItem->setXLow(convert(rectItem->xLow(), Axis::X));
69  rectItem->setYLow(convert(rectItem->yLow(), Axis::Y));
70  rectItem->setXUp(convert(rectItem->xUp(), Axis::X));
71  rectItem->setYUp(convert(rectItem->yUp(), Axis::Y));
72  } else if (auto* poly = dynamic_cast<PolygonItem*>(maskItem)) {
73  for (PolygonPointItem* pointItem : poly->points()) {
74  pointItem->setPosX(convert(pointItem->posX(), Axis::X));
75  pointItem->setPosY(convert(pointItem->posY(), Axis::Y));
76  }
77  } else if (auto* vlineItem = dynamic_cast<VerticalLineItem*>(maskItem)) {
78  vlineItem->setPosX(convert(vlineItem->posX(), Axis::X));
79  } else if (auto* hlineItem = dynamic_cast<HorizontalLineItem*>(maskItem)) {
80  hlineItem->setPosY(convert(hlineItem->posY(), Axis::Y));
81  } else if (auto* ellItem = dynamic_cast<EllipseItem*>(maskItem)) {
82  double xc = ellItem->xCenter();
83  double yc = ellItem->yCenter();
84  double xR = ellItem->xRadius();
85  double yR = ellItem->yRadius();
86 
87  double x2 = xc + xR;
88  double y2 = yc + yR;
89 
90  if (m_direction == TO_NBINS) {
91  FramUtil::coordinatesToBinf(xc, yc, m_data->frame());
92  FramUtil::coordinatesToBinf(x2, y2, m_data->frame());
93  } else {
94  FramUtil::coordinatesFromBinf(xc, yc, m_data->frame());
95  FramUtil::coordinatesFromBinf(x2, y2, m_data->frame());
96  }
97  ellItem->setXCenter(xc);
98  ellItem->setYCenter(yc);
99  ellItem->setXRadius(x2 - xc);
100  ellItem->setYRadius(y2 - yc);
101  }
102 }

References convert(), m_data, m_direction, TO_NBINS, X, and Y.

Referenced by convertIntensityDataItem().

Here is the call graph for this function:

◆ convertToNbins()

void MaskUnitsConverter::convertToNbins ( IntensityDataItem intensityData)

Converts all masks on board of IntensityDataItem into bin-fraction coordinates.

Definition at line 29 of file MaskUnitsConverter.cpp.

30 {
32  convertIntensityDataItem(intensityData);
33 }

References convertIntensityDataItem(), m_direction, and TO_NBINS.

Referenced by IntensityDataItem::reset(), and IntensityDataItem::updateCoords().

Here is the call graph for this function:

Member Data Documentation

◆ m_data

const Datafield* MaskUnitsConverter::m_data
private

Definition at line 51 of file MaskUnitsConverter.h.

Referenced by convert(), convertIntensityDataItem(), and convertMask().

◆ m_direction

EConvertionDirection MaskUnitsConverter::m_direction
private

Definition at line 52 of file MaskUnitsConverter.h.

Referenced by convert(), convertFromNbins(), convertMask(), and convertToNbins().


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