diff --git a/Device/Histo/ImageUtils.cpp b/Device/Histo/HistoUtils.cpp similarity index 89% rename from Device/Histo/ImageUtils.cpp rename to Device/Histo/HistoUtils.cpp index d34fed6ac7c557d30e341b4ed0bba934324b75ee..30a4428f68449d254733c20bc508bd74133bd348 100644 --- a/Device/Histo/ImageUtils.cpp +++ b/Device/Histo/HistoUtils.cpp @@ -2,7 +2,7 @@ // // BornAgain: simulate and fit scattering at grazing incidence // -//! @file Device/Histo/ImageUtils.cpp +//! @file Device/Histo/HistoUtils.cpp //! @brief PyObvject forward declaration. //! //! @homepage http://www.bornagainproject.org @@ -12,7 +12,7 @@ // // ************************************************************************************************ -#include "Device/Histo/ImageUtils.h" +#include "Device/Histo/HistoUtils.h" #include "Base/Math/Numeric.h" #include "Device/Data/DataUtils.h" #include "Device/Histo/Histogram2D.h" @@ -20,7 +20,7 @@ #include <cmath> #include <tspectrum.h> // third-party code, extracted from CERN ROOT (class TSpectrum2) -std::vector<std::pair<double, double>> ImageUtils::FindPeaks(const Histogram2D& hist, double sigma, +std::vector<std::pair<double, double>> HistoUtils::FindPeaks(const Histogram2D& hist, double sigma, const std::string& option, double threshold) { std::unique_ptr<OutputData<double>> data(hist.createOutputData()); @@ -54,9 +54,9 @@ std::vector<std::pair<double, double>> ImageUtils::FindPeaks(const Histogram2D& //! Returns sum of relative differences between each pair of elements: //! (a, b) -> 2*abs(a - b)/(|a| + |b|) ( and zero if a=b=0 within epsilon ) -double ImageUtils::RelativeDifference(const SimulationResult& dat, const SimulationResult& ref) { +double HistoUtils::RelativeDifference(const SimulationResult& dat, const SimulationResult& ref) { if (dat.size() != ref.size()) - throw std::runtime_error("Error in ImageUtils::RelativeDifference: " + throw std::runtime_error("Error in HistoUtils::RelativeDifference: " "different number of elements"); if (dat.empty()) return 0.0; @@ -66,7 +66,7 @@ double ImageUtils::RelativeDifference(const SimulationResult& dat, const Simulat return sum_of_diff / dat.size(); } -double ImageUtils::getRelativeDifference(const IHistogram& dat, const IHistogram& ref) { +double HistoUtils::getRelativeDifference(const IHistogram& dat, const IHistogram& ref) { return DataUtils::getRelativeDifference( *std::unique_ptr<OutputData<double>>(dat.getData().meanValues()), *std::unique_ptr<OutputData<double>>(ref.getData().meanValues())); diff --git a/Device/Histo/ImageUtils.h b/Device/Histo/HistoUtils.h similarity index 94% rename from Device/Histo/ImageUtils.h rename to Device/Histo/HistoUtils.h index 5e646fa5770bf47cbae86f14957f9c3a7d57b644..768b4aa3aaf3cac5b0a81a07351f6be6da12ea5d 100644 --- a/Device/Histo/ImageUtils.h +++ b/Device/Histo/HistoUtils.h @@ -2,7 +2,7 @@ // // BornAgain: simulate and fit scattering at grazing incidence // -//! @file Device/Histo/ImageUtils.h +//! @file Device/Histo/HistoUtils.h //! @brief PyObvject forward declaration. //! //! @homepage http://www.bornagainproject.org @@ -25,7 +25,7 @@ class SimulationResult; //! Collection of utils for 1D and 2D image processing (background, peaks, ets). -namespace ImageUtils { +namespace HistoUtils { //! Returns vector of peak center coordinates, for peaks in given histogram. @@ -39,6 +39,6 @@ double RelativeDifference(const SimulationResult& dat, const SimulationResult& r double getRelativeDifference(const IHistogram& dat, const IHistogram& ref); -} // namespace ImageUtils +} // namespace HistoUtils #endif // BORNAGAIN_DEVICE_HISTO_IMAGEUTILS_H diff --git a/Tests/UnitTests/Core/Other/SpectrumTest.cpp b/Tests/UnitTests/Core/Other/SpectrumTest.cpp index 03585be36980775efd265e968384535548d62554..bdb3e3c8bd322c97f9bffbcf28c704284b22dd60 100644 --- a/Tests/UnitTests/Core/Other/SpectrumTest.cpp +++ b/Tests/UnitTests/Core/Other/SpectrumTest.cpp @@ -1,4 +1,4 @@ -#include "Device/Histo/ImageUtils.h" +#include "Device/Histo/HistoUtils.h" #include "Device/Histo/Histogram2D.h" #include "Tests/GTestWrapper/google_test.h" #include <iostream> @@ -34,7 +34,7 @@ TEST_F(SpectrumTest, histogramPeaks) { EXPECT_EQ(hist.binContent(4, 2), 10.0); - auto peaks = ImageUtils::FindPeaks(hist, 3, "nomarkov", 0.1); + auto peaks = HistoUtils::FindPeaks(hist, 3, "nomarkov", 0.1); EXPECT_NEAR(peaks[0].first, 55.0, 0.01); // center of histogram x-axis bin with index=4 EXPECT_NEAR(peaks[0].second, 25.0, 0.01); // center of histogram y-axis bin with index=2 } diff --git a/Wrap/Swig/libBornAgainDevice.i b/Wrap/Swig/libBornAgainDevice.i index 3e2550c2e06d7e45f78bcc70ab4225493f037558..4ccca5c8dde7c039a347ba6e44daa84e44e2e435 100644 --- a/Wrap/Swig/libBornAgainDevice.i +++ b/Wrap/Swig/libBornAgainDevice.i @@ -53,7 +53,7 @@ #include "Device/Instrument/ChiSquaredModule.h" #include "Device/Instrument/IChiSquaredModule.h" #include "Device/Instrument/PyArrayImportUtils.h" -#include "Device/Histo/ImageUtils.h" +#include "Device/Histo/HistoUtils.h" #include "Device/Instrument/VarianceFunctions.h" #include "Device/Intensity/IIntensityFunction.h" #include "Device/Intensity/IIntensityFunction.h" @@ -114,7 +114,7 @@ %include "Device/Instrument/IChiSquaredModule.h" %include "Device/Instrument/ChiSquaredModule.h" %include "Device/Instrument/PyArrayImportUtils.h" -%include "Device/Histo/ImageUtils.h" +%include "Device/Histo/HistoUtils.h" %include "Device/Instrument/VarianceFunctions.h" %include "Device/Unit/IUnitConverter.h" diff --git a/auto/Wrap/doxygenDevice.i b/auto/Wrap/doxygenDevice.i index 7a5c1ac0f26507a61f0b8752fb6849b99401a060..c5ed4c48cb0f5cb62f3be6ba0b1421f8d90b14ef 100644 --- a/auto/Wrap/doxygenDevice.i +++ b/auto/Wrap/doxygenDevice.i @@ -2969,16 +2969,16 @@ Returns true if area defined by two bins is inside or on border of polygon (more // File: namespace_0d10.xml -// File: namespace_0d107.xml +// File: namespace_0d105.xml // File: namespace_0d37.xml -// File: namespace_0d64.xml +// File: namespace_0d62.xml -// File: namespace_0d70.xml +// File: namespace_0d68.xml // File: namespaceArrayUtils.xml @@ -3157,20 +3157,20 @@ Creates Fourier Transform ( OutputData format) of intensity map ( OutputData for "; -// File: namespaceImageUtils.xml -%feature("docstring") ImageUtils::FindPeaks "std::vector< std::pair< double, double > > ImageUtils::FindPeaks(const Histogram2D &hist, double sigma=2, const std::string &option={}, double threshold=0.05) +// File: namespaceHistoUtils.xml +%feature("docstring") HistoUtils::FindPeaks "std::vector< std::pair< double, double > > HistoUtils::FindPeaks(const Histogram2D &hist, double sigma=2, const std::string &option={}, double threshold=0.05) Returns vector of peak center coordinates, for peaks in given histogram. "; -%feature("docstring") ImageUtils::RelativeDifference "double ImageUtils::RelativeDifference(const SimulationResult &dat, const SimulationResult &ref) +%feature("docstring") HistoUtils::RelativeDifference "double HistoUtils::RelativeDifference(const SimulationResult &dat, const SimulationResult &ref) Returns sum of relative differences between each pair of elements: (a, b) -> 2*abs(a - b)/(a + b) ( and zero if a-b=0 ) Returns sum of relative differences between each pair of elements: (a, b) -> 2*abs(a - b)/(|a| + |b|) ( and zero if a=b=0 within epsilon ) "; -%feature("docstring") ImageUtils::getRelativeDifference "double ImageUtils::getRelativeDifference(const IHistogram &dat, const IHistogram &ref) +%feature("docstring") HistoUtils::getRelativeDifference "double HistoUtils::getRelativeDifference(const IHistogram &dat, const IHistogram &ref) "; @@ -3351,22 +3351,16 @@ make Swappable // File: Histogram2D_8h.xml -// File: IHistogram_8cpp.xml - - -// File: IHistogram_8h.xml +// File: HistoUtils_8cpp.xml -// File: ImageUtils_8cpp.xml +// File: HistoUtils_8h.xml -// File: ImageUtils_8h.xml - - -// File: IntensityDataFunctions_8cpp.xml +// File: IHistogram_8cpp.xml -// File: IntensityDataFunctions_8h.xml +// File: IHistogram_8h.xml // File: IntensityDataIOFactory_8cpp.xml diff --git a/auto/Wrap/libBornAgainDevice.py b/auto/Wrap/libBornAgainDevice.py index 2dac05e516d18ff9c21b6386e337e2f5c8dd6750..3ffa4ce078fcd59d1e3c5546e15c65537a19558f 100644 --- a/auto/Wrap/libBornAgainDevice.py +++ b/auto/Wrap/libBornAgainDevice.py @@ -3922,7 +3922,7 @@ def importArrayToOutputData(*args): def FindPeaks(*args): r""" FindPeaks(Histogram2D hist, double sigma=2, std::string const & option={}, double threshold=0.05) -> vector_pvacuum_double_t - std::vector< std::pair< double, double > > ImageUtils::FindPeaks(const Histogram2D &hist, double sigma=2, const std::string &option={}, double threshold=0.05) + std::vector< std::pair< double, double > > HistoUtils::FindPeaks(const Histogram2D &hist, double sigma=2, const std::string &option={}, double threshold=0.05) Returns vector of peak center coordinates, for peaks in given histogram. @@ -3932,7 +3932,7 @@ def FindPeaks(*args): def RelativeDifference(dat, ref): r""" RelativeDifference(SimulationResult dat, SimulationResult ref) -> double - double ImageUtils::RelativeDifference(const SimulationResult &dat, const SimulationResult &ref) + double HistoUtils::RelativeDifference(const SimulationResult &dat, const SimulationResult &ref) Returns sum of relative differences between each pair of elements: (a, b) -> 2*abs(a - b)/(a + b) ( and zero if a-b=0 ) @@ -3944,7 +3944,7 @@ def RelativeDifference(dat, ref): def getRelativeDifference(dat, ref): r""" getRelativeDifference(IHistogram dat, IHistogram ref) -> double - double ImageUtils::getRelativeDifference(const IHistogram &dat, const IHistogram &ref) + double HistoUtils::getRelativeDifference(const IHistogram &dat, const IHistogram &ref) """ return _libBornAgainDevice.getRelativeDifference(dat, ref) diff --git a/auto/Wrap/libBornAgainDevice_wrap.cpp b/auto/Wrap/libBornAgainDevice_wrap.cpp index 45f79694d183e3cebf8e26e4666008c6d076b3c7..6ecaa195c40d63008e1e421d8a7a9dae5afd27a2 100644 --- a/auto/Wrap/libBornAgainDevice_wrap.cpp +++ b/auto/Wrap/libBornAgainDevice_wrap.cpp @@ -6730,7 +6730,7 @@ SWIGINTERN void std_vector_Sl_std_pair_Sl_double_Sc_double_Sg__Sg__insert__SWIG_ #include "Device/Instrument/ChiSquaredModule.h" #include "Device/Instrument/IChiSquaredModule.h" #include "Device/Instrument/PyArrayImportUtils.h" -#include "Device/Histo/ImageUtils.h" +#include "Device/Histo/HistoUtils.h" #include "Device/Instrument/VarianceFunctions.h" #include "Device/Intensity/IIntensityFunction.h" #include "Device/Intensity/IIntensityFunction.h" @@ -35512,7 +35512,7 @@ SWIGINTERN PyObject *_wrap_FindPeaks__SWIG_0(PyObject *SWIGUNUSEDPARM(self), Py_ SWIG_exception_fail(SWIG_ArgError(ecode4), "in method '" "FindPeaks" "', argument " "4"" of type '" "double""'"); } arg4 = static_cast< double >(val4); - result = ImageUtils::FindPeaks((Histogram2D const &)*arg1,arg2,(std::string const &)*arg3,arg4); + result = HistoUtils::FindPeaks((Histogram2D const &)*arg1,arg2,(std::string const &)*arg3,arg4); resultobj = swig::from(static_cast< std::vector< std::pair< double,double >,std::allocator< std::pair< double,double > > > >(result)); if (SWIG_IsNewObj(res3)) delete arg3; return resultobj; @@ -35559,7 +35559,7 @@ SWIGINTERN PyObject *_wrap_FindPeaks__SWIG_1(PyObject *SWIGUNUSEDPARM(self), Py_ } arg3 = ptr; } - result = ImageUtils::FindPeaks((Histogram2D const &)*arg1,arg2,(std::string const &)*arg3); + result = HistoUtils::FindPeaks((Histogram2D const &)*arg1,arg2,(std::string const &)*arg3); resultobj = swig::from(static_cast< std::vector< std::pair< double,double >,std::allocator< std::pair< double,double > > > >(result)); if (SWIG_IsNewObj(res3)) delete arg3; return resultobj; @@ -35593,7 +35593,7 @@ SWIGINTERN PyObject *_wrap_FindPeaks__SWIG_2(PyObject *SWIGUNUSEDPARM(self), Py_ SWIG_exception_fail(SWIG_ArgError(ecode2), "in method '" "FindPeaks" "', argument " "2"" of type '" "double""'"); } arg2 = static_cast< double >(val2); - result = ImageUtils::FindPeaks((Histogram2D const &)*arg1,arg2); + result = HistoUtils::FindPeaks((Histogram2D const &)*arg1,arg2); resultobj = swig::from(static_cast< std::vector< std::pair< double,double >,std::allocator< std::pair< double,double > > > >(result)); return resultobj; fail: @@ -35617,7 +35617,7 @@ SWIGINTERN PyObject *_wrap_FindPeaks__SWIG_3(PyObject *SWIGUNUSEDPARM(self), Py_ SWIG_exception_fail(SWIG_ValueError, "invalid null reference " "in method '" "FindPeaks" "', argument " "1"" of type '" "Histogram2D const &""'"); } arg1 = reinterpret_cast< Histogram2D * >(argp1); - result = ImageUtils::FindPeaks((Histogram2D const &)*arg1); + result = HistoUtils::FindPeaks((Histogram2D const &)*arg1); resultobj = swig::from(static_cast< std::vector< std::pair< double,double >,std::allocator< std::pair< double,double > > > >(result)); return resultobj; fail: @@ -35701,10 +35701,10 @@ SWIGINTERN PyObject *_wrap_FindPeaks(PyObject *self, PyObject *args) { fail: SWIG_Python_RaiseOrModifyTypeError("Wrong number or type of arguments for overloaded function 'FindPeaks'.\n" " Possible C/C++ prototypes are:\n" - " ImageUtils::FindPeaks(Histogram2D const &,double,std::string const &,double)\n" - " ImageUtils::FindPeaks(Histogram2D const &,double,std::string const &)\n" - " ImageUtils::FindPeaks(Histogram2D const &,double)\n" - " ImageUtils::FindPeaks(Histogram2D const &)\n"); + " HistoUtils::FindPeaks(Histogram2D const &,double,std::string const &,double)\n" + " HistoUtils::FindPeaks(Histogram2D const &,double,std::string const &)\n" + " HistoUtils::FindPeaks(Histogram2D const &,double)\n" + " HistoUtils::FindPeaks(Histogram2D const &)\n"); return 0; } @@ -35737,7 +35737,7 @@ SWIGINTERN PyObject *_wrap_RelativeDifference(PyObject *SWIGUNUSEDPARM(self), Py SWIG_exception_fail(SWIG_ValueError, "invalid null reference " "in method '" "RelativeDifference" "', argument " "2"" of type '" "SimulationResult const &""'"); } arg2 = reinterpret_cast< SimulationResult * >(argp2); - result = (double)ImageUtils::RelativeDifference((SimulationResult const &)*arg1,(SimulationResult const &)*arg2); + result = (double)HistoUtils::RelativeDifference((SimulationResult const &)*arg1,(SimulationResult const &)*arg2); resultobj = SWIG_From_double(static_cast< double >(result)); return resultobj; fail: @@ -35773,7 +35773,7 @@ SWIGINTERN PyObject *_wrap_getRelativeDifference(PyObject *SWIGUNUSEDPARM(self), SWIG_exception_fail(SWIG_ValueError, "invalid null reference " "in method '" "getRelativeDifference" "', argument " "2"" of type '" "IHistogram const &""'"); } arg2 = reinterpret_cast< IHistogram * >(argp2); - result = (double)ImageUtils::getRelativeDifference((IHistogram const &)*arg1,(IHistogram const &)*arg2); + result = (double)HistoUtils::getRelativeDifference((IHistogram const &)*arg1,(IHistogram const &)*arg2); resultobj = SWIG_From_double(static_cast< double >(result)); return resultobj; fail: @@ -46395,14 +46395,14 @@ static PyMethodDef SwigMethods[] = { ""}, { "FindPeaks", _wrap_FindPeaks, METH_VARARGS, "\n" "FindPeaks(Histogram2D hist, double sigma=2, std::string const & option={}, double threshold=0.05) -> vector_pvacuum_double_t\n" - "std::vector< std::pair< double, double > > ImageUtils::FindPeaks(const Histogram2D &hist, double sigma=2, const std::string &option={}, double threshold=0.05)\n" + "std::vector< std::pair< double, double > > HistoUtils::FindPeaks(const Histogram2D &hist, double sigma=2, const std::string &option={}, double threshold=0.05)\n" "\n" "Returns vector of peak center coordinates, for peaks in given histogram. \n" "\n" ""}, { "RelativeDifference", _wrap_RelativeDifference, METH_VARARGS, "\n" "RelativeDifference(SimulationResult dat, SimulationResult ref) -> double\n" - "double ImageUtils::RelativeDifference(const SimulationResult &dat, const SimulationResult &ref)\n" + "double HistoUtils::RelativeDifference(const SimulationResult &dat, const SimulationResult &ref)\n" "\n" "Returns sum of relative differences between each pair of elements: (a, b) -> 2*abs(a - b)/(a + b) ( and zero if a-b=0 )\n" "\n" @@ -46411,7 +46411,7 @@ static PyMethodDef SwigMethods[] = { ""}, { "getRelativeDifference", _wrap_getRelativeDifference, METH_VARARGS, "\n" "getRelativeDifference(IHistogram dat, IHistogram ref) -> double\n" - "double ImageUtils::getRelativeDifference(const IHistogram &dat, const IHistogram &ref)\n" + "double HistoUtils::getRelativeDifference(const IHistogram &dat, const IHistogram &ref)\n" "\n" ""}, { "delete_IVarianceFunction", _wrap_delete_IVarianceFunction, METH_O, "\n"