BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
SpecularDataItem.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file GUI/coregui/Models/SpecularDataItem.cpp
6 //! @brief Implements class SpecularDataItem
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 
20 
21 const QString SpecularDataItem::P_TITLE = "Title";
22 const QString SpecularDataItem::P_XAXIS = "x-axis";
23 const QString SpecularDataItem::P_YAXIS = "y-axis";
24 
26 {
27  addProperty(P_TITLE, QString())->setVisible(false);
28 
29  auto basicAxis = addProperty<BasicAxisItem>(P_XAXIS);
30  basicAxis->getItem(BasicAxisItem::P_NBINS)->setVisible(false);
31 
32  auto amplitudeAxis = addProperty<AmplitudeAxisItem>(P_YAXIS);
33  amplitudeAxis->getItem(BasicAxisItem::P_NBINS)->setVisible(false);
34  amplitudeAxis->getItem(BasicAxisItem::P_TITLE)->setVisible(true);
35 
36  amplitudeAxis->getItem(AmplitudeAxisItem::P_IS_VISIBLE)->setValue(true);
37  amplitudeAxis->getItem(AmplitudeAxisItem::P_IS_VISIBLE)->setVisible(false);
38 
41 }
42 
44 {
45  if (data != nullptr) {
46  if (data->rank() != 1)
47  throw GUIHelpers::Error(
48  "Error in SpecularDataItem::setOutputData: cannot handle non-1D data");
51  } else {
53  }
54 
56 }
57 
59 {
60  return xAxisItem()->binCount();
61 }
62 
64 {
65  return xAxisItem()->lowerBound();
66 }
67 
69 {
70  return xAxisItem()->upperBound();
71 }
72 
74 {
75  const double defaultXmin(0.0);
76  return m_data ? m_data->axis(0).lowerBound() : defaultXmin;
77 }
78 
80 {
81  const double defaultXmax(1.0);
82  return m_data ? m_data->axis(0).upperBound() : defaultXmax;
83 }
84 
86 {
87  return yAxisItem()->lowerBound();
88 }
89 
91 {
92  return yAxisItem()->upperBound();
93 }
94 
96 {
97  return dataRange().first;
98 }
99 
101 {
102  return dataRange().second;
103 }
104 
106 {
107  return yAxisItem()->isLogScale();
108 }
109 
111 {
112  return xAxisItem()->title();
113 }
114 
116 {
117  return yAxisItem()->title();
118 }
119 
120 void SpecularDataItem::setXaxisTitle(const QString& title)
121 {
122  xAxisItem()->setTitle(title);
123 }
124 
125 void SpecularDataItem::setYaxisTitle(const QString& title)
126 {
127  yAxisItem()->setTitle(title);
128 }
129 
130 //! set zoom range of x,y axes to axes of input data
132 {
133  setLowerX(getXmin());
134  setUpperX(getXmax());
135  setLowerY(getYmin());
136  setUpperY(getYmax());
137 }
138 
140 {
141  JobItemUtils::updateDataAxes(this, instrument);
142 }
143 
144 std::vector<int> SpecularDataItem::shape() const
145 {
146  return {getNbins()};
147 }
148 
150 {
151  ComboProperty combo = ComboProperty() << data.unitsLabel();
154 
155  setXaxisTitle(data.axisLabel(0));
156  setYaxisTitle(data.axisLabel(1));
157  setOutputData(std::move(data).intensityData().release());
159 }
160 
161 void SpecularDataItem::setLowerX(double value)
162 {
164 }
165 
166 void SpecularDataItem::setUpperX(double value)
167 {
169 }
170 
171 void SpecularDataItem::setLowerY(double value)
172 {
174 }
175 
176 void SpecularDataItem::setUpperY(double value)
177 {
179 }
180 
181 void SpecularDataItem::setLog(bool log_flag)
182 {
183  yAxisItem()->setLogScale(log_flag);
184 }
185 
186 //! Sets zoom range of X,Y axes, if it was not yet defined.
187 
189 {
190  // set zoom range of x-axis to min, max values if it was not set already
191  if (getUpperX() < getLowerX()) {
192  setLowerX(getXmin());
193  setUpperX(getXmax());
194  }
195 
196  // set zoom range of y-axis to min, max values if it was not set already
197  if (getUpperY() < getLowerY()) {
198  setLowerY(getYmin());
199  setUpperY(getYmax());
200  }
201 
202  const int nx = static_cast<int>(m_data->axis(0).size());
204 }
205 
206 //! Init ymin, ymax to match the intensity values range.
207 QPair<double, double> SpecularDataItem::dataRange() const
208 {
209  const double default_min = 0.0;
210  const double default_max = 1.0;
211  const OutputData<double>* data = getOutputData();
212  if (!data)
213  return QPair<double, double>(default_min, default_max);
214  double min(*std::min_element(data->begin(), data->end()));
215  double max(*std::max_element(data->begin(), data->end()));
216 
217  min /= 2.0;
218  min = std::numeric_limits<double>::epsilon() < min ? min : default_min;
219  max *= 2.0;
220  max = max > min ? max : default_max;
221 
222  return QPair<double, double>(min, max);
223 }
224 
226 {
227  return item<BasicAxisItem>(P_XAXIS);
228 }
229 
231 {
232  return item<BasicAxisItem>(P_XAXIS);
233 }
234 
236 {
237  return item<AmplitudeAxisItem>(P_YAXIS);
238 }
239 
241 {
242  return item<AmplitudeAxisItem>(P_YAXIS);
243 }
244 
245 //! Set axes viewport to original data.
246 
248 {
250 }
Defines various axis items.
Defines class GUIHelpers functions.
Defines ImportDataUtils namespace.
Defines class JobItemUtils.
Defines class SpecularDataItem.
bool isLogScale() const
Definition: AxesItems.cpp:113
void setLogScale(bool value)
Definition: AxesItems.cpp:118
static const QString P_NBINS
Definition: AxesItems.h:26
static const QString P_TITLE
Definition: AxesItems.h:29
double upperBound() const
Definition: AxesItems.cpp:52
QString title() const
Definition: AxesItems.cpp:62
static const QString P_IS_VISIBLE
Definition: AxesItems.h:25
int binCount() const
Definition: AxesItems.cpp:32
double lowerBound() const
Definition: AxesItems.cpp:42
void setLowerBound(double value)
Definition: AxesItems.cpp:47
void setUpperBound(double value)
Definition: AxesItems.cpp:57
void setTitle(const QString &title)
Definition: AxesItems.cpp:67
Custom property to define list of string values with multiple selections.
Definition: ComboProperty.h:25
QVariant variant() const
Constructs variant enclosing given ComboProperty.
Provides common functionality for IntensityDataItem and SpecularDataItem.
Definition: DataItem.h:29
OutputData< double > * getOutputData()
Definition: DataItem.h:36
virtual void setOutputData(OutputData< double > *data)=0
The given pointer becomes owned by this class!!
Definition: DataItem.cpp:24
static const QString P_AXES_UNITS
Definition: DataItem.h:34
std::unique_ptr< OutputData< double > > m_data
simulation results
Definition: DataItem.h:72
Carries information about loaded data.
QString unitsLabel() const
QString axisLabel(size_t axis_index) const
iterator end()
Returns read/write iterator that points to the one past last element.
Definition: OutputData.h:93
size_t rank() const
Returns number of dimensions.
Definition: OutputData.h:56
iterator begin()
Returns read/write iterator that points to the first element.
Definition: OutputData.h:343
SessionItem * addProperty(const QString &name, const QVariant &variant)
Add new property item and register new tag.
QVariant value() const
Get value.
void setVisible(bool enabled)
Flags accessors.
void setItemValue(const QString &tag, const QVariant &variant)
Directly set value of item under given tag.
void emitDataChanged(int role=Qt::DisplayRole)
Notify model about data changes.
SessionItem * getItem(const QString &tag="", int row=0) const
Returns item in given row of given tag.
void setYaxisTitle(const QString &title) override
double getLowerY() const
returns lower and upper zoom ranges of y-axis
QString getXaxisTitle() const
void updateAxesZoomLevel()
Sets zoom range of X,Y axes, if it was not yet defined.
int getNbins() const
Number of bins in data.
void setUpperY(double value)
double getXmax() const
void setXaxisTitle(const QString &title) override
void setUpperX(double value)
void setLowerX(double value)
void setOutputData(OutputData< double > *data) override
The given pointer becomes owned by this class!!
static const QString P_YAXIS
std::vector< int > shape() const override
static const QString P_TITLE
static const QString P_XAXIS
void setLowerY(double value)
void setLog(bool log_flag)
double getUpperY() const
void updateAxesUnits(const InstrumentItem *instrument) override
double getYmax() const
double getLowerX() const
returns lower and upper zoom ranges of x-axis
void setAxesRangeToData() override
set zoom range of x,y axes to axes of input data
QString getYaxisTitle() const
double getXmin() const
returns min and max range of x-axis as given by IntensityData
void resetView()
Set axes viewport to original data.
QPair< double, double > dataRange() const
Init ymin, ymax to match the intensity values range.
double getYmin() const
returns min and max range of y-axis as given by IntensityData
double getUpperX() const
const AmplitudeAxisItem * yAxisItem() const
void reset(ImportDataInfo data) override
Returns data to the state defined by user (imported) data.
const BasicAxisItem * xAxisItem() const
void updateDataAxes(DataItem *intensityItem, const InstrumentItem *instrumentItem)
updates axes of OutputData in IntensityData item
const QString y_axis_default_name
const QString x_axis_default_name