DGtal  1.5.beta
testRayIntersection.cpp File Reference
#include <iostream>
#include "DGtal/base/Common.h"
#include "ConfigTest.h"
#include "DGtal/helpers/StdDefs.h"
#include "DGtal/geometry/tools/RayIntersectionPredicates.h"
#include "DGtal/shapes/implicit/ImplicitBall.h"
#include "DGtal/shapes/GaussDigitizer.h"
#include "DGtal/topology/LightImplicitDigitalSurface.h"
#include "DGtal/topology/DigitalSurface.h"
Include dependency graph for testRayIntersection.cpp:

Go to the source code of this file.

Functions

template<typename Point >
bool testRayIntersection ()
 
bool testRayQuadIntersection ()
 
bool testRaySurfelIntersection ()
 
bool testRaySurface ()
 
int main (int argc, char **argv)
 

Detailed Description

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Author
David Coeurjolly (david.nosp@m..coe.nosp@m.urjol.nosp@m.ly@l.nosp@m.iris..nosp@m.cnrs.nosp@m..fr ) Laboratoire d'InfoRmatique en Image et Systemes d'information - LIRIS (CNRS, UMR 5205), CNRS, France
Date
2014/08/14

Functions for testing class RayIntersection.

This file is part of the DGtal library.

Definition in file testRayIntersection.cpp.

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 236 of file testRayIntersection.cpp.

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 
244  bool res = testRayIntersection<Z3i::Point>()
245  && testRayIntersection<Z3i::RealPoint>()
248  && testRaySurface(); // && ... other tests
249  trace.emphase() << ( res ? "Passed." : "Error." ) << endl;
250  trace.endBlock();
251  return res ? 0 : 1;
252 }
void beginBlock(const std::string &keyword="")
std::ostream & emphase()
std::ostream & info()
double endBlock()
Trace trace
Definition: Common.h:153
bool testRaySurface()
bool testRayQuadIntersection()
bool testRaySurfelIntersection()

References DGtal::Trace::beginBlock(), DGtal::Trace::emphase(), DGtal::Trace::endBlock(), DGtal::Trace::info(), testRayQuadIntersection(), testRaySurface(), testRaySurfelIntersection(), and DGtal::trace.

◆ testRayIntersection()

template<typename Point >
bool testRayIntersection ( )

Example of a test. To be completed.

Definition at line 58 of file testRayIntersection.cpp.

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 }
This class implements various intersection predicates between a ray and a triangle,...
MyPointD Point
Definition: testClone2.cpp:383

References DGtal::Trace::beginBlock(), DGtal::Trace::endBlock(), DGtal::Trace::info(), and DGtal::trace.

◆ testRayQuadIntersection()

bool testRayQuadIntersection ( )

Definition at line 115 of file testRayIntersection.cpp.

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 }

References DGtal::Trace::beginBlock(), DGtal::Trace::endBlock(), DGtal::Trace::info(), and DGtal::trace.

Referenced by main().

◆ testRaySurface()

bool testRaySurface ( )

Definition at line 188 of file testRayIntersection.cpp.

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 );
200  Z3i::KSpace K;
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 
207  Z3i::KSpace::Surfel bel = Surfaces<Z3i::KSpace>::findABel( K, dshape, 10000 );
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 
216  Z3i::KSpace::Cell::Point(2,2,2));
217 
219  Z3i::KSpace::Cell::Point(1,0,0));
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 }
Aim: Represents a set of n-1-cells in a nD space, together with adjacency relation between these cell...
DigitalSurfaceContainer::SurfelConstIterator ConstIterator
Aim: A class for computing the Gauss digitization of some Euclidean shape, i.e. its intersection with...
const Point & getLowerBound() const
void attach(ConstAlias< EuclideanShape > shape)
const Point & getUpperBound() 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....
Definition: ImplicitBall.h:65
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.
Aim: A model of CDigitalSurfaceContainer which defines the digital surface as the boundary of an impl...
Aim: Implements basic operations that will be used in Point and Vector classes.
Definition: PointVector.h:593
Aim: A utility class for constructing surfaces (i.e. set of (n-1)-cells).
Definition: Surfaces.h:79
Aim: Represent adjacencies between surfel elements, telling if it follows an interior to exterior ord...
std::ostream & error()
DigitalSurface< MyDigitalSurfaceContainer > MyDigitalSurface
Represents a signed cell in a cellular grid space by its Khalimsky coordinates and a boolean value.
KSpace K

References DGtal::GaussDigitizer< TSpace, TEuclideanShape >::attach(), DGtal::DigitalSurface< TDigitalSurfaceContainer >::begin(), DGtal::Trace::beginBlock(), DGtal::DigitalSurface< TDigitalSurfaceContainer >::end(), DGtal::Trace::endBlock(), DGtal::Trace::error(), DGtal::GaussDigitizer< TSpace, TEuclideanShape >::getLowerBound(), DGtal::GaussDigitizer< TSpace, TEuclideanShape >::getUpperBound(), DGtal::Trace::info(), DGtal::KhalimskySpaceND< dim, TInteger >::init(), DGtal::GaussDigitizer< TSpace, TEuclideanShape >::init(), K, and DGtal::trace.

Referenced by main().

◆ testRaySurfelIntersection()

bool testRaySurfelIntersection ( )

Definition at line 148 of file testRayIntersection.cpp.

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 }
SCell sCell(const SPreCell &c) const
From a signed cell, returns a signed cell lying into this Khalismky space.

References DGtal::Trace::beginBlock(), DGtal::Trace::endBlock(), DGtal::Trace::info(), DGtal::KhalimskySpaceND< dim, TInteger >::init(), DGtal::KhalimskySpaceND< dim, TInteger >::sCell(), and DGtal::trace.

Referenced by main().