DGtal  0.6.devel
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
testSCellsFunctor.cpp
1 
29 
30 #include <iostream>
31 #include "DGtal/base/Common.h"
32 #include "DGtal/base/CUnaryFunctor.h"
33 
34 #include "DGtal/topology/SCellsFunctors.h"
35 
36 #include "DGtal/topology/KhalimskySpaceND.h"
37 
39 
40 using namespace std;
41 using namespace DGtal;
42 
44 // Functions for testing the scells functors.
46 
47 template <typename TFunctor, typename TArg, typename TRes >
48 void checkingConcepts()
49 {
50  BOOST_CONCEPT_ASSERT(( CUnaryFunctor<TFunctor, TArg, TRes > ));
51 }
52 
53 
58 bool testSCellsFunctors()
59 {
60  unsigned int nbok = 0;
61  unsigned int nb = 0;
62 
63  trace.beginBlock ( "Testing block ..." );
64 
65  //0-scell 2 point
66  {
67  typedef KhalimskySpaceND<3> K3;
68  K3 theKSpace;
69  SCellToPoint<K3> m(theKSpace);
70  K3::SCell s = theKSpace.sPointel( K3::Point(3,3,4) );
71  K3::Point aPoint = m( s );
72  trace.info() << s << aPoint <<std::endl;
73  nbok += ( aPoint == K3::Point(3,3,4) ) ? 1 : 0;
74  nb++;
75  }
76  trace.info() << "(" << nbok << "/" << nb << ") " << std::endl;
77  //1-scell 2 point
78  {
79  typedef KhalimskySpaceND<3> K3;
80  K3 theKSpace;
81  SCellToPoint<K3> m(theKSpace);
82  K3::SCell s(K3::Point(0,0,0), true); //default point and orientation
83  theKSpace.sSetKCoords( s, K3::Point(5,6,8) );
84  K3::Point aPoint = m( s );
85  trace.info() << s << aPoint <<std::endl;
86  nbok += ( aPoint == K3::Point(3,3,4) ) ? 1 : 0;
87  nb++;
88  }
89  trace.info() << "(" << nbok << "/" << nb << ") " << std::endl;
90  //scell 2 midPoint
91  {
92  typedef KhalimskySpaceND<2> K2;
93  K2 theKSpace;
94  SCellToMidPoint<K2> m(theKSpace);
95  K2::SCell s = theKSpace.sCell( K2::Point(0,1) );
96  K2::Space::RealPoint aPoint = m( s );
97  trace.info() << s << aPoint <<std::endl;
98  nbok += ( aPoint == K2::Space::RealPoint(0,0.5) ) ? 1 : 0;
99  nb++;
100  }
101  trace.info() << "(" << nbok << "/" << nb << ") " << std::endl;
102 
103  //scell 2 arrow
104  {
105  typedef KhalimskySpaceND<2> K2;
106  K2 theKSpace;
107  SCellToArrow<K2> m(theKSpace);
108  K2::SCell s = theKSpace.sCell( K2::Point(0,1) );
109  std::pair<K2::Point, K2::Vector> aArrow = m( s );
110  trace.info() << s << aArrow.first << aArrow.second <<std::endl;
111  K2::Point p(0,1);
112  K2::Vector v(0,-1);
113  nbok += ( ((aArrow.first == p) && (aArrow.second == v)) ) ? 1 : 0;
114  nb++;
115  }
116  trace.info() << "(" << nbok << "/" << nb << ") " << std::endl;
117 
118  //scell 2 inner point
119  {
120  typedef KhalimskySpaceND<2> K2;
121  K2 theKSpace;
122  SCellToInnerPoint<K2> m(theKSpace);
123  K2::SCell s = theKSpace.sCell( K2::Point(0,1) );
124  K2::Point aPoint = m( s );
125  trace.info() << s << aPoint <<std::endl;
126  nbok += ( aPoint == K2::Point(-1,0) ) ? 1 : 0;
127  nb++;
128  }
129  trace.info() << "(" << nbok << "/" << nb << ") " << std::endl;
130 
131  //scell 2 outer point
132  {
133  typedef KhalimskySpaceND<2> K2;
134  K2 theKSpace;
135  SCellToOuterPoint<K2> m(theKSpace);
136  K2::SCell s = theKSpace.sCell( K2::Point(0,1) );
137  K2::Point aPoint = m( s );
138  trace.info() << s << aPoint <<std::endl;
139  nbok += ( aPoint == K2::Point(0,0) ) ? 1 : 0;
140  nb++;
141  }
142  trace.info() << "(" << nbok << "/" << nb << ") " << std::endl;
143 
144  //scell 2 incident pixels
145  {
146  typedef KhalimskySpaceND<2> K2;
147  K2 theKSpace;
148  SCellToIncidentPoints<K2> m(theKSpace);
149  K2::SCell s = theKSpace.sCell( K2::Point(0,1) );
150  std::pair<K2::Point, K2::Point> aPair = m( s );
151  trace.info() << s << aPair.first << aPair.second <<std::endl;
152  K2::Point p1(-1,0);
153  K2::Point p2(0,0);
154  nbok += ( ((aPair.first == p1) && (aPair.second == p2)) ) ? 1 : 0;
155  nb++;
156  }
157  trace.info() << "(" << nbok << "/" << nb << ") " << std::endl;
158 
159  //scell 2 code
160  {
161  typedef KhalimskySpaceND<2> K2;
162  K2 theKSpace;
163  SCellToCode<K2> m(theKSpace);
164  K2::SCell s = theKSpace.sCell( K2::Point(0,1) );
165  char aCode = m( s );
166  trace.info() << s << aCode <<std::endl;
167  nbok += ( aCode == '3' ) ? 1 : 0;
168  nb++;
169  }
170 
171  trace.info() << "(" << nbok << "/" << nb << ") " << std::endl;
172  trace.endBlock();
173 
174  return nbok == nb;
175 }
176 
178 // Standard services - public :
179 
180 int main( int argc, char** argv )
181 {
182  trace.beginBlock ( "Testing SCells functors" );
183  trace.info() << "Args:";
184  for ( int i = 0; i < argc; ++i )
185  trace.info() << " " << argv[ i ];
186  trace.info() << endl;
187 
188  //concepts
189  typedef KhalimskySpaceND<2> K2;
190  checkingConcepts<SCellToPoint<K2>, K2::SCell, K2::Point >();
191  checkingConcepts<SCellToMidPoint<K2>, K2::SCell, K2::Space::RealPoint >();
192  checkingConcepts<SCellToArrow<K2>, K2::SCell, std::pair<K2::Point, K2::Vector> >();
193  checkingConcepts<SCellToInnerPoint<K2>, K2::SCell, K2::Point >();
194  checkingConcepts<SCellToOuterPoint<K2>, K2::SCell, K2::Point >();
195  checkingConcepts<SCellToIncidentPoints<K2>, K2::SCell, std::pair<K2::Point, K2::Point> >();
196  checkingConcepts<SCellToCode<K2>, K2::SCell, char >();
197 
198  bool res = testSCellsFunctors(); // && ... other tests
199  trace.emphase() << ( res ? "Passed." : "Error." ) << endl;
200  trace.endBlock();
201  return res ? 0 : 1;
202 }
203 // //