DGtal  1.2.0
testAdjacency.cpp
Go to the documentation of this file.
1 
31 #include <iostream>
32 #include <vector>
33 #include "DGtal/helpers/StdDefs.h"
34 
35 #include "DGtal/base/Common.h"
36 #include "DGtal/kernel/SpaceND.h"
37 #include "DGtal/topology/MetricAdjacency.h"
38 #include "DGtal/graph/CUndirectedSimpleLocalGraph.h"
40 
41 
42 
43 using namespace std;
44 using namespace DGtal;
45 using namespace DGtal::concepts;
46 
55 // Functions for testing class Adjacency.
57 
62 {
63  unsigned int nbok = 0;
64  unsigned int nb = 0;
65 
66  typedef SpaceND<3> Space3D;
67  typedef Space3D::Point Point;
68  typedef Z3i::Adj6 Adj6;
69  typedef Z3i::Adj18 Adj18;
70  typedef Z3i::Adj26 Adj26;
71  Point p( 3, -5, 10 );
72 
73 
74  trace.beginBlock ( "Testing neighbors of" );
75  Adj6::selfDisplay( trace.info() );
76  trace.info() << " p = " << p << std::endl;
77  vector<Point> neigh6;
78  back_insert_iterator< vector<Point> > bii6( neigh6 );
79  Adj6::writeNeighbors( bii6, p );
80  nbok += neigh6.size() == 6 ? 1 : 0;
81  nb++;
82  trace.info() << "(" << nbok << "/" << nb << ") "
83  << "Card(6-neigh): " << neigh6.size()
84  << "== 6 ?" << std::endl;
85  trace.beginBlock ( "Enumerating neighbors." );
86  unsigned int nb_correct = 0;
87  for ( unsigned int i = 0; i < neigh6.size(); ++i )
88  {
89  if ( Adj6::isProperlyAdjacentTo( p, neigh6[ i ] ) )
90  {
91  trace.info() << neigh6[ i ] << "* " << std::endl;
92  ++nb_correct;
93  }
94  else
95  trace.info() << neigh6[ i ] << "- " << std::endl;
96  }
97  trace.endBlock();
98  nbok += nb_correct == 6 ? 1 : 0;
99  nb++;
100  trace.info() << "(" << nbok << "/" << nb << ") "
101  << "Within, #proper adjacent : " << nb_correct
102  << "== 6 ?" << std::endl;
103  trace.endBlock();
104 
105 
106 
107  trace.beginBlock ( "Testing neighborhood of" );
108  Adj18::selfDisplay( trace.info() );
109  trace.info() << " p = " << p << std::endl;
110  vector<Point> neigh18;
111  back_insert_iterator< vector<Point> > bii18( neigh18 );
112  Adj18::writeNeighbors( bii18, p );
113  nbok += neigh18.size() == 18 ? 1 : 0;
114  nb++;
115  trace.info() << "(" << nbok << "/" << nb << ") "
116  << "Card(18-neigh): " << neigh18.size()
117  << "== 18 ?" << std::endl;
118  trace.beginBlock ( "Enumerating neighbors." );
119  nb_correct = 0;
120  for ( unsigned int i = 0; i < neigh18.size(); ++i )
121  {
122  if ( Adj18::isProperlyAdjacentTo( p, neigh18[ i ] ) )
123  {
124  trace.info() << neigh18[ i ] << "* " << std::endl;
125  ++nb_correct;
126  }
127  else
128  trace.info() << neigh18[ i ] << "- " << std::endl;
129  }
130  trace.endBlock();
131  nbok += nb_correct == 18 ? 1 : 0;
132  nb++;
133  trace.info() << "(" << nbok << "/" << nb << ") "
134  << "Within, #proper adjacent : " << nb_correct
135  << "== 18 ?" << std::endl;
136  trace.endBlock();
137 
138 
139  trace.beginBlock ( "Testing neighborhood of" );
140  Adj26::selfDisplay( trace.info() );
141  trace.info() << " p = " << p << std::endl;
142  vector<Point> neigh26;
143  back_insert_iterator< vector<Point> > bii26( neigh26 );
144  Adj26::writeNeighbors( bii26, p );
145  nbok += neigh26.size() == 26 ? 1 : 0;
146  nb++;
147  trace.info() << "(" << nbok << "/" << nb << ") "
148  << "Card(26-neigh): " << neigh26.size()
149  << "== 26 ?" << std::endl;
150  trace.beginBlock ( "Enumerating neighbors." );
151  nb_correct = 0;
152  for ( unsigned int i = 0; i < neigh26.size(); ++i )
153  {
154  if ( Adj26::isProperlyAdjacentTo( p, neigh26[ i ] ) )
155  {
156  trace.info() << neigh26[ i ] << "* " << std::endl;
157  ++nb_correct;
158  }
159  else
160  trace.info() << neigh26[ i ] << "- " << std::endl;
161  }
162  trace.endBlock();
163  nbok += nb_correct == 26 ? 1 : 0;
164  nb++;
165  trace.info() << "(" << nbok << "/" << nb << ") "
166  << "Within, #proper adjacent : " << nb_correct
167  << "== 26 ?" << std::endl;
168  trace.endBlock();
169 
170  return nbok == nb;
171 }
172 
173 
175 {
176  trace.beginBlock ( "Testing graph model" );
177  unsigned int nbok=0,nb=0;
178 
180  BOOST_CONCEPT_ASSERT(( CUndirectedSimpleLocalGraph<Adj> ));
181 
182 
183  nbok += Adj::bestCapacity() == 72 ? 1 : 0;
184  nb++;
185  trace.info() << "(" << nbok << "/" << nb << ") "
186  << "Within, bestCapacity : " << Adj::bestCapacity()
187  << "== 72 ?" << std::endl;
188  trace.endBlock();
189 
190 
191 
192  return nbok == nb;
193 }
194 
195 
197 // Standard services - public :
198 
199 int main( int argc, char** argv )
200 {
201  trace.beginBlock ( "Testing class Adjacency" );
202  trace.info() << "Args:";
203  for ( int i = 0; i < argc; ++i )
204  trace.info() << " " << argv[ i ];
205  trace.info() << endl;
206 
207  bool res = testMetricAdjacency() && testLocalGraphModel(); // && ... other tests
208  trace.emphase() << ( res ? "Passed." : "Error." ) << endl;
209  trace.endBlock();
210  return res ? 0 : 1;
211 }
212 // //
Aim: Describes digital adjacencies in digital spaces that are defined with the 1-norm and the infinit...
void beginBlock(const std::string &keyword="")
std::ostream & emphase()
std::ostream & info()
double endBlock()
Aim: Gathers several functions useful for concept checks.
DGtal is the top-level namespace which contains all DGtal functions and types.
Trace trace
Definition: Common.h:154
int main(int argc, char **argv)
bool testLocalGraphModel()
bool testMetricAdjacency()
MyPointD Point
Definition: testClone2.cpp:383