File: Detector2DTest.cpp

package info (click to toggle)
bornagain 23.0-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 103,936 kB
  • sloc: cpp: 423,131; python: 40,997; javascript: 11,167; awk: 630; sh: 318; ruby: 173; xml: 130; makefile: 51; ansic: 24
file content (110 lines) | stat: -rw-r--r-- 4,422 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#include "Device/Detector/SphericalDetector.h"

#include "Base/Axis/Frame.h"
#include "Base/Axis/MakeScale.h"
#include "Base/Axis/Scale.h"
#include "Base/Const/Units.h"
#include "Device/Beam/Beam.h"
#include "Device/Data/Datafield.h"
#include "Device/Mask/MaskStack.h"
#include "Device/Mask/Polygon.h"
#include "Device/Mask/Rectangle.h"
#include "Device/Resolution/ConvolutionDetectorResolution.h"
#include "Device/Resolution/ResolutionFunction2DGaussian.h"
#include "Tests/GTestWrapper/google_test.h"
#include <memory>

using Units::deg;

// Construction of the detector via classical constructor.
TEST(SphericalDetector, constructionWithParameters)
{
    SphericalDetector detector(10, -1 * deg, 1 * deg, 20, 0, 2 * deg);
    EXPECT_EQ(10u, detector.axis(0).size());
    EXPECT_EQ(-1 * deg, detector.axis(0).min());
    EXPECT_EQ(1 * deg, detector.axis(0).max());
    EXPECT_EQ(20u, detector.axis(1).size());
    EXPECT_EQ(0 * deg, detector.axis(1).min());
    EXPECT_EQ(2 * deg, detector.axis(1).max());
}

// Creation of the detector map with axes in given units
TEST(SphericalDetector, createDetectorMap)
{
    SphericalDetector detector(10, -1 * deg, 1 * deg, 20, 0, 2 * deg);

    // creating map in default units, which are radians and checking axes
    auto data = detector.createDetectorMap();
    EXPECT_EQ(data.axis(0).size(), 10u);
    EXPECT_EQ(data.axis(0).min(), -1.0 * deg);
    EXPECT_EQ(data.axis(0).max(), 1.0 * deg);
    EXPECT_EQ(data.axis(1).size(), 20u);
    EXPECT_EQ(data.axis(1).min(), 0.0 * deg);
    EXPECT_EQ(data.axis(1).max(), 2.0 * deg);
}

// Testing region of interest.
TEST(SphericalDetector, regionOfInterest)
{
    SphericalDetector detector(6, -2 * deg, 6 * deg, 4, 0 * deg, 4 * deg);

    // creating region of interest
    double xlow(-2 * deg), ylow(1 * deg), xup(4 * deg), yup(3 * deg);
    detector.setRegionOfInterest(xlow, ylow, xup, yup);
    EXPECT_TRUE(detector.hasExplicitRegionOfInterest());
    EXPECT_EQ(detector.regionOfInterestBounds(0).first, xlow);
    EXPECT_EQ(detector.regionOfInterestBounds(0).second, xup);
    EXPECT_EQ(detector.regionOfInterestBounds(1).first, ylow);
    EXPECT_EQ(detector.regionOfInterestBounds(1).second, yup);

    // replacing region of interest with a new one
    double xlow2(-2.1 * deg), ylow2(1.1 * deg), xup2(4.1 * deg), yup2(3.1 * deg);
    detector.setRegionOfInterest(xlow2, ylow2, xup2, yup2);
    EXPECT_EQ(detector.regionOfInterestBounds(0).first, xlow2);
    EXPECT_EQ(detector.regionOfInterestBounds(0).second, xup2);
    EXPECT_EQ(detector.regionOfInterestBounds(1).first, ylow2);
    EXPECT_EQ(detector.regionOfInterestBounds(1).second, yup2);
}

// Create detector map in the presence of region of interest.
TEST(SphericalDetector, regionOfInterestAndDetectorMap)
{
    SphericalDetector detector(6, -2 * deg, 6 * deg, 4, 0 * deg, 4 * deg);

    detector.setRegionOfInterest(0.1 * deg, 1.1 * deg, 2.999 * deg, 2.9 * deg);
    // Creating map in default units, which are radians and checking that axes are clipped
    // to region of interest.
    auto data = detector.createDetectorMap();
    EXPECT_EQ(data.axis(0).size(), 3u);
    EXPECT_EQ(data.axis(0).min(), 0.1 * deg);
    EXPECT_EQ(data.axis(1).size(), 2u);
    EXPECT_EQ(data.axis(1).min(), 1.1 * deg);
    EXPECT_EQ(data.axis(1).max(), 2.9 * deg);
}

// Checking clone in the presence of ROI and masks.
TEST(SphericalDetector, Clone)
{
    SphericalDetector detector(6, -2 * deg, 6 * deg, 4, 0 * deg, 4 * deg);
    detector.setRegionOfInterest(0.1 * deg, 1.1 * deg, 3.9 * deg, 2.9 * deg);
    detector.addMask(Rectangle(-0.9 * deg, 0.1 * deg, 0.9 * deg, 1.9 * deg), true);
    detector.addMask(Rectangle(3.1 * deg, 2.1 * deg, 4.9 * deg, 3.9 * deg), true);
    detector.setDetectorResolution(
        ConvolutionDetectorResolution(ResolutionFunction2DGaussian(1, 1)));

    std::vector<size_t> indexes1 = detector.activeIndices();

    std::unique_ptr<SphericalDetector> clone(detector.clone());

    auto data = clone->createDetectorMap();
    EXPECT_EQ(data.axis(0).size(), 4u);
    EXPECT_EQ(data.axis(0).min(), 0.1 * deg);
    EXPECT_EQ(data.axis(0).max(), 3.9 * deg);
    EXPECT_EQ(data.axis(1).size(), 2u);
    EXPECT_EQ(data.axis(1).min(), 1.1 * deg);
    EXPECT_EQ(data.axis(1).max(), 2.9 * deg);

    // checking iteration over the map of cloned detector
    std::vector<size_t> indexes2 = detector.activeIndices();
    EXPECT_EQ(indexes2, indexes1);
}