DGtal  1.5.beta
testPlaneProbingParallelepipedEstimator.cpp
Go to the documentation of this file.
1 
31 #include <iostream>
32 #include <vector>
33 #include "DGtal/base/Common.h"
34 #include "ConfigTest.h"
35 #include "DGtalCatch.h"
36 #include "DGtal/helpers/StdDefs.h"
37 #include "DGtal/arithmetic/IntegerComputer.h"
38 #include "DGtal/geometry/surfaces/DigitalPlanePredicate.h"
39 #include "DGtal/geometry/surfaces/estimation/PlaneProbingParallelepipedEstimator.h"
41 
42 using namespace std;
43 using namespace DGtal;
44 
46 // Functions for testing class PlaneProbingParallelepipedEstimator.
48 
49 static const Z3i::Vector NORMALS[100] = {
50  {1, 117, 148}, {1, 118, 149}, {1, 120, 25}, {1, 120, 152}, {1, 121, 153}, {1, 122, 154}, {1, 123, 155}, {1, 123, 156}, {1, 124, 26}, {1, 124, 157},
51  {1, 125, 26}, {1, 125, 158}, {1, 126, 77}, {1, 126, 159}, {1, 127, 160}, {1, 127, 161}, {1, 128, 27}, {1, 128, 162}, {1, 129, 27}, {1, 129, 163},
52  {1, 130, 164}, {1, 130, 165}, {1, 131, 165}, {1, 131, 166}, {1, 132, 28}, {1, 132, 166}, {1, 132, 167}, {1, 133, 28}, {1, 133, 168}, {1, 134, 169},
53  {1, 134, 170}, {1, 135, 170}, {1, 135, 171}, {1, 136, 171}, {1, 136, 172}, {1, 137, 29}, {1, 137, 173}, {1, 137, 174}, {1, 138, 174}, {1, 138, 175},
54  {1, 139, 175}, {1, 139, 176}, {1, 140, 176}, {1, 140, 177}, {1, 140, 178}, {1, 141, 30}, {1, 141, 178}, {1, 141, 179}, {1, 142, 179}, {1, 142, 180},
55  {1, 143, 180}, {1, 143, 181}, {1, 144, 182}, {1, 144, 183}, {1, 145, 183}, {1, 145, 184}, {1, 146, 184}, {1, 146, 185}, {1, 147, 186}, {1, 147, 187},
56  {1, 148, 187}, {1, 148, 188}, {1, 149, 188}, {1, 149, 189}, {1, 150, 190}, {1, 151, 191}, {1, 151, 192}, {1, 152, 192}, {1, 152, 193}, {1, 153, 194},
57  {1, 154, 195}, {1, 154, 196}, {1, 155, 196}, {1, 155, 197}, {1, 156, 198}, {1, 157, 199}, {1, 173, 30}, {1, 174, 30}, {1, 175, 30}, {1, 178, 31},
58  {1, 179, 31}, {1, 180, 31}, {1, 181, 31}, {1, 184, 32}, {1, 185, 32}, {1, 186, 32}, {1, 187, 32}, {1, 188, 32}, {1, 189, 33}, {1, 190, 33},
59  {1, 191, 33}, {1, 192, 33}, {1, 193, 33}, {1, 194, 33}, {1, 194, 34}, {1, 195, 34}, {1, 196, 34}, {1, 197, 34}, {1, 198, 34}, {1, 199, 34},
60 };
61 
62 static const Z3i::Vector NORMALS_BIG[2] = {
63  {1, 59438, 82499}, {2071, 8513, 6444},
64 };
65 
66 template < typename Integer, ProbingMode mode >
67 struct TestPlaneProbingParallelepipedEstimator
68 {
69  using Space = SpaceND<3, Integer>;
71  using Point = typename DigitalPlane::Vector;
73 
74  template < typename F >
75  static void compute (Point const& n, int height, F const& f)
76  {
77  Point o(0, 0, 0);
78  std::array<Point, 3> frame = { Point(1, 0, 0), Point(0, 1, 0), Point(0, 0, 1) };
79 
80  DigitalPlane plane(n, -height, n.norm1());
81  Estimator estimator(o, frame, plane, 2 * n.norm1());
82 
83  f(estimator);
84  }
85 };
86 
87 TEST_CASE( "Testing PlaneProbingParallelepipedEstimator" )
88 {
89  static const int MAX_HEIGHT = 10;
90 
91  SECTION("H-algorithm should return the correct normal")
92  {
93  int nbNormals = 0;
94  int nbOk = 0;
95 
96  for (const auto& n: NORMALS) {
97  for (int height = 0; height < min(int(n.normInfinity()), MAX_HEIGHT); ++height) {
98  ++nbNormals;
99 
100  TestPlaneProbingParallelepipedEstimator<int, ProbingMode::H>::compute
101  (n, height,
103  auto estimated = estimator.compute();
104  bool isReducedH = estimator.isReduced();
105 
106  if (estimated == n && !isReducedH)
107  {
108  nbOk++;
109  }
110  });
111  }
112  }
113 
114  REQUIRE(nbNormals == nbOk);
115  }
116 
117  SECTION("R1-algorithm should return the correct normal and a reduced basis")
118  {
119  int nbNormals = 0;
120  int nbOk = 0;
121 
122  for (const auto& n: NORMALS) {
123  for (int height = 0; height < min(int(n.normInfinity()), MAX_HEIGHT); ++height) {
124  ++nbNormals;
125 
126  TestPlaneProbingParallelepipedEstimator<int, ProbingMode::R1>::compute
127  (n, height,
129  auto estimated = estimator.compute();
130  bool isReducedR = estimator.isReduced();
131 
132  if (estimated == n && isReducedR)
133  {
134  nbOk++;
135  }
136  });
137  }
138  }
139 
140  REQUIRE(nbNormals == nbOk);
141  }
142 
143  SECTION("L-algorithm should return the correct normal and a reduced basis")
144  {
145  int nbNormals = 0;
146  int nbOk = 0;
147 
148  for (const auto& n: NORMALS) {
149  for (int height = 0; height < min(int(n.normInfinity()), MAX_HEIGHT); ++height) {
150  ++nbNormals;
151 
152  TestPlaneProbingParallelepipedEstimator<int, ProbingMode::L>::compute
153  (n, height,
155  auto estimated = estimator.compute();
156  bool isReduced = estimator.isReduced();
157 
158  if (estimated == n && isReduced)
159  {
160  nbOk++;
161  }
162  });
163  }
164  }
165 
166  REQUIRE(nbNormals == nbOk);
167  }
168 
169 #ifdef WITH_GMP
170  SECTION("H-algorithm should return the correct normal with BigInteger")
171  {
172  int nbNormals = 0;
173  int nbOk = 0;
174 
175  for (const auto& n: NORMALS_BIG) {
176  for (int height = 0; height < MAX_HEIGHT; ++height) {
177  ++nbNormals;
178 
179  TestPlaneProbingParallelepipedEstimator<BigInteger, ProbingMode::H>::compute
180  (n, height,
182  auto estimated = estimator.compute();
183 
184  if (estimated == n)
185  {
186  nbOk++;
187  }
188  });
189  }
190  }
191 
192  REQUIRE(nbNormals == nbOk);
193  }
194 #endif
195 }
196 
Aim: Representing digital planes, which are digitizations of Euclidean planes, as point predicates.
Quantity compute(std::vector< PointOnProbingRay > const &aNeighbors)
DGtal is the top-level namespace which contains all DGtal functions and types.
MyPointD Point
Definition: testClone2.cpp:383
TEST_CASE("Testing PlaneProbingParallelepipedEstimator")
static const Z3i::Vector NORMALS_BIG[2]
static const Z3i::Vector NORMALS[100]
SECTION("Testing constant forward iterators")
REQUIRE(domain.isInside(aPoint))