DGtal  1.4.beta
testCombinDSS.cpp File Reference

Tests for the class OneBalancedWordComputer. More...

#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
 

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.

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 139 of file testCombinDSS.cpp.

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

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

Referenced by main().

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 296 of file testCombinDSS.cpp.

297 {
298  trace.beginBlock ( "Testing class CombinDSS" );
299  trace.info() << "Args:";
300  for ( int i = 0; i < argc; ++i )
301  trace.info() << " " << argv[ i ];
302  trace.info() << endl;
303 
304  bool res = testOneBalancedWordComputer()
308 
309  trace.emphase() << ( res ? "Passed." : "Error." ) << endl;
310  trace.endBlock();
311 
312  return res ? 0 : 1;
313 }
std::ostream & emphase()
std::ostream & info()
bool showGreedySegmantation()
bool testOneBalancedWordComputer()
bool testInGreedySegmentation()
bool CompareToArithmetical()

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

◆ 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 243 of file testCombinDSS.cpp.

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

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().

◆ testInGreedySegmentation()

bool testInGreedySegmentation ( )

Definition at line 207 of file testCombinDSS.cpp.

208 {
209 
211  typedef GreedySegmentation<combinDSS> combinSegmentation;
212 
213  std::string filename = testPath + "samples/BigBall.fc";
214  std::fstream fst;
215  fst.open (filename.c_str(), std::ios::in);
216  Contour theContour(fst);
217 
218  trace.beginBlock ( "Test OneBalancedWordComputer in greedy segmentation" );
219  combinSegmentation combin_dec( theContour.chain.begin(), theContour.chain.end(), combinDSS() );
220  vector<combinDSS> theCombinDSS;
221  for ( combinSegmentation::SegmentComputerIterator i = combin_dec.begin();
222  i != combin_dec.end(); ++i )
223  {
224  combinDSS c( *i );
225  theCombinDSS.push_back( c );
226  }
227  bool ok = ( theCombinDSS.size() == 1593 );
228  trace.endBlock();
229 
230  return ok;
231 }

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

Referenced by main().

◆ testOneBalancedWordComputer()

bool testOneBalancedWordComputer ( )

Test exted and retract function on a complex chape

Definition at line 66 of file testCombinDSS.cpp.

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

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().