From 2a5a0bf64e187370ee59941c4454f01ed152f161 Mon Sep 17 00:00:00 2001 From: "Joachim Wuttke (h)" <j.wuttke@fz-juelich.de> Date: Thu, 22 Apr 2021 23:12:57 +0200 Subject: [PATCH 01/18] fct comment --- GUI/coregui/Models/RealDataItem.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/GUI/coregui/Models/RealDataItem.cpp b/GUI/coregui/Models/RealDataItem.cpp index 67b9146d7ae..949999d78b2 100644 --- a/GUI/coregui/Models/RealDataItem.cpp +++ b/GUI/coregui/Models/RealDataItem.cpp @@ -170,7 +170,7 @@ void RealDataItem::setNativeOutputData(OutputData<double>* data) nativeData()->setOutputData(data); // takes ownership of odata } -//! Creates data item if not existing so far. +//! Creates and inserts a data item except if such item with same tag already exists. //! Checks for rank compatibility if already existing. //! No further initialization (like clearing the data etc). -- GitLab From 9874dafadf15baaf74c6b5b8cb80130298ce4e8a Mon Sep 17 00:00:00 2001 From: "Joachim Wuttke (h)" <j.wuttke@fz-juelich.de> Date: Fri, 23 Apr 2021 10:26:30 +0200 Subject: [PATCH 02/18] mv fct createOutputData --- Core/Simulation/UnitConverterUtils.cpp | 10 ---------- Core/Simulation/UnitConverterUtils.h | 4 ---- Device/Unit/IUnitConverter.cpp | 12 ++++++++++++ Device/Unit/IUnitConverter.h | 9 +++++++++ GUI/coregui/Models/DataViewUtils.cpp | 2 +- GUI/coregui/Models/JobItemUtils.cpp | 1 - auto/Wrap/doxygenCore.i | 5 ----- auto/Wrap/doxygenDevice.i | 7 +++++++ 8 files changed, 29 insertions(+), 21 deletions(-) diff --git a/Core/Simulation/UnitConverterUtils.cpp b/Core/Simulation/UnitConverterUtils.cpp index 4754636a5bc..723ab3517cf 100644 --- a/Core/Simulation/UnitConverterUtils.cpp +++ b/Core/Simulation/UnitConverterUtils.cpp @@ -18,16 +18,6 @@ #include "Device/Detector/SphericalDetector.h" #include "Device/Instrument/Instrument.h" -std::unique_ptr<OutputData<double>> -UnitConverterUtils::createOutputData(const IUnitConverter& converter, Axes::Units units) -{ - std::unique_ptr<OutputData<double>> result = std::make_unique<OutputData<double>>(); - for (size_t i = 0; i < converter.dimension(); ++i) - result->addAxis(*converter.createConvertedAxis(i, units)); - result->setAllTo(0.0); - return result; -} - std::unique_ptr<IUnitConverter> UnitConverterUtils::createConverterForGISAS(const Instrument& instrument) { diff --git a/Core/Simulation/UnitConverterUtils.h b/Core/Simulation/UnitConverterUtils.h index c6289b1f5e6..cfb4ac7c99d 100644 --- a/Core/Simulation/UnitConverterUtils.h +++ b/Core/Simulation/UnitConverterUtils.h @@ -29,10 +29,6 @@ template <class T> class OutputData; namespace UnitConverterUtils { -//! Returns zero-valued output data array in specified units -std::unique_ptr<OutputData<double>> createOutputData(const IUnitConverter& converter, - Axes::Units units); - //! Helper factory function to use in GISASSimulation. Depending on the type of detector, //! returns either RectangularConverter or SphericalConverter. std::unique_ptr<IUnitConverter> createConverterForGISAS(const Instrument& instrument); diff --git a/Device/Unit/IUnitConverter.cpp b/Device/Unit/IUnitConverter.cpp index 416cf875b85..7c3fd4b86e2 100644 --- a/Device/Unit/IUnitConverter.cpp +++ b/Device/Unit/IUnitConverter.cpp @@ -16,6 +16,7 @@ #include "Device/Data/OutputData.h" #include "Device/Unit/AxisNames.h" + IUnitConverter::~IUnitConverter() = default; std::string IUnitConverter::axisName(size_t i_axis, const Axes::Units& units_type) const @@ -57,3 +58,14 @@ Axes::Units IUnitConverter::substituteDefaultUnits(Axes::Units units) const { return units == Axes::Units::DEFAULT ? defaultUnits() : units; } + + +std::unique_ptr<OutputData<double>> +UnitConverterUtils::createOutputData(const IUnitConverter& converter, Axes::Units units) +{ + std::unique_ptr<OutputData<double>> result = std::make_unique<OutputData<double>>(); + for (size_t i = 0; i < converter.dimension(); ++i) + result->addAxis(*converter.createConvertedAxis(i, units)); + result->setAllTo(0.0); + return result; +} diff --git a/Device/Unit/IUnitConverter.h b/Device/Unit/IUnitConverter.h index 226c0c8ef32..01e89417b43 100644 --- a/Device/Unit/IUnitConverter.h +++ b/Device/Unit/IUnitConverter.h @@ -26,6 +26,7 @@ #include <string> #include <vector> + class IAxis; template <class T> class OutputData; @@ -74,6 +75,14 @@ private: virtual std::vector<std::map<Axes::Units, std::string>> createNameMaps() const = 0; }; + +namespace UnitConverterUtils { + +//! Returns zero-valued output data array in specified units +std::unique_ptr<OutputData<double>> createOutputData(const IUnitConverter& converter, + Axes::Units units); +} + #endif // USER_API #endif // BORNAGAIN_DEVICE_UNIT_IUNITCONVERTER_H diff --git a/GUI/coregui/Models/DataViewUtils.cpp b/GUI/coregui/Models/DataViewUtils.cpp index bed8a964442..4b1dafa5f63 100644 --- a/GUI/coregui/Models/DataViewUtils.cpp +++ b/GUI/coregui/Models/DataViewUtils.cpp @@ -13,7 +13,7 @@ // ************************************************************************************************ #include "GUI/coregui/Models/DataViewUtils.h" -#include "Core/Simulation/UnitConverterUtils.h" +#include "Device/Unit/IUnitConverter.h" #include "GUI/coregui/Models/Data1DViewItem.h" #include "GUI/coregui/Models/DataItem.h" #include "GUI/coregui/Models/DataPropertyContainer.h" diff --git a/GUI/coregui/Models/JobItemUtils.cpp b/GUI/coregui/Models/JobItemUtils.cpp index 032911b5ece..c21720fed8f 100644 --- a/GUI/coregui/Models/JobItemUtils.cpp +++ b/GUI/coregui/Models/JobItemUtils.cpp @@ -14,7 +14,6 @@ #include "GUI/coregui/Models/JobItemUtils.h" #include "Core/Simulation/ISimulation.h" -#include "Core/Simulation/UnitConverterUtils.h" #include "GUI/coregui/Models/DataItem.h" #include "GUI/coregui/Models/DomainObjectBuilder.h" #include "GUI/coregui/Models/InstrumentItems.h" diff --git a/auto/Wrap/doxygenCore.i b/auto/Wrap/doxygenCore.i index a2dd8151f19..41c715f7ba3 100644 --- a/auto/Wrap/doxygenCore.i +++ b/auto/Wrap/doxygenCore.i @@ -2683,11 +2683,6 @@ GISAS simulation with an extra long wavelength. // File: namespaceUnitConverterUtils.xml -%feature("docstring") UnitConverterUtils::createOutputData "std::unique_ptr< OutputData< double > > UnitConverterUtils::createOutputData(const IUnitConverter &converter, Axes::Units units) - -Returns zero-valued output data array in specified units. -"; - %feature("docstring") UnitConverterUtils::createConverterForGISAS "std::unique_ptr< IUnitConverter > UnitConverterUtils::createConverterForGISAS(const Instrument &instrument) Helper factory function to use in GISASSimulation. Depending on the type of detector, returns either RectangularConverter or SphericalConverter. diff --git a/auto/Wrap/doxygenDevice.i b/auto/Wrap/doxygenDevice.i index e9458edc8a1..d77a1b060dc 100644 --- a/auto/Wrap/doxygenDevice.i +++ b/auto/Wrap/doxygenDevice.i @@ -2945,6 +2945,13 @@ Returns true if SimulatioResult agrees with data from reference file. "; +// File: namespaceUnitConverterUtils.xml +%feature("docstring") UnitConverterUtils::createOutputData "std::unique_ptr< OutputData< double > > UnitConverterUtils::createOutputData(const IUnitConverter &converter, Axes::Units units) + +Returns zero-valued output data array in specified units. +"; + + // File: Beam_8cpp.xml -- GitLab From f0a64aec01e537f6b4665013fc54daa63a33c748 Mon Sep 17 00:00:00 2001 From: "Joachim Wuttke (h)" <j.wuttke@fz-juelich.de> Date: Fri, 23 Apr 2021 10:34:10 +0200 Subject: [PATCH 03/18] createOutputData is now member of IUnitConverter --- Core/Fitting/SimDataPair.cpp | 4 ++-- Device/Unit/IUnitConverter.cpp | 22 +++++++++++----------- Device/Unit/IUnitConverter.h | 11 +++-------- GUI/coregui/Models/DataViewUtils.cpp | 2 +- GUI/coregui/Models/JobItemUtils.cpp | 4 ++-- auto/Wrap/doxygenDevice.i | 12 +++++------- 6 files changed, 24 insertions(+), 31 deletions(-) diff --git a/Core/Fitting/SimDataPair.cpp b/Core/Fitting/SimDataPair.cpp index 03db8dc1c8e..ff336ec5b38 100644 --- a/Core/Fitting/SimDataPair.cpp +++ b/Core/Fitting/SimDataPair.cpp @@ -74,7 +74,7 @@ SimulationResult convertData(const ISimulation& simulation, const OutputData<dou bool put_masked_areas_to_zero) { auto converter = createConverter(simulation); - auto roi_data = UnitConverterUtils::createOutputData(*converter, converter->defaultUnits()); + auto roi_data = converter->createOutputData(converter->defaultUnits()); if (roi_data->hasSameDimensions(data)) { // data is already cropped to ROI @@ -165,7 +165,7 @@ void SimDataPair::execSimulation(const mumufit::Parameters& params) } else { const IUnitConverter& converter = m_sim_data.converter(); std::unique_ptr<OutputData<double>> dummy_array = - UnitConverterUtils::createOutputData(converter, converter.defaultUnits()); + converter.createOutputData(converter.defaultUnits()); m_uncertainties = SimulationResult(*dummy_array, converter); } diff --git a/Device/Unit/IUnitConverter.cpp b/Device/Unit/IUnitConverter.cpp index 7c3fd4b86e2..c025796e892 100644 --- a/Device/Unit/IUnitConverter.cpp +++ b/Device/Unit/IUnitConverter.cpp @@ -19,6 +19,17 @@ IUnitConverter::~IUnitConverter() = default; + + +std::unique_ptr<OutputData<double>> IUnitConverter::createOutputData(Axes::Units units) const +{ + std::unique_ptr<OutputData<double>> result = std::make_unique<OutputData<double>>(); + for (size_t i = 0; i < dimension(); ++i) + result->addAxis(*createConvertedAxis(i, units)); + result->setAllTo(0.0); + return result; +} + std::string IUnitConverter::axisName(size_t i_axis, const Axes::Units& units_type) const { const auto& name_maps = createNameMaps(); @@ -58,14 +69,3 @@ Axes::Units IUnitConverter::substituteDefaultUnits(Axes::Units units) const { return units == Axes::Units::DEFAULT ? defaultUnits() : units; } - - -std::unique_ptr<OutputData<double>> -UnitConverterUtils::createOutputData(const IUnitConverter& converter, Axes::Units units) -{ - std::unique_ptr<OutputData<double>> result = std::make_unique<OutputData<double>>(); - for (size_t i = 0; i < converter.dimension(); ++i) - result->addAxis(*converter.createConvertedAxis(i, units)); - result->setAllTo(0.0); - return result; -} diff --git a/Device/Unit/IUnitConverter.h b/Device/Unit/IUnitConverter.h index 01e89417b43..72a633f31de 100644 --- a/Device/Unit/IUnitConverter.h +++ b/Device/Unit/IUnitConverter.h @@ -46,6 +46,9 @@ public: virtual IUnitConverter* clone() const = 0; + //! Returns zero-valued output data array in specified units + std::unique_ptr<OutputData<double>> createOutputData(Axes::Units units) const; + virtual size_t dimension() const = 0; virtual double calculateMin(size_t i_axis, Axes::Units units_type) const = 0; @@ -75,14 +78,6 @@ private: virtual std::vector<std::map<Axes::Units, std::string>> createNameMaps() const = 0; }; - -namespace UnitConverterUtils { - -//! Returns zero-valued output data array in specified units -std::unique_ptr<OutputData<double>> createOutputData(const IUnitConverter& converter, - Axes::Units units); -} - #endif // USER_API #endif // BORNAGAIN_DEVICE_UNIT_IUNITCONVERTER_H diff --git a/GUI/coregui/Models/DataViewUtils.cpp b/GUI/coregui/Models/DataViewUtils.cpp index 4b1dafa5f63..6ba163040da 100644 --- a/GUI/coregui/Models/DataViewUtils.cpp +++ b/GUI/coregui/Models/DataViewUtils.cpp @@ -62,7 +62,7 @@ std::unique_ptr<OutputData<double>> DataViewUtils::getTranslatedData(Data1DViewI auto converter = getConverter(view_item); auto current_units = selectedUnits(view_item); - result = UnitConverterUtils::createOutputData(*converter, current_units); + result = converter->createOutputData(current_units); result->setRawDataVector(data_item->getOutputData()->getRawDataVector()); return result; diff --git a/GUI/coregui/Models/JobItemUtils.cpp b/GUI/coregui/Models/JobItemUtils.cpp index c21720fed8f..c70544c1f87 100644 --- a/GUI/coregui/Models/JobItemUtils.cpp +++ b/GUI/coregui/Models/JobItemUtils.cpp @@ -60,7 +60,7 @@ void JobItemUtils::updateDataAxes(DataItem* intensityItem, const InstrumentItem* Axes::Units requested_units = axesUnitsFromName(intensityItem->selectedAxesUnits()); const auto converter = DomainObjectBuilder::createUnitConverter(instrumentItem); - auto newData = UnitConverterUtils::createOutputData(*converter.get(), requested_units); + auto newData = converter->createOutputData(requested_units); newData->setRawDataVector(intensityItem->getOutputData()->getRawDataVector()); intensityItem->setOutputData(newData.release()); @@ -107,7 +107,7 @@ void JobItemUtils::createDefaultDetectorMap(DataItem* intensityItem, const InstrumentItem* instrumentItem) { const auto converter = DomainObjectBuilder::createUnitConverter(instrumentItem); - auto output_data = UnitConverterUtils::createOutputData(*converter, converter->defaultUnits()); + auto output_data = converter->createOutputData(converter->defaultUnits()); intensityItem->setOutputData(output_data.release()); setIntensityItemAxesUnits(intensityItem, *converter); updateAxesTitle(intensityItem, *converter, converter->defaultUnits()); diff --git a/auto/Wrap/doxygenDevice.i b/auto/Wrap/doxygenDevice.i index d77a1b060dc..e6e275b5b8d 100644 --- a/auto/Wrap/doxygenDevice.i +++ b/auto/Wrap/doxygenDevice.i @@ -1469,6 +1469,11 @@ C++ includes: IUnitConverter.h %feature("docstring") IUnitConverter::clone "virtual IUnitConverter* IUnitConverter::clone() const =0 "; +%feature("docstring") IUnitConverter::createOutputData "std::unique_ptr< OutputData< double > > IUnitConverter::createOutputData(Axes::Units units) const + +Returns zero-valued output data array in specified units. +"; + %feature("docstring") IUnitConverter::dimension "virtual size_t IUnitConverter::dimension() const =0 "; @@ -2945,13 +2950,6 @@ Returns true if SimulatioResult agrees with data from reference file. "; -// File: namespaceUnitConverterUtils.xml -%feature("docstring") UnitConverterUtils::createOutputData "std::unique_ptr< OutputData< double > > UnitConverterUtils::createOutputData(const IUnitConverter &converter, Axes::Units units) - -Returns zero-valued output data array in specified units. -"; - - // File: Beam_8cpp.xml -- GitLab From 453625d5633393865c105ffe167202823bd4bec4 Mon Sep 17 00:00:00 2001 From: "Joachim Wuttke (h)" <j.wuttke@fz-juelich.de> Date: Fri, 23 Apr 2021 10:47:29 +0200 Subject: [PATCH 04/18] rm UnitConverterUtils; last fct made static member --- Core/Fitting/SimDataPair.cpp | 7 ++-- Core/Simulation/GISASSimulation.cpp | 4 +-- Core/Simulation/UnitConverterUtils.cpp | 33 ------------------ Core/Simulation/UnitConverterUtils.h | 39 ---------------------- Device/Detector/SimpleUnitConverters.cpp | 16 ++++++++- Device/Detector/SimpleUnitConverters.h | 6 ++++ GUI/coregui/Models/DomainObjectBuilder.cpp | 14 +++----- 7 files changed, 31 insertions(+), 88 deletions(-) delete mode 100644 Core/Simulation/UnitConverterUtils.cpp delete mode 100644 Core/Simulation/UnitConverterUtils.h diff --git a/Core/Fitting/SimDataPair.cpp b/Core/Fitting/SimDataPair.cpp index ff336ec5b38..f6ab295de6a 100644 --- a/Core/Fitting/SimDataPair.cpp +++ b/Core/Fitting/SimDataPair.cpp @@ -15,7 +15,7 @@ #include "Core/Fitting/SimDataPair.h" #include "Base/Math/Numeric.h" #include "Core/Scan/UnitConverter1D.h" -#include "Core/Simulation/UnitConverterUtils.h" +#include "Device/Detector/SimpleUnitConverters.h" #include "Core/Simulation/includeSimulations.h" #include "Device/Data/DataUtils.h" @@ -51,7 +51,7 @@ bool detHasSameDimensions(const IDetector& detector, const OutputData<double>& d std::unique_ptr<IUnitConverter> createConverter(const ISimulation& simulation) { if (auto gisas = dynamic_cast<const GISASSimulation*>(&simulation)) - return UnitConverterUtils::createConverterForGISAS(gisas->instrument()); + return UnitConverterSimple::createConverterForGISAS(gisas->instrument()); if (auto spec = dynamic_cast<const SpecularSimulation*>(&simulation)) return UnitConverter1D::createUnitConverter(*spec->dataHandler()); @@ -62,8 +62,7 @@ std::unique_ptr<IUnitConverter> createConverter(const ISimulation& simulation) if (auto off_spec = dynamic_cast<const OffSpecularSimulation*>(&simulation)) return off_spec->createUnitConverter(); - throw std::runtime_error("UnitConverterUtils::createConverter -> " - "Not implemented simulation."); + ASSERT(0); } //! Convert user data to SimulationResult object for later drawing in various axes units. diff --git a/Core/Simulation/GISASSimulation.cpp b/Core/Simulation/GISASSimulation.cpp index fb556a2fd64..b97a1056f61 100644 --- a/Core/Simulation/GISASSimulation.cpp +++ b/Core/Simulation/GISASSimulation.cpp @@ -13,7 +13,7 @@ // ************************************************************************************************ #include "Core/Simulation/GISASSimulation.h" -#include "Core/Simulation/UnitConverterUtils.h" +#include "Device/Detector/SimpleUnitConverters.h" #include "Sample/SampleBuilderEngine/ISampleBuilder.h" GISASSimulation::GISASSimulation(const Beam& beam, const MultiLayer& sample, @@ -57,7 +57,7 @@ void GISASSimulation::prepareSimulation() SimulationResult GISASSimulation::result() const { - const auto converter = UnitConverterUtils::createConverterForGISAS(instrument()); + const auto converter = UnitConverterSimple::createConverterForGISAS(instrument()); const std::unique_ptr<OutputData<double>> data( detector().createDetectorIntensity(m_sim_elements)); return SimulationResult(*data, *converter); diff --git a/Core/Simulation/UnitConverterUtils.cpp b/Core/Simulation/UnitConverterUtils.cpp deleted file mode 100644 index 723ab3517cf..00000000000 --- a/Core/Simulation/UnitConverterUtils.cpp +++ /dev/null @@ -1,33 +0,0 @@ -// ************************************************************************************************ -// -// BornAgain: simulate and fit reflection and scattering -// -//! @file Core/Simulation/UnitConverterUtils.cpp -//! @brief Implements utilities for unit convertion. -//! -//! @homepage http://www.bornagainproject.org -//! @license GNU General Public License v3 or higher (see COPYING) -//! @copyright Forschungszentrum Jülich GmbH 2018 -//! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS) -// -// ************************************************************************************************ - -#include "Core/Simulation/UnitConverterUtils.h" -#include "Device/Detector/RectangularDetector.h" -#include "Device/Detector/SimpleUnitConverters.h" -#include "Device/Detector/SphericalDetector.h" -#include "Device/Instrument/Instrument.h" - -std::unique_ptr<IUnitConverter> -UnitConverterUtils::createConverterForGISAS(const Instrument& instrument) -{ - const IDetector* const detector = instrument.getDetector(); - - if (const auto* const det = dynamic_cast<const SphericalDetector*>(detector)) - return std::make_unique<SphericalConverter>(*det, instrument.beam()); - - if (const auto* const det = dynamic_cast<const RectangularDetector*>(detector)) - return std::make_unique<RectangularConverter>(*det, instrument.beam()); - - throw std::runtime_error("Error in createConverterForGISAS: wrong or absent detector type"); -} diff --git a/Core/Simulation/UnitConverterUtils.h b/Core/Simulation/UnitConverterUtils.h deleted file mode 100644 index cfb4ac7c99d..00000000000 --- a/Core/Simulation/UnitConverterUtils.h +++ /dev/null @@ -1,39 +0,0 @@ -// ************************************************************************************************ -// -// BornAgain: simulate and fit reflection and scattering -// -//! @file Core/Simulation/UnitConverterUtils.h -//! @brief Declares utilities for unit converters. -//! -//! @homepage http://www.bornagainproject.org -//! @license GNU General Public License v3 or higher (see COPYING) -//! @copyright Forschungszentrum Jülich GmbH 2018 -//! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS) -// -// ************************************************************************************************ - -#ifdef SWIG -#error no need to expose this header to Swig -#endif - -#ifndef USER_API -#ifndef BORNAGAIN_CORE_SIMULATION_UNITCONVERTERUTILS_H -#define BORNAGAIN_CORE_SIMULATION_UNITCONVERTERUTILS_H - -#include "Device/Unit/IUnitConverter.h" - -class Instrument; -template <class T> class OutputData; - -//! Namespace enclosing a number of utilities/helpers for unit converters - -namespace UnitConverterUtils { - -//! Helper factory function to use in GISASSimulation. Depending on the type of detector, -//! returns either RectangularConverter or SphericalConverter. -std::unique_ptr<IUnitConverter> createConverterForGISAS(const Instrument& instrument); - -} // namespace UnitConverterUtils - -#endif // BORNAGAIN_CORE_SIMULATION_UNITCONVERTERUTILS_H -#endif // USER_API diff --git a/Device/Detector/SimpleUnitConverters.cpp b/Device/Detector/SimpleUnitConverters.cpp index 7be4f59181d..10e08f5f967 100644 --- a/Device/Detector/SimpleUnitConverters.cpp +++ b/Device/Detector/SimpleUnitConverters.cpp @@ -16,7 +16,7 @@ #include "Base/Const/Units.h" #include "Base/Math/Constants.h" #include "Base/Pixel/RectangularPixel.h" -#include "Device/Beam/Beam.h" +#include "Device/Instrument/Instrument.h" #include "Device/Detector/RectangularDetector.h" #include "Device/Detector/SphericalDetector.h" #include "Device/ProDetector/RegionOfInterest.h" @@ -117,6 +117,20 @@ void UnitConverterSimple::addDetectorAxis(const IDetector& detector, size_t i_ax P_roi_axis->size()); } +std::unique_ptr<UnitConverterSimple> +UnitConverterSimple::createConverterForGISAS(const Instrument& instrument) +{ + const IDetector* const detector = instrument.getDetector(); + + if (const auto* const det = dynamic_cast<const SphericalDetector*>(detector)) + return std::make_unique<SphericalConverter>(*det, instrument.beam()); + + if (const auto* const det = dynamic_cast<const RectangularDetector*>(detector)) + return std::make_unique<RectangularConverter>(*det, instrument.beam()); + + throw std::runtime_error("Error in createConverterForGISAS: wrong or absent detector type"); +} + // ************************************************************************************************ // class SphericalConverter // ************************************************************************************************ diff --git a/Device/Detector/SimpleUnitConverters.h b/Device/Detector/SimpleUnitConverters.h index 464877ca6a6..b2f52e59eda 100644 --- a/Device/Detector/SimpleUnitConverters.h +++ b/Device/Detector/SimpleUnitConverters.h @@ -26,6 +26,7 @@ class Beam; class IDetector; class IDetector2D; +class Instrument; class RectangularDetector; class RectangularPixel; class SphericalDetector; @@ -49,6 +50,11 @@ public: std::unique_ptr<IAxis> createConvertedAxis(size_t i_axis, Axes::Units units) const override; + //! Helper factory function to use in GISASSimulation. Depending on the type of detector, + //! returns either RectangularConverter or SphericalConverter. + static std::unique_ptr<UnitConverterSimple> createConverterForGISAS( + const Instrument& instrument); + protected: UnitConverterSimple(const UnitConverterSimple& other); void addDetectorAxis(const IDetector& detector, size_t i_axis); diff --git a/GUI/coregui/Models/DomainObjectBuilder.cpp b/GUI/coregui/Models/DomainObjectBuilder.cpp index d4e7d16ac1b..91946b33fc7 100644 --- a/GUI/coregui/Models/DomainObjectBuilder.cpp +++ b/GUI/coregui/Models/DomainObjectBuilder.cpp @@ -15,7 +15,6 @@ #include "GUI/coregui/Models/DomainObjectBuilder.h" #include "Base/Const/Units.h" #include "Core/Scan/UnitConverter1D.h" -#include "Core/Simulation/UnitConverterUtils.h" #include "Device/Detector/IDetector2D.h" #include "Device/Detector/SimpleUnitConverters.h" #include "GUI/coregui/Models/AxesItems.h" @@ -40,11 +39,10 @@ std::unique_ptr<MultiLayer> DomainObjectBuilder::buildMultiLayer(const SessionIt ASSERT(roughnessItem); auto P_roughness = TransformToDomain::createLayerRoughness(*roughnessItem); if (P_layer) { - if (P_roughness) { + if (P_roughness) P_multilayer->addLayerWithTopRoughness(*P_layer, *P_roughness); - } else { + else P_multilayer->addLayer(*P_layer); - } } } } @@ -58,9 +56,8 @@ std::unique_ptr<Layer> DomainObjectBuilder::buildLayer(const SessionItem& item) for (int i = 0; i < children.size(); ++i) { if (children[i]->modelType() == "ParticleLayout") { auto P_layout = buildParticleLayout(*children[i]); - if (P_layout) { + if (P_layout) P_layer->addLayout(*P_layout); - } } } return P_layer; @@ -109,9 +106,8 @@ std::unique_ptr<ParticleLayout> DomainObjectBuilder::buildParticleLayout(const S QVector<SessionItem*> interferences = item.getItems(ParticleLayoutItem::T_INTERFERENCE); for (int i = 0; i < interferences.size(); i++) { auto P_interference = buildInterferenceFunction(*interferences[i]); - if (P_interference) { + if (P_interference) P_layout->setInterferenceFunction(*P_interference); - } } return P_layout; } @@ -143,7 +139,7 @@ DomainObjectBuilder::createUnitConverter(const InstrumentItem* instrumentItem) instrument->initDetector(); if (instrumentItem->is<GISASInstrumentItem>()) - return UnitConverterUtils::createConverterForGISAS(*instrument); + return UnitConverterSimple::createConverterForGISAS(*instrument); if (instrumentItem->is<OffSpecularInstrumentItem>()) { auto axis_item = -- GitLab From 201710b820ab877f2628d2697c8ca55826ae68e7 Mon Sep 17 00:00:00 2001 From: "Joachim Wuttke (h)" <j.wuttke@fz-juelich.de> Date: Fri, 23 Apr 2021 10:50:58 +0200 Subject: [PATCH 05/18] rename class and files -> UnitConverter2D --- Core/Fitting/SimDataPair.cpp | 2 +- Core/Simulation/DepthProbeSimulation.cpp | 2 +- Core/Simulation/GISASSimulation.cpp | 2 +- Core/Simulation/OffSpecularSimulation.cpp | 2 +- ...UnitConverters.cpp => UnitConverter2D.cpp} | 4 +-- ...mpleUnitConverters.h => UnitConverter2D.h} | 2 +- .../Models/DepthProbeInstrumentItem.cpp | 2 +- GUI/coregui/Models/DomainObjectBuilder.cpp | 2 +- .../Core/Core/DepthProbeConverterTest.cpp | 2 +- .../Instrument/OffSpecularConverterTest.cpp | 2 +- .../Instrument/RectangularConverterTest.cpp | 2 +- .../Instrument/SphericalConverterTest.cpp | 2 +- auto/Wrap/doxygenDevice.i | 26 +++++++++---------- 13 files changed, 26 insertions(+), 26 deletions(-) rename Device/Detector/{SimpleUnitConverters.cpp => UnitConverter2D.cpp} (99%) rename Device/Detector/{SimpleUnitConverters.h => UnitConverter2D.h} (99%) diff --git a/Core/Fitting/SimDataPair.cpp b/Core/Fitting/SimDataPair.cpp index f6ab295de6a..29f50b8548d 100644 --- a/Core/Fitting/SimDataPair.cpp +++ b/Core/Fitting/SimDataPair.cpp @@ -15,7 +15,7 @@ #include "Core/Fitting/SimDataPair.h" #include "Base/Math/Numeric.h" #include "Core/Scan/UnitConverter1D.h" -#include "Device/Detector/SimpleUnitConverters.h" +#include "Device/Detector/UnitConverter2D.h" #include "Core/Simulation/includeSimulations.h" #include "Device/Data/DataUtils.h" diff --git a/Core/Simulation/DepthProbeSimulation.cpp b/Core/Simulation/DepthProbeSimulation.cpp index b23198d7588..535814835cd 100644 --- a/Core/Simulation/DepthProbeSimulation.cpp +++ b/Core/Simulation/DepthProbeSimulation.cpp @@ -16,7 +16,7 @@ #include "Core/Computation/DepthProbeComputation.h" #include "Core/Computation/IBackground.h" #include "Device/Beam/IFootprintFactor.h" -#include "Device/Detector/SimpleUnitConverters.h" +#include "Device/Detector/UnitConverter2D.h" #include "Device/Detector/SpecularDetector1D.h" #include "Param/Base/ParameterPool.h" #include "Param/Base/RealParameter.h" diff --git a/Core/Simulation/GISASSimulation.cpp b/Core/Simulation/GISASSimulation.cpp index b97a1056f61..fa98019d9af 100644 --- a/Core/Simulation/GISASSimulation.cpp +++ b/Core/Simulation/GISASSimulation.cpp @@ -13,7 +13,7 @@ // ************************************************************************************************ #include "Core/Simulation/GISASSimulation.h" -#include "Device/Detector/SimpleUnitConverters.h" +#include "Device/Detector/UnitConverter2D.h" #include "Sample/SampleBuilderEngine/ISampleBuilder.h" GISASSimulation::GISASSimulation(const Beam& beam, const MultiLayer& sample, diff --git a/Core/Simulation/OffSpecularSimulation.cpp b/Core/Simulation/OffSpecularSimulation.cpp index f9b002bf15a..ff8fe0d03db 100644 --- a/Core/Simulation/OffSpecularSimulation.cpp +++ b/Core/Simulation/OffSpecularSimulation.cpp @@ -13,7 +13,7 @@ // ************************************************************************************************ #include "Core/Simulation/OffSpecularSimulation.h" -#include "Device/Detector/SimpleUnitConverters.h" +#include "Device/Detector/UnitConverter2D.h" #include "Param/Base/ParameterPool.h" #include "Param/Base/RealParameter.h" #include "Param/Distrib/Distributions.h" diff --git a/Device/Detector/SimpleUnitConverters.cpp b/Device/Detector/UnitConverter2D.cpp similarity index 99% rename from Device/Detector/SimpleUnitConverters.cpp rename to Device/Detector/UnitConverter2D.cpp index 10e08f5f967..411dead2e09 100644 --- a/Device/Detector/SimpleUnitConverters.cpp +++ b/Device/Detector/UnitConverter2D.cpp @@ -2,7 +2,7 @@ // // BornAgain: simulate and fit reflection and scattering // -//! @file Device/Detector/SimpleUnitConverters.cpp +//! @file Device/Detector/UnitConverter2D.cpp //! @brief Implements IUnitConverter classes. //! //! @homepage http://www.bornagainproject.org @@ -12,7 +12,7 @@ // // ************************************************************************************************ -#include "Device/Detector/SimpleUnitConverters.h" +#include "Device/Detector/UnitConverter2D.h" #include "Base/Const/Units.h" #include "Base/Math/Constants.h" #include "Base/Pixel/RectangularPixel.h" diff --git a/Device/Detector/SimpleUnitConverters.h b/Device/Detector/UnitConverter2D.h similarity index 99% rename from Device/Detector/SimpleUnitConverters.h rename to Device/Detector/UnitConverter2D.h index b2f52e59eda..0e47eb9935c 100644 --- a/Device/Detector/SimpleUnitConverters.h +++ b/Device/Detector/UnitConverter2D.h @@ -2,7 +2,7 @@ // // BornAgain: simulate and fit reflection and scattering // -//! @file Device/Detector/SimpleUnitConverters.h +//! @file Device/Detector/UnitConverter2D.h //! @brief Defines interface UnitConverterSimple and its subclasses. //! //! @homepage http://www.bornagainproject.org diff --git a/GUI/coregui/Models/DepthProbeInstrumentItem.cpp b/GUI/coregui/Models/DepthProbeInstrumentItem.cpp index 9cb127634dc..1c6f5399e44 100644 --- a/GUI/coregui/Models/DepthProbeInstrumentItem.cpp +++ b/GUI/coregui/Models/DepthProbeInstrumentItem.cpp @@ -15,7 +15,7 @@ #include "GUI/coregui/Models/DepthProbeInstrumentItem.h" #include "Base/Const/Units.h" #include "Core/Simulation/DepthProbeSimulation.h" -#include "Device/Detector/SimpleUnitConverters.h" +#include "Device/Detector/UnitConverter2D.h" #include "GUI/coregui/Models/AxesItems.h" #include "GUI/coregui/Models/BeamItems.h" #include "GUI/coregui/Models/BeamWavelengthItem.h" diff --git a/GUI/coregui/Models/DomainObjectBuilder.cpp b/GUI/coregui/Models/DomainObjectBuilder.cpp index 91946b33fc7..0b548a24d89 100644 --- a/GUI/coregui/Models/DomainObjectBuilder.cpp +++ b/GUI/coregui/Models/DomainObjectBuilder.cpp @@ -16,7 +16,7 @@ #include "Base/Const/Units.h" #include "Core/Scan/UnitConverter1D.h" #include "Device/Detector/IDetector2D.h" -#include "Device/Detector/SimpleUnitConverters.h" +#include "Device/Detector/UnitConverter2D.h" #include "GUI/coregui/Models/AxesItems.h" #include "GUI/coregui/Models/ComboProperty.h" #include "GUI/coregui/Models/DepthProbeInstrumentItem.h" diff --git a/Tests/UnitTests/Core/Core/DepthProbeConverterTest.cpp b/Tests/UnitTests/Core/Core/DepthProbeConverterTest.cpp index b7b0653beab..ae0bcd7a710 100644 --- a/Tests/UnitTests/Core/Core/DepthProbeConverterTest.cpp +++ b/Tests/UnitTests/Core/Core/DepthProbeConverterTest.cpp @@ -2,7 +2,7 @@ #include "Base/Const/Units.h" #include "Base/Math/Constants.h" #include "Device/Beam/Beam.h" -#include "Device/Detector/SimpleUnitConverters.h" +#include "Device/Detector/UnitConverter2D.h" #include "Tests/GTestWrapper/google_test.h" class DepthProbeConverterTest : public ::testing::Test { diff --git a/Tests/UnitTests/Core/Instrument/OffSpecularConverterTest.cpp b/Tests/UnitTests/Core/Instrument/OffSpecularConverterTest.cpp index 7cc188c5963..00981acf626 100644 --- a/Tests/UnitTests/Core/Instrument/OffSpecularConverterTest.cpp +++ b/Tests/UnitTests/Core/Instrument/OffSpecularConverterTest.cpp @@ -1,6 +1,6 @@ #include "Base/Const/Units.h" #include "Device/Beam/Beam.h" -#include "Device/Detector/SimpleUnitConverters.h" +#include "Device/Detector/UnitConverter2D.h" #include "Device/Detector/SphericalDetector.h" #include "Tests/GTestWrapper/google_test.h" diff --git a/Tests/UnitTests/Core/Instrument/RectangularConverterTest.cpp b/Tests/UnitTests/Core/Instrument/RectangularConverterTest.cpp index 9e30d02554e..0f7aca1215d 100644 --- a/Tests/UnitTests/Core/Instrument/RectangularConverterTest.cpp +++ b/Tests/UnitTests/Core/Instrument/RectangularConverterTest.cpp @@ -1,7 +1,7 @@ #include "Base/Const/Units.h" #include "Device/Beam/Beam.h" #include "Device/Detector/RectangularDetector.h" -#include "Device/Detector/SimpleUnitConverters.h" +#include "Device/Detector/UnitConverter2D.h" #include "Tests/GTestWrapper/google_test.h" #include <cmath> diff --git a/Tests/UnitTests/Core/Instrument/SphericalConverterTest.cpp b/Tests/UnitTests/Core/Instrument/SphericalConverterTest.cpp index a849606e317..0823271f580 100644 --- a/Tests/UnitTests/Core/Instrument/SphericalConverterTest.cpp +++ b/Tests/UnitTests/Core/Instrument/SphericalConverterTest.cpp @@ -1,6 +1,6 @@ #include "Base/Const/Units.h" #include "Device/Beam/Beam.h" -#include "Device/Detector/SimpleUnitConverters.h" +#include "Device/Detector/UnitConverter2D.h" #include "Device/Detector/SphericalDetector.h" #include "Tests/GTestWrapper/google_test.h" diff --git a/auto/Wrap/doxygenDevice.i b/auto/Wrap/doxygenDevice.i index e6e275b5b8d..2d46df823e6 100644 --- a/auto/Wrap/doxygenDevice.i +++ b/auto/Wrap/doxygenDevice.i @@ -224,7 +224,7 @@ C++ includes: CumulativeValue.h DepthProbeConverter class handles the unit translations for depth probe simulations Its default units are radians for x-axis and nm for y-axis -C++ includes: SimpleUnitConverters.h +C++ includes: UnitConverter2D.h "; %feature("docstring") DepthProbeConverter::DepthProbeConverter "DepthProbeConverter::DepthProbeConverter(const Beam &beam, const IAxis &alpha_axis, const IAxis &z_axis) @@ -1456,7 +1456,7 @@ Returns true if area defined by two bins is inside or on border of polygon (more Interface to provide axis translations to different units for simulation output. Child classes are currently declared in - Device/Detector/SimpleUnitConverters.h, +Device/Detector/SimpleUnitConverters.h, Core/Scan/UnitConverter1D.h. @@ -1582,7 +1582,7 @@ C++ includes: LLData.h IUnitConverter class that handles the unit translations for off-specular simulations with a spherical detector Its default units are radians for both axes -C++ includes: SimpleUnitConverters.h +C++ includes: UnitConverter2D.h "; %feature("docstring") OffSpecularConverter::OffSpecularConverter "OffSpecularConverter::OffSpecularConverter(const IDetector2D &detector, const Beam &beam, const IAxis &alpha_axis) @@ -2146,7 +2146,7 @@ Returns true if area defined by two bins is inside or on border of polygon (more IUnitConverter class that handles the unit translations for rectangular detectors Its default units are mm for both axes -C++ includes: SimpleUnitConverters.h +C++ includes: UnitConverter2D.h "; %feature("docstring") RectangularConverter::RectangularConverter "RectangularConverter::RectangularConverter(const RectangularDetector &detector, const Beam &beam) @@ -2588,7 +2588,7 @@ Return default axes units. IUnitConverter class that handles the unit translations for spherical detectors Its default units are radians for both axes -C++ includes: SimpleUnitConverters.h +C++ includes: UnitConverter2D.h "; %feature("docstring") SphericalConverter::SphericalConverter "SphericalConverter::SphericalConverter(const SphericalDetector &detector, const Beam &beam) @@ -2689,7 +2689,7 @@ return default axes units Interface for objects that provide axis translations to different units for IDetector objects -C++ includes: SimpleUnitConverters.h +C++ includes: UnitConverter2D.h "; %feature("docstring") UnitConverterSimple::UnitConverterSimple "UnitConverterSimple::UnitConverterSimple(const Beam &beam) @@ -2759,7 +2759,7 @@ Returns true if area defined by two bins is inside or on border of polygon (more // File: namespace_0d11.xml -// File: namespace_0d28.xml +// File: namespace_0d36.xml // File: namespace_0d51.xml @@ -3040,12 +3040,6 @@ make Swappable // File: RectangularDetector_8h.xml -// File: SimpleUnitConverters_8cpp.xml - - -// File: SimpleUnitConverters_8h.xml - - // File: SimulationArea_8cpp.xml @@ -3070,6 +3064,12 @@ make Swappable // File: SphericalDetector_8h.xml +// File: UnitConverter2D_8cpp.xml + + +// File: UnitConverter2D_8h.xml + + // File: Histogram1D_8cpp.xml -- GitLab From 887753d71454e4f2bcdbdeda8d05ca2eb4890ba8 Mon Sep 17 00:00:00 2001 From: "Joachim Wuttke (h)" <j.wuttke@fz-juelich.de> Date: Fri, 23 Apr 2021 11:15:19 +0200 Subject: [PATCH 06/18] defaultAxesUnits pure virtual in base class --- Device/Detector/IDetector.h | 2 +- Device/Detector/RectangularDetector.cpp | 5 ----- Device/Detector/RectangularDetector.h | 2 +- Device/Detector/SpecularDetector1D.cpp | 5 ----- Device/Detector/SpecularDetector1D.h | 3 ++- Device/Detector/SphericalDetector.cpp | 5 ----- Device/Detector/SphericalDetector.h | 2 +- auto/Wrap/doxygenDevice.i | 8 ++++---- auto/Wrap/libBornAgainDevice.py | 6 +++--- auto/Wrap/libBornAgainDevice_wrap.cpp | 6 +++--- 10 files changed, 15 insertions(+), 29 deletions(-) diff --git a/Device/Detector/IDetector.h b/Device/Detector/IDetector.h index 24d3d5d8df6..c6b71924ae2 100644 --- a/Device/Detector/IDetector.h +++ b/Device/Detector/IDetector.h @@ -95,7 +95,7 @@ public: createDetectorIntensity(const std::vector<SimulationElement>& elements) const; //! Return default axes units - virtual Axes::Units defaultAxesUnits() const { return Axes::Units::DEFAULT; } + virtual Axes::Units defaultAxesUnits() const = 0; //! Returns number of simulation elements. size_t numberOfSimulationElements() const; diff --git a/Device/Detector/RectangularDetector.cpp b/Device/Detector/RectangularDetector.cpp index e5df3ededff..517ffed8a0b 100644 --- a/Device/Detector/RectangularDetector.cpp +++ b/Device/Detector/RectangularDetector.cpp @@ -161,11 +161,6 @@ RectangularDetector::EDetectorArrangement RectangularDetector::getDetectorArrang return m_detector_arrangement; } -Axes::Units RectangularDetector::defaultAxesUnits() const -{ - return Axes::Units::MM; -} - RectangularPixel* RectangularDetector::regionOfInterestPixel() const { const IAxis& u_axis = axis(0); diff --git a/Device/Detector/RectangularDetector.h b/Device/Detector/RectangularDetector.h index c21c912ea62..774af2c4779 100644 --- a/Device/Detector/RectangularDetector.h +++ b/Device/Detector/RectangularDetector.h @@ -73,7 +73,7 @@ public: EDetectorArrangement getDetectorArrangment() const; //! return default axes units - Axes::Units defaultAxesUnits() const override; + virtual Axes::Units defaultAxesUnits() const final { return Axes::Units::MM; } RectangularPixel* regionOfInterestPixel() const; diff --git a/Device/Detector/SpecularDetector1D.cpp b/Device/Detector/SpecularDetector1D.cpp index 9ed6713ce6e..1fc74af3801 100644 --- a/Device/Detector/SpecularDetector1D.cpp +++ b/Device/Detector/SpecularDetector1D.cpp @@ -37,11 +37,6 @@ SpecularDetector1D* SpecularDetector1D::clone() const return new SpecularDetector1D(*this); } -Axes::Units SpecularDetector1D::defaultAxesUnits() const -{ - return Axes::Units::RADIANS; -} - std::string SpecularDetector1D::axisName(size_t index) const { if (index == 0) { diff --git a/Device/Detector/SpecularDetector1D.h b/Device/Detector/SpecularDetector1D.h index 353cb8ab047..09501594e10 100644 --- a/Device/Detector/SpecularDetector1D.h +++ b/Device/Detector/SpecularDetector1D.h @@ -49,7 +49,8 @@ public: void setAxis(const IAxis& axis); //! Return default axes units - Axes::Units defaultAxesUnits() const override; + virtual Axes::Units defaultAxesUnits() const final { return Axes::Units::RADIANS; } + protected: SpecularDetector1D(const SpecularDetector1D& other); diff --git a/Device/Detector/SphericalDetector.cpp b/Device/Detector/SphericalDetector.cpp index 6c4803f6529..a1686167e80 100644 --- a/Device/Detector/SphericalDetector.cpp +++ b/Device/Detector/SphericalDetector.cpp @@ -48,11 +48,6 @@ SphericalDetector* SphericalDetector::clone() const return new SphericalDetector(*this); } -Axes::Units SphericalDetector::defaultAxesUnits() const -{ - return Axes::Units::RADIANS; -} - IPixel* SphericalDetector::createPixel(size_t index) const { const IAxis& phi_axis = axis(0); diff --git a/Device/Detector/SphericalDetector.h b/Device/Detector/SphericalDetector.h index f31460c4cbb..52eef2a455a 100644 --- a/Device/Detector/SphericalDetector.h +++ b/Device/Detector/SphericalDetector.h @@ -53,7 +53,7 @@ public: ~SphericalDetector() override {} //! return default axes units - Axes::Units defaultAxesUnits() const override; + virtual Axes::Units defaultAxesUnits() const final { return Axes::Units::RADIANS; } protected: //! Creates an IPixel for the given OutputData object and index diff --git a/auto/Wrap/doxygenDevice.i b/auto/Wrap/doxygenDevice.i index 2d46df823e6..ef9fd2fa7af 100644 --- a/auto/Wrap/doxygenDevice.i +++ b/auto/Wrap/doxygenDevice.i @@ -881,7 +881,7 @@ Returns detection properties. Returns new intensity map with resolution applied, and cropped to ROI if applicable. "; -%feature("docstring") IDetector::defaultAxesUnits "virtual Axes::Units IDetector::defaultAxesUnits() const +%feature("docstring") IDetector::defaultAxesUnits "virtual Axes::Units IDetector::defaultAxesUnits() const =0 Return default axes units. "; @@ -2263,7 +2263,7 @@ Inits detector with the beam settings. %feature("docstring") RectangularDetector::getDetectorArrangment "RectangularDetector::EDetectorArrangement RectangularDetector::getDetectorArrangment() const "; -%feature("docstring") RectangularDetector::defaultAxesUnits "Axes::Units RectangularDetector::defaultAxesUnits() const override +%feature("docstring") RectangularDetector::defaultAxesUnits "virtual Axes::Units RectangularDetector::defaultAxesUnits() const final return default axes units "; @@ -2577,7 +2577,7 @@ Resets region of interest making whole detector plane available for the simulati %feature("docstring") SpecularDetector1D::setAxis "void SpecularDetector1D::setAxis(const IAxis &axis) "; -%feature("docstring") SpecularDetector1D::defaultAxesUnits "Axes::Units SpecularDetector1D::defaultAxesUnits() const override +%feature("docstring") SpecularDetector1D::defaultAxesUnits "virtual Axes::Units SpecularDetector1D::defaultAxesUnits() const final Return default axes units. "; @@ -2678,7 +2678,7 @@ central alpha angle %feature("docstring") SphericalDetector::~SphericalDetector "SphericalDetector::~SphericalDetector() override "; -%feature("docstring") SphericalDetector::defaultAxesUnits "Axes::Units SphericalDetector::defaultAxesUnits() const override +%feature("docstring") SphericalDetector::defaultAxesUnits "virtual Axes::Units SphericalDetector::defaultAxesUnits() const final return default axes units "; diff --git a/auto/Wrap/libBornAgainDevice.py b/auto/Wrap/libBornAgainDevice.py index 8fc149e36b3..cb2f32659e3 100644 --- a/auto/Wrap/libBornAgainDevice.py +++ b/auto/Wrap/libBornAgainDevice.py @@ -4037,7 +4037,7 @@ class IDetector(libBornAgainBase.ICloneable, libBornAgainParam.INode): def defaultAxesUnits(self): r""" defaultAxesUnits(IDetector self) -> Axes::Units - virtual Axes::Units IDetector::defaultAxesUnits() const + virtual Axes::Units IDetector::defaultAxesUnits() const =0 Return default axes units. @@ -4402,7 +4402,7 @@ class RectangularDetector(IDetector2D): def defaultAxesUnits(self): r""" defaultAxesUnits(RectangularDetector self) -> Axes::Units - Axes::Units RectangularDetector::defaultAxesUnits() const override + virtual Axes::Units RectangularDetector::defaultAxesUnits() const final return default axes units @@ -4464,7 +4464,7 @@ class SphericalDetector(IDetector2D): def defaultAxesUnits(self): r""" defaultAxesUnits(SphericalDetector self) -> Axes::Units - Axes::Units SphericalDetector::defaultAxesUnits() const override + virtual Axes::Units SphericalDetector::defaultAxesUnits() const final return default axes units diff --git a/auto/Wrap/libBornAgainDevice_wrap.cpp b/auto/Wrap/libBornAgainDevice_wrap.cpp index e73747c2a4b..a88ac3eff81 100644 --- a/auto/Wrap/libBornAgainDevice_wrap.cpp +++ b/auto/Wrap/libBornAgainDevice_wrap.cpp @@ -45206,7 +45206,7 @@ static PyMethodDef SwigMethods[] = { ""}, { "IDetector_defaultAxesUnits", _wrap_IDetector_defaultAxesUnits, METH_O, "\n" "IDetector_defaultAxesUnits(IDetector self) -> Axes::Units\n" - "virtual Axes::Units IDetector::defaultAxesUnits() const\n" + "virtual Axes::Units IDetector::defaultAxesUnits() const =0\n" "\n" "Return default axes units. \n" "\n" @@ -45431,7 +45431,7 @@ static PyMethodDef SwigMethods[] = { ""}, { "RectangularDetector_defaultAxesUnits", _wrap_RectangularDetector_defaultAxesUnits, METH_O, "\n" "RectangularDetector_defaultAxesUnits(RectangularDetector self) -> Axes::Units\n" - "Axes::Units RectangularDetector::defaultAxesUnits() const override\n" + "virtual Axes::Units RectangularDetector::defaultAxesUnits() const final\n" "\n" "return default axes units \n" "\n" @@ -45468,7 +45468,7 @@ static PyMethodDef SwigMethods[] = { ""}, { "SphericalDetector_defaultAxesUnits", _wrap_SphericalDetector_defaultAxesUnits, METH_O, "\n" "SphericalDetector_defaultAxesUnits(SphericalDetector self) -> Axes::Units\n" - "Axes::Units SphericalDetector::defaultAxesUnits() const override\n" + "virtual Axes::Units SphericalDetector::defaultAxesUnits() const final\n" "\n" "return default axes units \n" "\n" -- GitLab From 9346609d77698bb2917771d04198e31cd369d093 Mon Sep 17 00:00:00 2001 From: "Joachim Wuttke (h)" <j.wuttke@fz-juelich.de> Date: Fri, 23 Apr 2021 11:27:45 +0200 Subject: [PATCH 07/18] argument units_type -> units --- Core/Scan/UnitConverter1D.cpp | 28 ++++++++++---------- Core/Scan/UnitConverter1D.h | 12 ++++----- Device/Detector/UnitConverter2D.cpp | 40 ++++++++++++++--------------- Device/Detector/UnitConverter2D.h | 16 ++++++------ Device/Unit/IUnitConverter.cpp | 4 +-- Device/Unit/IUnitConverter.h | 6 ++--- auto/Wrap/doxygenCore.i | 23 ++++------------- auto/Wrap/doxygenDevice.i | 10 ++++---- 8 files changed, 63 insertions(+), 76 deletions(-) diff --git a/Core/Scan/UnitConverter1D.cpp b/Core/Scan/UnitConverter1D.cpp index b214b42d4f1..7155695e798 100644 --- a/Core/Scan/UnitConverter1D.cpp +++ b/Core/Scan/UnitConverter1D.cpp @@ -67,24 +67,24 @@ size_t UnitConverter1D::dimension() const return 1u; } -double UnitConverter1D::calculateMin(size_t i_axis, Axes::Units units_type) const +double UnitConverter1D::calculateMin(size_t i_axis, Axes::Units units) const { ASSERT(i_axis == 0); - units_type = substituteDefaultUnits(units_type); - if (units_type == Axes::Units::NBINS) + units = substituteDefaultUnits(units); + if (units == Axes::Units::NBINS) return 0.0; - auto translator = getTraslatorTo(units_type); + auto translator = getTraslatorTo(units); return translator(coordinateAxis()->binCenter(0)); } -double UnitConverter1D::calculateMax(size_t i_axis, Axes::Units units_type) const +double UnitConverter1D::calculateMax(size_t i_axis, Axes::Units units) const { ASSERT(i_axis == 0); - units_type = substituteDefaultUnits(units_type); + units = substituteDefaultUnits(units); auto coordinate_axis = coordinateAxis(); - if (units_type == Axes::Units::NBINS) + if (units == Axes::Units::NBINS) return static_cast<double>(coordinate_axis->size()); - auto translator = getTraslatorTo(units_type); + auto translator = getTraslatorTo(units); return translator(coordinate_axis->binCenter(coordinate_axis->size() - 1)); } @@ -170,9 +170,9 @@ std::vector<std::map<Axes::Units, std::string>> UnitConverterConvSpec::createNam return {AxisNames::specAxis}; } -std::function<double(double)> UnitConverterConvSpec::getTraslatorFrom(Axes::Units units_type) const +std::function<double(double)> UnitConverterConvSpec::getTraslatorFrom(Axes::Units units) const { - switch (units_type) { + switch (units) { case Axes::Units::RADIANS: return [](double value) { return value; }; case Axes::Units::DEGREES: @@ -185,9 +185,9 @@ std::function<double(double)> UnitConverterConvSpec::getTraslatorFrom(Axes::Unit } } -std::function<double(double)> UnitConverterConvSpec::getTraslatorTo(Axes::Units units_type) const +std::function<double(double)> UnitConverterConvSpec::getTraslatorTo(Axes::Units units) const { - switch (units_type) { + switch (units) { case Axes::Units::RADIANS: return [](double value) { return value; }; case Axes::Units::DEGREES: @@ -249,9 +249,9 @@ std::vector<std::map<Axes::Units, std::string>> UnitConverterQSpec::createNameMa } //! Returns translating functional (inv. nm --> desired units) -std::function<double(double)> UnitConverterQSpec::getTraslatorTo(Axes::Units units_type) const +std::function<double(double)> UnitConverterQSpec::getTraslatorTo(Axes::Units units) const { - switch (units_type) { + switch (units) { case Axes::Units::QSPACE: return [](double value) { return value; }; case Axes::Units::RQ4: diff --git a/Core/Scan/UnitConverter1D.h b/Core/Scan/UnitConverter1D.h index 1c86f80cc6d..d2257a6a235 100644 --- a/Core/Scan/UnitConverter1D.h +++ b/Core/Scan/UnitConverter1D.h @@ -44,10 +44,10 @@ public: size_t dimension() const override; //! Calculates minimum on-axis value in given units. - double calculateMin(size_t i_axis, Axes::Units units_type) const override; + double calculateMin(size_t i_axis, Axes::Units units) const override; //! Calculates maximum on-axis value in given units. - double calculateMax(size_t i_axis, Axes::Units units_type) const override; + double calculateMax(size_t i_axis, Axes::Units units) const override; //! Creates axis in converted units. std::unique_ptr<IAxis> createConvertedAxis(size_t i_axis, Axes::Units units) const override; @@ -58,7 +58,7 @@ public: protected: //! Returns translating functional (rads --> output units) - virtual std::function<double(double)> getTraslatorTo(Axes::Units units_type) const = 0; + virtual std::function<double(double)> getTraslatorTo(Axes::Units units) const = 0; virtual const IAxis* coordinateAxis() const = 0; }; @@ -90,10 +90,10 @@ protected: std::vector<std::map<Axes::Units, std::string>> createNameMaps() const override; //! Returns translating functional (input units --> rads) - std::function<double(double)> getTraslatorFrom(Axes::Units units_type) const; + std::function<double(double)> getTraslatorFrom(Axes::Units units) const; //! Returns translating functional (rads --> desired units) - std::function<double(double)> getTraslatorTo(Axes::Units units_type) const override; + std::function<double(double)> getTraslatorTo(Axes::Units units) const override; const IAxis* coordinateAxis() const override { return m_axis.get(); } @@ -125,7 +125,7 @@ protected: std::vector<std::map<Axes::Units, std::string>> createNameMaps() const override; //! Returns translating functional (inv. nm --> desired units) - std::function<double(double)> getTraslatorTo(Axes::Units units_type) const override; + std::function<double(double)> getTraslatorTo(Axes::Units units) const override; const IAxis* coordinateAxis() const override { return m_axis.get(); } diff --git a/Device/Detector/UnitConverter2D.cpp b/Device/Detector/UnitConverter2D.cpp index 411dead2e09..4c49d007d89 100644 --- a/Device/Detector/UnitConverter2D.cpp +++ b/Device/Detector/UnitConverter2D.cpp @@ -54,24 +54,24 @@ void UnitConverterSimple::addAxisData(std::string name, double min, double max, m_axis_data_table.emplace_back(AxisData{name, min, max, default_units, nbins}); } -double UnitConverterSimple::calculateMin(size_t i_axis, Axes::Units units_type) const +double UnitConverterSimple::calculateMin(size_t i_axis, Axes::Units units) const { ASSERT(i_axis < dimension()); - units_type = substituteDefaultUnits(units_type); + units = substituteDefaultUnits(units); const auto& axis_data = m_axis_data_table[i_axis]; - if (units_type == Axes::Units::NBINS) + if (units == Axes::Units::NBINS) return 0.0; - return calculateValue(i_axis, units_type, axis_data.min); + return calculateValue(i_axis, units, axis_data.min); } -double UnitConverterSimple::calculateMax(size_t i_axis, Axes::Units units_type) const +double UnitConverterSimple::calculateMax(size_t i_axis, Axes::Units units) const { ASSERT(i_axis < dimension()); - units_type = substituteDefaultUnits(units_type); + units = substituteDefaultUnits(units); const auto& axis_data = m_axis_data_table[i_axis]; - if (units_type == Axes::Units::NBINS) + if (units == Axes::Units::NBINS) return static_cast<double>(axis_data.nbins); - return calculateValue(i_axis, units_type, axis_data.max); + return calculateValue(i_axis, units, axis_data.max); } size_t UnitConverterSimple::axisSize(size_t i_axis) const @@ -166,9 +166,9 @@ SphericalConverter::SphericalConverter(const SphericalConverter& other) : UnitCo { } -double SphericalConverter::calculateValue(size_t i_axis, Axes::Units units_type, double value) const +double SphericalConverter::calculateValue(size_t i_axis, Axes::Units units, double value) const { - switch (units_type) { + switch (units) { case Axes::Units::RADIANS: return value; case Axes::Units::DEGREES: @@ -247,10 +247,10 @@ RectangularConverter::RectangularConverter(const RectangularConverter& other) { } -double RectangularConverter::calculateValue(size_t i_axis, Axes::Units units_type, +double RectangularConverter::calculateValue(size_t i_axis, Axes::Units units, double value) const { - if (units_type == Axes::Units::MM) + if (units == Axes::Units::MM) return value; const auto k00 = m_detector_pixel->getPosition(0.0, 0.0); const auto k01 = m_detector_pixel->getPosition(0.0, 1.0); @@ -258,7 +258,7 @@ double RectangularConverter::calculateValue(size_t i_axis, Axes::Units units_typ const auto& max_pos = i_axis == 0 ? k10 : k01; // position of max along given axis const double shift = value - m_axis_data_table[i_axis].min; const auto k_f = normalizeToWavelength(k00 + shift * (max_pos - k00).unit()); - switch (units_type) { + switch (units) { case Axes::Units::RADIANS: return axisAngle(i_axis, k_f); case Axes::Units::DEGREES: @@ -342,9 +342,9 @@ OffSpecularConverter::OffSpecularConverter(const OffSpecularConverter& other) { } -double OffSpecularConverter::calculateValue(size_t, Axes::Units units_type, double value) const +double OffSpecularConverter::calculateValue(size_t, Axes::Units units, double value) const { - switch (units_type) { + switch (units) { case Axes::Units::RADIANS: return value; case Axes::Units::DEGREES: @@ -425,13 +425,13 @@ DepthProbeConverter::DepthProbeConverter(const DepthProbeConverter& other) { } -double DepthProbeConverter::calculateValue(size_t i_axis, Axes::Units units_type, +double DepthProbeConverter::calculateValue(size_t i_axis, Axes::Units units, double value) const { - checkUnits(units_type); + checkUnits(units); if (i_axis == 1) return value; // unit conversions are not applied to sample position axis - switch (units_type) { + switch (units) { case Axes::Units::DEGREES: return Units::rad2deg(value); case Axes::Units::QSPACE: @@ -446,10 +446,10 @@ std::vector<std::map<Axes::Units, std::string>> DepthProbeConverter::createNameM return {AxisNames::specAxis, AxisNames::sampleDepthAxis}; } -void DepthProbeConverter::checkUnits(Axes::Units units_type) const +void DepthProbeConverter::checkUnits(Axes::Units units) const { const auto& available_units = availableUnits(); - if (std::find(available_units.begin(), available_units.end(), units_type) + if (std::find(available_units.begin(), available_units.end(), units) == available_units.cend()) throwUnitsError("DepthProbeConverter::checkUnits", available_units); } diff --git a/Device/Detector/UnitConverter2D.h b/Device/Detector/UnitConverter2D.h index 0e47eb9935c..4231eece938 100644 --- a/Device/Detector/UnitConverter2D.h +++ b/Device/Detector/UnitConverter2D.h @@ -41,8 +41,8 @@ public: virtual size_t dimension() const override; - double calculateMin(size_t i_axis, Axes::Units units_type) const override; - double calculateMax(size_t i_axis, Axes::Units units_type) const override; + double calculateMin(size_t i_axis, Axes::Units units) const override; + double calculateMax(size_t i_axis, Axes::Units units) const override; size_t axisSize(size_t i_axis) const override; //! Returns the list of all available units @@ -76,7 +76,7 @@ protected: double m_phi_i; private: - virtual double calculateValue(size_t i_axis, Axes::Units units_type, double value) const = 0; + virtual double calculateValue(size_t i_axis, Axes::Units units, double value) const = 0; }; //! IUnitConverter class that handles the unit translations for spherical detectors @@ -98,7 +98,7 @@ public: private: SphericalConverter(const SphericalConverter& other); - double calculateValue(size_t i_axis, Axes::Units units_type, double value) const override; + double calculateValue(size_t i_axis, Axes::Units units, double value) const override; std::vector<std::map<Axes::Units, std::string>> createNameMaps() const override; }; @@ -120,7 +120,7 @@ public: private: RectangularConverter(const RectangularConverter& other); - double calculateValue(size_t i_axis, Axes::Units units_type, double value) const override; + double calculateValue(size_t i_axis, Axes::Units units, double value) const override; std::vector<std::map<Axes::Units, std::string>> createNameMaps() const override; kvector_t normalizeToWavelength(kvector_t vector) const; double axisAngle(size_t i_axis, kvector_t k_f) const; @@ -143,7 +143,7 @@ public: private: OffSpecularConverter(const OffSpecularConverter& other); - double calculateValue(size_t i_axis, Axes::Units units_type, double value) const override; + double calculateValue(size_t i_axis, Axes::Units units, double value) const override; std::vector<std::map<Axes::Units, std::string>> createNameMaps() const override; void addDetectorYAxis(const IDetector2D& detector); }; @@ -166,9 +166,9 @@ public: private: DepthProbeConverter(const DepthProbeConverter& other); - double calculateValue(size_t, Axes::Units units_type, double value) const override; + double calculateValue(size_t, Axes::Units units, double value) const override; std::vector<std::map<Axes::Units, std::string>> createNameMaps() const override; - void checkUnits(Axes::Units units_type) const; + void checkUnits(Axes::Units units) const; }; #endif // BORNAGAIN_DEVICE_DETECTOR_SIMPLEUNITCONVERTERS_H diff --git a/Device/Unit/IUnitConverter.cpp b/Device/Unit/IUnitConverter.cpp index c025796e892..b4805e7d020 100644 --- a/Device/Unit/IUnitConverter.cpp +++ b/Device/Unit/IUnitConverter.cpp @@ -30,7 +30,7 @@ std::unique_ptr<OutputData<double>> IUnitConverter::createOutputData(Axes::Units return result; } -std::string IUnitConverter::axisName(size_t i_axis, const Axes::Units& units_type) const +std::string IUnitConverter::axisName(size_t i_axis, const Axes::Units& units) const { const auto& name_maps = createNameMaps(); if (name_maps.size() <= i_axis) @@ -38,7 +38,7 @@ std::string IUnitConverter::axisName(size_t i_axis, const Axes::Units& units_typ "is smaller or equal to the axis index" + std::to_string(static_cast<int>(i_axis))); const auto& name_map = name_maps[i_axis]; - const auto& it = name_map.find(substituteDefaultUnits(units_type)); + const auto& it = name_map.find(substituteDefaultUnits(units)); if (it == name_map.cend()) throwUnitsError("IUnitConverter::axisName", availableUnits()); return it->second; diff --git a/Device/Unit/IUnitConverter.h b/Device/Unit/IUnitConverter.h index 72a633f31de..3fd0e1740e5 100644 --- a/Device/Unit/IUnitConverter.h +++ b/Device/Unit/IUnitConverter.h @@ -51,11 +51,11 @@ public: virtual size_t dimension() const = 0; - virtual double calculateMin(size_t i_axis, Axes::Units units_type) const = 0; - virtual double calculateMax(size_t i_axis, Axes::Units units_type) const = 0; + virtual double calculateMin(size_t i_axis, Axes::Units units) const = 0; + virtual double calculateMax(size_t i_axis, Axes::Units units) const = 0; virtual size_t axisSize(size_t i_axis) const = 0; - std::string axisName(size_t i_axis, const Axes::Units& units_type = Axes::Units::DEFAULT) const; + std::string axisName(size_t i_axis, const Axes::Units& units = Axes::Units::DEFAULT) const; virtual std::vector<Axes::Units> availableUnits() const = 0; virtual Axes::Units defaultUnits() const = 0; diff --git a/auto/Wrap/doxygenCore.i b/auto/Wrap/doxygenCore.i index 41c715f7ba3..bc97c0bad6f 100644 --- a/auto/Wrap/doxygenCore.i +++ b/auto/Wrap/doxygenCore.i @@ -2165,12 +2165,12 @@ C++ includes: UnitConverter1D.h Returns dimensionality of converted canvas. "; -%feature("docstring") UnitConverter1D::calculateMin "double UnitConverter1D::calculateMin(size_t i_axis, Axes::Units units_type) const override +%feature("docstring") UnitConverter1D::calculateMin "double UnitConverter1D::calculateMin(size_t i_axis, Axes::Units units) const override Calculates minimum on-axis value in given units. "; -%feature("docstring") UnitConverter1D::calculateMax "double UnitConverter1D::calculateMax(size_t i_axis, Axes::Units units_type) const override +%feature("docstring") UnitConverter1D::calculateMax "double UnitConverter1D::calculateMax(size_t i_axis, Axes::Units units) const override Calculates maximum on-axis value in given units. "; @@ -2290,9 +2290,6 @@ C++ includes: VarianceFunctions.h "; -// File: namespace_0d100.xml - - // File: namespace_0d15.xml @@ -2335,6 +2332,9 @@ C++ includes: VarianceFunctions.h // File: namespace_0d94.xml +// File: namespace_0d98.xml + + // File: namespaceExportToPython.xml %feature("docstring") ExportToPython::sampleCode "std::string ExportToPython::sampleCode(const MultiLayer &multilayer) "; @@ -2682,13 +2682,6 @@ GISAS simulation with an extra long wavelength. "; -// File: namespaceUnitConverterUtils.xml -%feature("docstring") UnitConverterUtils::createConverterForGISAS "std::unique_ptr< IUnitConverter > UnitConverterUtils::createConverterForGISAS(const Instrument &instrument) - -Helper factory function to use in GISASSimulation. Depending on the type of detector, returns either RectangularConverter or SphericalConverter. -"; - - // File: ComputationStatus_8h.xml @@ -2977,12 +2970,6 @@ Helper factory function to use in GISASSimulation. Depending on the type of det // File: StandardSimulations_8h.xml -// File: UnitConverterUtils_8cpp.xml - - -// File: UnitConverterUtils_8h.xml - - // File: DepthProbeComputationTerm_8cpp.xml diff --git a/auto/Wrap/doxygenDevice.i b/auto/Wrap/doxygenDevice.i index ef9fd2fa7af..e6669fa20fe 100644 --- a/auto/Wrap/doxygenDevice.i +++ b/auto/Wrap/doxygenDevice.i @@ -1477,16 +1477,16 @@ Returns zero-valued output data array in specified units. %feature("docstring") IUnitConverter::dimension "virtual size_t IUnitConverter::dimension() const =0 "; -%feature("docstring") IUnitConverter::calculateMin "virtual double IUnitConverter::calculateMin(size_t i_axis, Axes::Units units_type) const =0 +%feature("docstring") IUnitConverter::calculateMin "virtual double IUnitConverter::calculateMin(size_t i_axis, Axes::Units units) const =0 "; -%feature("docstring") IUnitConverter::calculateMax "virtual double IUnitConverter::calculateMax(size_t i_axis, Axes::Units units_type) const =0 +%feature("docstring") IUnitConverter::calculateMax "virtual double IUnitConverter::calculateMax(size_t i_axis, Axes::Units units) const =0 "; %feature("docstring") IUnitConverter::axisSize "virtual size_t IUnitConverter::axisSize(size_t i_axis) const =0 "; -%feature("docstring") IUnitConverter::axisName "std::string IUnitConverter::axisName(size_t i_axis, const Axes::Units &units_type=Axes::Units::DEFAULT) const +%feature("docstring") IUnitConverter::axisName "std::string IUnitConverter::axisName(size_t i_axis, const Axes::Units &units=Axes::Units::DEFAULT) const "; %feature("docstring") IUnitConverter::availableUnits "virtual std::vector<Axes::Units> IUnitConverter::availableUnits() const =0 @@ -2701,10 +2701,10 @@ C++ includes: UnitConverter2D.h %feature("docstring") UnitConverterSimple::dimension "size_t UnitConverterSimple::dimension() const override "; -%feature("docstring") UnitConverterSimple::calculateMin "double UnitConverterSimple::calculateMin(size_t i_axis, Axes::Units units_type) const override +%feature("docstring") UnitConverterSimple::calculateMin "double UnitConverterSimple::calculateMin(size_t i_axis, Axes::Units units) const override "; -%feature("docstring") UnitConverterSimple::calculateMax "double UnitConverterSimple::calculateMax(size_t i_axis, Axes::Units units_type) const override +%feature("docstring") UnitConverterSimple::calculateMax "double UnitConverterSimple::calculateMax(size_t i_axis, Axes::Units units) const override "; %feature("docstring") UnitConverterSimple::axisSize "size_t UnitConverterSimple::axisSize(size_t i_axis) const override -- GitLab From a9aefdf6986fb54c3f433d5caee20192057b6bf2 Mon Sep 17 00:00:00 2001 From: "Joachim Wuttke (h)" <j.wuttke@fz-juelich.de> Date: Fri, 23 Apr 2021 11:37:52 +0200 Subject: [PATCH 08/18] now really class UnitConverter2D --- Core/Fitting/SimDataPair.cpp | 2 +- Core/Simulation/GISASSimulation.cpp | 2 +- Device/Detector/UnitConverter2D.cpp | 48 +++++++++++----------- Device/Detector/UnitConverter2D.h | 20 ++++----- Device/Unit/IUnitConverter.cpp | 5 +-- GUI/coregui/Models/DomainObjectBuilder.cpp | 2 +- 6 files changed, 38 insertions(+), 41 deletions(-) diff --git a/Core/Fitting/SimDataPair.cpp b/Core/Fitting/SimDataPair.cpp index 29f50b8548d..fd4548c0772 100644 --- a/Core/Fitting/SimDataPair.cpp +++ b/Core/Fitting/SimDataPair.cpp @@ -51,7 +51,7 @@ bool detHasSameDimensions(const IDetector& detector, const OutputData<double>& d std::unique_ptr<IUnitConverter> createConverter(const ISimulation& simulation) { if (auto gisas = dynamic_cast<const GISASSimulation*>(&simulation)) - return UnitConverterSimple::createConverterForGISAS(gisas->instrument()); + return UnitConverter2D::createConverterForGISAS(gisas->instrument()); if (auto spec = dynamic_cast<const SpecularSimulation*>(&simulation)) return UnitConverter1D::createUnitConverter(*spec->dataHandler()); diff --git a/Core/Simulation/GISASSimulation.cpp b/Core/Simulation/GISASSimulation.cpp index fa98019d9af..fc87164d162 100644 --- a/Core/Simulation/GISASSimulation.cpp +++ b/Core/Simulation/GISASSimulation.cpp @@ -57,7 +57,7 @@ void GISASSimulation::prepareSimulation() SimulationResult GISASSimulation::result() const { - const auto converter = UnitConverterSimple::createConverterForGISAS(instrument()); + const auto converter = UnitConverter2D::createConverterForGISAS(instrument()); const std::unique_ptr<OutputData<double>> data( detector().createDetectorIntensity(m_sim_elements)); return SimulationResult(*data, *converter); diff --git a/Device/Detector/UnitConverter2D.cpp b/Device/Detector/UnitConverter2D.cpp index 4c49d007d89..29f24afd5ac 100644 --- a/Device/Detector/UnitConverter2D.cpp +++ b/Device/Detector/UnitConverter2D.cpp @@ -33,28 +33,28 @@ double getQ(double wavelength, double angle) } // namespace // ************************************************************************************************ -// class UnitConverterSimple +// class UnitConverter2D // ************************************************************************************************ -UnitConverterSimple::UnitConverterSimple(const Beam& beam) +UnitConverter2D::UnitConverter2D(const Beam& beam) : m_wavelength(beam.wavelength()) , m_alpha_i(-beam.direction().alpha()) , m_phi_i(beam.direction().phi()) { } -size_t UnitConverterSimple::dimension() const +size_t UnitConverter2D::dimension() const { return m_axis_data_table.size(); } -void UnitConverterSimple::addAxisData(std::string name, double min, double max, +void UnitConverter2D::addAxisData(std::string name, double min, double max, Axes::Units default_units, size_t nbins) { m_axis_data_table.emplace_back(AxisData{name, min, max, default_units, nbins}); } -double UnitConverterSimple::calculateMin(size_t i_axis, Axes::Units units) const +double UnitConverter2D::calculateMin(size_t i_axis, Axes::Units units) const { ASSERT(i_axis < dimension()); units = substituteDefaultUnits(units); @@ -64,7 +64,7 @@ double UnitConverterSimple::calculateMin(size_t i_axis, Axes::Units units) const return calculateValue(i_axis, units, axis_data.min); } -double UnitConverterSimple::calculateMax(size_t i_axis, Axes::Units units) const +double UnitConverter2D::calculateMax(size_t i_axis, Axes::Units units) const { ASSERT(i_axis < dimension()); units = substituteDefaultUnits(units); @@ -74,18 +74,18 @@ double UnitConverterSimple::calculateMax(size_t i_axis, Axes::Units units) const return calculateValue(i_axis, units, axis_data.max); } -size_t UnitConverterSimple::axisSize(size_t i_axis) const +size_t UnitConverter2D::axisSize(size_t i_axis) const { ASSERT(i_axis < dimension()); return m_axis_data_table[i_axis].nbins; } -std::vector<Axes::Units> UnitConverterSimple::availableUnits() const +std::vector<Axes::Units> UnitConverter2D::availableUnits() const { return {Axes::Units::NBINS, Axes::Units::RADIANS, Axes::Units::DEGREES}; } -std::unique_ptr<IAxis> UnitConverterSimple::createConvertedAxis(size_t i_axis, +std::unique_ptr<IAxis> UnitConverter2D::createConvertedAxis(size_t i_axis, Axes::Units units) const { const double min = calculateMin(i_axis, units); @@ -95,7 +95,7 @@ std::unique_ptr<IAxis> UnitConverterSimple::createConvertedAxis(size_t i_axis, return std::make_unique<FixedBinAxis>(axis_name, axis_size, min, max); } -UnitConverterSimple::UnitConverterSimple(const UnitConverterSimple& other) +UnitConverter2D::UnitConverter2D(const UnitConverter2D& other) : m_axis_data_table(other.m_axis_data_table) , m_wavelength(other.m_wavelength) , m_alpha_i(other.m_alpha_i) @@ -103,7 +103,7 @@ UnitConverterSimple::UnitConverterSimple(const UnitConverterSimple& other) { } -void UnitConverterSimple::addDetectorAxis(const IDetector& detector, size_t i_axis) +void UnitConverter2D::addDetectorAxis(const IDetector& detector, size_t i_axis) { const auto& axis = detector.axis(i_axis); const auto* p_roi = detector.regionOfInterest(); @@ -117,8 +117,8 @@ void UnitConverterSimple::addDetectorAxis(const IDetector& detector, size_t i_ax P_roi_axis->size()); } -std::unique_ptr<UnitConverterSimple> -UnitConverterSimple::createConverterForGISAS(const Instrument& instrument) +std::unique_ptr<UnitConverter2D> +UnitConverter2D::createConverterForGISAS(const Instrument& instrument) { const IDetector* const detector = instrument.getDetector(); @@ -136,7 +136,7 @@ UnitConverterSimple::createConverterForGISAS(const Instrument& instrument) // ************************************************************************************************ SphericalConverter::SphericalConverter(const SphericalDetector& detector, const Beam& beam) - : UnitConverterSimple(beam) + : UnitConverter2D(beam) { ASSERT(detector.dimension() == 2); addDetectorAxis(detector, 0); @@ -152,7 +152,7 @@ SphericalConverter* SphericalConverter::clone() const std::vector<Axes::Units> SphericalConverter::availableUnits() const { - auto result = UnitConverterSimple::availableUnits(); + auto result = UnitConverter2D::availableUnits(); result.push_back(Axes::Units::QSPACE); return result; } @@ -162,7 +162,7 @@ Axes::Units SphericalConverter::defaultUnits() const return Axes::Units::DEGREES; } -SphericalConverter::SphericalConverter(const SphericalConverter& other) : UnitConverterSimple(other) +SphericalConverter::SphericalConverter(const SphericalConverter& other) : UnitConverter2D(other) { } @@ -214,7 +214,7 @@ std::vector<std::map<Axes::Units, std::string>> SphericalConverter::createNameMa // ************************************************************************************************ RectangularConverter::RectangularConverter(const RectangularDetector& detector, const Beam& beam) - : UnitConverterSimple(beam) + : UnitConverter2D(beam) { ASSERT(detector.dimension() == 2); addDetectorAxis(detector, 0); @@ -231,7 +231,7 @@ RectangularConverter* RectangularConverter::clone() const std::vector<Axes::Units> RectangularConverter::availableUnits() const { - auto result = UnitConverterSimple::availableUnits(); + auto result = UnitConverter2D::availableUnits(); result.push_back(Axes::Units::QSPACE); result.push_back(Axes::Units::MM); return result; @@ -243,7 +243,7 @@ Axes::Units RectangularConverter::defaultUnits() const } RectangularConverter::RectangularConverter(const RectangularConverter& other) - : UnitConverterSimple(other), m_detector_pixel(other.m_detector_pixel->clone()) + : UnitConverter2D(other), m_detector_pixel(other.m_detector_pixel->clone()) { } @@ -317,7 +317,7 @@ double RectangularConverter::axisAngle(size_t i_axis, kvector_t k_f) const OffSpecularConverter::OffSpecularConverter(const IDetector2D& detector, const Beam& beam, const IAxis& alpha_axis) - : UnitConverterSimple(beam) + : UnitConverter2D(beam) { ASSERT(detector.dimension() == 2); addAxisData(axisName(0), alpha_axis.lowerBound(), alpha_axis.upperBound(), defaultUnits(), @@ -338,7 +338,7 @@ Axes::Units OffSpecularConverter::defaultUnits() const } OffSpecularConverter::OffSpecularConverter(const OffSpecularConverter& other) - : UnitConverterSimple(other) + : UnitConverter2D(other) { } @@ -396,7 +396,7 @@ const std::string z_axis_name = "Position [nm]"; DepthProbeConverter::DepthProbeConverter(const Beam& beam, const IAxis& alpha_axis, const IAxis& z_axis) - : UnitConverterSimple(beam) + : UnitConverter2D(beam) { const auto& alpha_axis_name = axisName(0); const auto& z_axis_name = axisName(1); @@ -415,13 +415,13 @@ DepthProbeConverter* DepthProbeConverter::clone() const std::vector<Axes::Units> DepthProbeConverter::availableUnits() const { - auto result = UnitConverterSimple::availableUnits(); + auto result = UnitConverter2D::availableUnits(); result.push_back(Axes::Units::QSPACE); return result; } DepthProbeConverter::DepthProbeConverter(const DepthProbeConverter& other) - : UnitConverterSimple(other) + : UnitConverter2D(other) { } diff --git a/Device/Detector/UnitConverter2D.h b/Device/Detector/UnitConverter2D.h index 4231eece938..ccfb7080aa2 100644 --- a/Device/Detector/UnitConverter2D.h +++ b/Device/Detector/UnitConverter2D.h @@ -3,7 +3,7 @@ // BornAgain: simulate and fit reflection and scattering // //! @file Device/Detector/UnitConverter2D.h -//! @brief Defines interface UnitConverterSimple and its subclasses. +//! @brief Defines interface UnitConverter2D and its subclasses. //! //! @homepage http://www.bornagainproject.org //! @license GNU General Public License v3 or higher (see COPYING) @@ -34,10 +34,10 @@ class SphericalDetector; //! Interface for objects that provide axis translations to different units for IDetector objects //! @ingroup simulation_internal -class UnitConverterSimple : public IUnitConverter { +class UnitConverter2D : public IUnitConverter { public: - UnitConverterSimple(const Beam& beam); - ~UnitConverterSimple() override = default; + UnitConverter2D(const Beam& beam); + ~UnitConverter2D() override = default; virtual size_t dimension() const override; @@ -52,11 +52,11 @@ public: //! Helper factory function to use in GISASSimulation. Depending on the type of detector, //! returns either RectangularConverter or SphericalConverter. - static std::unique_ptr<UnitConverterSimple> createConverterForGISAS( + static std::unique_ptr<UnitConverter2D> createConverterForGISAS( const Instrument& instrument); protected: - UnitConverterSimple(const UnitConverterSimple& other); + UnitConverter2D(const UnitConverter2D& other); void addDetectorAxis(const IDetector& detector, size_t i_axis); void addAxisData(std::string name, double min, double max, Axes::Units default_units, @@ -83,7 +83,7 @@ private: //! Its default units are radians for both axes //! @ingroup simulation_internal -class SphericalConverter : public UnitConverterSimple { +class SphericalConverter : public UnitConverter2D { public: SphericalConverter(const SphericalDetector& detector, const Beam& beam); @@ -106,7 +106,7 @@ private: //! Its default units are mm for both axes //! @ingroup simulation_internal -class RectangularConverter : public UnitConverterSimple { +class RectangularConverter : public UnitConverter2D { public: RectangularConverter(const RectangularDetector& detector, const Beam& beam); ~RectangularConverter() override; @@ -132,7 +132,7 @@ private: //! Its default units are radians for both axes //! @ingroup simulation_internal -class OffSpecularConverter : public UnitConverterSimple { +class OffSpecularConverter : public UnitConverter2D { public: OffSpecularConverter(const IDetector2D& detector, const Beam& beam, const IAxis& alpha_axis); ~OffSpecularConverter() override; @@ -152,7 +152,7 @@ private: //! Its default units are radians for x-axis and nm for y-axis //! @ingroup simulation_internal -class DepthProbeConverter : public UnitConverterSimple { +class DepthProbeConverter : public UnitConverter2D { public: DepthProbeConverter(const Beam& beam, const IAxis& alpha_axis, const IAxis& z_axis); ~DepthProbeConverter() override; diff --git a/Device/Unit/IUnitConverter.cpp b/Device/Unit/IUnitConverter.cpp index b4805e7d020..6c2f114744f 100644 --- a/Device/Unit/IUnitConverter.cpp +++ b/Device/Unit/IUnitConverter.cpp @@ -19,8 +19,6 @@ IUnitConverter::~IUnitConverter() = default; - - std::unique_ptr<OutputData<double>> IUnitConverter::createOutputData(Axes::Units units) const { std::unique_ptr<OutputData<double>> result = std::make_unique<OutputData<double>>(); @@ -39,8 +37,7 @@ std::string IUnitConverter::axisName(size_t i_axis, const Axes::Units& units) co + std::to_string(static_cast<int>(i_axis))); const auto& name_map = name_maps[i_axis]; const auto& it = name_map.find(substituteDefaultUnits(units)); - if (it == name_map.cend()) - throwUnitsError("IUnitConverter::axisName", availableUnits()); + ASSERT(it != name_map.cend()); return it->second; } diff --git a/GUI/coregui/Models/DomainObjectBuilder.cpp b/GUI/coregui/Models/DomainObjectBuilder.cpp index 0b548a24d89..12708ff1b0f 100644 --- a/GUI/coregui/Models/DomainObjectBuilder.cpp +++ b/GUI/coregui/Models/DomainObjectBuilder.cpp @@ -139,7 +139,7 @@ DomainObjectBuilder::createUnitConverter(const InstrumentItem* instrumentItem) instrument->initDetector(); if (instrumentItem->is<GISASInstrumentItem>()) - return UnitConverterSimple::createConverterForGISAS(*instrument); + return UnitConverter2D::createConverterForGISAS(*instrument); if (instrumentItem->is<OffSpecularInstrumentItem>()) { auto axis_item = -- GitLab From cbcd07e582416df58baec50cbd940fdcccbcf832 Mon Sep 17 00:00:00 2001 From: "Joachim Wuttke (h)" <j.wuttke@fz-juelich.de> Date: Fri, 23 Apr 2021 12:30:33 +0200 Subject: [PATCH 09/18] clang-format --- Core/Fitting/SimDataPair.cpp | 2 +- Core/Simulation/DepthProbeSimulation.cpp | 2 +- Device/Detector/UnitConverter2D.cpp | 23 +++++++------------ Device/Detector/UnitConverter2D.h | 3 +-- GUI/coregui/Models/RealDataItem.cpp | 2 +- .../RealDataSelectorWidget.cpp | 4 ++-- .../Instrument/OffSpecularConverterTest.cpp | 2 +- .../Instrument/SphericalConverterTest.cpp | 2 +- auto/Wrap/doxygenDevice.i | 22 +++++++++--------- 9 files changed, 27 insertions(+), 35 deletions(-) diff --git a/Core/Fitting/SimDataPair.cpp b/Core/Fitting/SimDataPair.cpp index fd4548c0772..d4f11ea909d 100644 --- a/Core/Fitting/SimDataPair.cpp +++ b/Core/Fitting/SimDataPair.cpp @@ -15,9 +15,9 @@ #include "Core/Fitting/SimDataPair.h" #include "Base/Math/Numeric.h" #include "Core/Scan/UnitConverter1D.h" -#include "Device/Detector/UnitConverter2D.h" #include "Core/Simulation/includeSimulations.h" #include "Device/Data/DataUtils.h" +#include "Device/Detector/UnitConverter2D.h" namespace { diff --git a/Core/Simulation/DepthProbeSimulation.cpp b/Core/Simulation/DepthProbeSimulation.cpp index 535814835cd..58d5b9f8f6a 100644 --- a/Core/Simulation/DepthProbeSimulation.cpp +++ b/Core/Simulation/DepthProbeSimulation.cpp @@ -16,8 +16,8 @@ #include "Core/Computation/DepthProbeComputation.h" #include "Core/Computation/IBackground.h" #include "Device/Beam/IFootprintFactor.h" -#include "Device/Detector/UnitConverter2D.h" #include "Device/Detector/SpecularDetector1D.h" +#include "Device/Detector/UnitConverter2D.h" #include "Param/Base/ParameterPool.h" #include "Param/Base/RealParameter.h" #include "Param/Distrib/Distributions.h" diff --git a/Device/Detector/UnitConverter2D.cpp b/Device/Detector/UnitConverter2D.cpp index 29f24afd5ac..74a6d1e96b9 100644 --- a/Device/Detector/UnitConverter2D.cpp +++ b/Device/Detector/UnitConverter2D.cpp @@ -16,9 +16,9 @@ #include "Base/Const/Units.h" #include "Base/Math/Constants.h" #include "Base/Pixel/RectangularPixel.h" -#include "Device/Instrument/Instrument.h" #include "Device/Detector/RectangularDetector.h" #include "Device/Detector/SphericalDetector.h" +#include "Device/Instrument/Instrument.h" #include "Device/ProDetector/RegionOfInterest.h" #include "Device/Unit/AxisNames.h" #include <algorithm> @@ -49,7 +49,7 @@ size_t UnitConverter2D::dimension() const } void UnitConverter2D::addAxisData(std::string name, double min, double max, - Axes::Units default_units, size_t nbins) + Axes::Units default_units, size_t nbins) { m_axis_data_table.emplace_back(AxisData{name, min, max, default_units, nbins}); } @@ -85,8 +85,7 @@ std::vector<Axes::Units> UnitConverter2D::availableUnits() const return {Axes::Units::NBINS, Axes::Units::RADIANS, Axes::Units::DEGREES}; } -std::unique_ptr<IAxis> UnitConverter2D::createConvertedAxis(size_t i_axis, - Axes::Units units) const +std::unique_ptr<IAxis> UnitConverter2D::createConvertedAxis(size_t i_axis, Axes::Units units) const { const double min = calculateMin(i_axis, units); const double max = calculateMax(i_axis, units); @@ -162,9 +161,7 @@ Axes::Units SphericalConverter::defaultUnits() const return Axes::Units::DEGREES; } -SphericalConverter::SphericalConverter(const SphericalConverter& other) : UnitConverter2D(other) -{ -} +SphericalConverter::SphericalConverter(const SphericalConverter& other) : UnitConverter2D(other) {} double SphericalConverter::calculateValue(size_t i_axis, Axes::Units units, double value) const { @@ -247,8 +244,7 @@ RectangularConverter::RectangularConverter(const RectangularConverter& other) { } -double RectangularConverter::calculateValue(size_t i_axis, Axes::Units units, - double value) const +double RectangularConverter::calculateValue(size_t i_axis, Axes::Units units, double value) const { if (units == Axes::Units::MM) return value; @@ -420,13 +416,11 @@ std::vector<Axes::Units> DepthProbeConverter::availableUnits() const return result; } -DepthProbeConverter::DepthProbeConverter(const DepthProbeConverter& other) - : UnitConverter2D(other) +DepthProbeConverter::DepthProbeConverter(const DepthProbeConverter& other) : UnitConverter2D(other) { } -double DepthProbeConverter::calculateValue(size_t i_axis, Axes::Units units, - double value) const +double DepthProbeConverter::calculateValue(size_t i_axis, Axes::Units units, double value) const { checkUnits(units); if (i_axis == 1) @@ -449,7 +443,6 @@ std::vector<std::map<Axes::Units, std::string>> DepthProbeConverter::createNameM void DepthProbeConverter::checkUnits(Axes::Units units) const { const auto& available_units = availableUnits(); - if (std::find(available_units.begin(), available_units.end(), units) - == available_units.cend()) + if (std::find(available_units.begin(), available_units.end(), units) == available_units.cend()) throwUnitsError("DepthProbeConverter::checkUnits", available_units); } diff --git a/Device/Detector/UnitConverter2D.h b/Device/Detector/UnitConverter2D.h index ccfb7080aa2..eddea1de3ce 100644 --- a/Device/Detector/UnitConverter2D.h +++ b/Device/Detector/UnitConverter2D.h @@ -52,8 +52,7 @@ public: //! Helper factory function to use in GISASSimulation. Depending on the type of detector, //! returns either RectangularConverter or SphericalConverter. - static std::unique_ptr<UnitConverter2D> createConverterForGISAS( - const Instrument& instrument); + static std::unique_ptr<UnitConverter2D> createConverterForGISAS(const Instrument& instrument); protected: UnitConverter2D(const UnitConverter2D& other); diff --git a/GUI/coregui/Models/RealDataItem.cpp b/GUI/coregui/Models/RealDataItem.cpp index 949999d78b2..bf528c58552 100644 --- a/GUI/coregui/Models/RealDataItem.cpp +++ b/GUI/coregui/Models/RealDataItem.cpp @@ -181,7 +181,7 @@ void RealDataItem::initDataItem(size_t rank, const QString& tag) const SessionItem* data_item = getItem(tag); if (data_item != nullptr) { if ((rank == 1 && !data_item->is<SpecularDataItem>()) - || (rank == 2 && !data_item->is<IntensityDataItem>())) + || (rank == 2 && !data_item->is<IntensityDataItem>())) throw GUIHelpers::Error("Error in RealDataItem::initDataItem: trying to set data " "incompatible with underlying data item"); } else { diff --git a/GUI/coregui/Views/ImportDataWidgets/RealDataSelectorWidget.cpp b/GUI/coregui/Views/ImportDataWidgets/RealDataSelectorWidget.cpp index 4609c658e2b..2e521f4585d 100644 --- a/GUI/coregui/Views/ImportDataWidgets/RealDataSelectorWidget.cpp +++ b/GUI/coregui/Views/ImportDataWidgets/RealDataSelectorWidget.cpp @@ -299,8 +299,8 @@ void RealDataSelectorWidget::importData2D() m_itemTreeModel->removeItem(realDataItem); const QString message = QString("Error while trying to read file\n\n'%1'\n\n%2") - .arg(fileName) - .arg(QString::fromStdString(std::string(ex.what()))); + .arg(fileName) + .arg(QString::fromStdString(std::string(ex.what()))); GUIHelpers::warning("File import", message); } } diff --git a/Tests/UnitTests/Core/Instrument/OffSpecularConverterTest.cpp b/Tests/UnitTests/Core/Instrument/OffSpecularConverterTest.cpp index 00981acf626..b89bf02b3cb 100644 --- a/Tests/UnitTests/Core/Instrument/OffSpecularConverterTest.cpp +++ b/Tests/UnitTests/Core/Instrument/OffSpecularConverterTest.cpp @@ -1,7 +1,7 @@ #include "Base/Const/Units.h" #include "Device/Beam/Beam.h" -#include "Device/Detector/UnitConverter2D.h" #include "Device/Detector/SphericalDetector.h" +#include "Device/Detector/UnitConverter2D.h" #include "Tests/GTestWrapper/google_test.h" class OffSpecularConverterTest : public ::testing::Test { diff --git a/Tests/UnitTests/Core/Instrument/SphericalConverterTest.cpp b/Tests/UnitTests/Core/Instrument/SphericalConverterTest.cpp index 0823271f580..b17776a8593 100644 --- a/Tests/UnitTests/Core/Instrument/SphericalConverterTest.cpp +++ b/Tests/UnitTests/Core/Instrument/SphericalConverterTest.cpp @@ -1,7 +1,7 @@ #include "Base/Const/Units.h" #include "Device/Beam/Beam.h" -#include "Device/Detector/UnitConverter2D.h" #include "Device/Detector/SphericalDetector.h" +#include "Device/Detector/UnitConverter2D.h" #include "Tests/GTestWrapper/google_test.h" class SphericalConverterTest : public ::testing::Test { diff --git a/auto/Wrap/doxygenDevice.i b/auto/Wrap/doxygenDevice.i index e6669fa20fe..9f8f40f0e17 100644 --- a/auto/Wrap/doxygenDevice.i +++ b/auto/Wrap/doxygenDevice.i @@ -10,7 +10,7 @@ C++ includes: Axes.h "; -// File: structUnitConverterSimple_1_1AxisData.xml +// File: structUnitConverter2D_1_1AxisData.xml // File: structAxisInfo.xml @@ -2684,38 +2684,38 @@ return default axes units "; -// File: classUnitConverterSimple.xml -%feature("docstring") UnitConverterSimple " +// File: classUnitConverter2D.xml +%feature("docstring") UnitConverter2D " Interface for objects that provide axis translations to different units for IDetector objects C++ includes: UnitConverter2D.h "; -%feature("docstring") UnitConverterSimple::UnitConverterSimple "UnitConverterSimple::UnitConverterSimple(const Beam &beam) +%feature("docstring") UnitConverter2D::UnitConverter2D "UnitConverter2D::UnitConverter2D(const Beam &beam) "; -%feature("docstring") UnitConverterSimple::~UnitConverterSimple "UnitConverterSimple::~UnitConverterSimple() override=default +%feature("docstring") UnitConverter2D::~UnitConverter2D "UnitConverter2D::~UnitConverter2D() override=default "; -%feature("docstring") UnitConverterSimple::dimension "size_t UnitConverterSimple::dimension() const override +%feature("docstring") UnitConverter2D::dimension "size_t UnitConverter2D::dimension() const override "; -%feature("docstring") UnitConverterSimple::calculateMin "double UnitConverterSimple::calculateMin(size_t i_axis, Axes::Units units) const override +%feature("docstring") UnitConverter2D::calculateMin "double UnitConverter2D::calculateMin(size_t i_axis, Axes::Units units) const override "; -%feature("docstring") UnitConverterSimple::calculateMax "double UnitConverterSimple::calculateMax(size_t i_axis, Axes::Units units) const override +%feature("docstring") UnitConverter2D::calculateMax "double UnitConverter2D::calculateMax(size_t i_axis, Axes::Units units) const override "; -%feature("docstring") UnitConverterSimple::axisSize "size_t UnitConverterSimple::axisSize(size_t i_axis) const override +%feature("docstring") UnitConverter2D::axisSize "size_t UnitConverter2D::axisSize(size_t i_axis) const override "; -%feature("docstring") UnitConverterSimple::availableUnits "std::vector< Axes::Units > UnitConverterSimple::availableUnits() const override +%feature("docstring") UnitConverter2D::availableUnits "std::vector< Axes::Units > UnitConverter2D::availableUnits() const override Returns the list of all available units. "; -%feature("docstring") UnitConverterSimple::createConvertedAxis "std::unique_ptr< IAxis > UnitConverterSimple::createConvertedAxis(size_t i_axis, Axes::Units units) const override +%feature("docstring") UnitConverter2D::createConvertedAxis "std::unique_ptr< IAxis > UnitConverter2D::createConvertedAxis(size_t i_axis, Axes::Units units) const override "; -- GitLab From 32bb8e6c0df8b338be219be41c52d7f8f5d5451d Mon Sep 17 00:00:00 2001 From: "Joachim Wuttke (h)" <j.wuttke@fz-juelich.de> Date: Fri, 23 Apr 2021 12:46:49 +0200 Subject: [PATCH 10/18] IUnitConverter::axisName: simplify --- Device/Unit/IUnitConverter.cpp | 9 +++------ Device/Unit/IUnitConverter.h | 2 +- auto/Wrap/doxygenDevice.i | 2 +- 3 files changed, 5 insertions(+), 8 deletions(-) diff --git a/Device/Unit/IUnitConverter.cpp b/Device/Unit/IUnitConverter.cpp index 6c2f114744f..1529d72e104 100644 --- a/Device/Unit/IUnitConverter.cpp +++ b/Device/Unit/IUnitConverter.cpp @@ -28,15 +28,12 @@ std::unique_ptr<OutputData<double>> IUnitConverter::createOutputData(Axes::Units return result; } -std::string IUnitConverter::axisName(size_t i_axis, const Axes::Units& units) const +std::string IUnitConverter::axisName(size_t i_axis, const Axes::Units units) const { const auto& name_maps = createNameMaps(); - if (name_maps.size() <= i_axis) - throw std::runtime_error("Error in IUnitConverter::axisName: the size of name map vector " - "is smaller or equal to the axis index" - + std::to_string(static_cast<int>(i_axis))); + ASSERT(i_axis < name_maps.size()); const auto& name_map = name_maps[i_axis]; - const auto& it = name_map.find(substituteDefaultUnits(units)); + const auto& it = name_map.find(units == Axes::Units::DEFAULT ? defaultUnits() : units); ASSERT(it != name_map.cend()); return it->second; } diff --git a/Device/Unit/IUnitConverter.h b/Device/Unit/IUnitConverter.h index 3fd0e1740e5..b9cf5ee2fdb 100644 --- a/Device/Unit/IUnitConverter.h +++ b/Device/Unit/IUnitConverter.h @@ -55,7 +55,7 @@ public: virtual double calculateMax(size_t i_axis, Axes::Units units) const = 0; virtual size_t axisSize(size_t i_axis) const = 0; - std::string axisName(size_t i_axis, const Axes::Units& units = Axes::Units::DEFAULT) const; + std::string axisName(size_t i_axis, const Axes::Units units = Axes::Units::DEFAULT) const; virtual std::vector<Axes::Units> availableUnits() const = 0; virtual Axes::Units defaultUnits() const = 0; diff --git a/auto/Wrap/doxygenDevice.i b/auto/Wrap/doxygenDevice.i index 9f8f40f0e17..df5b6ea6ebf 100644 --- a/auto/Wrap/doxygenDevice.i +++ b/auto/Wrap/doxygenDevice.i @@ -1486,7 +1486,7 @@ Returns zero-valued output data array in specified units. %feature("docstring") IUnitConverter::axisSize "virtual size_t IUnitConverter::axisSize(size_t i_axis) const =0 "; -%feature("docstring") IUnitConverter::axisName "std::string IUnitConverter::axisName(size_t i_axis, const Axes::Units &units=Axes::Units::DEFAULT) const +%feature("docstring") IUnitConverter::axisName "std::string IUnitConverter::axisName(size_t i_axis, const Axes::Units units=Axes::Units::DEFAULT) const "; %feature("docstring") IUnitConverter::availableUnits "virtual std::vector<Axes::Units> IUnitConverter::availableUnits() const =0 -- GitLab From 7710e20e095812dfaba5436c4d7fd07f88419b79 Mon Sep 17 00:00:00 2001 From: "Joachim Wuttke (h)" <j.wuttke@fz-juelich.de> Date: Fri, 23 Apr 2021 13:31:25 +0200 Subject: [PATCH 11/18] Axes::Units::UNDEFINED <- DEFAULT --- Device/Histo/SimulationResult.h | 12 +++--- Device/Unit/Axes.h | 2 +- Device/Unit/AxisNames.h | 12 ++++-- Device/Unit/IUnitConverter.cpp | 4 +- Device/Unit/IUnitConverter.h | 2 +- .../RealLifeReflectometryFitting.py | 2 +- .../Core/Axes/UnitConverter1DTest.cpp | 24 +++++------ .../Core/Core/DepthProbeConverterTest.cpp | 14 +++---- .../Instrument/OffSpecularConverterTest.cpp | 32 +++++++-------- .../Instrument/RectangularConverterTest.cpp | 40 +++++++++---------- .../Instrument/SphericalConverterTest.cpp | 32 +++++++-------- Wrap/Python/ba_fitmonitor.py | 6 +-- Wrap/Python/ba_plot.py | 4 +- Wrap/Swig/libBornAgainDevice.i | 2 +- auto/Wrap/doxygenDevice.i | 14 +++---- auto/Wrap/libBornAgainDevice.py | 20 +++++----- auto/Wrap/libBornAgainDevice_wrap.cpp | 20 +++++----- 17 files changed, 123 insertions(+), 119 deletions(-) diff --git a/Device/Histo/SimulationResult.h b/Device/Histo/SimulationResult.h index 3fdda784780..818f97003a7 100644 --- a/Device/Histo/SimulationResult.h +++ b/Device/Histo/SimulationResult.h @@ -49,13 +49,13 @@ public: SimulationResult& operator=(SimulationResult&& other); #ifndef SWIG - std::unique_ptr<OutputData<double>> data(Axes::Units units = Axes::Units::DEFAULT) const; + std::unique_ptr<OutputData<double>> data(Axes::Units units = Axes::Units::UNDEFINED) const; #endif - Histogram2D* histogram2d(Axes::Units units = Axes::Units::DEFAULT) const; + Histogram2D* histogram2d(Axes::Units units = Axes::Units::UNDEFINED) const; //! Provide AxisInfo for each axis and the given units - std::vector<AxisInfo> axisInfo(Axes::Units units = Axes::Units::DEFAULT) const; + std::vector<AxisInfo> axisInfo(Axes::Units units = Axes::Units::UNDEFINED) const; //! Returns underlying unit converter const IUnitConverter& converter() const; @@ -69,14 +69,14 @@ public: //! returns intensity data as Python numpy array #ifdef BORNAGAIN_PYTHON - PyObject* array(Axes::Units units = Axes::Units::DEFAULT) const; + PyObject* array(Axes::Units units = Axes::Units::UNDEFINED) const; #endif - std::vector<double> axis(Axes::Units units = Axes::Units::DEFAULT) const; + std::vector<double> axis(Axes::Units units = Axes::Units::UNDEFINED) const; //! Returns axis coordinates as a numpy array. With no parameters given //! returns coordinates of x-axis in default units. - std::vector<double> axis(size_t i_axis, Axes::Units units = Axes::Units::DEFAULT) const; + std::vector<double> axis(size_t i_axis, Axes::Units units = Axes::Units::UNDEFINED) const; private: void checkDimensions() const; diff --git a/Device/Unit/Axes.h b/Device/Unit/Axes.h index 7e4fe791875..7183e599867 100644 --- a/Device/Unit/Axes.h +++ b/Device/Unit/Axes.h @@ -21,7 +21,7 @@ class Axes { public: - enum Units { DEFAULT, NBINS, RADIANS, DEGREES, MM, QSPACE, QXQY, RQ4 }; + enum Units { UNDEFINED, NBINS, RADIANS, DEGREES, MM, QSPACE, QXQY, RQ4 }; }; #endif // BORNAGAIN_DEVICE_UNIT_AXES_H diff --git a/Device/Unit/AxisNames.h b/Device/Unit/AxisNames.h index 600496a852a..06f0f370277 100644 --- a/Device/Unit/AxisNames.h +++ b/Device/Unit/AxisNames.h @@ -25,10 +25,14 @@ #include <map> #include <string> -const std::map<Axes::Units, const char*> axisUnitLabel = { - {Axes::Units::DEFAULT, "undefined"}, {Axes::Units::NBINS, "bin"}, {Axes::Units::RADIANS, "rad"}, - {Axes::Units::DEGREES, "deg"}, {Axes::Units::MM, "mm"}, {Axes::Units::QSPACE, "1/nm"}, - {Axes::Units::QXQY, "1/nm"}, {Axes::Units::RQ4, "nm^-4?"}}; +const std::map<Axes::Units, const char*> axisUnitLabel = {{Axes::Units::UNDEFINED, "undefined"}, + {Axes::Units::NBINS, "bin"}, + {Axes::Units::RADIANS, "rad"}, + {Axes::Units::DEGREES, "deg"}, + {Axes::Units::MM, "mm"}, + {Axes::Units::QSPACE, "1/nm"}, + {Axes::Units::QXQY, "1/nm"}, + {Axes::Units::RQ4, "nm^-4?"}}; //! Contains const maps that give the right axis names for different detector types and units //! @ingroup detector diff --git a/Device/Unit/IUnitConverter.cpp b/Device/Unit/IUnitConverter.cpp index 1529d72e104..c85d66bb8a7 100644 --- a/Device/Unit/IUnitConverter.cpp +++ b/Device/Unit/IUnitConverter.cpp @@ -33,7 +33,7 @@ std::string IUnitConverter::axisName(size_t i_axis, const Axes::Units units) con const auto& name_maps = createNameMaps(); ASSERT(i_axis < name_maps.size()); const auto& name_map = name_maps[i_axis]; - const auto& it = name_map.find(units == Axes::Units::DEFAULT ? defaultUnits() : units); + const auto& it = name_map.find(units == Axes::Units::UNDEFINED ? defaultUnits() : units); ASSERT(it != name_map.cend()); return it->second; } @@ -61,5 +61,5 @@ void IUnitConverter::throwUnitsError(std::string method, std::vector<Axes::Units Axes::Units IUnitConverter::substituteDefaultUnits(Axes::Units units) const { - return units == Axes::Units::DEFAULT ? defaultUnits() : units; + return units == Axes::Units::UNDEFINED ? defaultUnits() : units; } diff --git a/Device/Unit/IUnitConverter.h b/Device/Unit/IUnitConverter.h index b9cf5ee2fdb..7217446b027 100644 --- a/Device/Unit/IUnitConverter.h +++ b/Device/Unit/IUnitConverter.h @@ -55,7 +55,7 @@ public: virtual double calculateMax(size_t i_axis, Axes::Units units) const = 0; virtual size_t axisSize(size_t i_axis) const = 0; - std::string axisName(size_t i_axis, const Axes::Units units = Axes::Units::DEFAULT) const; + std::string axisName(size_t i_axis, const Axes::Units units = Axes::Units::UNDEFINED) const; virtual std::vector<Axes::Units> availableUnits() const = 0; virtual Axes::Units defaultUnits() const = 0; diff --git a/Examples/fit55_SpecularIntro/RealLifeReflectometryFitting.py b/Examples/fit55_SpecularIntro/RealLifeReflectometryFitting.py index f959222a8a8..843ebfbef8a 100755 --- a/Examples/fit55_SpecularIntro/RealLifeReflectometryFitting.py +++ b/Examples/fit55_SpecularIntro/RealLifeReflectometryFitting.py @@ -272,7 +272,7 @@ def plot_result(sim_result, ref_result, bin_start=0, bin_end=-1): get_real_data_values(bin_start, bin_end), sim_result.axis(), sim_data, ref_result.axis(), ref_data) - xlabel = ba_plot.get_axes_labels(sim_result, ba.Axes.DEFAULT)[0] + xlabel = ba_plot.get_axes_labels(sim_result, ba.Axes.UNDEFINED)[0] ylabel = "Intensity" plt.xlabel(xlabel, fontsize=16) plt.ylabel(ylabel, fontsize=16) diff --git a/Tests/UnitTests/Core/Axes/UnitConverter1DTest.cpp b/Tests/UnitTests/Core/Axes/UnitConverter1DTest.cpp index 9256f39aa38..95c782a92cc 100644 --- a/Tests/UnitTests/Core/Axes/UnitConverter1DTest.cpp +++ b/Tests/UnitTests/Core/Axes/UnitConverter1DTest.cpp @@ -34,7 +34,7 @@ UnitConverter1DTest::UnitConverter1DTest() void UnitConverter1DTest::checkConventionalConverter(const UnitConverter1D& test_object) { double expected_min = m_axis.binCenter(0); - EXPECT_NEAR(test_object.calculateMin(0, Axes::Units::DEFAULT), Units::rad2deg(expected_min), + EXPECT_NEAR(test_object.calculateMin(0, Axes::Units::UNDEFINED), Units::rad2deg(expected_min), Units::rad2deg(expected_min) * 1e-10); EXPECT_NEAR(test_object.calculateMin(0, Axes::Units::NBINS), 0.0, 1e-10); EXPECT_NEAR(test_object.calculateMin(0, Axes::Units::RADIANS), expected_min, @@ -47,7 +47,7 @@ void UnitConverter1DTest::checkConventionalConverter(const UnitConverter1D& test getQ(expected_min) * 1e-10); double expected_max = m_axis.binCenters().back(); - EXPECT_NEAR(test_object.calculateMax(0, Axes::Units::DEFAULT), Units::rad2deg(expected_max), + EXPECT_NEAR(test_object.calculateMax(0, Axes::Units::UNDEFINED), Units::rad2deg(expected_max), Units::rad2deg(expected_max) * 1e-10); EXPECT_NEAR(test_object.calculateMax(0, Axes::Units::NBINS), static_cast<double>(m_axis.size()), 1e-10); @@ -61,11 +61,11 @@ void UnitConverter1DTest::checkConventionalConverter(const UnitConverter1D& test getQ(expected_max) * 1e-10); // DEFAULT - auto axis_default = test_object.createConvertedAxis(0, Axes::Units::DEFAULT); + auto axis_default = test_object.createConvertedAxis(0, Axes::Units::UNDEFINED); EXPECT_TRUE(dynamic_cast<PointwiseAxis*>(axis_default.get())); EXPECT_EQ(axis_default->size(), test_object.axisSize(0)); - EXPECT_EQ(axis_default->lowerBound(), test_object.calculateMin(0, Axes::Units::DEFAULT)); - EXPECT_EQ(axis_default->upperBound(), test_object.calculateMax(0, Axes::Units::DEFAULT)); + EXPECT_EQ(axis_default->lowerBound(), test_object.calculateMin(0, Axes::Units::UNDEFINED)); + EXPECT_EQ(axis_default->upperBound(), test_object.calculateMax(0, Axes::Units::UNDEFINED)); // QSPACE auto axis_qspace = test_object.createConvertedAxis(0, Axes::Units::QSPACE); @@ -115,24 +115,24 @@ void UnitConverter1DTest::checkConventionalConverter(const UnitConverter1D& test void UnitConverter1DTest::checkQSpecConverter(const UnitConverter1D& test_object) { double expected_min = m_q_axis.binCenter(0); - EXPECT_EQ(test_object.calculateMin(0, Axes::Units::DEFAULT), expected_min); + EXPECT_EQ(test_object.calculateMin(0, Axes::Units::UNDEFINED), expected_min); EXPECT_NEAR(test_object.calculateMin(0, Axes::Units::NBINS), 0.0, 1e-10); EXPECT_EQ(test_object.calculateMin(0, Axes::Units::QSPACE), expected_min); EXPECT_EQ(test_object.calculateMin(0, Axes::Units::RQ4), expected_min); double expected_max = m_q_axis.binCenters().back(); - EXPECT_EQ(test_object.calculateMax(0, Axes::Units::DEFAULT), expected_max); + EXPECT_EQ(test_object.calculateMax(0, Axes::Units::UNDEFINED), expected_max); EXPECT_NEAR(test_object.calculateMax(0, Axes::Units::NBINS), static_cast<double>(m_q_axis.size()), 1e-10); EXPECT_EQ(test_object.calculateMax(0, Axes::Units::QSPACE), expected_max); EXPECT_EQ(test_object.calculateMax(0, Axes::Units::RQ4), expected_max); // DEFAULT - auto axis_default = test_object.createConvertedAxis(0, Axes::Units::DEFAULT); + auto axis_default = test_object.createConvertedAxis(0, Axes::Units::UNDEFINED); EXPECT_TRUE(dynamic_cast<PointwiseAxis*>(axis_default.get())); EXPECT_EQ(axis_default->size(), test_object.axisSize(0)); - EXPECT_EQ(axis_default->lowerBound(), test_object.calculateMin(0, Axes::Units::DEFAULT)); - EXPECT_EQ(axis_default->upperBound(), test_object.calculateMax(0, Axes::Units::DEFAULT)); + EXPECT_EQ(axis_default->lowerBound(), test_object.calculateMin(0, Axes::Units::UNDEFINED)); + EXPECT_EQ(axis_default->upperBound(), test_object.calculateMax(0, Axes::Units::UNDEFINED)); // QSPACE auto axis_qspace = test_object.createConvertedAxis(0, Axes::Units::QSPACE); @@ -197,7 +197,7 @@ TEST_F(UnitConverter1DTest, Exceptions) EXPECT_THROW(converter.calculateMax(1, Axes::Units::RADIANS), std::runtime_error); EXPECT_THROW(converter.createConvertedAxis(0, Axes::Units::MM), std::runtime_error); - EXPECT_THROW(converter.createConvertedAxis(1, Axes::Units::DEFAULT), std::runtime_error); + EXPECT_THROW(converter.createConvertedAxis(1, Axes::Units::UNDEFINED), std::runtime_error); FixedBinAxis axis("Angles", 100, 0.0, 2.0 * M_PI); EXPECT_THROW(UnitConverterConvSpec converter2(m_beam, axis), std::runtime_error); @@ -215,7 +215,7 @@ TEST_F(UnitConverter1DTest, Exceptions) // wrong axis index EXPECT_THROW(converter2.calculateMin(1, Axes::Units::QSPACE), std::runtime_error); EXPECT_THROW(converter2.calculateMax(1, Axes::Units::RQ4), std::runtime_error); - EXPECT_THROW(converter2.createConvertedAxis(1, Axes::Units::DEFAULT), std::runtime_error); + EXPECT_THROW(converter2.createConvertedAxis(1, Axes::Units::UNDEFINED), std::runtime_error); } TEST_F(UnitConverter1DTest, Clone) diff --git a/Tests/UnitTests/Core/Core/DepthProbeConverterTest.cpp b/Tests/UnitTests/Core/Core/DepthProbeConverterTest.cpp index ae0bcd7a710..f44e38eaf0d 100644 --- a/Tests/UnitTests/Core/Core/DepthProbeConverterTest.cpp +++ b/Tests/UnitTests/Core/Core/DepthProbeConverterTest.cpp @@ -33,7 +33,7 @@ void DepthProbeConverterTest::checkMainFunctionality(const DepthProbeConverter& { EXPECT_EQ(test_object.dimension(), 2u); - EXPECT_NEAR(test_object.calculateMin(0, Axes::Units::DEFAULT), 2.8647889757e+1, + EXPECT_NEAR(test_object.calculateMin(0, Axes::Units::UNDEFINED), 2.8647889757e+1, 2.8647889757e+1 * 1e-10); EXPECT_NEAR(test_object.calculateMin(0, Axes::Units::DEGREES), 2.8647889757e+1, 2.8647889757e+1 * 1e-10); @@ -42,7 +42,7 @@ void DepthProbeConverterTest::checkMainFunctionality(const DepthProbeConverter& EXPECT_EQ(test_object.calculateMin(0, Axes::Units::RADIANS), m_alpha_start); EXPECT_EQ(test_object.calculateMin(0, Axes::Units::NBINS), 0.0); - EXPECT_NEAR(test_object.calculateMax(0, Axes::Units::DEFAULT), 5.7295779513e+1, + EXPECT_NEAR(test_object.calculateMax(0, Axes::Units::UNDEFINED), 5.7295779513e+1, 5.7295779513e+1 * 1e-10); EXPECT_NEAR(test_object.calculateMax(0, Axes::Units::DEGREES), 5.7295779513e+1, 5.7295779513e+1 * 1e-10); @@ -52,13 +52,13 @@ void DepthProbeConverterTest::checkMainFunctionality(const DepthProbeConverter& const double n_bins = static_cast<double>(m_nbins); EXPECT_NEAR(test_object.calculateMax(0, Axes::Units::NBINS), n_bins, n_bins * 1e-10); - checkAlphaAxis(Axes::Units::DEFAULT, test_object); + checkAlphaAxis(Axes::Units::UNDEFINED, test_object); checkAlphaAxis(Axes::Units::DEGREES, test_object); checkAlphaAxis(Axes::Units::RADIANS, test_object); checkAlphaAxis(Axes::Units::QSPACE, test_object); checkAlphaAxis(Axes::Units::NBINS, test_object); - checkZAxis(Axes::Units::DEFAULT, test_object); + checkZAxis(Axes::Units::UNDEFINED, test_object); checkZAxis(Axes::Units::DEGREES, test_object); checkZAxis(Axes::Units::RADIANS, test_object); checkZAxis(Axes::Units::QSPACE, test_object); @@ -104,11 +104,11 @@ TEST_F(DepthProbeConverterTest, DepthProbeConverterExceptions) EXPECT_THROW(converter.axisName(0, Axes::Units::MM), std::runtime_error); EXPECT_THROW(converter.axisName(1, Axes::Units::MM), std::runtime_error); - EXPECT_THROW(converter.axisName(2, Axes::Units::DEFAULT), std::runtime_error); + EXPECT_THROW(converter.axisName(2, Axes::Units::UNDEFINED), std::runtime_error); EXPECT_THROW(converter.calculateMin(0, Axes::Units::MM), std::runtime_error); EXPECT_THROW(converter.calculateMin(1, Axes::Units::MM), std::runtime_error); - EXPECT_THROW(converter.calculateMin(2, Axes::Units::DEFAULT), std::runtime_error); + EXPECT_THROW(converter.calculateMin(2, Axes::Units::UNDEFINED), std::runtime_error); EXPECT_THROW(converter.calculateMax(0, Axes::Units::MM), std::runtime_error); EXPECT_THROW(converter.calculateMax(1, Axes::Units::MM), std::runtime_error); @@ -116,7 +116,7 @@ TEST_F(DepthProbeConverterTest, DepthProbeConverterExceptions) EXPECT_THROW(converter.createConvertedAxis(0, Axes::Units::MM), std::runtime_error); EXPECT_THROW(converter.createConvertedAxis(1, Axes::Units::MM), std::runtime_error); - EXPECT_THROW(converter.createConvertedAxis(2, Axes::Units::DEFAULT), std::runtime_error); + EXPECT_THROW(converter.createConvertedAxis(2, Axes::Units::UNDEFINED), std::runtime_error); } TEST_F(DepthProbeConverterTest, DepthProbeConverterClone) diff --git a/Tests/UnitTests/Core/Instrument/OffSpecularConverterTest.cpp b/Tests/UnitTests/Core/Instrument/OffSpecularConverterTest.cpp index b89bf02b3cb..58a5a9c9830 100644 --- a/Tests/UnitTests/Core/Instrument/OffSpecularConverterTest.cpp +++ b/Tests/UnitTests/Core/Instrument/OffSpecularConverterTest.cpp @@ -27,42 +27,42 @@ TEST_F(OffSpecularConverterTest, OffSpecularConverter) EXPECT_EQ(converter.dimension(), 2u); - EXPECT_DOUBLE_EQ(converter.calculateMin(0, Axes::Units::DEFAULT), 0.0); + EXPECT_DOUBLE_EQ(converter.calculateMin(0, Axes::Units::UNDEFINED), 0.0); EXPECT_DOUBLE_EQ(converter.calculateMin(0, Axes::Units::NBINS), 0.0); EXPECT_DOUBLE_EQ(converter.calculateMin(0, Axes::Units::RADIANS), 0.0); EXPECT_DOUBLE_EQ(converter.calculateMin(0, Axes::Units::DEGREES), 0.0); EXPECT_THROW(converter.calculateMin(0, Axes::Units::QSPACE), std::runtime_error); EXPECT_THROW(converter.calculateMin(0, Axes::Units::MM), std::runtime_error); - EXPECT_DOUBLE_EQ(converter.calculateMax(0, Axes::Units::DEFAULT), 7.0); + EXPECT_DOUBLE_EQ(converter.calculateMax(0, Axes::Units::UNDEFINED), 7.0); EXPECT_DOUBLE_EQ(converter.calculateMax(0, Axes::Units::NBINS), 51.0); EXPECT_DOUBLE_EQ(converter.calculateMax(0, Axes::Units::RADIANS), Units::deg2rad(7.0)); EXPECT_DOUBLE_EQ(converter.calculateMax(0, Axes::Units::DEGREES), 7.0); EXPECT_THROW(converter.calculateMax(0, Axes::Units::QSPACE), std::runtime_error); EXPECT_THROW(converter.calculateMax(0, Axes::Units::MM), std::runtime_error); - EXPECT_DOUBLE_EQ(converter.calculateMin(1, Axes::Units::DEFAULT), -2.0); + EXPECT_DOUBLE_EQ(converter.calculateMin(1, Axes::Units::UNDEFINED), -2.0); EXPECT_DOUBLE_EQ(converter.calculateMin(1, Axes::Units::NBINS), 0.0); EXPECT_DOUBLE_EQ(converter.calculateMin(1, Axes::Units::RADIANS), Units::deg2rad(-2.0)); EXPECT_DOUBLE_EQ(converter.calculateMin(1, Axes::Units::DEGREES), -2.0); EXPECT_THROW(converter.calculateMin(1, Axes::Units::QSPACE), std::runtime_error); EXPECT_THROW(converter.calculateMin(1, Axes::Units::MM), std::runtime_error); - EXPECT_DOUBLE_EQ(converter.calculateMax(1, Axes::Units::DEFAULT), Units::rad2deg(1.5)); + EXPECT_DOUBLE_EQ(converter.calculateMax(1, Axes::Units::UNDEFINED), Units::rad2deg(1.5)); EXPECT_DOUBLE_EQ(converter.calculateMax(1, Axes::Units::NBINS), 70.0); EXPECT_DOUBLE_EQ(converter.calculateMax(1, Axes::Units::RADIANS), 1.5); EXPECT_DOUBLE_EQ(converter.calculateMax(1, Axes::Units::DEGREES), Units::rad2deg(1.5)); EXPECT_THROW(converter.calculateMax(1, Axes::Units::QSPACE), std::runtime_error); EXPECT_THROW(converter.calculateMax(1, Axes::Units::MM), std::runtime_error); - EXPECT_THROW(converter.calculateMin(2, Axes::Units::DEFAULT), std::runtime_error); - EXPECT_THROW(converter.calculateMax(2, Axes::Units::DEFAULT), std::runtime_error); + EXPECT_THROW(converter.calculateMin(2, Axes::Units::UNDEFINED), std::runtime_error); + EXPECT_THROW(converter.calculateMax(2, Axes::Units::UNDEFINED), std::runtime_error); - auto axis = converter.createConvertedAxis(0, Axes::Units::DEFAULT); + auto axis = converter.createConvertedAxis(0, Axes::Units::UNDEFINED); EXPECT_TRUE(dynamic_cast<FixedBinAxis*>(axis.get())); EXPECT_EQ(axis->size(), converter.axisSize(0)); - EXPECT_EQ(axis->lowerBound(), converter.calculateMin(0, Axes::Units::DEFAULT)); - EXPECT_EQ(axis->upperBound(), converter.calculateMax(0, Axes::Units::DEFAULT)); + EXPECT_EQ(axis->lowerBound(), converter.calculateMin(0, Axes::Units::UNDEFINED)); + EXPECT_EQ(axis->upperBound(), converter.calculateMax(0, Axes::Units::UNDEFINED)); auto axis2 = converter.createConvertedAxis(1, Axes::Units::RADIANS); EXPECT_TRUE(dynamic_cast<FixedBinAxis*>(axis2.get())); @@ -70,7 +70,7 @@ TEST_F(OffSpecularConverterTest, OffSpecularConverter) EXPECT_EQ(axis2->lowerBound(), converter.calculateMin(1, Axes::Units::RADIANS)); EXPECT_EQ(axis2->upperBound(), converter.calculateMax(1, Axes::Units::RADIANS)); - EXPECT_THROW(converter.createConvertedAxis(2, Axes::Units::DEFAULT), std::runtime_error); + EXPECT_THROW(converter.createConvertedAxis(2, Axes::Units::UNDEFINED), std::runtime_error); EXPECT_THROW(converter.createConvertedAxis(1, Axes::Units::QSPACE), std::runtime_error); } @@ -81,34 +81,34 @@ TEST_F(OffSpecularConverterTest, OffSpecularConverterClone) EXPECT_EQ(P_clone->dimension(), 2u); - EXPECT_DOUBLE_EQ(P_clone->calculateMin(0, Axes::Units::DEFAULT), 0.0); + EXPECT_DOUBLE_EQ(P_clone->calculateMin(0, Axes::Units::UNDEFINED), 0.0); EXPECT_DOUBLE_EQ(P_clone->calculateMin(0, Axes::Units::NBINS), 0.0); EXPECT_DOUBLE_EQ(P_clone->calculateMin(0, Axes::Units::RADIANS), 0.0); EXPECT_DOUBLE_EQ(P_clone->calculateMin(0, Axes::Units::DEGREES), 0.0); EXPECT_THROW(P_clone->calculateMin(0, Axes::Units::QSPACE), std::runtime_error); EXPECT_THROW(P_clone->calculateMin(0, Axes::Units::MM), std::runtime_error); - EXPECT_DOUBLE_EQ(P_clone->calculateMax(0, Axes::Units::DEFAULT), 7.0); + EXPECT_DOUBLE_EQ(P_clone->calculateMax(0, Axes::Units::UNDEFINED), 7.0); EXPECT_DOUBLE_EQ(P_clone->calculateMax(0, Axes::Units::NBINS), 51.0); EXPECT_DOUBLE_EQ(P_clone->calculateMax(0, Axes::Units::RADIANS), Units::deg2rad(7.0)); EXPECT_DOUBLE_EQ(P_clone->calculateMax(0, Axes::Units::DEGREES), 7.0); EXPECT_THROW(P_clone->calculateMax(0, Axes::Units::QSPACE), std::runtime_error); EXPECT_THROW(P_clone->calculateMax(0, Axes::Units::MM), std::runtime_error); - EXPECT_DOUBLE_EQ(P_clone->calculateMin(1, Axes::Units::DEFAULT), -2.0); + EXPECT_DOUBLE_EQ(P_clone->calculateMin(1, Axes::Units::UNDEFINED), -2.0); EXPECT_DOUBLE_EQ(P_clone->calculateMin(1, Axes::Units::NBINS), 0.0); EXPECT_DOUBLE_EQ(P_clone->calculateMin(1, Axes::Units::RADIANS), Units::deg2rad(-2.0)); EXPECT_DOUBLE_EQ(P_clone->calculateMin(1, Axes::Units::DEGREES), -2.0); EXPECT_THROW(P_clone->calculateMin(1, Axes::Units::QSPACE), std::runtime_error); EXPECT_THROW(P_clone->calculateMin(1, Axes::Units::MM), std::runtime_error); - EXPECT_DOUBLE_EQ(P_clone->calculateMax(1, Axes::Units::DEFAULT), Units::rad2deg(1.5)); + EXPECT_DOUBLE_EQ(P_clone->calculateMax(1, Axes::Units::UNDEFINED), Units::rad2deg(1.5)); EXPECT_DOUBLE_EQ(P_clone->calculateMax(1, Axes::Units::NBINS), 70.0); EXPECT_DOUBLE_EQ(P_clone->calculateMax(1, Axes::Units::RADIANS), 1.5); EXPECT_DOUBLE_EQ(P_clone->calculateMax(1, Axes::Units::DEGREES), Units::rad2deg(1.5)); EXPECT_THROW(P_clone->calculateMax(1, Axes::Units::QSPACE), std::runtime_error); EXPECT_THROW(P_clone->calculateMax(1, Axes::Units::MM), std::runtime_error); - EXPECT_THROW(P_clone->calculateMin(2, Axes::Units::DEFAULT), std::runtime_error); - EXPECT_THROW(P_clone->calculateMax(2, Axes::Units::DEFAULT), std::runtime_error); + EXPECT_THROW(P_clone->calculateMin(2, Axes::Units::UNDEFINED), std::runtime_error); + EXPECT_THROW(P_clone->calculateMax(2, Axes::Units::UNDEFINED), std::runtime_error); } diff --git a/Tests/UnitTests/Core/Instrument/RectangularConverterTest.cpp b/Tests/UnitTests/Core/Instrument/RectangularConverterTest.cpp index 0f7aca1215d..4470377b4ac 100644 --- a/Tests/UnitTests/Core/Instrument/RectangularConverterTest.cpp +++ b/Tests/UnitTests/Core/Instrument/RectangularConverterTest.cpp @@ -44,7 +44,7 @@ TEST_F(RectangularConverterTest, RectangularConverter) EXPECT_EQ(converter.dimension(), 2u); - EXPECT_NEAR(converter.calculateMin(0, Axes::Units::DEFAULT), 0.0, 1e-12); + EXPECT_NEAR(converter.calculateMin(0, Axes::Units::UNDEFINED), 0.0, 1e-12); EXPECT_NEAR(converter.calculateMin(0, Axes::Units::NBINS), 0.0, 1e-12); EXPECT_NEAR(converter.calculateMin(0, Axes::Units::MM), 0.0, 1e-12); EXPECT_NEAR(converter.calculateMin(0, Axes::Units::RADIANS), -m_phi, m_phi * 1e-10); @@ -52,7 +52,7 @@ TEST_F(RectangularConverterTest, RectangularConverter) Units::rad2deg(m_phi) * 1e-10); EXPECT_NEAR(converter.calculateMin(0, Axes::Units::QSPACE), -m_kfy, m_kfy * 1e-10); - EXPECT_NEAR(converter.calculateMax(0, Axes::Units::DEFAULT), det_width, det_width * 1e-10); + EXPECT_NEAR(converter.calculateMax(0, Axes::Units::UNDEFINED), det_width, det_width * 1e-10); EXPECT_NEAR(converter.calculateMax(0, Axes::Units::NBINS), static_cast<double>(det_nx), det_nx * 1e-10); EXPECT_NEAR(converter.calculateMax(0, Axes::Units::MM), det_width, det_width * 1e-10); @@ -61,14 +61,14 @@ TEST_F(RectangularConverterTest, RectangularConverter) Units::rad2deg(m_phi) * 1e-10); EXPECT_NEAR(converter.calculateMax(0, Axes::Units::QSPACE), m_kfy, m_kfy * 1e-10); - EXPECT_NEAR(converter.calculateMin(1, Axes::Units::DEFAULT), 0.0, 1e-12); + EXPECT_NEAR(converter.calculateMin(1, Axes::Units::UNDEFINED), 0.0, 1e-12); EXPECT_NEAR(converter.calculateMin(1, Axes::Units::NBINS), 0.0, 1e-12); EXPECT_NEAR(converter.calculateMin(1, Axes::Units::MM), 0.0, 1e-12); EXPECT_NEAR(converter.calculateMin(1, Axes::Units::RADIANS), 0.0, 1e-12); EXPECT_NEAR(converter.calculateMin(1, Axes::Units::DEGREES), 0.0, 1e-12); EXPECT_NEAR(converter.calculateMin(1, Axes::Units::QSPACE), -m_kiz, std::abs(m_kiz) * 1e-10); - EXPECT_NEAR(converter.calculateMax(1, Axes::Units::DEFAULT), det_height, det_height * 1e-10); + EXPECT_NEAR(converter.calculateMax(1, Axes::Units::UNDEFINED), det_height, det_height * 1e-10); EXPECT_NEAR(converter.calculateMax(1, Axes::Units::NBINS), static_cast<double>(det_ny), det_ny * 1e-10); EXPECT_NEAR(converter.calculateMax(1, Axes::Units::MM), det_height, det_height * 1e-10); @@ -78,14 +78,14 @@ TEST_F(RectangularConverterTest, RectangularConverter) EXPECT_NEAR(converter.calculateMax(1, Axes::Units::QSPACE), m_kfz - m_kiz, std::abs(m_kfz - m_kiz) * 1e-10); - EXPECT_THROW(converter.calculateMin(2, Axes::Units::DEFAULT), std::runtime_error); - EXPECT_THROW(converter.calculateMax(2, Axes::Units::DEFAULT), std::runtime_error); + EXPECT_THROW(converter.calculateMin(2, Axes::Units::UNDEFINED), std::runtime_error); + EXPECT_THROW(converter.calculateMax(2, Axes::Units::UNDEFINED), std::runtime_error); - auto axis = converter.createConvertedAxis(0, Axes::Units::DEFAULT); + auto axis = converter.createConvertedAxis(0, Axes::Units::UNDEFINED); EXPECT_TRUE(dynamic_cast<FixedBinAxis*>(axis.get())); EXPECT_EQ(axis->size(), converter.axisSize(0)); - EXPECT_EQ(axis->lowerBound(), converter.calculateMin(0, Axes::Units::DEFAULT)); - EXPECT_EQ(axis->upperBound(), converter.calculateMax(0, Axes::Units::DEFAULT)); + EXPECT_EQ(axis->lowerBound(), converter.calculateMin(0, Axes::Units::UNDEFINED)); + EXPECT_EQ(axis->upperBound(), converter.calculateMax(0, Axes::Units::UNDEFINED)); auto axis2 = converter.createConvertedAxis(1, Axes::Units::QSPACE); EXPECT_TRUE(dynamic_cast<FixedBinAxis*>(axis2.get())); @@ -93,7 +93,7 @@ TEST_F(RectangularConverterTest, RectangularConverter) EXPECT_EQ(axis2->lowerBound(), converter.calculateMin(1, Axes::Units::QSPACE)); EXPECT_EQ(axis2->upperBound(), converter.calculateMax(1, Axes::Units::QSPACE)); - EXPECT_THROW(converter.createConvertedAxis(2, Axes::Units::DEFAULT), std::runtime_error); + EXPECT_THROW(converter.createConvertedAxis(2, Axes::Units::UNDEFINED), std::runtime_error); } TEST_F(RectangularConverterTest, RectangularConverterClone) @@ -103,7 +103,7 @@ TEST_F(RectangularConverterTest, RectangularConverterClone) EXPECT_EQ(P_clone->dimension(), 2u); - EXPECT_NEAR(P_clone->calculateMin(0, Axes::Units::DEFAULT), 0.0, 1e-12); + EXPECT_NEAR(P_clone->calculateMin(0, Axes::Units::UNDEFINED), 0.0, 1e-12); EXPECT_NEAR(P_clone->calculateMin(0, Axes::Units::NBINS), 0.0, 1e-12); EXPECT_NEAR(P_clone->calculateMin(0, Axes::Units::MM), 0.0, 1e-12); EXPECT_NEAR(P_clone->calculateMin(0, Axes::Units::RADIANS), -m_phi, m_phi * 1e-10); @@ -111,7 +111,7 @@ TEST_F(RectangularConverterTest, RectangularConverterClone) Units::rad2deg(m_phi) * 1e-10); EXPECT_NEAR(P_clone->calculateMin(0, Axes::Units::QSPACE), -m_kfy, m_kfy * 1e-10); - EXPECT_NEAR(P_clone->calculateMax(0, Axes::Units::DEFAULT), det_width, det_width * 1e-10); + EXPECT_NEAR(P_clone->calculateMax(0, Axes::Units::UNDEFINED), det_width, det_width * 1e-10); EXPECT_NEAR(P_clone->calculateMax(0, Axes::Units::NBINS), static_cast<double>(det_nx), det_nx * 1e-10); EXPECT_NEAR(P_clone->calculateMax(0, Axes::Units::MM), det_width, det_width * 1e-10); @@ -120,14 +120,14 @@ TEST_F(RectangularConverterTest, RectangularConverterClone) Units::rad2deg(m_phi) * 1e-10); EXPECT_NEAR(P_clone->calculateMax(0, Axes::Units::QSPACE), m_kfy, m_kfy * 1e-10); - EXPECT_NEAR(P_clone->calculateMin(1, Axes::Units::DEFAULT), 0.0, 1e-12); + EXPECT_NEAR(P_clone->calculateMin(1, Axes::Units::UNDEFINED), 0.0, 1e-12); EXPECT_NEAR(P_clone->calculateMin(1, Axes::Units::NBINS), 0.0, 1e-12); EXPECT_NEAR(P_clone->calculateMin(1, Axes::Units::MM), 0.0, 1e-12); EXPECT_NEAR(P_clone->calculateMin(1, Axes::Units::RADIANS), 0.0, 1e-12); EXPECT_NEAR(P_clone->calculateMin(1, Axes::Units::DEGREES), 0.0, 1e-12); EXPECT_NEAR(P_clone->calculateMin(1, Axes::Units::QSPACE), -m_kiz, std::abs(m_kiz) * 1e-10); - EXPECT_NEAR(P_clone->calculateMax(1, Axes::Units::DEFAULT), det_height, det_height * 1e-10); + EXPECT_NEAR(P_clone->calculateMax(1, Axes::Units::UNDEFINED), det_height, det_height * 1e-10); EXPECT_NEAR(P_clone->calculateMax(1, Axes::Units::NBINS), static_cast<double>(det_ny), det_ny * 1e-10); EXPECT_NEAR(P_clone->calculateMax(1, Axes::Units::MM), det_height, det_height * 1e-10); @@ -137,8 +137,8 @@ TEST_F(RectangularConverterTest, RectangularConverterClone) EXPECT_NEAR(P_clone->calculateMax(1, Axes::Units::QSPACE), m_kfz - m_kiz, std::abs(m_kfz - m_kiz) * 1e-10); - EXPECT_THROW(P_clone->calculateMin(2, Axes::Units::DEFAULT), std::runtime_error); - EXPECT_THROW(P_clone->calculateMax(2, Axes::Units::DEFAULT), std::runtime_error); + EXPECT_THROW(P_clone->calculateMin(2, Axes::Units::UNDEFINED), std::runtime_error); + EXPECT_THROW(P_clone->calculateMax(2, Axes::Units::UNDEFINED), std::runtime_error); } TEST_F(RectangularConverterTest, RectangularConverterWithROI) @@ -151,10 +151,10 @@ TEST_F(RectangularConverterTest, RectangularConverterWithROI) m_detector.setRegionOfInterest(roi_xmin, roi_ymin, roi_xmax, roi_ymax); RectangularConverter converter(m_detector, m_beam); - EXPECT_EQ(converter.calculateMin(0, Axes::Units::DEFAULT), 100); - EXPECT_EQ(converter.calculateMax(0, Axes::Units::DEFAULT), 152); - EXPECT_EQ(converter.calculateMin(1, Axes::Units::DEFAULT), 50); - EXPECT_EQ(converter.calculateMax(1, Axes::Units::DEFAULT), 102); + EXPECT_EQ(converter.calculateMin(0, Axes::Units::UNDEFINED), 100); + EXPECT_EQ(converter.calculateMax(0, Axes::Units::UNDEFINED), 152); + EXPECT_EQ(converter.calculateMin(1, Axes::Units::UNDEFINED), 50); + EXPECT_EQ(converter.calculateMax(1, Axes::Units::UNDEFINED), 102); EXPECT_NEAR(converter.calculateMin(0, Axes::Units::DEGREES), 0.0, 1e-10); EXPECT_NEAR(converter.calculateMax(0, Axes::Units::DEGREES), 2.97669946811, 1e-10); diff --git a/Tests/UnitTests/Core/Instrument/SphericalConverterTest.cpp b/Tests/UnitTests/Core/Instrument/SphericalConverterTest.cpp index b17776a8593..3882829aee1 100644 --- a/Tests/UnitTests/Core/Instrument/SphericalConverterTest.cpp +++ b/Tests/UnitTests/Core/Instrument/SphericalConverterTest.cpp @@ -32,42 +32,42 @@ TEST_F(SphericalConverterTest, SphericalConverter) EXPECT_EQ(converter.dimension(), 2u); - EXPECT_DOUBLE_EQ(converter.calculateMin(0, Axes::Units::DEFAULT), 0.0); + EXPECT_DOUBLE_EQ(converter.calculateMin(0, Axes::Units::UNDEFINED), 0.0); EXPECT_DOUBLE_EQ(converter.calculateMin(0, Axes::Units::NBINS), 0.0); EXPECT_DOUBLE_EQ(converter.calculateMin(0, Axes::Units::RADIANS), 0.0); EXPECT_DOUBLE_EQ(converter.calculateMin(0, Axes::Units::DEGREES), 0.0); EXPECT_DOUBLE_EQ(converter.calculateMin(0, Axes::Units::QSPACE), 0.0); EXPECT_THROW(converter.calculateMin(0, Axes::Units::MM), std::runtime_error); - EXPECT_DOUBLE_EQ(converter.calculateMax(0, Axes::Units::DEFAULT), 5.0); + EXPECT_DOUBLE_EQ(converter.calculateMax(0, Axes::Units::UNDEFINED), 5.0); EXPECT_DOUBLE_EQ(converter.calculateMax(0, Axes::Units::NBINS), 100.0); EXPECT_DOUBLE_EQ(converter.calculateMax(0, Axes::Units::RADIANS), Units::deg2rad(5.0)); EXPECT_DOUBLE_EQ(converter.calculateMax(0, Axes::Units::DEGREES), 5.0); EXPECT_DOUBLE_EQ(converter.calculateMax(0, Axes::Units::QSPACE), m_kfy); EXPECT_THROW(converter.calculateMax(0, Axes::Units::MM), std::runtime_error); - EXPECT_DOUBLE_EQ(converter.calculateMin(1, Axes::Units::DEFAULT), -2.0); + EXPECT_DOUBLE_EQ(converter.calculateMin(1, Axes::Units::UNDEFINED), -2.0); EXPECT_DOUBLE_EQ(converter.calculateMin(1, Axes::Units::NBINS), 0.0); EXPECT_DOUBLE_EQ(converter.calculateMin(1, Axes::Units::RADIANS), Units::deg2rad(-2.0)); EXPECT_DOUBLE_EQ(converter.calculateMin(1, Axes::Units::DEGREES), -2.0); EXPECT_DOUBLE_EQ(converter.calculateMin(1, Axes::Units::QSPACE), m_kfz1 - m_kiz); EXPECT_THROW(converter.calculateMin(1, Axes::Units::MM), std::runtime_error); - EXPECT_DOUBLE_EQ(converter.calculateMax(1, Axes::Units::DEFAULT), Units::rad2deg(1.5)); + EXPECT_DOUBLE_EQ(converter.calculateMax(1, Axes::Units::UNDEFINED), Units::rad2deg(1.5)); EXPECT_DOUBLE_EQ(converter.calculateMax(1, Axes::Units::NBINS), 70.0); EXPECT_DOUBLE_EQ(converter.calculateMax(1, Axes::Units::RADIANS), 1.5); EXPECT_DOUBLE_EQ(converter.calculateMax(1, Axes::Units::DEGREES), Units::rad2deg(1.5)); EXPECT_DOUBLE_EQ(converter.calculateMax(1, Axes::Units::QSPACE), m_kfz2 - m_kiz); EXPECT_THROW(converter.calculateMax(1, Axes::Units::MM), std::runtime_error); - EXPECT_THROW(converter.calculateMin(2, Axes::Units::DEFAULT), std::runtime_error); - EXPECT_THROW(converter.calculateMax(2, Axes::Units::DEFAULT), std::runtime_error); + EXPECT_THROW(converter.calculateMin(2, Axes::Units::UNDEFINED), std::runtime_error); + EXPECT_THROW(converter.calculateMax(2, Axes::Units::UNDEFINED), std::runtime_error); - auto axis = converter.createConvertedAxis(0, Axes::Units::DEFAULT); + auto axis = converter.createConvertedAxis(0, Axes::Units::UNDEFINED); EXPECT_TRUE(dynamic_cast<FixedBinAxis*>(axis.get())); EXPECT_EQ(axis->size(), converter.axisSize(0)); - EXPECT_EQ(axis->lowerBound(), converter.calculateMin(0, Axes::Units::DEFAULT)); - EXPECT_EQ(axis->upperBound(), converter.calculateMax(0, Axes::Units::DEFAULT)); + EXPECT_EQ(axis->lowerBound(), converter.calculateMin(0, Axes::Units::UNDEFINED)); + EXPECT_EQ(axis->upperBound(), converter.calculateMax(0, Axes::Units::UNDEFINED)); auto axis2 = converter.createConvertedAxis(1, Axes::Units::QSPACE); EXPECT_TRUE(dynamic_cast<FixedBinAxis*>(axis2.get())); @@ -75,7 +75,7 @@ TEST_F(SphericalConverterTest, SphericalConverter) EXPECT_EQ(axis2->lowerBound(), converter.calculateMin(1, Axes::Units::QSPACE)); EXPECT_EQ(axis2->upperBound(), converter.calculateMax(1, Axes::Units::QSPACE)); - EXPECT_THROW(converter.createConvertedAxis(2, Axes::Units::DEFAULT), std::runtime_error); + EXPECT_THROW(converter.createConvertedAxis(2, Axes::Units::UNDEFINED), std::runtime_error); } TEST_F(SphericalConverterTest, SphericalConverterClone) @@ -85,34 +85,34 @@ TEST_F(SphericalConverterTest, SphericalConverterClone) EXPECT_EQ(P_clone->dimension(), 2u); - EXPECT_DOUBLE_EQ(P_clone->calculateMin(0, Axes::Units::DEFAULT), 0.0); + EXPECT_DOUBLE_EQ(P_clone->calculateMin(0, Axes::Units::UNDEFINED), 0.0); EXPECT_DOUBLE_EQ(P_clone->calculateMin(0, Axes::Units::NBINS), 0.0); EXPECT_DOUBLE_EQ(P_clone->calculateMin(0, Axes::Units::RADIANS), 0.0); EXPECT_DOUBLE_EQ(P_clone->calculateMin(0, Axes::Units::DEGREES), 0.0); EXPECT_DOUBLE_EQ(P_clone->calculateMin(0, Axes::Units::QSPACE), 0.0); EXPECT_THROW(P_clone->calculateMin(0, Axes::Units::MM), std::runtime_error); - EXPECT_DOUBLE_EQ(P_clone->calculateMax(0, Axes::Units::DEFAULT), 5.0); + EXPECT_DOUBLE_EQ(P_clone->calculateMax(0, Axes::Units::UNDEFINED), 5.0); EXPECT_DOUBLE_EQ(P_clone->calculateMax(0, Axes::Units::NBINS), 100.0); EXPECT_DOUBLE_EQ(P_clone->calculateMax(0, Axes::Units::RADIANS), Units::deg2rad(5.0)); EXPECT_DOUBLE_EQ(P_clone->calculateMax(0, Axes::Units::DEGREES), 5.0); EXPECT_DOUBLE_EQ(P_clone->calculateMax(0, Axes::Units::QSPACE), m_kfy); EXPECT_THROW(P_clone->calculateMax(0, Axes::Units::MM), std::runtime_error); - EXPECT_DOUBLE_EQ(P_clone->calculateMin(1, Axes::Units::DEFAULT), -2.0); + EXPECT_DOUBLE_EQ(P_clone->calculateMin(1, Axes::Units::UNDEFINED), -2.0); EXPECT_DOUBLE_EQ(P_clone->calculateMin(1, Axes::Units::NBINS), 0.0); EXPECT_DOUBLE_EQ(P_clone->calculateMin(1, Axes::Units::RADIANS), Units::deg2rad(-2.0)); EXPECT_DOUBLE_EQ(P_clone->calculateMin(1, Axes::Units::DEGREES), -2.0); EXPECT_DOUBLE_EQ(P_clone->calculateMin(1, Axes::Units::QSPACE), m_kfz1 - m_kiz); EXPECT_THROW(P_clone->calculateMin(1, Axes::Units::MM), std::runtime_error); - EXPECT_DOUBLE_EQ(P_clone->calculateMax(1, Axes::Units::DEFAULT), Units::rad2deg(1.5)); + EXPECT_DOUBLE_EQ(P_clone->calculateMax(1, Axes::Units::UNDEFINED), Units::rad2deg(1.5)); EXPECT_DOUBLE_EQ(P_clone->calculateMax(1, Axes::Units::NBINS), 70.0); EXPECT_DOUBLE_EQ(P_clone->calculateMax(1, Axes::Units::RADIANS), 1.5); EXPECT_DOUBLE_EQ(P_clone->calculateMax(1, Axes::Units::DEGREES), Units::rad2deg(1.5)); EXPECT_DOUBLE_EQ(P_clone->calculateMax(1, Axes::Units::QSPACE), m_kfz2 - m_kiz); EXPECT_THROW(P_clone->calculateMax(1, Axes::Units::MM), std::runtime_error); - EXPECT_THROW(P_clone->calculateMin(2, Axes::Units::DEFAULT), std::runtime_error); - EXPECT_THROW(P_clone->calculateMax(2, Axes::Units::DEFAULT), std::runtime_error); + EXPECT_THROW(P_clone->calculateMin(2, Axes::Units::UNDEFINED), std::runtime_error); + EXPECT_THROW(P_clone->calculateMax(2, Axes::Units::UNDEFINED), std::runtime_error); } diff --git a/Wrap/Python/ba_fitmonitor.py b/Wrap/Python/ba_fitmonitor.py index 5c040ca61bb..33b14cd7303 100644 --- a/Wrap/Python/ba_fitmonitor.py +++ b/Wrap/Python/ba_fitmonitor.py @@ -33,7 +33,7 @@ class Plotter: zmax=None, xlabel=None, ylabel=None, - units=ba.Axes.DEFAULT, + units=ba.Axes.UNDEFINED, aspect=None): self._fig = plt.figure(figsize=(10.25, 7.69)) @@ -65,7 +65,7 @@ class PlotterGISAS(Plotter): zmax=None, xlabel=None, ylabel=None, - units=ba.Axes.DEFAULT, + units=ba.Axes.UNDEFINED, aspect=None): Plotter.__init__(self, zmin, zmax, xlabel, ylabel, units, aspect) @@ -145,7 +145,7 @@ class PlotterSpecular(Plotter): """ Draws fit progress, for specular simulation. """ - def __init__(self, units=ba.Axes.DEFAULT): + def __init__(self, units=ba.Axes.UNDEFINED): Plotter.__init__(self) self.gs = gridspec.GridSpec(1, 2, width_ratios=[2.5, 1], wspace=0) self.units = units diff --git a/Wrap/Python/ba_plot.py b/Wrap/Python/ba_plot.py index 243266f098a..eec9274c1ca 100644 --- a/Wrap/Python/ba_plot.py +++ b/Wrap/Python/ba_plot.py @@ -167,7 +167,7 @@ def plot_colormap(result, **kwargs): :param zmax: Max value on amplitude's color bar """ - units = kwargs.pop('units', ba.Axes.DEFAULT) + units = kwargs.pop('units', ba.Axes.UNDEFINED) axes_limits = get_axes_limits(result, units) axes_labels = get_axes_labels(result, units) @@ -188,7 +188,7 @@ def plot_specular_simulation_result(result, **kwargs): :param units: units on the x-axis """ - units = kwargs.pop('units', ba.Axes.DEFAULT) + units = kwargs.pop('units', ba.Axes.UNDEFINED) intensity = result.array(units) x_axis = result.axis(units) diff --git a/Wrap/Swig/libBornAgainDevice.i b/Wrap/Swig/libBornAgainDevice.i index 3bfda58e6f0..6e1beacd20b 100644 --- a/Wrap/Swig/libBornAgainDevice.i +++ b/Wrap/Swig/libBornAgainDevice.i @@ -69,7 +69,7 @@ %newobject ScanResolution::scanRelativeResolution; %newobject ScanResolution::scanAbsoluteResolution; -%newobject SimulationResult::histogram2d(Axes::Units units_type = Axes::Units::DEFAULT) const; +%newobject SimulationResult::histogram2d(Axes::Units units_type = Axes::Units::UNDEFINED) const; %newobject IntensityDataIOFactory::readOutputData(const std::string& file_name); %newobject IntensityDataIOFactory::readIntensityData(const std::string& file_name); diff --git a/auto/Wrap/doxygenDevice.i b/auto/Wrap/doxygenDevice.i index df5b6ea6ebf..a896ca2be7e 100644 --- a/auto/Wrap/doxygenDevice.i +++ b/auto/Wrap/doxygenDevice.i @@ -1486,7 +1486,7 @@ Returns zero-valued output data array in specified units. %feature("docstring") IUnitConverter::axisSize "virtual size_t IUnitConverter::axisSize(size_t i_axis) const =0 "; -%feature("docstring") IUnitConverter::axisName "std::string IUnitConverter::axisName(size_t i_axis, const Axes::Units units=Axes::Units::DEFAULT) const +%feature("docstring") IUnitConverter::axisName "std::string IUnitConverter::axisName(size_t i_axis, const Axes::Units units=Axes::Units::UNDEFINED) const "; %feature("docstring") IUnitConverter::availableUnits "virtual std::vector<Axes::Units> IUnitConverter::availableUnits() const =0 @@ -2480,13 +2480,13 @@ C++ includes: SimulationResult.h %feature("docstring") SimulationResult::SimulationResult "SimulationResult::SimulationResult(SimulationResult &&other) "; -%feature("docstring") SimulationResult::data "std::unique_ptr< OutputData< double > > SimulationResult::data(Axes::Units units=Axes::Units::DEFAULT) const +%feature("docstring") SimulationResult::data "std::unique_ptr< OutputData< double > > SimulationResult::data(Axes::Units units=Axes::Units::UNDEFINED) const "; -%feature("docstring") SimulationResult::histogram2d "Histogram2D * SimulationResult::histogram2d(Axes::Units units=Axes::Units::DEFAULT) const +%feature("docstring") SimulationResult::histogram2d "Histogram2D * SimulationResult::histogram2d(Axes::Units units=Axes::Units::UNDEFINED) const "; -%feature("docstring") SimulationResult::axisInfo "std::vector< AxisInfo > SimulationResult::axisInfo(Axes::Units units=Axes::Units::DEFAULT) const +%feature("docstring") SimulationResult::axisInfo "std::vector< AxisInfo > SimulationResult::axisInfo(Axes::Units units=Axes::Units::UNDEFINED) const Provide AxisInfo for each axis and the given units. "; @@ -2505,15 +2505,15 @@ Returns underlying unit converter. %feature("docstring") SimulationResult::empty "bool SimulationResult::empty() const "; -%feature("docstring") SimulationResult::array "PyObject * SimulationResult::array(Axes::Units units=Axes::Units::DEFAULT) const +%feature("docstring") SimulationResult::array "PyObject * SimulationResult::array(Axes::Units units=Axes::Units::UNDEFINED) const returns intensity data as Python numpy array "; -%feature("docstring") SimulationResult::axis "std::vector< double > SimulationResult::axis(Axes::Units units=Axes::Units::DEFAULT) const +%feature("docstring") SimulationResult::axis "std::vector< double > SimulationResult::axis(Axes::Units units=Axes::Units::UNDEFINED) const "; -%feature("docstring") SimulationResult::axis "std::vector< double > SimulationResult::axis(size_t i_axis, Axes::Units units=Axes::Units::DEFAULT) const +%feature("docstring") SimulationResult::axis "std::vector< double > SimulationResult::axis(size_t i_axis, Axes::Units units=Axes::Units::UNDEFINED) const Returns axis coordinates as a numpy array. With no parameters given returns coordinates of x-axis in default units. "; diff --git a/auto/Wrap/libBornAgainDevice.py b/auto/Wrap/libBornAgainDevice.py index cb2f32659e3..c1607ab3b50 100644 --- a/auto/Wrap/libBornAgainDevice.py +++ b/auto/Wrap/libBornAgainDevice.py @@ -3695,7 +3695,7 @@ class Axes(object): thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag") __repr__ = _swig_repr - DEFAULT = _libBornAgainDevice.Axes_DEFAULT + UNDEFINED = _libBornAgainDevice.Axes_UNDEFINED NBINS = _libBornAgainDevice.Axes_NBINS @@ -5422,16 +5422,16 @@ class SimulationResult(object): def histogram2d(self, *args): r""" - histogram2d(SimulationResult self, Axes::Units units=Axes::Units::DEFAULT) -> Histogram2D - Histogram2D * SimulationResult::histogram2d(Axes::Units units=Axes::Units::DEFAULT) const + histogram2d(SimulationResult self, Axes::Units units=Axes::Units::UNDEFINED) -> Histogram2D + Histogram2D * SimulationResult::histogram2d(Axes::Units units=Axes::Units::UNDEFINED) const """ return _libBornAgainDevice.SimulationResult_histogram2d(self, *args) def axisInfo(self, *args): r""" - axisInfo(SimulationResult self, Axes::Units units=Axes::Units::DEFAULT) -> std::vector< AxisInfo,std::allocator< AxisInfo > > - std::vector< AxisInfo > SimulationResult::axisInfo(Axes::Units units=Axes::Units::DEFAULT) const + axisInfo(SimulationResult self, Axes::Units units=Axes::Units::UNDEFINED) -> std::vector< AxisInfo,std::allocator< AxisInfo > > + std::vector< AxisInfo > SimulationResult::axisInfo(Axes::Units units=Axes::Units::UNDEFINED) const Provide AxisInfo for each axis and the given units. @@ -5474,8 +5474,8 @@ class SimulationResult(object): def array(self, *args): r""" - array(SimulationResult self, Axes::Units units=Axes::Units::DEFAULT) -> PyObject - PyObject * SimulationResult::array(Axes::Units units=Axes::Units::DEFAULT) const + array(SimulationResult self, Axes::Units units=Axes::Units::UNDEFINED) -> PyObject + PyObject * SimulationResult::array(Axes::Units units=Axes::Units::UNDEFINED) const returns intensity data as Python numpy array @@ -5484,9 +5484,9 @@ class SimulationResult(object): def axis(self, *args): r""" - axis(SimulationResult self, Axes::Units units=Axes::Units::DEFAULT) -> vdouble1d_t - axis(SimulationResult self, size_t i_axis, Axes::Units units=Axes::Units::DEFAULT) -> vdouble1d_t - std::vector< double > SimulationResult::axis(size_t i_axis, Axes::Units units=Axes::Units::DEFAULT) const + axis(SimulationResult self, Axes::Units units=Axes::Units::UNDEFINED) -> vdouble1d_t + axis(SimulationResult self, size_t i_axis, Axes::Units units=Axes::Units::UNDEFINED) -> vdouble1d_t + std::vector< double > SimulationResult::axis(size_t i_axis, Axes::Units units=Axes::Units::UNDEFINED) const Returns axis coordinates as a numpy array. With no parameters given returns coordinates of x-axis in default units. diff --git a/auto/Wrap/libBornAgainDevice_wrap.cpp b/auto/Wrap/libBornAgainDevice_wrap.cpp index a88ac3eff81..c67d4847085 100644 --- a/auto/Wrap/libBornAgainDevice_wrap.cpp +++ b/auto/Wrap/libBornAgainDevice_wrap.cpp @@ -46028,13 +46028,13 @@ static PyMethodDef SwigMethods[] = { "\n" ""}, { "SimulationResult_histogram2d", _wrap_SimulationResult_histogram2d, METH_VARARGS, "\n" - "SimulationResult_histogram2d(SimulationResult self, Axes::Units units=Axes::Units::DEFAULT) -> Histogram2D\n" - "Histogram2D * SimulationResult::histogram2d(Axes::Units units=Axes::Units::DEFAULT) const\n" + "SimulationResult_histogram2d(SimulationResult self, Axes::Units units=Axes::Units::UNDEFINED) -> Histogram2D\n" + "Histogram2D * SimulationResult::histogram2d(Axes::Units units=Axes::Units::UNDEFINED) const\n" "\n" ""}, { "SimulationResult_axisInfo", _wrap_SimulationResult_axisInfo, METH_VARARGS, "\n" - "SimulationResult_axisInfo(SimulationResult self, Axes::Units units=Axes::Units::DEFAULT) -> std::vector< AxisInfo,std::allocator< AxisInfo > >\n" - "std::vector< AxisInfo > SimulationResult::axisInfo(Axes::Units units=Axes::Units::DEFAULT) const\n" + "SimulationResult_axisInfo(SimulationResult self, Axes::Units units=Axes::Units::UNDEFINED) -> std::vector< AxisInfo,std::allocator< AxisInfo > >\n" + "std::vector< AxisInfo > SimulationResult::axisInfo(Axes::Units units=Axes::Units::UNDEFINED) const\n" "\n" "Provide AxisInfo for each axis and the given units. \n" "\n" @@ -46062,16 +46062,16 @@ static PyMethodDef SwigMethods[] = { "\n" ""}, { "SimulationResult_array", _wrap_SimulationResult_array, METH_VARARGS, "\n" - "SimulationResult_array(SimulationResult self, Axes::Units units=Axes::Units::DEFAULT) -> PyObject\n" - "PyObject * SimulationResult::array(Axes::Units units=Axes::Units::DEFAULT) const\n" + "SimulationResult_array(SimulationResult self, Axes::Units units=Axes::Units::UNDEFINED) -> PyObject\n" + "PyObject * SimulationResult::array(Axes::Units units=Axes::Units::UNDEFINED) const\n" "\n" "returns intensity data as Python numpy array \n" "\n" ""}, { "SimulationResult_axis", _wrap_SimulationResult_axis, METH_VARARGS, "\n" - "SimulationResult_axis(SimulationResult self, Axes::Units units=Axes::Units::DEFAULT) -> vdouble1d_t\n" - "SimulationResult_axis(SimulationResult self, size_t i_axis, Axes::Units units=Axes::Units::DEFAULT) -> vdouble1d_t\n" - "std::vector< double > SimulationResult::axis(size_t i_axis, Axes::Units units=Axes::Units::DEFAULT) const\n" + "SimulationResult_axis(SimulationResult self, Axes::Units units=Axes::Units::UNDEFINED) -> vdouble1d_t\n" + "SimulationResult_axis(SimulationResult self, size_t i_axis, Axes::Units units=Axes::Units::UNDEFINED) -> vdouble1d_t\n" + "std::vector< double > SimulationResult::axis(size_t i_axis, Axes::Units units=Axes::Units::UNDEFINED) const\n" "\n" "Returns axis coordinates as a numpy array. With no parameters given returns coordinates of x-axis in default units. \n" "\n" @@ -47524,7 +47524,7 @@ SWIG_init(void) { // thread safe initialization swig::container_owner_attribute(); - SWIG_Python_SetConstant(d, "Axes_DEFAULT",SWIG_From_int(static_cast< int >(Axes::DEFAULT))); + SWIG_Python_SetConstant(d, "Axes_UNDEFINED",SWIG_From_int(static_cast< int >(Axes::UNDEFINED))); SWIG_Python_SetConstant(d, "Axes_NBINS",SWIG_From_int(static_cast< int >(Axes::NBINS))); SWIG_Python_SetConstant(d, "Axes_RADIANS",SWIG_From_int(static_cast< int >(Axes::RADIANS))); SWIG_Python_SetConstant(d, "Axes_DEGREES",SWIG_From_int(static_cast< int >(Axes::DEGREES))); -- GitLab From f0621abbfd18fdc18a78a319a669b36ec805572d Mon Sep 17 00:00:00 2001 From: "Joachim Wuttke (h)" <j.wuttke@fz-juelich.de> Date: Fri, 23 Apr 2021 13:32:06 +0200 Subject: [PATCH 12/18] rm local var --- GUI/coregui/utils/ImportDataInfo.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/GUI/coregui/utils/ImportDataInfo.cpp b/GUI/coregui/utils/ImportDataInfo.cpp index d78fd812efa..11e0f748dd5 100644 --- a/GUI/coregui/utils/ImportDataInfo.cpp +++ b/GUI/coregui/utils/ImportDataInfo.cpp @@ -99,9 +99,7 @@ QString ImportDataInfo::axisLabel(size_t axis_index) const else if (rank == 1) { if (axis_index > 0) return "Signal [a.u.]"; - - auto label_map = AxisNames::specAxis; - return QString::fromStdString(label_map[m_units]); + return QString::fromStdString(AxisNames::specAxis.at(m_units)); } throw GUIHelpers::Error("Error in ImportDataInfo::axisLabel: unsupported data type"); } -- GitLab From e8730df8b2e678f70d3e5e3c7277473c456f9d49 Mon Sep 17 00:00:00 2001 From: "Joachim Wuttke (h)" <j.wuttke@fz-juelich.de> Date: Fri, 23 Apr 2021 13:35:34 +0200 Subject: [PATCH 13/18] rm unused fct --- .../CsvImportAssistant/CsvDataColumn.cpp | 8 ++------ .../ImportDataWidgets/CsvImportAssistant/CsvDataColumn.h | 1 - 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/GUI/coregui/Views/ImportDataWidgets/CsvImportAssistant/CsvDataColumn.cpp b/GUI/coregui/Views/ImportDataWidgets/CsvImportAssistant/CsvDataColumn.cpp index 78e11f84b94..2f68a9a26ff 100644 --- a/GUI/coregui/Views/ImportDataWidgets/CsvImportAssistant/CsvDataColumn.cpp +++ b/GUI/coregui/Views/ImportDataWidgets/CsvImportAssistant/CsvDataColumn.cpp @@ -79,16 +79,12 @@ CsvCoordinateColumn::CsvCoordinateColumn(int colNum, double multiplier, csv::Dat : CsvIntensityColumn(colNum, multiplier, values), m_units(units) { } -// Getters: + Axes::Units CsvCoordinateColumn::units() const { return m_units; } -// Setters: -void CsvCoordinateColumn::setUnits(Axes::Units const units) -{ - m_units = units; -} + void CsvCoordinateColumn::setName(csv::ColumnType const name) { m_name = name; diff --git a/GUI/coregui/Views/ImportDataWidgets/CsvImportAssistant/CsvDataColumn.h b/GUI/coregui/Views/ImportDataWidgets/CsvImportAssistant/CsvDataColumn.h index 3b5cd9ba3e0..4b610e94787 100644 --- a/GUI/coregui/Views/ImportDataWidgets/CsvImportAssistant/CsvDataColumn.h +++ b/GUI/coregui/Views/ImportDataWidgets/CsvImportAssistant/CsvDataColumn.h @@ -54,7 +54,6 @@ public: csv::ColumnType name() const { return m_name; } // Setters: - void setUnits(Axes::Units const units); void setName(csv::ColumnType const name); void resetColumn(int colNum = -1, double multiplier = 1., csv::DataColumn values = {}, Axes::Units units = Axes::Units::NBINS, -- GitLab From 354a4e8bab1829d104998caae0241e46a15dd6c0 Mon Sep 17 00:00:00 2001 From: "Joachim Wuttke (h)" <j.wuttke@fz-juelich.de> Date: Fri, 23 Apr 2021 13:43:31 +0200 Subject: [PATCH 14/18] fuse one-line fct --- GUI/coregui/Models/DepthProbeInstrumentItem.cpp | 6 ------ GUI/coregui/Models/DepthProbeInstrumentItem.h | 2 -- GUI/coregui/Models/DomainObjectBuilder.cpp | 3 ++- 3 files changed, 2 insertions(+), 9 deletions(-) diff --git a/GUI/coregui/Models/DepthProbeInstrumentItem.cpp b/GUI/coregui/Models/DepthProbeInstrumentItem.cpp index 1c6f5399e44..afea9a15517 100644 --- a/GUI/coregui/Models/DepthProbeInstrumentItem.cpp +++ b/GUI/coregui/Models/DepthProbeInstrumentItem.cpp @@ -15,7 +15,6 @@ #include "GUI/coregui/Models/DepthProbeInstrumentItem.h" #include "Base/Const/Units.h" #include "Core/Simulation/DepthProbeSimulation.h" -#include "Device/Detector/UnitConverter2D.h" #include "GUI/coregui/Models/AxesItems.h" #include "GUI/coregui/Models/BeamItems.h" #include "GUI/coregui/Models/BeamWavelengthItem.h" @@ -98,8 +97,3 @@ std::unique_ptr<DepthProbeSimulation> DepthProbeInstrumentItem::createSimulation return simulation; } - -std::unique_ptr<IUnitConverter> DepthProbeInstrumentItem::createUnitConverter() const -{ - return createSimulation()->createUnitConverter(); -} diff --git a/GUI/coregui/Models/DepthProbeInstrumentItem.h b/GUI/coregui/Models/DepthProbeInstrumentItem.h index 73d92b9c1da..ba1f29d09a0 100644 --- a/GUI/coregui/Models/DepthProbeInstrumentItem.h +++ b/GUI/coregui/Models/DepthProbeInstrumentItem.h @@ -38,8 +38,6 @@ public: // FIXME switch to base ISimulation class after InstrumentItem refactoring and // after ISimulation gets createUnitConverter method std::unique_ptr<DepthProbeSimulation> createSimulation() const; - - std::unique_ptr<IUnitConverter> createUnitConverter() const; }; #endif // BORNAGAIN_GUI_COREGUI_MODELS_DEPTHPROBEINSTRUMENTITEM_H diff --git a/GUI/coregui/Models/DomainObjectBuilder.cpp b/GUI/coregui/Models/DomainObjectBuilder.cpp index 12708ff1b0f..a2a359ef452 100644 --- a/GUI/coregui/Models/DomainObjectBuilder.cpp +++ b/GUI/coregui/Models/DomainObjectBuilder.cpp @@ -15,6 +15,7 @@ #include "GUI/coregui/Models/DomainObjectBuilder.h" #include "Base/Const/Units.h" #include "Core/Scan/UnitConverter1D.h" +#include "Core/Simulation/DepthProbeSimulation.h" #include "Device/Detector/IDetector2D.h" #include "Device/Detector/UnitConverter2D.h" #include "GUI/coregui/Models/AxesItems.h" @@ -133,7 +134,7 @@ DomainObjectBuilder::createUnitConverter(const InstrumentItem* instrumentItem) return specular_instrument->createUnitConverter(); if (auto depth_instrument = dynamic_cast<const DepthProbeInstrumentItem*>(instrumentItem)) - return depth_instrument->createUnitConverter(); + return depth_instrument->createSimulation()->createUnitConverter(); const auto instrument = instrumentItem->createInstrument(); instrument->initDetector(); -- GitLab From b357535d42b1113e85617a93015537faadd5b07f Mon Sep 17 00:00:00 2001 From: "Joachim Wuttke (h)" <j.wuttke@fz-juelich.de> Date: Fri, 23 Apr 2021 13:44:29 +0200 Subject: [PATCH 15/18] anon. namespace to top --- GUI/coregui/Models/JobItemUtils.cpp | 19 +++++++++---------- GUI/coregui/Models/PointwiseAxisItem.cpp | 20 ++++++++++---------- 2 files changed, 19 insertions(+), 20 deletions(-) diff --git a/GUI/coregui/Models/JobItemUtils.cpp b/GUI/coregui/Models/JobItemUtils.cpp index c70544c1f87..4f99a8075ee 100644 --- a/GUI/coregui/Models/JobItemUtils.cpp +++ b/GUI/coregui/Models/JobItemUtils.cpp @@ -24,6 +24,7 @@ #include <QFileInfo> namespace { + const std::map<QString, Axes::Units> units_from_names{{"nbins", Axes::Units::NBINS}, {"Radians", Axes::Units::RADIANS}, {"Degrees", Axes::Units::DEGREES}, @@ -37,9 +38,16 @@ const std::map<Axes::Units, QString> names_from_units{{Axes::Units::NBINS, "nbin {Axes::Units::DEGREES, "Degrees"}}; //! Updates axes' titles -void updateAxesTitle(DataItem* intensityItem, const IUnitConverter& converter, Axes::Units units); +void updateAxesTitle(DataItem* intensityItem, const IUnitConverter& converter, Axes::Units units) +{ + intensityItem->setXaxisTitle(QString::fromStdString(converter.axisName(0, units))); + if (converter.dimension() > 1) + intensityItem->setYaxisTitle(QString::fromStdString(converter.axisName(1, units))); +} + } // namespace + //! Updates axes of OutputData in IntensityData item to correspond with ::P_AXES_UNITS selection. //! InstrumentItem is used to get domain's detector map for given units. @@ -138,12 +146,3 @@ ComboProperty JobItemUtils::availableUnits(const IUnitConverter& converter) result.setValue(nameFromAxesUnits(converter.defaultUnits())); return result; } - -namespace { -void updateAxesTitle(DataItem* intensityItem, const IUnitConverter& converter, Axes::Units units) -{ - intensityItem->setXaxisTitle(QString::fromStdString(converter.axisName(0, units))); - if (converter.dimension() > 1) - intensityItem->setYaxisTitle(QString::fromStdString(converter.axisName(1, units))); -} -} // namespace diff --git a/GUI/coregui/Models/PointwiseAxisItem.cpp b/GUI/coregui/Models/PointwiseAxisItem.cpp index 5f040fbc8e1..303225e2bd7 100644 --- a/GUI/coregui/Models/PointwiseAxisItem.cpp +++ b/GUI/coregui/Models/PointwiseAxisItem.cpp @@ -20,12 +20,21 @@ #include "GUI/coregui/Models/InstrumentItems.h" namespace { -std::unique_ptr<OutputData<double>> makeOutputData(const IAxis& axis); + +std::unique_ptr<OutputData<double>> makeOutputData(const IAxis& axis) +{ + std::unique_ptr<OutputData<double>> result(new OutputData<double>); + result->addAxis(axis); + return result; } +} // namespace + + const QString PointwiseAxisItem::P_NATIVE_AXIS_UNITS = "NativeAxisUnits"; const QString PointwiseAxisItem::P_FILE_NAME = "FileName"; + PointwiseAxisItem::PointwiseAxisItem() : BasicAxisItem("PointwiseAxis"), m_instrument(nullptr) { getItem(P_MIN_DEG)->setEnabled(false); @@ -144,12 +153,3 @@ void PointwiseAxisItem::updateIndicators() emitDataChanged(); } - -namespace { -std::unique_ptr<OutputData<double>> makeOutputData(const IAxis& axis) -{ - std::unique_ptr<OutputData<double>> result(new OutputData<double>); - result->addAxis(axis); - return result; -} -} // namespace -- GitLab From d62a6753cf23019027e50412a72cd1a311eadeeb Mon Sep 17 00:00:00 2001 From: "Joachim Wuttke (h)" <j.wuttke@fz-juelich.de> Date: Fri, 23 Apr 2021 14:03:43 +0200 Subject: [PATCH 16/18] InstrumentItems: sectioning --- GUI/coregui/Models/InstrumentItems.cpp | 58 ++++++++++++++++++-------- GUI/coregui/Models/InstrumentItems.h | 6 +++ 2 files changed, 47 insertions(+), 17 deletions(-) diff --git a/GUI/coregui/Models/InstrumentItems.cpp b/GUI/coregui/Models/InstrumentItems.cpp index c0c85d68a72..86bb6056d4a 100644 --- a/GUI/coregui/Models/InstrumentItems.cpp +++ b/GUI/coregui/Models/InstrumentItems.cpp @@ -30,12 +30,32 @@ #include "GUI/coregui/utils/GUIHelpers.h" namespace { + const QString background_group_label = "Type"; const QStringList instrument_names{"GISASInstrument", "OffSpecularInstrument", "SpecularInstrument"}; -void addAxisGroupProperty(SessionItem* parent, const QString& tag); + +void addAxisGroupProperty(SessionItem* parent, const QString& tag) +{ + auto axisItem = parent->addProperty<BasicAxisItem>(tag); + axisItem->setToolTip("Incoming alpha range [deg]"); + axisItem->getItem(BasicAxisItem::P_TITLE)->setVisible(false); + axisItem->getItem(BasicAxisItem::P_NBINS)->setToolTip("Number of points in scan"); + axisItem->getItem(BasicAxisItem::P_MIN_DEG)->setToolTip("Starting value [deg]"); + axisItem->getItem(BasicAxisItem::P_MAX_DEG)->setToolTip("Ending value [deg]"); + + axisItem->setTitle("alpha_i"); + axisItem->setLowerBound(0.0); + axisItem->setUpperBound(10.0); +} + } // namespace + +// ************************************************************************************************ +// class InstrumentItem +// ************************************************************************************************ + const QString InstrumentItem::P_IDENTIFIER = "Identifier"; const QString InstrumentItem::P_BEAM = "Beam"; const QString InstrumentItem::P_BACKGROUND = "Background"; @@ -118,6 +138,11 @@ void InstrumentItem::initBackgroundGroup() item->setToolTip("Background type"); } + +// ************************************************************************************************ +// class SpecularInstrumentItem +// ************************************************************************************************ + SpecularInstrumentItem::SpecularInstrumentItem() : InstrumentItem("SpecularInstrument") { addProperty<SpecularBeamItem>(P_BEAM); @@ -201,6 +226,11 @@ QString SpecularInstrumentItem::defaultName() const return "Specular"; } + +// ************************************************************************************************ +// class Instrument2DItem +// ************************************************************************************************ + const QString Instrument2DItem::P_DETECTOR = "Detector"; Instrument2DItem::Instrument2DItem(const QString& modelType) : InstrumentItem(modelType) @@ -249,6 +279,11 @@ std::unique_ptr<Instrument> Instrument2DItem::createInstrument() const return result; } + +// ************************************************************************************************ +// class GISASInstrumentItem +// ************************************************************************************************ + GISASInstrumentItem::GISASInstrumentItem() : Instrument2DItem("GISASInstrument") {} std::vector<int> GISASInstrumentItem::shape() const @@ -275,6 +310,11 @@ QString GISASInstrumentItem::defaultName() const return "GISAS"; } + +// ************************************************************************************************ +// class OffSpecularInstrumentItem +// ************************************************************************************************ + const QString OffSpecularInstrumentItem::P_ALPHA_AXIS = "Alpha axis"; OffSpecularInstrumentItem::OffSpecularInstrumentItem() : Instrument2DItem("OffSpecularInstrument") @@ -314,19 +354,3 @@ QString OffSpecularInstrumentItem::defaultName() const { return "OffSpecular"; } - -namespace { -void addAxisGroupProperty(SessionItem* parent, const QString& tag) -{ - auto axisItem = parent->addProperty<BasicAxisItem>(tag); - axisItem->setToolTip("Incoming alpha range [deg]"); - axisItem->getItem(BasicAxisItem::P_TITLE)->setVisible(false); - axisItem->getItem(BasicAxisItem::P_NBINS)->setToolTip("Number of points in scan"); - axisItem->getItem(BasicAxisItem::P_MIN_DEG)->setToolTip("Starting value [deg]"); - axisItem->getItem(BasicAxisItem::P_MAX_DEG)->setToolTip("Ending value [deg]"); - - axisItem->setTitle("alpha_i"); - axisItem->setLowerBound(0.0); - axisItem->setUpperBound(10.0); -} -} // namespace diff --git a/GUI/coregui/Models/InstrumentItems.h b/GUI/coregui/Models/InstrumentItems.h index ca4f17774d0..f733e2c7fd2 100644 --- a/GUI/coregui/Models/InstrumentItems.h +++ b/GUI/coregui/Models/InstrumentItems.h @@ -26,6 +26,8 @@ class IUnitConverter; class MaskContainerItem; class RealDataItem; +//! Abstract base class for instrument-specific item classes. + class BA_CORE_API_ InstrumentItem : public SessionItem { private: static const QString P_IDENTIFIER; @@ -63,6 +65,7 @@ protected: void initBackgroundGroup(); }; + class BA_CORE_API_ SpecularInstrumentItem : public InstrumentItem { public: SpecularInstrumentItem(); @@ -79,6 +82,7 @@ public: std::unique_ptr<IUnitConverter> createUnitConverter() const; }; + class BA_CORE_API_ Instrument2DItem : public InstrumentItem { public: static const QString P_DETECTOR; @@ -99,6 +103,7 @@ protected: explicit Instrument2DItem(const QString& modelType); }; + class BA_CORE_API_ GISASInstrumentItem : public Instrument2DItem { public: GISASInstrumentItem(); @@ -107,6 +112,7 @@ public: virtual QString defaultName() const override; }; + class BA_CORE_API_ OffSpecularInstrumentItem : public Instrument2DItem { public: static const QString P_ALPHA_AXIS; -- GitLab From ee4232d798babe1ee64288e4561cf3f262d79c6e Mon Sep 17 00:00:00 2001 From: "Joachim Wuttke (h)" <j.wuttke@fz-juelich.de> Date: Fri, 23 Apr 2021 14:08:51 +0200 Subject: [PATCH 17/18] class comments --- Core/Scan/UnitConverter1D.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Core/Scan/UnitConverter1D.h b/Core/Scan/UnitConverter1D.h index d2257a6a235..118a0557451 100644 --- a/Core/Scan/UnitConverter1D.h +++ b/Core/Scan/UnitConverter1D.h @@ -29,7 +29,9 @@ class ISpecularScan; class AngularSpecScan; class QSpecScan; -//! Conversion of axis units for the case of 1D simulation result. + +//! Abstract base class to support coordinate transforms and axis labels for 1D scans. +//! Inherited by UnitConverterConvSpec and UnitConverterQSpec. class UnitConverter1D : public IUnitConverter { public: @@ -63,6 +65,7 @@ protected: virtual const IAxis* coordinateAxis() const = 0; }; + //! Conversion of axis units for the case of conventional (angle-based) reflectometry. class UnitConverterConvSpec : public UnitConverter1D { public: @@ -101,6 +104,7 @@ protected: std::unique_ptr<IAxis> m_axis; //!< basic inclination angles (in rads). }; + //! Conversion of axis units for the case of q-defined reflectometry. class UnitConverterQSpec : public UnitConverter1D { public: -- GitLab From 869075d60bce67b931e3ea62b3fec4b45638e866 Mon Sep 17 00:00:00 2001 From: "Joachim Wuttke (h)" <j.wuttke@fz-juelich.de> Date: Fri, 23 Apr 2021 14:11:35 +0200 Subject: [PATCH 18/18] more expressive names (Angular|Wavenumber)ReflectometryConverter --- Core/Scan/UnitConverter1D.cpp | 66 +++++----- Core/Scan/UnitConverter1D.h | 26 ++-- GUI/coregui/Models/InstrumentItems.cpp | 6 +- .../Core/Axes/UnitConverter1DTest.cpp | 24 ++-- auto/Wrap/doxygenCore.i | 122 +++++++++--------- 5 files changed, 126 insertions(+), 118 deletions(-) diff --git a/Core/Scan/UnitConverter1D.cpp b/Core/Scan/UnitConverter1D.cpp index 7155695e798..530f9143d75 100644 --- a/Core/Scan/UnitConverter1D.cpp +++ b/Core/Scan/UnitConverter1D.cpp @@ -54,10 +54,10 @@ createTranslatedAxis(const IAxis& axis, std::function<double(double)> translator std::unique_ptr<UnitConverter1D> UnitConverter1D::createUnitConverter(const ISpecularScan& scan) { if (const auto* aScan = dynamic_cast<const AngularSpecScan*>(&scan)) - return std::make_unique<UnitConverterConvSpec>(*aScan); + return std::make_unique<AngularReflectometryConverter>(*aScan); if (const auto* qScan = dynamic_cast<const QSpecScan*>(&scan)) - return std::make_unique<UnitConverterQSpec>(*qScan); + return std::make_unique<WavenumberReflectometryConverter>(*qScan); throw std::runtime_error("Bug in UnitConverter1D::createUnitConverter: invalid case"); } @@ -119,11 +119,11 @@ UnitConverter1D::createConvertedData(const OutputData<double>& data, Axes::Units // ************************************************************************************************ -// class UnitConverterConvSpec +// class AngularReflectometryConverter // ************************************************************************************************ -UnitConverterConvSpec::UnitConverterConvSpec(const Beam& beam, const IAxis& axis, - Axes::Units axis_units) +AngularReflectometryConverter::AngularReflectometryConverter(const Beam& beam, const IAxis& axis, + Axes::Units axis_units) : m_wavelength(beam.wavelength()) { m_axis = createTranslatedAxis(axis, getTraslatorFrom(axis_units), axisName(0, axis_units)); @@ -131,46 +131,49 @@ UnitConverterConvSpec::UnitConverterConvSpec(const Beam& beam, const IAxis& axis throw std::runtime_error("Error in UnitConverter1D: input axis range is out of bounds"); } -UnitConverterConvSpec::UnitConverterConvSpec(const AngularSpecScan& handler) +AngularReflectometryConverter::AngularReflectometryConverter(const AngularSpecScan& handler) : m_wavelength(handler.wavelength()), m_axis(handler.coordinateAxis()->clone()) { } -UnitConverterConvSpec::~UnitConverterConvSpec() = default; +AngularReflectometryConverter::~AngularReflectometryConverter() = default; -UnitConverterConvSpec* UnitConverterConvSpec::clone() const +AngularReflectometryConverter* AngularReflectometryConverter::clone() const { - return new UnitConverterConvSpec(*this); + return new AngularReflectometryConverter(*this); } -size_t UnitConverterConvSpec::axisSize(size_t i_axis) const +size_t AngularReflectometryConverter::axisSize(size_t i_axis) const { ASSERT(i_axis == 0); return m_axis->size(); } -std::vector<Axes::Units> UnitConverterConvSpec::availableUnits() const +std::vector<Axes::Units> AngularReflectometryConverter::availableUnits() const { return {Axes::Units::NBINS, Axes::Units::RADIANS, Axes::Units::DEGREES, Axes::Units::QSPACE, Axes::Units::RQ4}; } -Axes::Units UnitConverterConvSpec::defaultUnits() const +Axes::Units AngularReflectometryConverter::defaultUnits() const { return Axes::Units::DEGREES; } -UnitConverterConvSpec::UnitConverterConvSpec(const UnitConverterConvSpec& other) +AngularReflectometryConverter::AngularReflectometryConverter( + const AngularReflectometryConverter& other) : m_wavelength(other.m_wavelength), m_axis(other.m_axis->clone()) { } -std::vector<std::map<Axes::Units, std::string>> UnitConverterConvSpec::createNameMaps() const +std::vector<std::map<Axes::Units, std::string>> +AngularReflectometryConverter::createNameMaps() const { return {AxisNames::specAxis}; } -std::function<double(double)> UnitConverterConvSpec::getTraslatorFrom(Axes::Units units) const +std::function<double(double)> +AngularReflectometryConverter::getTraslatorFrom(Axes::Units units) const { switch (units) { case Axes::Units::RADIANS: @@ -180,12 +183,12 @@ std::function<double(double)> UnitConverterConvSpec::getTraslatorFrom(Axes::Unit case Axes::Units::QSPACE: return [this](double value) { return getInvQ(m_wavelength, value); }; default: - throwUnitsError("UnitConverterConvSpec::getTraslatorFrom", + throwUnitsError("AngularReflectometryConverter::getTraslatorFrom", {Axes::Units::RADIANS, Axes::Units::DEGREES, Axes::Units::QSPACE}); } } -std::function<double(double)> UnitConverterConvSpec::getTraslatorTo(Axes::Units units) const +std::function<double(double)> AngularReflectometryConverter::getTraslatorTo(Axes::Units units) const { switch (units) { case Axes::Units::RADIANS: @@ -197,59 +200,62 @@ std::function<double(double)> UnitConverterConvSpec::getTraslatorTo(Axes::Units case Axes::Units::RQ4: return [wl = m_wavelength](double value) { return getQ(wl, value); }; default: - throwUnitsError("UnitConverterConvSpec::getTraslatorTo", availableUnits()); + throwUnitsError("AngularReflectometryConverter::getTraslatorTo", availableUnits()); } } // ************************************************************************************************ -// class UnitConverterQSpec +// class WavenumberReflectometryConverter // ************************************************************************************************ -UnitConverterQSpec::UnitConverterQSpec(const QSpecScan& handler) +WavenumberReflectometryConverter::WavenumberReflectometryConverter(const QSpecScan& handler) : m_axis(handler.coordinateAxis()->clone()) { } -UnitConverterQSpec::~UnitConverterQSpec() = default; +WavenumberReflectometryConverter::~WavenumberReflectometryConverter() = default; -UnitConverterQSpec* UnitConverterQSpec::clone() const +WavenumberReflectometryConverter* WavenumberReflectometryConverter::clone() const { - return new UnitConverterQSpec(*this); + return new WavenumberReflectometryConverter(*this); } //! Returns the size of underlying axis. -size_t UnitConverterQSpec::axisSize(size_t i_axis) const +size_t WavenumberReflectometryConverter::axisSize(size_t i_axis) const { ASSERT(i_axis == 0); return m_axis->size(); } //! Returns the list of all available units -std::vector<Axes::Units> UnitConverterQSpec::availableUnits() const +std::vector<Axes::Units> WavenumberReflectometryConverter::availableUnits() const { return {Axes::Units::NBINS, Axes::Units::QSPACE, Axes::Units::RQ4}; } //! Returns default units to convert to. -Axes::Units UnitConverterQSpec::defaultUnits() const +Axes::Units WavenumberReflectometryConverter::defaultUnits() const { return Axes::Units::QSPACE; } -UnitConverterQSpec::UnitConverterQSpec(const UnitConverterQSpec& other) +WavenumberReflectometryConverter::WavenumberReflectometryConverter( + const WavenumberReflectometryConverter& other) : m_axis(std::unique_ptr<IAxis>(other.coordinateAxis()->clone())) { } //! Creates name map for axis in various units -std::vector<std::map<Axes::Units, std::string>> UnitConverterQSpec::createNameMaps() const +std::vector<std::map<Axes::Units, std::string>> +WavenumberReflectometryConverter::createNameMaps() const { return {AxisNames::specAxisQ}; } //! Returns translating functional (inv. nm --> desired units) -std::function<double(double)> UnitConverterQSpec::getTraslatorTo(Axes::Units units) const +std::function<double(double)> +WavenumberReflectometryConverter::getTraslatorTo(Axes::Units units) const { switch (units) { case Axes::Units::QSPACE: @@ -257,6 +263,6 @@ std::function<double(double)> UnitConverterQSpec::getTraslatorTo(Axes::Units uni case Axes::Units::RQ4: return [](double value) { return value; }; default: - throwUnitsError("UnitConverterQSpec::getTraslatorTo", availableUnits()); + throwUnitsError("WavenumberReflectometryConverter::getTraslatorTo", availableUnits()); } } diff --git a/Core/Scan/UnitConverter1D.h b/Core/Scan/UnitConverter1D.h index 118a0557451..a17f5838256 100644 --- a/Core/Scan/UnitConverter1D.h +++ b/Core/Scan/UnitConverter1D.h @@ -31,7 +31,7 @@ class QSpecScan; //! Abstract base class to support coordinate transforms and axis labels for 1D scans. -//! Inherited by UnitConverterConvSpec and UnitConverterQSpec. +//! Inherited by AngularReflectometryConverter and WavenumberReflectometryConverter. class UnitConverter1D : public IUnitConverter { public: @@ -67,15 +67,15 @@ protected: //! Conversion of axis units for the case of conventional (angle-based) reflectometry. -class UnitConverterConvSpec : public UnitConverter1D { +class AngularReflectometryConverter : public UnitConverter1D { public: //! Constructs the object for unit conversion. - UnitConverterConvSpec(const Beam& beam, const IAxis& axis, - Axes::Units axis_units = Axes::Units::RADIANS); - UnitConverterConvSpec(const AngularSpecScan& handler); - ~UnitConverterConvSpec() override; + AngularReflectometryConverter(const Beam& beam, const IAxis& axis, + Axes::Units axis_units = Axes::Units::RADIANS); + AngularReflectometryConverter(const AngularSpecScan& handler); + ~AngularReflectometryConverter() override; - UnitConverterConvSpec* clone() const override; + AngularReflectometryConverter* clone() const override; //! Returns the size of underlying axis. size_t axisSize(size_t i_axis) const override; @@ -87,7 +87,7 @@ public: Axes::Units defaultUnits() const override; protected: - UnitConverterConvSpec(const UnitConverterConvSpec& other); + AngularReflectometryConverter(const AngularReflectometryConverter& other); //! Creates name map for axis in various units std::vector<std::map<Axes::Units, std::string>> createNameMaps() const override; @@ -106,12 +106,12 @@ protected: //! Conversion of axis units for the case of q-defined reflectometry. -class UnitConverterQSpec : public UnitConverter1D { +class WavenumberReflectometryConverter : public UnitConverter1D { public: - UnitConverterQSpec(const QSpecScan& handler); - ~UnitConverterQSpec() override; + WavenumberReflectometryConverter(const QSpecScan& handler); + ~WavenumberReflectometryConverter() override; - UnitConverterQSpec* clone() const override; + WavenumberReflectometryConverter* clone() const override; //! Returns the size of underlying axis. size_t axisSize(size_t i_axis) const override; @@ -123,7 +123,7 @@ public: Axes::Units defaultUnits() const override; protected: - UnitConverterQSpec(const UnitConverterQSpec& other); + WavenumberReflectometryConverter(const WavenumberReflectometryConverter& other); //! Creates name map for axis in various units std::vector<std::map<Axes::Units, std::string>> createNameMaps() const override; diff --git a/GUI/coregui/Models/InstrumentItems.cpp b/GUI/coregui/Models/InstrumentItems.cpp index 86bb6056d4a..cf03ebbeccc 100644 --- a/GUI/coregui/Models/InstrumentItems.cpp +++ b/GUI/coregui/Models/InstrumentItems.cpp @@ -214,10 +214,10 @@ std::unique_ptr<IUnitConverter> SpecularInstrumentItem::createUnitConverter() co if (!pointwise_axis->containsNonXMLData()) // workaround for loading project return nullptr; Axes::Units native_units = JobItemUtils::axesUnitsFromName(pointwise_axis->getUnitsLabel()); - return std::make_unique<UnitConverterConvSpec>(instrument->beam(), *pointwise_axis->axis(), - native_units); + return std::make_unique<AngularReflectometryConverter>( + instrument->beam(), *pointwise_axis->axis(), native_units); } else - return std::make_unique<UnitConverterConvSpec>( + return std::make_unique<AngularReflectometryConverter>( instrument->beam(), *axis_item->createAxis(1.0), Axes::Units::DEGREES); } diff --git a/Tests/UnitTests/Core/Axes/UnitConverter1DTest.cpp b/Tests/UnitTests/Core/Axes/UnitConverter1DTest.cpp index 95c782a92cc..738c318c1ea 100644 --- a/Tests/UnitTests/Core/Axes/UnitConverter1DTest.cpp +++ b/Tests/UnitTests/Core/Axes/UnitConverter1DTest.cpp @@ -182,13 +182,13 @@ void UnitConverter1DTest::checkQSpecConverter(const UnitConverter1D& test_object TEST_F(UnitConverter1DTest, MainFunctionality) { - checkConventionalConverter(UnitConverterConvSpec(m_beam, m_axis)); - checkQSpecConverter(UnitConverterQSpec(m_qscan)); + checkConventionalConverter(AngularReflectometryConverter(m_beam, m_axis)); + checkQSpecConverter(WavenumberReflectometryConverter(m_qscan)); } TEST_F(UnitConverter1DTest, Exceptions) { - UnitConverterConvSpec converter(m_beam, m_axis); + AngularReflectometryConverter converter(m_beam, m_axis); EXPECT_THROW(converter.calculateMin(0, Axes::Units::MM), std::runtime_error); EXPECT_THROW(converter.calculateMin(1, Axes::Units::RADIANS), std::runtime_error); @@ -200,9 +200,9 @@ TEST_F(UnitConverter1DTest, Exceptions) EXPECT_THROW(converter.createConvertedAxis(1, Axes::Units::UNDEFINED), std::runtime_error); FixedBinAxis axis("Angles", 100, 0.0, 2.0 * M_PI); - EXPECT_THROW(UnitConverterConvSpec converter2(m_beam, axis), std::runtime_error); + EXPECT_THROW(AngularReflectometryConverter converter2(m_beam, axis), std::runtime_error); - UnitConverterQSpec converter2(m_qscan); + WavenumberReflectometryConverter converter2(m_qscan); // wrong units EXPECT_THROW(converter2.calculateMin(0, Axes::Units::MM), std::runtime_error); EXPECT_THROW(converter2.calculateMin(0, Axes::Units::RADIANS), std::runtime_error); @@ -220,11 +220,11 @@ TEST_F(UnitConverter1DTest, Exceptions) TEST_F(UnitConverter1DTest, Clone) { - UnitConverterConvSpec converter(m_beam, m_axis); + AngularReflectometryConverter converter(m_beam, m_axis); std::unique_ptr<UnitConverter1D> converter_clone(converter.clone()); checkConventionalConverter(*converter_clone); - UnitConverterQSpec converterQ(m_qscan); + WavenumberReflectometryConverter converterQ(m_qscan); std::unique_ptr<UnitConverter1D> converterQ_clone(converterQ.clone()); checkQSpecConverter(*converterQ_clone); } @@ -233,9 +233,10 @@ TEST_F(UnitConverter1DTest, NonDefaultUnitsInInput) { PointwiseAxis axis("x", std::vector<double>{0.0, 0.5, 1.0}); - EXPECT_THROW(UnitConverterConvSpec(m_beam, axis, Axes::Units::NBINS), std::runtime_error); + EXPECT_THROW(AngularReflectometryConverter(m_beam, axis, Axes::Units::NBINS), + std::runtime_error); - UnitConverterConvSpec converter(m_beam, axis, Axes::Units::DEGREES); + AngularReflectometryConverter converter(m_beam, axis, Axes::Units::DEGREES); auto axis_deg_output = converter.createConvertedAxis(0, Axes::Units::DEGREES); EXPECT_TRUE(axis.size() == axis_deg_output->size()); EXPECT_DOUBLE_EQ(axis[0], (*axis_deg_output)[0]); @@ -245,12 +246,13 @@ TEST_F(UnitConverter1DTest, NonDefaultUnitsInInput) auto values = axis.binCenters(); std::for_each(values.begin(), values.end(), [this](double& value) { value = getQ(value); }); PointwiseAxis q_axis("q", values); - UnitConverterConvSpec converter2(m_beam, q_axis, Axes::Units::QSPACE); + AngularReflectometryConverter converter2(m_beam, q_axis, Axes::Units::QSPACE); auto axis_rad_output = converter2.createConvertedAxis(0, Axes::Units::RADIANS); EXPECT_TRUE(axis.size() == axis_rad_output->size()); EXPECT_DOUBLE_EQ(axis[0], (*axis_rad_output)[0]); EXPECT_DOUBLE_EQ(axis[1], (*axis_rad_output)[1]); EXPECT_DOUBLE_EQ(axis[2], (*axis_rad_output)[2]); - EXPECT_THROW(UnitConverterConvSpec(m_beam, q_axis, Axes::Units::RQ4), std::runtime_error); + EXPECT_THROW(AngularReflectometryConverter(m_beam, q_axis, Axes::Units::RQ4), + std::runtime_error); } diff --git a/auto/Wrap/doxygenCore.i b/auto/Wrap/doxygenCore.i index bc97c0bad6f..ef3daa84044 100644 --- a/auto/Wrap/doxygenCore.i +++ b/auto/Wrap/doxygenCore.i @@ -1,6 +1,44 @@ // File: index.xml +// File: classAngularReflectometryConverter.xml +%feature("docstring") AngularReflectometryConverter " + +Conversion of axis units for the case of conventional (angle-based) reflectometry. + +C++ includes: UnitConverter1D.h +"; + +%feature("docstring") AngularReflectometryConverter::AngularReflectometryConverter "AngularReflectometryConverter::AngularReflectometryConverter(const Beam &beam, const IAxis &axis, Axes::Units axis_units=Axes::Units::RADIANS) + +Constructs the object for unit conversion. +"; + +%feature("docstring") AngularReflectometryConverter::AngularReflectometryConverter "AngularReflectometryConverter::AngularReflectometryConverter(const AngularSpecScan &handler) +"; + +%feature("docstring") AngularReflectometryConverter::~AngularReflectometryConverter "AngularReflectometryConverter::~AngularReflectometryConverter() override +"; + +%feature("docstring") AngularReflectometryConverter::clone "AngularReflectometryConverter * AngularReflectometryConverter::clone() const override +"; + +%feature("docstring") AngularReflectometryConverter::axisSize "size_t AngularReflectometryConverter::axisSize(size_t i_axis) const override + +Returns the size of underlying axis. +"; + +%feature("docstring") AngularReflectometryConverter::availableUnits "std::vector< Axes::Units > AngularReflectometryConverter::availableUnits() const override + +Returns the list of all available units. +"; + +%feature("docstring") AngularReflectometryConverter::defaultUnits "Axes::Units AngularReflectometryConverter::defaultUnits() const override + +Returns default units to convert to. +"; + + // File: classAngularSpecScan.xml %feature("docstring") AngularSpecScan " @@ -2149,7 +2187,7 @@ Returns kz values for Abeles computation of reflection/transition coefficients. // File: classUnitConverter1D.xml %feature("docstring") UnitConverter1D " -Conversion of axis units for the case of 1D simulation result. +Abstract base class to support coordinate transforms and axis labels for 1D scans. Inherited by AngularReflectometryConverter and WavenumberReflectometryConverter. C++ includes: UnitConverter1D.h "; @@ -2186,110 +2224,72 @@ Creates OutputData array in converter units. "; -// File: classUnitConverterConvSpec.xml -%feature("docstring") UnitConverterConvSpec " +// File: classVarianceConstantFunction.xml +%feature("docstring") VarianceConstantFunction " -Conversion of axis units for the case of conventional (angle-based) reflectometry. +Returns 1.0 as variance value -C++ includes: UnitConverter1D.h +C++ includes: VarianceFunctions.h "; -%feature("docstring") UnitConverterConvSpec::UnitConverterConvSpec "UnitConverterConvSpec::UnitConverterConvSpec(const Beam &beam, const IAxis &axis, Axes::Units axis_units=Axes::Units::RADIANS) - -Constructs the object for unit conversion. +%feature("docstring") VarianceConstantFunction::clone "VarianceConstantFunction * VarianceConstantFunction::clone() const override "; -%feature("docstring") UnitConverterConvSpec::UnitConverterConvSpec "UnitConverterConvSpec::UnitConverterConvSpec(const AngularSpecScan &handler) +%feature("docstring") VarianceConstantFunction::variance "double VarianceConstantFunction::variance(double, double) const override "; -%feature("docstring") UnitConverterConvSpec::~UnitConverterConvSpec "UnitConverterConvSpec::~UnitConverterConvSpec() override -"; -%feature("docstring") UnitConverterConvSpec::clone "UnitConverterConvSpec * UnitConverterConvSpec::clone() const override -"; +// File: classVarianceSimFunction.xml +%feature("docstring") VarianceSimFunction " -%feature("docstring") UnitConverterConvSpec::axisSize "size_t UnitConverterConvSpec::axisSize(size_t i_axis) const override +Returns max(sim, epsilon) -Returns the size of underlying axis. +C++ includes: VarianceFunctions.h "; -%feature("docstring") UnitConverterConvSpec::availableUnits "std::vector< Axes::Units > UnitConverterConvSpec::availableUnits() const override - -Returns the list of all available units. +%feature("docstring") VarianceSimFunction::VarianceSimFunction "VarianceSimFunction::VarianceSimFunction(double epsilon=1.0) "; -%feature("docstring") UnitConverterConvSpec::defaultUnits "Axes::Units UnitConverterConvSpec::defaultUnits() const override +%feature("docstring") VarianceSimFunction::clone "VarianceSimFunction * VarianceSimFunction::clone() const override +"; -Returns default units to convert to. +%feature("docstring") VarianceSimFunction::variance "double VarianceSimFunction::variance(double exp, double sim) const override "; -// File: classUnitConverterQSpec.xml -%feature("docstring") UnitConverterQSpec " +// File: classWavenumberReflectometryConverter.xml +%feature("docstring") WavenumberReflectometryConverter " Conversion of axis units for the case of q-defined reflectometry. C++ includes: UnitConverter1D.h "; -%feature("docstring") UnitConverterQSpec::UnitConverterQSpec "UnitConverterQSpec::UnitConverterQSpec(const QSpecScan &handler) +%feature("docstring") WavenumberReflectometryConverter::WavenumberReflectometryConverter "WavenumberReflectometryConverter::WavenumberReflectometryConverter(const QSpecScan &handler) "; -%feature("docstring") UnitConverterQSpec::~UnitConverterQSpec "UnitConverterQSpec::~UnitConverterQSpec() override +%feature("docstring") WavenumberReflectometryConverter::~WavenumberReflectometryConverter "WavenumberReflectometryConverter::~WavenumberReflectometryConverter() override "; -%feature("docstring") UnitConverterQSpec::clone "UnitConverterQSpec * UnitConverterQSpec::clone() const override +%feature("docstring") WavenumberReflectometryConverter::clone "WavenumberReflectometryConverter * WavenumberReflectometryConverter::clone() const override "; -%feature("docstring") UnitConverterQSpec::axisSize "size_t UnitConverterQSpec::axisSize(size_t i_axis) const override +%feature("docstring") WavenumberReflectometryConverter::axisSize "size_t WavenumberReflectometryConverter::axisSize(size_t i_axis) const override Returns the size of underlying axis. "; -%feature("docstring") UnitConverterQSpec::availableUnits "std::vector< Axes::Units > UnitConverterQSpec::availableUnits() const override +%feature("docstring") WavenumberReflectometryConverter::availableUnits "std::vector< Axes::Units > WavenumberReflectometryConverter::availableUnits() const override Returns the list of all available units. "; -%feature("docstring") UnitConverterQSpec::defaultUnits "Axes::Units UnitConverterQSpec::defaultUnits() const override +%feature("docstring") WavenumberReflectometryConverter::defaultUnits "Axes::Units WavenumberReflectometryConverter::defaultUnits() const override Returns default units to convert to. "; -// File: classVarianceConstantFunction.xml -%feature("docstring") VarianceConstantFunction " - -Returns 1.0 as variance value - -C++ includes: VarianceFunctions.h -"; - -%feature("docstring") VarianceConstantFunction::clone "VarianceConstantFunction * VarianceConstantFunction::clone() const override -"; - -%feature("docstring") VarianceConstantFunction::variance "double VarianceConstantFunction::variance(double, double) const override -"; - - -// File: classVarianceSimFunction.xml -%feature("docstring") VarianceSimFunction " - -Returns max(sim, epsilon) - -C++ includes: VarianceFunctions.h -"; - -%feature("docstring") VarianceSimFunction::VarianceSimFunction "VarianceSimFunction::VarianceSimFunction(double epsilon=1.0) -"; - -%feature("docstring") VarianceSimFunction::clone "VarianceSimFunction * VarianceSimFunction::clone() const override -"; - -%feature("docstring") VarianceSimFunction::variance "double VarianceSimFunction::variance(double exp, double sim) const override -"; - - // File: namespace_0d15.xml -- GitLab