Loading [MathJax]/extensions/TeX/AMSsymbols.js
DGtal 2.0.0
testMeshVoxelization.cpp
Go to the documentation of this file.
1
16
28#include <iostream>
29#include "ConfigTest.h"
30#include "DGtalCatch.h"
31#include "DGtal/shapes/MeshVoxelizer.h"
32#include "DGtal/kernel/sets/CDigitalSet.h"
33#include "DGtal/kernel/domains/HyperRectDomain.h"
34#include "DGtal/io/readers/MeshReader.h"
35#include "DGtal/io/readers/MeshReader.h"
37
38using namespace DGtal;
39using namespace Z3i;
40
41TEST_CASE("Basic voxelization test", "[voxelization]")
42{
43 using PointR3 = PointVector<3, double>;
44 using VectorR3 = PointVector<3, double>;
45 using PointR2 = PointVector<2, double>;
46 using PointZ3 = PointVector<3, int>;
47
48 using MeshVoxelizer26 = MeshVoxelizer< DigitalSet, 26>;
49 using MeshVoxelizer6 = MeshVoxelizer< DigitalSet, 6>;
50
51 using TriOr = MeshVoxelizer6::TriangleOrientation;
52
53 // ---------------------------------------------------------
54 SECTION("Test distance point/plan 3D")
55 {
56 // Triangle ABC in R3
57 const PointR3 A(38.6908 , 14.5441 , -0.71205);
58 const PointR3 B(34.6171 , 13.5999 , 2.44455);
59 const PointR3 C(37.4205 , 2.44239 , 6.31301);
60
61 // Point v
62 const PointZ3 v(35, 2, 5);
63
64 const VectorR3 e1 = A - B;
65 const VectorR3 e2 = A - C;
66
67 double distance = MeshVoxelizer6::distance(A, e1.crossProduct(e2), v);
68
69 REQUIRE( 2.40 < distance );
70 REQUIRE( distance < 2.41 );
71 }
72
73 // ---------------------------------------------------------
74 SECTION("Test if 2D point is inside triangle 2D")
75 {
76 // Triangle ABC in R2
77 PointR2 A(1.0, 1.0);
78 PointR2 B(2.0, 3.0);
79 PointR2 C(3.0, 1.0);
80
81 typedef InHalfPlaneBySimple3x3Matrix<PointR2, double> OrientationFunctor;
82 OrientationFunctor orientationFunctor;
83
84 //geometric predicate
85 PredicateFromOrientationFunctor2<OrientationFunctor> pointPredicate( orientationFunctor );
86
87 if(! pointPredicate(A, B, C))
88 {
89 std::swap(A, C);
90 }
91
92 // Test if point v is inside triangle ABC
93 // 0 : outside
94 // 1 : inside
95 // 2 : on edge
96 // 3 : on vertex
97 PointR2 v;
98
99 v[0] = 3.0;
100 v[1] = 3.0;
101 REQUIRE(MeshVoxelizer6::pointIsInside2DTriangle(A, B, C, v) == TriOr::TRIANGLE_OUTSIDE);
102
103 v[0] = 2.0;
104 v[1] = 2.0;
105 REQUIRE(MeshVoxelizer6::pointIsInside2DTriangle(A, B, C, v) == TriOr::TRIANGLE_INSIDE);
106
107 v[0] = 2;
108 v[1] = 1;
109 REQUIRE(MeshVoxelizer6::pointIsInside2DTriangle(A, B, C, v) == TriOr::TRIANGLE_ONEDGE);
110
111 v[0] = 3;
112 v[1] = 1;
113 REQUIRE(MeshVoxelizer6::pointIsInside2DTriangle(A, B, C, v) == TriOr::TRIANGLE_ONVERTEX);
114
115 // another case
116 A = { 16.3299, 0. };
117 B = { 0., 16.3299 };
118 C = { -16.3299, 0. };
119 v = { -17., 0.};
120 REQUIRE(MeshVoxelizer6::pointIsInside2DTriangle(A, B, C, v) == TriOr::TRIANGLE_OUTSIDE);
121
122 // another case
123 A = { -0.891282, 9.91201 };
124 B = { -1.40823, 9.91261 };
125 C = { -1.36963, 9.37414 };
126 v = { -1.16961, 9.83039 };
127 REQUIRE(MeshVoxelizer6::pointIsInside2DTriangle(A, B, C, v) == TriOr::TRIANGLE_INSIDE);
128 }
129
130 // ---------------------------------------------------------
131 SECTION("Test if 3D point is inside voxel")
132 {
133 // Triangle ABC in R2
134 PointR3 P(-0.89, 9.91, 0.86);
135 PointZ3 v(-1, 10, 1);
136
137 REQUIRE(MeshVoxelizer6::pointIsInsideVoxel(P, v) == true); // inside
138
139 P[0] = -1.41;
140 P[1] = 9.91;
141 REQUIRE(MeshVoxelizer6::pointIsInsideVoxel(P, v) == true); // inside
142
143 P[0] = -1.37;
144 P[1] = 9.37;
145 REQUIRE(MeshVoxelizer6::pointIsInsideVoxel(P, v) == false); // outside
146
147 P[0] = -1.17;
148 P[1] = 9.83;
149 P[2] = 0;
150 REQUIRE(MeshVoxelizer6::pointIsInsideVoxel(P, v) == false); // outside
151 }
152
153 // ---------------------------------------------------------
154 SECTION("26-sep voxelization of a single triangle")
155 {
156 Domain domain(Point(0,0,0), Point(10,10,10));
157 DigitalSet outputSet(domain);
158 MeshVoxelizer26 voxelizer;
159
160 voxelizer.voxelize(outputSet, Point(5,0,0), Point(0,5,0), Point(0,0,5));
161 REQUIRE( outputSet.size() == 46 );
162 }
163
164 // ---------------------------------------------------------
165 SECTION("6-sep voxelization of a single triangle")
166 {
167 Domain domain(Point(0,0,0), Point(10,10,10));
168 DigitalSet outputSet(domain);
169 MeshVoxelizer6 voxelizer;
170
171 voxelizer.voxelize(outputSet, Point(5,0,0), Point(0,5,0), Point(0,0,5));
172 REQUIRE( outputSet.size() == 21 );
173 }
174
175 // ---------------------------------------------------------
176 SECTION("6-sep voxelization of a OFF cube mesh")
177 {
178 //Importing OFF mesh
179 Mesh<Z3i::RealPoint> inputMesh;
180 MeshReader<Z3i::RealPoint>::importOFFFile(testPath +"/samples/box.off" , inputMesh);
181 Z3i::Domain domain( Point().diagonal(-30), Point().diagonal(30));
182 DigitalSet outputSet(domain);
183 MeshVoxelizer6 voxelizer;
184
185 CAPTURE(inputMesh.nbFaces());
186
187 voxelizer.voxelize(outputSet, inputMesh, 10.0 );
188
189 CAPTURE(outputSet.size());
190 //hard coded test.
191 REQUIRE( outputSet.size() == 2562 );
192 }
193 // ---------------------------------------------------------
194 SECTION("26-sep voxelization of a OFF cube mesh")
195 {
196 //Importing OFF mesh
197 Mesh<Z3i::RealPoint> inputMesh;
198 MeshReader<Z3i::RealPoint>::importOFFFile(testPath +"/samples/box.off" , inputMesh);
199 Z3i::Domain domain( Point().diagonal(-30), Point().diagonal(30));
200 DigitalSet outputSet(domain);
201 MeshVoxelizer26 voxelizer;
202
203 CAPTURE(inputMesh.nbFaces());
204
205 voxelizer.voxelize(outputSet, inputMesh, 10.0 );
206
207 CAPTURE(outputSet.size());
208 //hard coded test.
209 REQUIRE( outputSet.size() == 4162 );
210 }
211}
Aim: Class that implements an orientation functor, ie. it provides a way to compute the orientation o...
Aim: A class for computing the digitization of a triangle or a Mesh.
Aim: This class is defined to represent a surface mesh through a set of vertices and faces....
Definition Mesh.h:92
Size nbFaces() const
Aim: Implements basic operations that will be used in Point and Vector classes.
Aim: Small adapter to models of COrientationFunctor2. It is a model of concepts::CPointPredicate....
Z3i this namespace gathers the standard of types for 3D imagery.
HyperRectDomain< Space > Domain
Definition StdDefs.h:172
Space::Point Point
Definition StdDefs.h:168
DigitalSetSelector< Domain, BIG_DS+HIGH_BEL_DS >::Type DigitalSet
Definition StdDefs.h:173
DGtal is the top-level namespace which contains all DGtal functions and types.
static bool importOFFFile(const std::string &filename, DGtal::Mesh< TPoint > &aMesh, bool invertVertexOrder=false, bool onlyFaceVertex=false)
CAPTURE(thicknessHV)
TEST_CASE("Basic voxelization test", "[voxelization]")
Domain domain
SECTION("Testing constant forward iterators")
REQUIRE(domain.isInside(aPoint))