DGtal  1.4.beta
testExpander.cpp File Reference
#include <iostream>
#include <sstream>
#include "DGtal/base/Common.h"
#include "DGtal/kernel/SpaceND.h"
#include "DGtal/kernel/domains/DomainPredicate.h"
#include "DGtal/kernel/domains/HyperRectDomain.h"
#include "DGtal/kernel/sets/DigitalSetSelector.h"
#include "DGtal/kernel/sets/DigitalSetConverter.h"
#include "DGtal/topology/MetricAdjacency.h"
#include "DGtal/topology/DomainMetricAdjacency.h"
#include "DGtal/topology/DomainAdjacency.h"
#include "DGtal/topology/DigitalTopology.h"
#include "DGtal/topology/Object.h"
#include "DGtal/graph/Expander.h"
Include dependency graph for testExpander.cpp:

Go to the source code of this file.

Macros

#define INBLOCK_TEST(x)
 
#define INBLOCK_TEST2(x, y)
 

Functions

bool testExpander ()
 
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/11

Functions for testing class Expander.

This file is part of the DGtal library.

Definition in file testExpander.cpp.

Macro Definition Documentation

◆ INBLOCK_TEST

#define INBLOCK_TEST (   x)
Value:
nbok += ( x ) ? 1 : 0; \
nb++; \
trace.info() << "(" << nbok << "/" << nb << ") " \
<< #x << std::endl;

Definition at line 50 of file testExpander.cpp.

◆ INBLOCK_TEST2

#define INBLOCK_TEST2 (   x,
 
)
Value:
nbok += ( x ) ? 1 : 0; \
nb++; \
trace.info() << "(" << nbok << "/" << nb << ") " \
<< y << std::endl;

Definition at line 56 of file testExpander.cpp.

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 180 of file testExpander.cpp.

181 {
182  trace.beginBlock ( "Testing class Expander" );
183  trace.info() << "Args:";
184  for ( int i = 0; i < argc; ++i )
185  trace.info() << " " << argv[ i ];
186  trace.info() << endl;
187 
188  bool res = testExpander(); // && ... other tests
189  trace.emphase() << ( res ? "Passed." : "Error." ) << endl;
190  trace.endBlock();
191  return res ? 0 : 1;
192 }
void beginBlock(const std::string &keyword="")
std::ostream & emphase()
std::ostream & info()
double endBlock()
Trace trace
Definition: Common.h:153
bool testExpander()

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

◆ testExpander()

bool testExpander ( )

Example of a test. To be completed.

Definition at line 69 of file testExpander.cpp.

70 {
71  unsigned int nbok = 0;
72  unsigned int nb = 0;
73 
74  // ------------------------------ Types ------------------------------
75  typedef SpaceND< 3 > Z3;
76  typedef Z3::Point Point;
77  typedef Point::Coordinate Coordinate;
79  typedef Domain::ConstIterator DomainConstIterator;
80 
81  typedef MetricAdjacency< Z3, 1 > MetricAdj6;
82  typedef MetricAdjacency< Z3, 2 > MetricAdj18;
85  // typedef MetricAdjacency< Z3, 1 > Adj6;
86  // typedef MetricAdjacency< Z3, 2 > Adj18;
87 
89 
91  typedef Object<DT6_18, DigitalSet> ObjectType;
92  typedef Expander< ObjectType > ObjectExpander;
93  // ----------------------- Domain, Topology ------------------------------
94  Point p1( -50, -50, -50 );
95  Point p2( 50, 50, 50 );
96  Domain domain( p1, p2 );
97 
98  MetricAdj6 madj6;
99  MetricAdj18 madj18;
100  Adj6 adj6( domain, madj6 );
101  Adj18 adj18( domain, madj18 );
102  // Adj6 adj6;
103  // Adj18 adj18;
104 
105  DT6_18 dt6_18( adj6, adj18, JORDAN_DT );
106  // ------------------------------- Object ------------------------------
107  Coordinate r = 9;
108  double radius = (double) (r+1);
109  Point c( 0, 0 );
110  Point l( r, 0 );
111  DigitalSet ball_set( domain );
112  ostringstream sstr;
113  sstr << "Creating 3D ball( r < " << radius << " ) ...";
114  trace.beginBlock ( sstr.str() );
115  for ( DomainConstIterator it = domain.begin();
116  it != domain.end();
117  ++it )
118  {
119  if ( (*it - c ).norm() < radius )
120  // insertNew is very important for vector container.
121  ball_set.insertNew( *it );
122  }
123  trace.endBlock();
124 
125  trace.beginBlock ( "Testing Object instanciation and smart copy ..." );
126  ObjectType ball( dt6_18, ball_set );
127  ObjectType ball2( ball );
128  INBLOCK_TEST( ball.size() == 4139 );
129  trace.info() << "ball.size() = " << ball.size()
130  << " 4/3*pi*r^3 = " << ( 4.0*M_PI*radius*radius*radius/3.0 )
131  << endl;
132  trace.info() << "ball = " << ball << endl;
133  trace.info() << "ball2 = " << ball2 << endl;
134  trace.endBlock();
135 
136  trace.beginBlock ( "Testing border extraction ..." );
137  ObjectType sphere = ball.border();
138  INBLOCK_TEST( sphere.size() == 1434 );
139  trace.info() << sphere << endl;
140  trace.info() << "sphere.size() = " << sphere.size()
141  << " 4*pi*r^2 = " << ( 4.0*M_PI*radius*radius )
142  << endl;
143  trace.endBlock();
144 
145  trace.beginBlock ( "Testing expansion by layers in the ball from center..." );
146  ObjectExpander expander( ball, c );
147  while ( ! expander.finished() )
148  {
149  trace.info() << expander << std::endl;
150  expander.nextLayer();
151  }
152  nbok += expander.distance() <= sqrt(3.0)*radius ? 1 : 0;
153  nb++;
154  trace.info() << "(" << nbok << "/" << nb << ") "
155  << "expander.distance() = " << expander.distance()
156  << " <= " << sqrt(3.0)*radius << std::endl;
157  trace.endBlock();
158 
159  trace.beginBlock ( "Testing expansion by layers on the sphere from a point ..." );
160  ObjectExpander expander2( sphere, l );
161  while ( ! expander2.finished() )
162  {
163  trace.info() << expander2 << std::endl;
164  expander2.nextLayer();
165  }
166  nbok += expander2.distance() <= sqrt(2.0)*M_PI*radius ? 1 : 0;
167  nb++;
168  trace.info() << "(" << nbok << "/" << nb << ") "
169  << "expander2.distance() = " << expander2.distance()
170  << " <= " << sqrt(2.0)*M_PI*radius << std::endl;
171  trace.endBlock();
172 
173 
174  return nbok == nb;
175 }
Aim: A wrapper class around a STL associative container for storing sets of digital points within som...
Aim: Represents a digital topology as a couple of adjacency relations.
Aim: Given a domain and an adjacency, limits the given adjacency to the specified domain for all adja...
Aim: This class is useful to visit an object by adjacencies, layer by layer.
Definition: Expander.h:98
Iterator for HyperRectDomain.
Aim: Parallelepidec region of a digital space, model of a 'CDomain'.
const ConstIterator & end() const
const ConstIterator & begin() const
Aim: Describes digital adjacencies in digital spaces that are defined with the 1-norm and the infinit...
Aim: An object (or digital object) represents a set in some digital space associated with a digital t...
Definition: Object.h:120
MetricAdjacency< Space, 2 > Adj18
Definition: StdDefs.h:161
Space Z3
Definition: StdDefs.h:145
MetricAdjacency< Space, 1 > Adj6
Definition: StdDefs.h:159
DigitalTopology< Adj6, Adj18 > DT6_18
Definition: StdDefs.h:164
MyPointD Point
Definition: testClone2.cpp:383
#define INBLOCK_TEST(x)
Domain domain
HyperRectDomain< Space > Domain
Z2i::DigitalSet DigitalSet

References DGtal::HyperRectDomain< TSpace >::begin(), DGtal::Trace::beginBlock(), domain, DGtal::HyperRectDomain< TSpace >::end(), DGtal::Trace::endBlock(), INBLOCK_TEST, DGtal::Trace::info(), DGtal::DigitalSetByAssociativeContainer< TDomain, TContainer >::insertNew(), DGtal::JORDAN_DT, and DGtal::trace.

Referenced by main().