DGtal  1.4.beta
testAdjacency.cpp File Reference
#include <iostream>
#include <vector>
#include "DGtal/helpers/StdDefs.h"
#include "DGtal/base/Common.h"
#include "DGtal/kernel/SpaceND.h"
#include "DGtal/topology/MetricAdjacency.h"
#include "DGtal/graph/CUndirectedSimpleLocalGraph.h"
Include dependency graph for testAdjacency.cpp:

Go to the source code of this file.

Functions

bool testMetricAdjacency ()
 
bool testLocalGraphModel ()
 
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
Jacques-Olivier Lachaud (jacqu.nosp@m.es-o.nosp@m.livie.nosp@m.r.la.nosp@m.chaud.nosp@m.@uni.nosp@m.v-sav.nosp@m.oie..nosp@m.fr ) Laboratory of Mathematics (CNRS, UMR 5807), University of Savoie, France
Date
2010/07/04

Functions for testing class Adjacency.

This file is part of the DGtal library.

Definition in file testAdjacency.cpp.

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 199 of file testAdjacency.cpp.

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 }
void beginBlock(const std::string &keyword="")
std::ostream & emphase()
std::ostream & info()
double endBlock()
Trace trace
Definition: Common.h:153
bool testLocalGraphModel()
bool testMetricAdjacency()

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

◆ testLocalGraphModel()

bool testLocalGraphModel ( )

Definition at line 174 of file testAdjacency.cpp.

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 }
Aim: Describes digital adjacencies in digital spaces that are defined with the 1-norm and the infinit...

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

Referenced by main().

◆ testMetricAdjacency()

bool testMetricAdjacency ( )

This file test the standard digital adjacencies, the one based on a metric. We have the classical 4- and 8- adjacencies in 2D, the 6-, 18- and 26- in 3D. Example of a test. To be completed.

Definition at line 61 of file testAdjacency.cpp.

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 }
MetricAdjacency< Space, 2 > Adj18
Definition: StdDefs.h:161
MetricAdjacency< Space, 3 > Adj26
Definition: StdDefs.h:163
MetricAdjacency< Space, 1 > Adj6
Definition: StdDefs.h:159
MyPointD Point
Definition: testClone2.cpp:383

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

Referenced by main().