DGtal  1.0.0
Functions
testBasicPointFunctors.cpp File Reference
#include <cstdio>
#include <cmath>
#include <iostream>
#include <fstream>
#include <vector>
#include "DGtal/base/Common.h"
#include "DGtal/base/CUnaryFunctor.h"
#include "DGtal/kernel/PointVector.h"
#include "DGtal/kernel/SpaceND.h"
#include "DGtal/kernel/BasicPointFunctors.h"
#include "DGtal/kernel/domains/HyperRectDomain.h"
Include dependency graph for testBasicPointFunctors.cpp:

Go to the source code of this file.

Functions

template<typename TFunctor , typename TArg , typename TRes >
void checkingConcepts ()
 
bool testProjector ()
 
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
Bertrand Kerautret (kerau.nosp@m.tre@.nosp@m.loria.nosp@m..fr ) LORIA (CNRS, UMR 7503), University of Nancy, France
Tristan Roussillon (trist.nosp@m.an.r.nosp@m.oussi.nosp@m.llon.nosp@m.@liri.nosp@m.s.cn.nosp@m.rs.fr ) Laboratoire d'InfoRmatique en Image et Systèmes d'information - LIRIS (CNRS, UMR 5205), CNRS, France
Date
2012/02/02

This file is part of the DGtal library

Definition in file testBasicPointFunctors.cpp.

Function Documentation

◆ checkingConcepts()

template<typename TFunctor , typename TArg , typename TRes >
void checkingConcepts ( )

Definition at line 47 of file testBasicPointFunctors.cpp.

48 {
49  BOOST_CONCEPT_ASSERT(( concepts::CUnaryFunctor<TFunctor, TArg, TRes > ));
50 }
Aim: Defines a unary functor, which associates arguments to results.
Definition: CUnaryFunctor.h:89

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 269 of file testBasicPointFunctors.cpp.

270 {
271  trace.beginBlock ( "Testing basic point functors" );
272  trace.info() << "Args:";
273  for ( int i = 0; i < argc; ++i )
274  trace.info() << " " << argv[ i ];
275  trace.info() << endl;
276 
277 
278  checkingConcepts<functors::Projector<SpaceND<2,int> >, PointVector<6,int>, PointVector<2,int> >();
279  //for instance, this does not compile because
280  //the point of dim 6 is projected on a point of dim 2 (and not 3)
281  //checkingConcepts<Projector<SpaceND<2,int> >, PointVector<6,int>, PointVector<3,int> >();
282 
283  bool res = testProjector();
284 
285  trace.emphase() << ( res ? "Passed." : "Error." ) << endl;
286  trace.endBlock();
287  return res ? 0 : 1;
288 }
void beginBlock(const std::string &keyword="")
Trace trace
Definition: Common.h:144
bool testProjector()
double endBlock()
Aim: Implements basic operations that will be used in Point and Vector classes.
Definition: PointVector.h:165
std::ostream & emphase()
std::ostream & info()

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

◆ testProjector()

bool testProjector ( )

Definition at line 52 of file testBasicPointFunctors.cpp.

53 {
54  unsigned int nbok = 0;
55  unsigned int nb = 0;
56 
57  trace.beginBlock ( "Checking projection on a subspace" );
58  {
59  //a 3d point
60  PointVector<3,int> p(0,1,2);
61 
62  //projectors
63  typedef DGtal::functors::Projector<SpaceND<2,int> > Projector2D;
64  std::vector<Dimension> v1, v2;
65  v1.push_back(0); v1.push_back(2);
66  v2.push_back(2); v2.push_back(1);
67  Projector2D proj1, proj2, proj3;
68  proj1.init(v1.begin(), v1.end());
69  proj2.init(v2.begin(), v2.end());
70 
71  //comparison
72  PointVector<2,int> res1(0,2);
73  trace.info() << "p " << p << " => " << proj1(p) << " == " << res1 << std::endl;
74  nbok += ( proj1(p) == res1 ) ? 1 : 0;
75  nb++;
76 
77  PointVector<2,int> res2(2,1);
78  trace.info() << "p " << p << " => " << proj2(p) << " == " << res2 << std::endl;
79  nbok += ( proj2(p) == res2 ) ? 1 : 0;
80  nb++;
81 
82  PointVector<2,int> res3(0,1);
83  trace.info() << "p " << p << " => " << proj3(p) << " == " << res3 << std::endl;
84  nbok += ( proj3(p) == res3 ) ? 1 : 0;
85  nb++;
86  }
87  trace.endBlock();
88 
89  trace.beginBlock ( "Checking projection on a greater space" );
90  {
91  //a 2d point
92  PointVector<2,int> p(5,2);
93 
94  //projectors
95  typedef DGtal::functors::Projector<SpaceND<3,int> > Projector3D;
96  std::vector<Dimension> v1, v2, v4;
97  v1.push_back(0); v1.push_back(2); v1.push_back(1);
98  v2.push_back(1); v2.push_back(0);
99  v4.push_back(1);
100  Projector3D proj1, proj2, proj3;
101  proj1.init(v1.begin(), v1.end());
102  proj2.init(v2.begin(), v2.end());
103  Projector3D proj4(-1);
104  proj4.init(v4.begin(), v4.end());
105 
106  //SliceRotator2D
107  PointVector<3, int> pt1(0,0, 0);
108  PointVector<3, int> pt2(10,10, 10);
109 
113  PointVector<2, int> pt(5,5);
114  PointVector<2, int> pt_2(10, 9);
115  PointVector<3, int> ptR(4,5,6);
116  PointVector<3, int> ptR2(0, 1, 7);
117 
118  trace.info() << "pt " << pt << " => " << sliceRot(pt) << " == " << ptR << std::endl;
119  nbok += ( sliceRot(pt) == ptR ) ? 1 : 0;
120  nb++;
121 
122  trace.info() << "pt " << pt_2 << " => " << sliceRot2(pt_2) << " == " << ptR2 << std::endl;
123  nbok += ( sliceRot2(pt_2) == ptR2 ) ? 1 : 0;
124  nb++;
125 
126  //Point2DEmbedderIn3D
127  PointVector<3,int> ptOrigin3D(3,3,3);
129  ptOrigin3D,
130  PointVector<3,int>(6,6,3),
131  PointVector<3,int>(3,3,5),
132  PointVector<3,int>(0,0,0));
133  PointVector<2, int> ptb(0, 0);
134  PointVector<2, int> pt_2b(4, 2);
135  trace.info() << "pt " << ptb << " => " << embedder(ptb) << " == " << PointVector<3,int>(3,3,3) << std::endl;
136  nbok += ( embedder(ptb) == PointVector<3,int>(3,3,3) ) ? 1 : 0;
137  nb++;
138 
139  trace.info() << "pt " << pt_2b << " => " << embedder(pt_2b) << " == " << PointVector<3,int>(5,5,5) << std::endl;
140  nbok += ( embedder(pt_2b) == PointVector<3,int>(5,5,5) ) ? 1 : 0;
141  nb++;
142 
143  //Point2DEmbedderIn3D (constructor from normal point)
144  PointVector<3,int> pt2Origin3D(5,5,3);
146  pt2Origin3D,
147  PointVector<3,int>(0,0,3),
148  4);
149  PointVector<2, int> pt2b(0, 0);
150  PointVector<2, int> pt2_2b(2, 2);
151  //trace.info() << "pt " << pt2b << " => " << embedder2(pt2b) << " == " << PointVector<3,int>(3,5,3) << std::endl;
152  //nbok += ( embedder2(pt2b) == PointVector<3,int>(3,5,3) ) ? 1 : 0;
153  trace.info() << "pt " << pt2b << " => " << embedder2(pt2b) << " == " << PointVector<3,int>(2,5,3) << std::endl;
154  nbok += ( embedder2(pt2b) == PointVector<3,int>(2,5,3) ) ? 1 : 0; // TODO: check expected result
155  nb++;
156 
157  //trace.info() << "pt " << pt2_2b << " => " << embedder2(pt2_2b) << " == " << PointVector<3,int>(5,4,3) << std::endl;
158  //nbok += ( embedder2(pt2_2b) == PointVector<3,int>(5,4,3) ) ? 1 : 0;
159  trace.info() << "pt " << pt2_2b << " => " << embedder2(pt2_2b) << " == " << PointVector<3,int>(4,4,3) << std::endl;
160  nbok += ( embedder2(pt2_2b) == PointVector<3,int>(4,4,3) ) ? 1 : 0; // TODO: check expected result
161  nb++;
162 
163 
164  //comparison
165  PointVector<3,int> res1(5,0,2);
166  trace.info() << "p " << p << " => " << proj1(p) << " == " << res1 << std::endl;
167  nbok += ( proj1(p) == res1 ) ? 1 : 0;
168  nb++;
169 
170  PointVector<3,int> res2(2,5,0);
171  trace.info() << "p " << p << " => " << proj2(p) << " == " << res2 << std::endl;
172  nbok += ( proj2(p) == res2 ) ? 1 : 0;
173  nb++;
174 
175  PointVector<3,int> res3(5,2,0);
176  trace.info() << "p " << p << " => " << proj3(p) << " == " << res3 << std::endl;
177  nbok += ( proj3(p) == res3 ) ? 1 : 0;
178  nb++;
179 
180  PointVector<3,int> res4(2,-1,-1);
181  trace.info() << "p " << p << " => " << proj4(p) << " == " << res4
182  << "(-1 as default value)" << std::endl;
183  nbok += ( proj4(p) == res4 ) ? 1 : 0;
184  nb++;
185  }
186  trace.endBlock();
187 
188 
189  trace.beginBlock ( "Checking Basic Domain SubSampler" );
190  {
191  // BasicDomainSubSampler 2D
193  std::vector< SpaceND<2, int>::Size > aGridSize;
194  aGridSize.push_back(5);
195  aGridSize.push_back(5);
196  PointVector<2,int> shiftVector(0 ,0);
198  aGridSize, shiftVector);
199  trace.info()<< "Subsampling functor on 2D domain " << domainSource <<" with grid size "
200  << aGridSize[0] << " " << aGridSize[1] << " and shift vector "<< shiftVector <<std::endl ;
201  PointVector<2,int> pointTest(1,0);
202  PointVector<2,int> pointInSourceDomain = subSampler(pointTest);
203  trace.info() << "Sampling point of coordinate "<< pointTest << ", => coordinates in source domain:"
204  << pointInSourceDomain << " == " << PointVector<2,int>(5,0) << std::endl;
205  nb++;
206  nbok += (pointInSourceDomain== PointVector<2,int>(5,0));
207 
208  // BasicDomainSubSampler 3D
209  HyperRectDomain<SpaceND<3, int> > domainSource3D (PointVector<3,int>(0,0, 0), PointVector<3,int>(10,10, 10));
210  std::vector< SpaceND<3, int>::Size > aGridSize3D;
211  aGridSize3D.push_back(5);
212  aGridSize3D.push_back(3);
213  aGridSize3D.push_back(1);
214  PointVector<3,int> shiftVector3D(0 ,1, -1);
216  aGridSize3D, shiftVector3D);
217  trace.info()<< "Subsampling functor on 3D domain " << domainSource3D <<" with grid size "
218  << aGridSize3D[0] << " " << aGridSize3D[1]<< " " << aGridSize3D[2] << " and shift vector "<< shiftVector3D <<std::endl ;
219  PointVector<3,int> pointTest3D(0,1,2);
220  PointVector<3,int> pointTest3D2(0,0,0);
221  PointVector<3,int> pointInSourceDomain3D = subSampler3D(pointTest3D);
222  PointVector<3,int> pointInSourceDomain3D2 = subSampler3D(pointTest3D2);
223  trace.info() << "Sampling point of coordinate "<< pointTest3D << ", => coordinates in source domain:"
224  << pointInSourceDomain3D << " == " << PointVector<3,int>(0, 4, 1) << std::endl;
225  trace.info() << "Sampling point of coordinate "<< pointTest3D2 << ", => coordinates in source domain:"
226  << pointInSourceDomain3D2 << " == " << PointVector<3,int>(0, 1, 0) << std::endl;
227  nb++;
228  nbok += (pointInSourceDomain3D== PointVector<3,int>(0, 4, 1)) &&
229  (pointInSourceDomain3D2== PointVector<3,int>(0, 1, 0));
230 
231  // FlipDomainAxis
232  std::vector<unsigned int> vectFlip;
233  vectFlip.push_back(1);
234  vectFlip.push_back(2);
235  functors::FlipDomainAxis<HyperRectDomain<SpaceND<3, int> > > flipFunctorAxis12(domainSource3D, vectFlip);
236  trace.info() << "Flip point of coordinate "<< pointTest3D << ", => fliped coordinates with axis 1 and 2:"
237  << flipFunctorAxis12(pointTest3D) << " == " << PointVector<3,int>(0, 9, 8) << std::endl;
238  nb++;
239  nbok += (flipFunctorAxis12(pointTest3D)== PointVector<3,int>(0, 9, 8));
240 
241 
242 
243  // BasicDomainReSampler 2D
244  std::vector< double > aGridSizeReSample;
245  aGridSizeReSample.push_back(0.25);
246  aGridSizeReSample.push_back(0.5);
248  DGtal::int32_t, double > reSampler(domainSource,
249  aGridSizeReSample, shiftVector);
250 
251  trace.info()<< "Resampling functor on 2D domain " << domainSource <<" with grid size "
252  << aGridSizeReSample[0] << " " << aGridSizeReSample[1] << " and shift vector "<< shiftVector <<std::endl ;
253  PointVector<2,int> pointTestRS(9,4);
254  PointVector<2,int> pointInSourceDomainRS = reSampler(pointTestRS);
255  trace.info() << "Sampling point of coordinate "<< pointTestRS << ", => coordinates in source domain:"
256  << pointInSourceDomainRS << " == " << PointVector<2,int>(2,2) << std::endl;
257  nb++;
258  nbok += (pointInSourceDomainRS== PointVector<2,int>(2,2));
259 
260 
261 
262  }
263  return nbok == nb;
264 }
void beginBlock(const std::string &keyword="")
Trace trace
Definition: Common.h:144
Aim: Parallelepidec region of a digital space, model of a 'CDomain'.
double endBlock()
Aim: Functor that maps a point P of dimension i to a point Q of dimension j. The member myDims is an ...
Aim: Functor that subsamples an initial domain by given a grid size and a shift vector....
Domain domain
Aim: Implements basic operations that will be used in Point and Vector classes.
Definition: PointVector.h:165
Aim: Functor that embeds a 2D point into a 3D space from two axis vectors and an origin point given i...
Aim: Functor that flips the domain coordinate system from some selected axis. For instance,...
std::ostream & info()
void init(const TIterator &itb, const TIterator &ite)
boost::int32_t int32_t
signed 32-bit integer.
Definition: BasicTypes.h:72
Special Point Functor that adds one dimension to a 2D point and apply on it a rotation of angle alpha...

References DGtal::Trace::beginBlock(), domain, DGtal::Trace::endBlock(), DGtal::Trace::info(), DGtal::functors::Projector< S >::init(), and DGtal::trace.

Referenced by main().