DGtal  1.5.beta
testSCellsFunctor.cpp File Reference
#include <iostream>
#include "DGtal/base/Common.h"
#include "DGtal/base/CUnaryFunctor.h"
#include "DGtal/topology/SCellsFunctors.h"
#include "DGtal/topology/CanonicSCellEmbedder.h"
#include "DGtal/topology/KhalimskySpaceND.h"
Include dependency graph for testSCellsFunctor.cpp:

Go to the source code of this file.

Functions

template<typename TFunctor , typename TArg , typename TRes >
void checkingConcepts ()
 
bool testSCellsFunctors ()
 
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
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

Functions for testing the functors on scells.

This file is part of the DGtal library.

Definition in file testSCellsFunctor.cpp.

Function Documentation

◆ checkingConcepts()

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

Definition at line 49 of file testSCellsFunctor.cpp.

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

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 181 of file testSCellsFunctor.cpp.

182 {
183  trace.beginBlock ( "Testing SCells functors" );
184  trace.info() << "Args:";
185  for ( int i = 0; i < argc; ++i )
186  trace.info() << " " << argv[ i ];
187  trace.info() << endl;
188 
189  //concepts
190  typedef KhalimskySpaceND<2> K2;
191  checkingConcepts<functors::SCellToPoint<K2>, K2::SCell, K2::Point >();
192  checkingConcepts<CanonicSCellEmbedder<K2>, K2::SCell, K2::Space::RealPoint >();
193  checkingConcepts<functors::SCellToArrow<K2>, K2::SCell, std::pair<K2::Point, K2::Vector> >();
194  checkingConcepts<functors::SCellToInnerPoint<K2>, K2::SCell, K2::Point >();
195  checkingConcepts<functors::SCellToOuterPoint<K2>, K2::SCell, K2::Point >();
196  checkingConcepts<functors::SCellToIncidentPoints<K2>, K2::SCell, std::pair<K2::Point, K2::Point> >();
197  checkingConcepts<functors::SCellToCode<K2>, K2::SCell, char >();
198 
199  bool res = testSCellsFunctors(); // && ... other tests
200  trace.emphase() << ( res ? "Passed." : "Error." ) << endl;
201  trace.endBlock();
202  return res ? 0 : 1;
203 }
Aim: This class is a model of CCellularGridSpaceND. It represents the cubical grid as a cell complex,...
void beginBlock(const std::string &keyword="")
std::ostream & emphase()
std::ostream & info()
double endBlock()
Z3i::SCell SCell
KSpace K2
Definition: StdDefs.h:78
Trace trace
Definition: Common.h:153
MyPointD Point
Definition: testClone2.cpp:383
bool testSCellsFunctors()
PointVector< 3, double > RealPoint

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

◆ testSCellsFunctors()

bool testSCellsFunctors ( )

Example of a test. To be completed.

Definition at line 59 of file testSCellsFunctor.cpp.

60 {
61  unsigned int nbok = 0;
62  unsigned int nb = 0;
63 
64  trace.beginBlock ( "Testing block ..." );
65 
66  //0-scell 2 point
67  {
68  typedef KhalimskySpaceND<3> K3;
69  K3 theKSpace;
70  functors::SCellToPoint<K3> m(theKSpace);
71  K3::SCell s = theKSpace.sPointel( K3::Point(3,3,4) );
72  K3::Point aPoint = m( s );
73  trace.info() << s << aPoint <<std::endl;
74  nbok += ( aPoint == K3::Point(3,3,4) ) ? 1 : 0;
75  nb++;
76  }
77  trace.info() << "(" << nbok << "/" << nb << ") " << std::endl;
78  //1-scell 2 point
79  {
80  typedef KhalimskySpaceND<3> K3;
81  K3 theKSpace;
82  functors::SCellToPoint<K3> m(theKSpace);
83  K3::SCell s = theKSpace.sCell(K3::Point(0,0,0), true); //default point and orientation
84  theKSpace.sSetKCoords( s, K3::Point(5,6,8) );
85  K3::Point aPoint = m( s );
86  trace.info() << s << aPoint <<std::endl;
87  nbok += ( aPoint == K3::Point(3,3,4) ) ? 1 : 0;
88  nb++;
89  }
90  trace.info() << "(" << nbok << "/" << nb << ") " << std::endl;
91  //scell 2 midPoint
92  {
93  typedef KhalimskySpaceND<2> K2;
94  K2 theKSpace;
95  CanonicSCellEmbedder<K2> m(theKSpace);
96  K2::SCell s = theKSpace.sCell( K2::Point(0,1) );
98  trace.info() << s << aPoint <<std::endl;
99  nbok += ( aPoint == K2::Space::RealPoint(-0.5,0) ) ? 1 : 0;
100  nb++;
101  }
102  trace.info() << "(" << nbok << "/" << nb << ") " << std::endl;
103 
104  //scell 2 arrow
105  {
106  typedef KhalimskySpaceND<2> K2;
107  K2 theKSpace;
108  functors::SCellToArrow<K2> m(theKSpace);
109  K2::SCell s = theKSpace.sCell( K2::Point(0,1) );
110  std::pair<K2::Point, K2::Vector> aArrow = m( s );
111  trace.info() << s << aArrow.first << aArrow.second <<std::endl;
112  K2::Point p(0,1);
113  K2::Vector v(0,-1);
114  nbok += ( ((aArrow.first == p) && (aArrow.second == v)) ) ? 1 : 0;
115  nb++;
116  }
117  trace.info() << "(" << nbok << "/" << nb << ") " << std::endl;
118 
119  //scell 2 inner point
120  {
121  typedef KhalimskySpaceND<2> K2;
122  K2 theKSpace;
123  functors::SCellToInnerPoint<K2> m(theKSpace);
124  K2::SCell s = theKSpace.sCell( K2::Point(0,1) );
125  K2::Point aPoint = m( s );
126  trace.info() << s << aPoint <<std::endl;
127  nbok += ( aPoint == K2::Point(0,0) ) ? 1 : 0;
128  nb++;
129  }
130  trace.info() << "(" << nbok << "/" << nb << ") " << std::endl;
131 
132  //scell 2 outer point
133  {
134  typedef KhalimskySpaceND<2> K2;
135  K2 theKSpace;
136  functors::SCellToOuterPoint<K2> m(theKSpace);
137  K2::SCell s = theKSpace.sCell( K2::Point(0,1) );
138  K2::Point aPoint = m( s );
139  trace.info() << s << aPoint <<std::endl;
140  nbok += ( aPoint == K2::Point(-1,0) ) ? 1 : 0;
141  nb++;
142  }
143  trace.info() << "(" << nbok << "/" << nb << ") " << std::endl;
144 
145  //scell 2 incident pixels
146  {
147  typedef KhalimskySpaceND<2> K2;
148  K2 theKSpace;
150  K2::SCell s = theKSpace.sCell( K2::Point(0,1) );
151  std::pair<K2::Point, K2::Point> aPair = m( s );
152  trace.info() << s << aPair.first << aPair.second <<std::endl;
153  K2::Point p1(0,0);
154  K2::Point p2(-1,0);
155  nbok += ( ((aPair.first == p1) && (aPair.second == p2)) ) ? 1 : 0;
156  nb++;
157  }
158  trace.info() << "(" << nbok << "/" << nb << ") " << std::endl;
159 
160  //scell 2 code
161  {
162  typedef KhalimskySpaceND<2> K2;
163  K2 theKSpace;
164  functors::SCellToCode<K2> m(theKSpace);
165  K2::SCell s = theKSpace.sCell( K2::Point(0,1) );
166  char aCode = m( s );
167  trace.info() << s << aCode <<std::endl;
168  nbok += ( aCode == '3' ) ? 1 : 0;
169  nb++;
170  }
171 
172  trace.info() << "(" << nbok << "/" << nb << ") " << std::endl;
173  trace.endBlock();
174 
175  return nbok == nb;
176 }
Aim: transforms a signed cell into an arrow, ie. a pair point-vector.
Aim: transforms a 2d signed cell, basically a linel, into a code (0,1,2 or 3),.
Aim: transforms a signed cell c into a pair of points corresponding to the signed cells of greater di...
Aim: transforms a signed cell c into a point corresponding to the signed cell of greater dimension th...
Aim: transforms a signed cell c into a point corresponding to the signed cell of greater dimension th...
Aim: transforms a scell into a point.
DigitalPlane::Point Vector
KSpace K3
Definition: StdDefs.h:147
Aim: A trivial embedder for signed cell, which corresponds to the canonic injection of cell centroids...
const Point aPoint(3, 4)

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

Referenced by main().