DGtal 1.3.0
Loading...
Searching...
No Matches
IntersectionTarget.h
1
17#pragma once
18
28#if !defined IntersectionTarget_h
30#define IntersectionTarget_h
31
32#include "DGtal/helpers/StdDefs.h"
33#include "DGtal/base/ConstAlias.h"
34#include "DGtal/shapes/Mesh.h"
35#include "DGtal/shapes/IntersectionTarget.h"
36#include "DGtal/kernel/SpaceND.h"
37#include "DGtal/kernel/sets/CDigitalSet.h"
38#include "DGtal/geometry/tools/determinant/PredicateFromOrientationFunctor2.h"
39#include "DGtal/geometry/tools/determinant/InHalfPlaneBySimple3x3Matrix.h"
40
41namespace DGtal
42{
43
45
56 template<typename TSpace, size_t TSeparation, size_t TDimension = 1>
58 {
60 BOOST_STATIC_ASSERT_MSG( TSpace::dimension == 3, "DigitalSet dimension must be 3");
61
63 BOOST_STATIC_ASSERT_MSG( TSeparation == 6 || TSeparation == 26, "Separation must be 6 or 26");
64
66 BOOST_STATIC_ASSERT_MSG( TDimension == 1, "Currently only 1D intersection target is implemented");
67
72
74 template<typename Space, size_t Separation, size_t Dimension = 1>
76
77 /****** Associated types *********************/
79 using PointR3 = typename TSpace::RealPoint;
80 using VectorR3 = typename TSpace::RealPoint;
81 using PointR2 = typename Space2D::RealPoint;
83 /*********************************************/
84
86 struct Edge
87 {
89 Edge() = default;
90 Edge(const Edge&) = default;
91 Edge(const PointR3& mf, const PointR3& ms) : myFirst(mf), mySecond(ms) {}
92 };
93
97 template<typename Space>
99 {
100 // ----------------------- Members ------------------------------
101
103 const std::array<Edge, 3> myTarget {{
104 { { 0.5, 0.0, 0.0 }, { -0.5, 0.0, 0.0} } , // AB
105 { { 0.0, 0.0, 0.5 }, { 0.0, 0.0, -0.5} } , // CD
106 { { 0.0, 0.5, 0.0 }, { 0.0, -0.5, 0.0} } // EF
107 }};
108
109 // ----------------------- Standard services --------------------
110
115 const std::array<Edge, 3>& operator()() {
116 return myTarget;
117 }
118
124 const Edge& operator()(int i) {
125 return myTarget[i];
126 }
127
134 PointR2 project(int i, const PointR3& p) const {
135 ASSERT( 0 <= i && i <= 2 );
136
137 if(myTarget[i].myFirst[0] == 0.5)
138 return { p[1], p[2] }; // ignore x
139 else if(myTarget[i].myFirst[1] == 0.5)
140 return { p[0], p[2] }; // ignore y
141 else
142 return { p[0], p[1] }; // ignore z
143 }
144 };
145
149 template<typename Space>
151 {
152 // ----------------------- Members ------------------------------
153
155 const std::array<Edge, 4> myTarget {{
156 { { -0.5, 0.5, 0.5}, { 0.5, -0.5, -0.5} } , // AG
157 { { 0.5, 0.5, 0.5}, { -0.5, -0.5, -0.5} } , // BH
158 { { 0.5, 0.5, -0.5}, { -0.5, -0.5, 0.5} } , // CE
159 { { -0.5, 0.5, -0.5}, { 0.5, -0.5, 0.5} } // DF
160 }};
161
163 std::array<VectorR3, 4> myE1base;
164
166 std::array<VectorR3, 4> myE2base;
167
172 {
173 const double coef = 1. / std::sqrt(3.);
174
175 std::array<VectorR3, 4> myNormal {{
176 { coef, -coef, -coef } ,
177 { -coef, -coef, -coef } ,
178 { -coef, -coef, coef } ,
179 { coef, -coef, coef }
180 }};
181
182 // computation of each e1/e2 bases foreach normal
183 for(int i = 0; i < 4; i++)
184 {
185 auto& x = myNormal[i][0];
186 auto& y = myNormal[i][1];
187 auto& z = myNormal[i][2];
188
189 myE1base[i] = std::move( VectorR3(-y, x, 0).getNormalized() );
190 myE2base[i] = std::move( VectorR3(-x*z, -y*z, x*x + y*y).getNormalized() );
191 }
192 }
193
194 // ----------------------- Standard services --------------------
195
200 const std::array<Edge, 4>& operator()() const {
201 return myTarget;
202 }
203
209 const Edge& operator()(int i) const {
210 return myTarget[i];
211 }
212
219 PointR2 project(int i, const PointR3& p) const {
220 ASSERT( 0 <= i && i <= 3 );
221
222 return { myE1base[i].dot(p), myE2base[i].dot(p) };
223 }
224 };
225 };
226}
227
228#endif // !defined MeshVoxelizer_h
PointVector< dim, double > RealPoint
Definition: SpaceND.h:117
DGtal is the top-level namespace which contains all DGtal functions and types.
Edge(const PointR3 &mf, const PointR3 &ms)
std::array< VectorR3, 4 > myE1base
E1 base for each target's edge.
Internal intersection target structure.
Aim: A class for intersection target used for voxelization.
typename Space2D::RealPoint PointR2
typename TSpace::RealPoint VectorR3
BOOST_STATIC_ASSERT_MSG(TSeparation==6||TSeparation==26, "Separation must be 6 or 26")
Separation Checking.
BOOST_STATIC_ASSERT_MSG(TSpace::dimension==3, "DigitalSet dimension must be 3")
Digital Set dimension Checking.
typename TSpace::RealPoint PointR3
BOOST_STATIC_ASSERT_MSG(TDimension==1, "Currently only 1D intersection target is implemented")
Dimension of the intersection target checking.