DGtal 1.4.2
Loading...
Searching...
No Matches
testRayIntersection.cpp
Go to the documentation of this file.
1
31#include <iostream>
32#include "DGtal/base/Common.h"
33#include "ConfigTest.h"
34#include "DGtal/helpers/StdDefs.h"
35#include "DGtal/geometry/tools/RayIntersectionPredicates.h"
36
38#include "DGtal/shapes/implicit/ImplicitBall.h"
39
41#include "DGtal/shapes/GaussDigitizer.h"
42#include "DGtal/topology/LightImplicitDigitalSurface.h"
43#include "DGtal/topology/DigitalSurface.h"
44
46
47using namespace std;
48using namespace DGtal;
49
51// Functions for testing class RayIntersection.
53
57template<typename Point>
59{
60 unsigned int nbok = 0;
61 unsigned int nb = 0;
62
63 trace.beginBlock ( "Testing RayTriangle ..." );
64
66 Ray ray(Point(0,0,0), Point(1,1,1));
67
68 trace.info() << "Ray intersection with 222-triangle "<<std::endl;
69 nbok += ray(Point(2,0,0),Point(0,0,2),Point(0,2,0)) ? 1 : 0;
70 nb++;
71 trace.info() << "(" << nbok << "/" << nb << ") "
72 << "true " << std::endl;
73
74 trace.info() << "Ray intersection with reversed 222-triangle "<<std::endl;
75 nbok += ray(Point(2,0,0),Point(0,2,0),Point(0,0,2)) ? 1 : 0;
76 nb++;
77 trace.info() << "(" << nbok << "/" << nb << ") "
78 << "true (no culling) " << std::endl;
79
80 Ray ray2(Point(100,0,0), Point(1,1,1));
81 trace.info() << "Ray intersection wrong ray with 222-triangle"<<std::endl;
82 nbok += !ray2(Point(2,0,0),Point(0,2,0),Point(0,0,2)) ? 1 : 0;
83 nb++;
84 trace.info() << "(" << nbok << "/" << nb << ") "
85 << "false (no intersection)" << std::endl;
86
87
88 Ray ray3(Point(0,0,0), Point(-1,-1,-1));
89 trace.info() << "Ray intersection reversed ray with 222-triangle "<<std::endl;
90 nbok += !ray3(Point(2,0,0),Point(0,2,0),Point(0,0,2)) ? 1 : 0;
91 nb++;
92 trace.info() << "(" << nbok << "/" << nb << ") "
93 << "false (reversed ray)" << std::endl;
94
95
96 trace.info() << "Ray intersection with -2-2-2-triangle "<<std::endl;
97 nbok += !ray(Point(-2,0,0),Point(0,-2,0),Point(0,0,-2)) ? 1 : 0;
98 nb++;
99 trace.info() << "(" << nbok << "/" << nb << ") "
100 << "false (reversed triangle)" << std::endl;
101
102 Ray ray4(Point(2,2,0), Point(-1,-1,0));
103 trace.info() << "Ray intersection in plane "<<std::endl;
104 nbok += !ray4(Point(0,0,0),Point(0,1,0),Point(1,1,0)) ? 1 : 0;
105 nb++;
106 trace.info() << "(" << nbok << "/" << nb << ") "
107 << "false (in plane)" << std::endl;
108
109
110 trace.endBlock();
111
112 return nbok == nb;
113}
114
116{
117 unsigned int nbok = 0;
118 unsigned int nb = 0;
119
120 trace.beginBlock ( "Testing RayQuad ..." );
121
122 using namespace Z3i;
123
125 Ray ray(Point(0,0,0), Point(1,1,1));
126
127 trace.info() << "Ray intersection with huge quad "<<std::endl;
128 nbok += ray(Point(10,0,0),Point(10,100,0),
129 Point(10,0,100),Point(10,100,100) ) ? 1 : 0;
130 nb++;
131 trace.info() << "(" << nbok << "/" << nb << ") "
132 << "true " << std::endl;
133 trace.info()<<std::endl;
134
135 trace.info() << "Ray intersection with far quad "<<std::endl;
136 nbok += !ray(Point(10,0,0),Point(10,1,0),
137 Point(10,0,1),Point(10,1,1) ) ? 1 : 0;
138 nb++;
139 trace.info() << "(" << nbok << "/" << nb << ") "
140 << "false " << std::endl;
141 trace.info()<<std::endl;
142
143 trace.endBlock();
144
145 return nbok == nb;
146}
147
149{
150 unsigned int nbok = 0;
151 unsigned int nb = 0;
152
153 trace.beginBlock ( "Testing RaySurfel ..." );
154
155 using namespace Z3i;
156
157 KSpace k;
158
159 k.init(Point(0,0,0), Point(10,10,10), true);
160
162 Ray ray(KSpace::Cell::Point(0,0,0),
163 KSpace::Cell::Point(2,1,1));
164
165 KSpace::Surfel surf = k.sCell( Point( 2,1,1) );
166 KSpace::Surfel surf2 = k.sCell( Point( 2,7,7) );
167
168 trace.info() << "Ray intersection with surf "<<std::endl;
169 nbok += ray(surf) ? 1 : 0;
170 nb++;
171 trace.info() << "(" << nbok << "/" << nb << ") "
172 << "true " << std::endl;
173 trace.info()<<std::endl;
174
175 trace.info() << "Ray intersection with surf2 "<<std::endl;
176 nbok += !ray(surf2 ) ? 1 : 0;
177 nb++;
178 trace.info() << "(" << nbok << "/" << nb << ") "
179 << "false " << std::endl;
180 trace.info()<<std::endl;
181
182 trace.endBlock();
183
184 return nbok == nb;
185}
186
187
189{
194 trace.beginBlock(" Ray shooting in digital surface");
195 trace.beginBlock( "Shape initialisation ..." );
196 ImplicitShape ishape( Z3i::RealPoint( 0, 0 ,0), 12 );
197 DigitalShape dshape;
198 dshape.attach( ishape );
199 dshape.init( Z3i::RealPoint( -20.0, -20.0 ,-20.0 ), Z3i::RealPoint( 20.0, 20.0, 20.0 ), 1.0 );
201 if ( !K.init( dshape.getLowerBound(), dshape.getUpperBound(), true ) )
202 {
203 trace.error() << "Problem with Khalimsky space init" << std::endl;
204 return false;
205 }
206
208 Boundary boundary( K, dshape, SurfelAdjacency<Z3i::KSpace::dimension>( true ), bel );
209 MyDigitalSurface surf ( boundary );
210 trace.endBlock();
211
212
213 trace.beginBlock(" Ray shooting the shape");
214
217
220
221 MyDigitalSurface::ConstIterator it = std::find_if(surf.begin(), surf.end(), ray);
222 trace.info() << "Ray shooting returns : "<< *it<<std::endl;
223
224 MyDigitalSurface::ConstIterator it2 = std::find_if(surf.begin(), surf.end(), ray2);
225 trace.info() << "Ray shooting returns : "<< *it2<<std::endl;
226
227 trace.endBlock();
228 trace.endBlock();
229
230 return true;
231}
232
234// Standard services - public :
235
236int main( int argc, char** argv )
237{
238 trace.beginBlock ( "Testing class RayIntersection" );
239 trace.info() << "Args:";
240 for ( int i = 0; i < argc; ++i )
241 trace.info() << " " << argv[ i ];
242 trace.info() << endl;
243
248 && testRaySurface(); // && ... other tests
249 trace.emphase() << ( res ? "Passed." : "Error." ) << endl;
250 trace.endBlock();
251 return res ? 0 : 1;
252}
253// //
Aim: Represents a set of n-1-cells in a nD space, together with adjacency relation between these cell...
ConstIterator begin() const
ConstIterator end() const
DigitalSurfaceContainer::SurfelConstIterator ConstIterator
Aim: A class for computing the Gauss digitization of some Euclidean shape, i.e. its intersection with...
const Point & getUpperBound() const
void attach(ConstAlias< EuclideanShape > shape)
const Point & getLowerBound() const
void init(const RealPoint &xLow, const RealPoint &xUp, typename RealVector::Component gridStep)
Aim: model of CEuclideanOrientedShape and CEuclideanBoundedShape concepts to create a ball in nD....
Aim: model of CEuclideanOrientedShape concepts to create a shape from a polynomial.
Aim: This class is a model of CCellularGridSpaceND. It represents the cubical grid as a cell complex,...
bool init(const Point &lower, const Point &upper, bool isClosed)
Specifies the upper and lower bounds for the maximal cells in this space.
SCell sCell(const SPreCell &c) const
From a signed cell, returns a signed cell lying into this Khalismky space.
Aim: A model of CDigitalSurfaceContainer which defines the digital surface as the boundary of an impl...
static SCell findABel(const KSpace &K, const PointPredicate &pp, unsigned int nbtries=1000)
Aim: Represent adjacencies between surfel elements, telling if it follows an interior to exterior ord...
void beginBlock(const std::string &keyword="")
std::ostream & emphase()
std::ostream & error()
std::ostream & info()
double endBlock()
DigitalSurface< MyDigitalSurfaceContainer > MyDigitalSurface
DGtal is the top-level namespace which contains all DGtal functions and types.
Trace trace
Definition Common.h:153
STL namespace.
This class implements various intersection predicates between a ray and a triangle,...
Represents a signed cell in a cellular grid space by its Khalimsky coordinates and a boolean value.
int main()
Definition testBits.cpp:56
MyPointD Point
KSpace K
bool testRaySurface()
bool testRayQuadIntersection()
bool testRayIntersection()
bool testRaySurfelIntersection()