DGtal 1.4.0
Loading...
Searching...
No Matches
testSCellsFunctor.cpp
Go to the documentation of this file.
1
30#include <iostream>
31#include "DGtal/base/Common.h"
32#include "DGtal/base/CUnaryFunctor.h"
33
34#include "DGtal/topology/SCellsFunctors.h"
35#include "DGtal/topology/CanonicSCellEmbedder.h"
36
37#include "DGtal/topology/KhalimskySpaceND.h"
38
40
41using namespace std;
42using namespace DGtal;
43
45// Functions for testing the scells functors.
47
48template <typename TFunctor, typename TArg, typename TRes >
50{
51 BOOST_CONCEPT_ASSERT(( concepts::CUnaryFunctor<TFunctor, TArg, TRes > ));
52}
53
54
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) );
97 K2::Space::RealPoint aPoint = m( s );
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;
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;
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}
177
179// Standard services - public :
180
181int main( int argc, char** argv )
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}
204// //
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()
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.
DGtal is the top-level namespace which contains all DGtal functions and types.
Trace trace
Definition Common.h:153
STL namespace.
Aim: A trivial embedder for signed cell, which corresponds to the canonic injection of cell centroids...
Aim: Defines a unary functor, which associates arguments to results.
int main()
Definition testBits.cpp:56
void checkingConcepts()
bool testSCellsFunctors()
const Point aPoint(3, 4)