DGtal  0.9.3
Typedefs | Functions
testCombinDSS.cpp File Reference
#include <iostream>
#include <fstream>
#include <list>
#include <vector>
#include "DGtal/base/Common.h"
#include "DGtal/helpers/StdDefs.h"
#include "DGtal/io/boards/Board2D.h"
#include "DGtal/geometry/curves/OneBalancedWordComputer.h"
#include "DGtal/geometry/curves/ArithmeticalDSSComputer.h"
#include "ConfigTest.h"
#include "DGtal/geometry/curves/CDynamicBidirectionalSegmentComputer.h"
#include "DGtal/geometry/curves/GreedySegmentation.h"
Include dependency graph for testCombinDSS.cpp:

Go to the source code of this file.

Typedefs

typedef FreemanChain< int > Contour
 
typedef FreemanChain< int >::Vector Vector
 

Functions

bool testOneBalancedWordComputer ()
 
bool CompareToArithmetical ()
 
bool testInGreedySegmentation ()
 
bool showGreedySegmantation ()
 
int main (int argc, char **argv)
 

Detailed Description

Tests for the class OneBalancedWordComputer.

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
Xavier Proven├žal (xavie.nosp@m.r.pr.nosp@m.ovenc.nosp@m.al@u.nosp@m.niv-s.nosp@m.avoi.nosp@m.e.fr ) Laboratory of Mathematics (CNRS, UMR 5807), University of Savoie, France
Date
2011/05/02

Functions for testing class CombinDSS.

This file is part of the DGtal library.

See also
CombiantorialDSS.h

Definition in file testCombinDSS.cpp.

Typedef Documentation

◆ Contour

typedef FreemanChain<int> Contour

Definition at line 59 of file testCombinDSS.cpp.

◆ Vector

typedef FreemanChain<int>::Vector Vector
Examples:
doc-examples/kernelDomain.cpp, and io/viewDualSurface.cpp.

Definition at line 60 of file testCombinDSS.cpp.

Function Documentation

◆ CompareToArithmetical()

bool CompareToArithmetical ( )

Builds OneBalancedWordComputer and ArithmeticalDSSComputer in the fourth quadrants and compares them, if both are equals, the test is passed.

Definition at line 140 of file testCombinDSS.cpp.

References DGtal::FreemanChain< TInteger >::begin(), DGtal::Trace::beginBlock(), DGtal::FreemanChain< TInteger >::chain, DGtal::Trace::endBlock(), and DGtal::trace.

Referenced by main().

141 {
142  typedef string::const_iterator codeIterator;
145 
146  trace.beginBlock ( "Comparing to ArithmeticalDSSComputer" );
147 
148  std::string filename = testPath + "samples/manche.fc";
149  std::fstream fst;
150  fst.open (filename.c_str(), std::ios::in);
151  Contour theContour(fst);
152  Contour::ConstIterator it = theContour.begin();
153  TestedType C;
154  C.init( it );
155  ReferenceType A(it);
156  A.extendFront();
157  bool res = true;
158  while ( C.end() != theContour.chain.end() )
159  {
160  bool a = A.extendFront();
161  bool c = C.extendFront();
162  if ( a ^ c )
163  {
164  res = false;
165  cout << "Extension test error\n";
166  break;
167  }
168  else if ( ! a )
169  {
170  A.retractBack();
171  C.retractBack();
172  }
173  // Compare positions
174  if ( ( C.back() != A.back() ) || ( C.front() != A.front() ) )
175  {
176  res = false;
177  cout << "Equality test error\n";
178  break;
179  }
180  // Compare arithmetic parameters
181  if ( ( C.getA() != A.a() ) || ( C.getB() != A.b() ) ||
182  ( C.getMu() != A.mu() ) || ( C.getOmega() != A.omega() ) ||
183  ( C.Uf() != A.Uf() ) || ( C.Ul() != A.Ul() ) ||
184  ( C.Lf() != A.Lf() ) || ( C.Ll() != A.Ll() )
185  )
186  {
187  cout << "Arithmetic parameters error\n";
188  cout << C << endl;
189  cout << A << endl;
190  cout << "a() " << C.getA() << " --- " << A.a() << "\n";
191  cout << "b() " << C.getB() << " --- " << A.b() << "\n";
192  cout << "mu() " << C.getMu() << " --- " << A.mu() << "\n";
193  cout << "omega()" << C.getOmega() << " --- " << A.omega() << "\n";
194  cout << "Uf() " << C.Uf() << " --- " << A.Uf() << "\n";
195  cout << "Ul() " << C.Ul() << " --- " << A.Ul() << "\n";
196  cout << "Lf() " << C.Lf() << " --- " << A.Lf() << "\n";
197  cout << "Ll() " << C.Ll() << " --- " << A.Ll() << endl;
198  res = false;
199  break;
200  }
201  }
202  trace.endBlock();
203  return res;
204 }
void beginBlock(const std::string &keyword="")
MyDigitalSurface::ConstIterator ConstIterator
Trace trace
Definition: Common.h:137
double endBlock()
Aim: This class is a wrapper around ArithmeticalDSS that is devoted to the dynamic recognition of dig...

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 297 of file testCombinDSS.cpp.

References DGtal::Trace::beginBlock(), CompareToArithmetical(), DGtal::Trace::emphase(), DGtal::Trace::endBlock(), DGtal::Trace::info(), showGreedySegmantation(), testInGreedySegmentation(), testOneBalancedWordComputer(), and DGtal::trace.

298 {
299  trace.beginBlock ( "Testing class CombinDSS" );
300  trace.info() << "Args:";
301  for ( int i = 0; i < argc; ++i )
302  trace.info() << " " << argv[ i ];
303  trace.info() << endl;
304 
305  bool res = testOneBalancedWordComputer()
309 
310  trace.emphase() << ( res ? "Passed." : "Error." ) << endl;
311  trace.endBlock();
312 
313  return res ? 0 : 1;
314 }
void beginBlock(const std::string &keyword="")
Trace trace
Definition: Common.h:137
bool showGreedySegmantation()
double endBlock()
std::ostream & emphase()
bool testInGreedySegmentation()
std::ostream & info()
bool CompareToArithmetical()
bool testOneBalancedWordComputer()

◆ showGreedySegmantation()

bool showGreedySegmantation ( )

This test is an adaptation to OneBalancedWordComputer of 'examples/geometre/curves/greedy-dss-decomposition.cpp' where is uses ArithmeticDSS.

It produces a slightly different decomposition since in a greedy-segmentation, consecutive ArithmeticDSS overlap a single point while OneBalancedWordComputer overlap on a code and thus on two points.

Definition at line 244 of file testCombinDSS.cpp.

References DGtal::Trace::beginBlock(), DGtal::FreemanChain< TInteger >::chain, DGtal::HyperRectDomain< TSpace >::className(), domain(), DGtal::Trace::endBlock(), LibBoard::Board::saveSVG(), and DGtal::trace.

Referenced by main().

245 {
246  trace.beginBlock ( "Example testCombinDSS-greedy" );
247 
249  typedef GreedySegmentation<combinDSS> Decomposition;
250  typedef StandardDSS4<int> arithDSS;
251 
252  std::stringstream ss(stringstream::in | stringstream::out);
253  ss << "31 16 11121212121212212121212212122122222322323233323333333323333323303330330030300000100010010010001000101010101111" << endl;
254  Contour theContour( ss );
255 
256  Decomposition theDecomposition( theContour.chain.begin(), theContour.chain.end(), combinDSS() );
257  Point p1( 0, 0 );
258  Point p2( 31, 31 );
259  Domain domain( p1, p2 );
260  Board2D aBoard;
261  aBoard << SetMode( domain.className(), "Grid" )
262  << domain
263  << SetMode( "PointVector", "Grid" )
264  << theContour;
265  //for each segment
266  Point p;
267  p[0] = 31;
268  p[1] = 16;
269  for ( Decomposition::SegmentComputerIterator i = theDecomposition.begin();
270  i != theDecomposition.end(); ++i )
271  {
272  combinDSS segment(*i);
273  // set the position of the combinatorilDSS
274  segment.setPosition( p );
275  // Since both DSS overlap on one code, the start point of the next one is
276  // the penultimate point of the current one.
277  p = *( --( --( segment.pointEnd() )));
278 
279  // Build an ArithmeticDSS from the OneBalancedWordComputer.
280  arithDSS toShow( *segment.pointBegin(), *segment.pointBegin() );
281  for (combinDSS::ConstPointIterator it = segment.pointBegin(),
282  itEnd = segment.pointEnd(); it != itEnd; ++it )
283  toShow.extendFront( *it );
284 
285  aBoard << SetMode( toShow.className(), "BoundingBox" )
286  << CustomStyle( toShow.className()+"/BoundingBox", new CustomPenColor( Color::Blue ) )
287  << toShow; // draw each segment
288  }
289  aBoard.saveSVG("testCombinDSS-greedy.svg");
290  trace.endBlock();
291  return 1;
292 }
void beginBlock(const std::string &keyword="")
const Domain domain(Point(1, 2), Point(6, 5))
Trace trace
Definition: Common.h:137
double endBlock()
void saveSVG(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:1012
Aim: Computes the greedy segmentation of a range given by a pair of ConstIterators. The last element of a given segment is the first one one of the next segment.
Aim: This class represents a standard digital straight segment (DSS), ie. the sequence of simply 4-co...
std::string className() const
Modifier class in a Board2D stream. Useful to choose your own mode for a given class. Realizes the concept CDrawableWithBoard2D.
Definition: Board2D.h:247
Custom style class redefining the pen color. You may use Board2D::Color::None for transparent color...
Definition: Board2D.h:312
Aim: This class specializes a &#39;Board&#39; class so as to display DGtal objects more naturally (with <<)...
Definition: Board2D.h:70

◆ testInGreedySegmentation()

bool testInGreedySegmentation ( )

Definition at line 208 of file testCombinDSS.cpp.

References DGtal::Trace::beginBlock(), DGtal::FreemanChain< TInteger >::chain, DGtal::Trace::endBlock(), and DGtal::trace.

Referenced by main().

209 {
210 
212  typedef GreedySegmentation<combinDSS> combinSegmentation;
213 
214  std::string filename = testPath + "samples/BigBall.fc";
215  std::fstream fst;
216  fst.open (filename.c_str(), std::ios::in);
217  Contour theContour(fst);
218 
219  trace.beginBlock ( "Test OneBalancedWordComputer in greedy segmentation" );
220  combinSegmentation combin_dec( theContour.chain.begin(), theContour.chain.end(), combinDSS() );
221  vector<combinDSS> theCombinDSS;
222  for ( combinSegmentation::SegmentComputerIterator i = combin_dec.begin();
223  i != combin_dec.end(); ++i )
224  {
225  combinDSS c( *i );
226  theCombinDSS.push_back( c );
227  }
228  bool ok = ( theCombinDSS.size() == 1593 );
229  trace.endBlock();
230 
231  return ok;
232 }
void beginBlock(const std::string &keyword="")
Trace trace
Definition: Common.h:137
double endBlock()
Aim: Computes the greedy segmentation of a range given by a pair of ConstIterators. The last element of a given segment is the first one one of the next segment.

◆ testOneBalancedWordComputer()

bool testOneBalancedWordComputer ( )

Test exted and retract function on a complex chape

Definition at line 67 of file testCombinDSS.cpp.

References DGtal::FreemanChain< TInteger >::begin(), DGtal::Trace::beginBlock(), DGtal::FreemanChain< TInteger >::chain, DGtal::Trace::endBlock(), DGtal::FreemanChain< TInteger >::firstPoint(), and DGtal::trace.

Referenced by main().

68 {
69  typedef string::const_iterator codeIterator;
70  typedef OneBalancedWordComputer< list<char>::iterator, int> OneBalancedWordComputer_list;
71  typedef OneBalancedWordComputer<codeIterator, int> OneBalancedWordComputer_string;
72 
75 
76  trace.beginBlock ( "Test different initialization methods" );
77 
78  std::string filename = testPath + "samples/france.fc";
79  std::fstream fst;
80  fst.open (filename.c_str(), std::ios::in);
81  Contour theContour(fst);
82 
83  list<char> l;
84  for ( string::const_iterator it = theContour.chain.begin(); it != theContour.chain.end(); ++it )
85  {
86  l.push_back( *it );
87  }
88 
89  list<char>::iterator it = l.begin();
90 
91  OneBalancedWordComputer_list C1;
92  C1.init( it, theContour.firstPoint() );
93 
94  OneBalancedWordComputer_list C2;
95  C2.init( C1.begin() );
96 
97  OneBalancedWordComputer_string C3;
98  C3.init( theContour );
99 
100  OneBalancedWordComputer_string C4;
101  C4.init( theContour.begin() );
102 
103  int nbRetract = 0;
104  while ( C3.end() != theContour.chain.end() )
105  {
106  bool b1 = C1.extendFront();
107  bool b2 = C2.extendFront();
108  bool b3 = C3.extendFront();
109  bool b4 = C4.extendFront();
110  if ( b1 && b2 && b3 && b4 )
111  {
112  }
113  else if ( !b1 && !b2 && !b3 && !b4 )
114  {
115  C1.retractBack();
116  C2.retractBack();
117  C3.retractBack();
118  C4.retractBack();
119  ++nbRetract;
120  }
121  else
122  {
123  cout << b1 << " " << b2 << " " << b3 << " " << b4 << endl;
124  cout << C1 << endl;
125  cout << C2 << endl;
126  cout << C3 << endl;
127  cout << C4 << endl;
128  return false;
129  }
130  }
131  trace.endBlock();
132  return (nbRetract == 3485) ;
133 }
void beginBlock(const std::string &keyword="")
Trace trace
Definition: Common.h:137
double endBlock()
Aim: Defines the concept describing a dynamic and bidirectional segment computer, ie...