From 4b50af682615a455f003c777ab6e1ee1d578842e Mon Sep 17 00:00:00 2001 From: Dmitry Yurov <d.yurov@fz-juelich.de> Date: Fri, 18 May 2018 17:11:05 +0200 Subject: [PATCH] shape() method for DataItems, RealDataItem and InstrumentItems Redmine: #2051 --- GUI/coregui/Models/BeamItems.cpp | 8 ++++++++ GUI/coregui/Models/BeamItems.h | 2 ++ GUI/coregui/Models/DataItem.h | 1 + GUI/coregui/Models/DetectorItems.h | 11 +++++++++++ GUI/coregui/Models/InstrumentItems.cpp | 19 +++++++++++++++++++ GUI/coregui/Models/InstrumentItems.h | 4 ++++ GUI/coregui/Models/IntensityDataItem.cpp | 5 +++++ GUI/coregui/Models/IntensityDataItem.h | 3 +++ GUI/coregui/Models/RealDataItem.cpp | 10 ++++++++++ GUI/coregui/Models/RealDataItem.h | 3 +++ .../Models/RectangularDetectorItem.cpp | 10 ++++++++++ GUI/coregui/Models/RectangularDetectorItem.h | 3 +++ GUI/coregui/Models/SpecularDataItem.cpp | 5 +++++ GUI/coregui/Models/SpecularDataItem.h | 1 + GUI/coregui/Models/SphericalDetectorItem.cpp | 12 ++++++++++++ GUI/coregui/Models/SphericalDetectorItem.h | 2 ++ 16 files changed, 99 insertions(+) diff --git a/GUI/coregui/Models/BeamItems.cpp b/GUI/coregui/Models/BeamItems.cpp index 4427715e713..fd3aab175c9 100644 --- a/GUI/coregui/Models/BeamItems.cpp +++ b/GUI/coregui/Models/BeamItems.cpp @@ -13,6 +13,7 @@ // ************************************************************************** // #include "BeamItems.h" +#include "AxesItems.h" #include "Beam.h" #include "BeamAngleItems.h" #include "BeamDistributionItem.h" @@ -22,6 +23,7 @@ #include "GUIHelpers.h" #include "ParameterTranslators.h" #include "SessionItemUtils.h" +#include "SpecularBeamInclinationItem.h" #include "Units.h" using SessionItemUtils::GetVectorItem; @@ -151,6 +153,12 @@ void SpecularBeamItem::setInclinationAngle(double value) BeamItem::setInclinationAngle(value); } +BasicAxisItem& SpecularBeamItem::getInclinationAngleAxis() +{ + return getItem(BeamItem::P_INCLINATION_ANGLE) + ->item<BasicAxisItem>(SpecularBeamInclinationItem::P_ALPHA_AXIS); +} + FootprintItem* SpecularBeamItem::currentFootprintItem() const { return &groupItem<FootprintItem>(P_FOOPTPRINT); diff --git a/GUI/coregui/Models/BeamItems.h b/GUI/coregui/Models/BeamItems.h index 3a7a7305a56..f527045743e 100644 --- a/GUI/coregui/Models/BeamItems.h +++ b/GUI/coregui/Models/BeamItems.h @@ -17,6 +17,7 @@ #include "SessionItem.h" +class BasicAxisItem; class Beam; class FootprintItem; @@ -62,6 +63,7 @@ public: double getInclinationAngle() const override; void setInclinationAngle(double value) override; + BasicAxisItem& getInclinationAngleAxis(); FootprintItem* currentFootprintItem() const; }; diff --git a/GUI/coregui/Models/DataItem.h b/GUI/coregui/Models/DataItem.h index 8bd0680a76f..2ba274af313 100644 --- a/GUI/coregui/Models/DataItem.h +++ b/GUI/coregui/Models/DataItem.h @@ -45,6 +45,7 @@ public: virtual void setYaxisTitle(QString ytitle) = 0; virtual void setAxesRangeToData() = 0; virtual void updateAxesUnits(const InstrumentItem* instrument) = 0; + virtual std::vector<int> shape() const = 0; //! Returns data to default state (no dimensional units, default axes' names) virtual void resetToDefault() = 0; diff --git a/GUI/coregui/Models/DetectorItems.h b/GUI/coregui/Models/DetectorItems.h index e10858df147..3a11d88c5e0 100644 --- a/GUI/coregui/Models/DetectorItems.h +++ b/GUI/coregui/Models/DetectorItems.h @@ -34,7 +34,18 @@ public: std::unique_ptr<IDetector2D> createDetector() const; + // TODO: consider using index-based access functions + + //! returns the size of x-axis of the detector + virtual int xSize() const = 0; + + //! returns the size of y-axis of the detector + virtual int ySize() const = 0; + + //! sets the size of x-axis of the detector virtual void setXSize(int nx) = 0; + + //! sets the size of y-axis of the detector virtual void setYSize(int ny) = 0; void clearMasks(); diff --git a/GUI/coregui/Models/InstrumentItems.cpp b/GUI/coregui/Models/InstrumentItems.cpp index f012f48d345..a2e85f5d968 100644 --- a/GUI/coregui/Models/InstrumentItems.cpp +++ b/GUI/coregui/Models/InstrumentItems.cpp @@ -114,6 +114,12 @@ std::unique_ptr<Instrument> SpecularInstrumentItem::createInstrument() const return InstrumentItem::createInstrument(); } +std::vector<int> SpecularInstrumentItem::shape() const +{ + const auto& axis_item = beamItem()->getInclinationAngleAxis(); + return {axis_item.getItemValue(BasicAxisItem::P_NBINS).toInt()}; +} + const QString Instrument2DItem::P_DETECTOR = "Detector"; Instrument2DItem::Instrument2DItem(const QString& modelType) @@ -167,6 +173,12 @@ GISASInstrumentItem::GISASInstrumentItem() { } +std::vector<int> GISASInstrumentItem::shape() const +{ + auto detector_item = detectorItem(); + return {detector_item->xSize(), detector_item->ySize()}; +} + const QString OffSpecInstrumentItem::P_ALPHA_AXIS = "Alpha axis"; OffSpecInstrumentItem::OffSpecInstrumentItem() @@ -175,6 +187,13 @@ OffSpecInstrumentItem::OffSpecInstrumentItem() addAxisGroupProperty(this, P_ALPHA_AXIS); } +std::vector<int> OffSpecInstrumentItem::shape() const +{ + const int x_size = getItem(P_ALPHA_AXIS)->getItemValue(BasicAxisItem::P_NBINS).toInt(); + auto detector_item = detectorItem(); + return {x_size, detector_item->ySize()}; +} + namespace { void addAxisGroupProperty(SessionItem* parent, const QString& tag) diff --git a/GUI/coregui/Models/InstrumentItems.h b/GUI/coregui/Models/InstrumentItems.h index f0dc2c31eb5..18a8cea6fc1 100644 --- a/GUI/coregui/Models/InstrumentItems.h +++ b/GUI/coregui/Models/InstrumentItems.h @@ -37,6 +37,7 @@ public: GroupItem* backgroundGroup(); virtual std::unique_ptr<Instrument> createInstrument() const = 0; + virtual std::vector<int> shape() const = 0; protected: explicit InstrumentItem(const QString& modelType); @@ -53,6 +54,7 @@ public: SpecularBeamItem* beamItem() const override; std::unique_ptr<Instrument> createInstrument() const override; + std::vector<int> shape() const override; }; class BA_CORE_API_ Instrument2DItem : public InstrumentItem @@ -81,6 +83,7 @@ class BA_CORE_API_ GISASInstrumentItem : public Instrument2DItem { public: GISASInstrumentItem(); + std::vector<int> shape() const override; }; class BA_CORE_API_ OffSpecInstrumentItem : public Instrument2DItem @@ -89,6 +92,7 @@ public: static const QString P_ALPHA_AXIS; OffSpecInstrumentItem(); + std::vector<int> shape() const override; }; #endif // INSTRUMENTITEMS_H diff --git a/GUI/coregui/Models/IntensityDataItem.cpp b/GUI/coregui/Models/IntensityDataItem.cpp index fefede9d047..031cc59d0f8 100644 --- a/GUI/coregui/Models/IntensityDataItem.cpp +++ b/GUI/coregui/Models/IntensityDataItem.cpp @@ -224,6 +224,11 @@ void IntensityDataItem::updateAxesUnits(const InstrumentItem* instrument) converter.convertFromNbins(this); } +std::vector<int> IntensityDataItem::shape() const +{ + return {getNbinsX(), getNbinsY()}; +} + void IntensityDataItem::resetToDefault() { assert(getOutputData() diff --git a/GUI/coregui/Models/IntensityDataItem.h b/GUI/coregui/Models/IntensityDataItem.h index e0cd3a11c03..ba1bd55d246 100644 --- a/GUI/coregui/Models/IntensityDataItem.h +++ b/GUI/coregui/Models/IntensityDataItem.h @@ -39,6 +39,8 @@ public: void setOutputData(OutputData<double>* data) override; void setRawDataVector(const OutputData<double>* data) override; + // TODO: consider using index-based functions for axes' handlers + int getNbinsX() const; int getNbinsY() const; @@ -92,6 +94,7 @@ public: void setYaxisTitle(QString ytitle) override; void setAxesRangeToData() override; void updateAxesUnits(const InstrumentItem* instrument) override; + std::vector<int> shape() const override; //! Returns data to default state (no dimensional units, default axes' names) void resetToDefault() override; diff --git a/GUI/coregui/Models/RealDataItem.cpp b/GUI/coregui/Models/RealDataItem.cpp index 67d205a8ead..65b90affc14 100644 --- a/GUI/coregui/Models/RealDataItem.cpp +++ b/GUI/coregui/Models/RealDataItem.cpp @@ -107,6 +107,16 @@ void RealDataItem::linkToInstrument(const InstrumentItem *instrument, bool make_ updateToInstrument(); } +std::vector<int> RealDataItem::shape() const +{ + auto data_item = dataItem(); + if (!data_item) { + assert(data_item); + return {}; + } + return data_item->shape(); +} + //! Updates the name of file to store intensity data. void RealDataItem::updateIntensityDataFileName() diff --git a/GUI/coregui/Models/RealDataItem.h b/GUI/coregui/Models/RealDataItem.h index 5b90f196f13..37df08ad6a2 100644 --- a/GUI/coregui/Models/RealDataItem.h +++ b/GUI/coregui/Models/RealDataItem.h @@ -42,6 +42,9 @@ public: void linkToInstrument(const InstrumentItem* instrument, bool make_update = true); + //! Returns the shape of undelying data item + std::vector<int> shape() const; + private: void updateIntensityDataFileName(); void updateToInstrument(); diff --git a/GUI/coregui/Models/RectangularDetectorItem.cpp b/GUI/coregui/Models/RectangularDetectorItem.cpp index 98f4a615c02..fa1f7c507a7 100644 --- a/GUI/coregui/Models/RectangularDetectorItem.cpp +++ b/GUI/coregui/Models/RectangularDetectorItem.cpp @@ -134,6 +134,16 @@ void RectangularDetectorItem::setDetectorAlignment(const QString& alignment) setItemValue(RectangularDetectorItem::P_ALIGNMENT, combo_property.variant()); } +int RectangularDetectorItem::xSize() const +{ + return getItem(RectangularDetectorItem::P_X_AXIS)->getItemValue(BasicAxisItem::P_NBINS).toInt(); +} + +int RectangularDetectorItem::ySize() const +{ + return getItem(RectangularDetectorItem::P_Y_AXIS)->getItemValue(BasicAxisItem::P_NBINS).toInt(); +} + void RectangularDetectorItem::setXSize(int nx) { getItem(RectangularDetectorItem::P_X_AXIS)->setItemValue(BasicAxisItem::P_NBINS, nx); diff --git a/GUI/coregui/Models/RectangularDetectorItem.h b/GUI/coregui/Models/RectangularDetectorItem.h index 1f9db868ab9..69f5e56e3ba 100644 --- a/GUI/coregui/Models/RectangularDetectorItem.h +++ b/GUI/coregui/Models/RectangularDetectorItem.h @@ -35,6 +35,9 @@ public: RectangularDetectorItem(); void setDetectorAlignment(const QString& alignment); + + int xSize() const override; + int ySize() const override; void setXSize(int nx) override; void setYSize(int ny) override; diff --git a/GUI/coregui/Models/SpecularDataItem.cpp b/GUI/coregui/Models/SpecularDataItem.cpp index 857c348c69e..234f5c29d9c 100644 --- a/GUI/coregui/Models/SpecularDataItem.cpp +++ b/GUI/coregui/Models/SpecularDataItem.cpp @@ -155,6 +155,11 @@ void SpecularDataItem::updateAxesUnits(const InstrumentItem* instrument) JobItemUtils::updateDataAxes(this, instrument); } +std::vector<int> SpecularDataItem::shape() const +{ + return {getNbins()}; +} + void SpecularDataItem::resetToDefault() { assert(getOutputData() diff --git a/GUI/coregui/Models/SpecularDataItem.h b/GUI/coregui/Models/SpecularDataItem.h index aebe4824689..971581c7848 100644 --- a/GUI/coregui/Models/SpecularDataItem.h +++ b/GUI/coregui/Models/SpecularDataItem.h @@ -69,6 +69,7 @@ public: void setYaxisTitle(QString ytitle) override; void setAxesRangeToData() override; void updateAxesUnits(const InstrumentItem* instrument) override; + std::vector<int> shape() const override; //! Returns data to default state (no dimensional units, default axes' names) void resetToDefault() override; diff --git a/GUI/coregui/Models/SphericalDetectorItem.cpp b/GUI/coregui/Models/SphericalDetectorItem.cpp index 1a8f185f7f8..df35d8bcc4d 100644 --- a/GUI/coregui/Models/SphericalDetectorItem.cpp +++ b/GUI/coregui/Models/SphericalDetectorItem.cpp @@ -65,6 +65,18 @@ std::unique_ptr<IDetector2D> SphericalDetectorItem::createDomainDetector() const return std::move(result); } +int SphericalDetectorItem::xSize() const +{ + return getItem(SphericalDetectorItem::P_PHI_AXIS)->getItemValue(BasicAxisItem::P_NBINS).toInt(); +} + +int SphericalDetectorItem::ySize() const +{ + return getItem(SphericalDetectorItem::P_ALPHA_AXIS) + ->getItemValue(BasicAxisItem::P_NBINS) + .toInt(); +} + void SphericalDetectorItem::setXSize(int nx) { getItem(SphericalDetectorItem::P_PHI_AXIS)->setItemValue(BasicAxisItem::P_NBINS, nx); diff --git a/GUI/coregui/Models/SphericalDetectorItem.h b/GUI/coregui/Models/SphericalDetectorItem.h index db4f9ccbc37..34874363574 100644 --- a/GUI/coregui/Models/SphericalDetectorItem.h +++ b/GUI/coregui/Models/SphericalDetectorItem.h @@ -24,6 +24,8 @@ public: static const QString P_ALPHA_AXIS; SphericalDetectorItem(); + int xSize() const override; + int ySize() const override; void setXSize(int nx) override; void setYSize(int ny) override; -- GitLab