DGtal 1.4.0
Loading...
Searching...
No Matches
testStabbingLineComputer.cpp File Reference

Functions for testing class StabbingLineComputer. More...

#include <iostream>
#include "DGtal/base/Common.h"
#include "DGtal/kernel/PointVector.h"
#include "DGtal/topology/KhalimskySpaceND.h"
#include "DGtal/geometry/curves/GridCurve.h"
#include "DGtal/geometry/curves/CBidirectionalSegmentComputer.h"
#include "DGtal/geometry/curves/StabbingLineComputer.h"
#include "DGtal/geometry/curves/GreedySegmentation.h"
#include "DGtal/geometry/curves/SaturatedSegmentation.h"
#include "DGtal/io/boards/Board2D.h"
#include "DGtal/io/boards/CDrawableWithBoard2D.h"
#include "ConfigTest.h"
Include dependency graph for testStabbingLineComputer.cpp:

Go to the source code of this file.

Functions

template<typename TCurve >
bool testStabbingLineComputer (const TCurve &curve)
 
template<typename TCurve >
bool drawingTestStabbingLineComputer (const TCurve &curve)
 
void testStabbingLineComputerConceptChecking ()
 
template<typename TCurve >
bool testSegmentation (const TCurve &curve)
 
int main (int argc, char **argv)
 

Detailed Description

Functions for testing class StabbingLineComputer.

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
Tristan Roussillon (trist.nosp@m.an.r.nosp@m.oussi.nosp@m.llon.nosp@m.@liri.nosp@m.s.cn.nosp@m.rs.fr ) Laboratoire d'InfoRmatique en Image et Systèmes d'information - LIRIS (CNRS, UMR 5205), CNRS, France
Date
2011/09/26

This file is part of the DGtal library.

Definition in file testStabbingLineComputer.cpp.

Function Documentation

◆ drawingTestStabbingLineComputer()

template<typename TCurve >
bool drawingTestStabbingLineComputer ( const TCurve & curve)

Definition at line 159 of file testStabbingLineComputer.cpp.

160{
161
162 typedef typename TCurve::IncidentPointsRange Range; //range
163 typedef typename Range::ConstIterator ConstIterator; //iterator
164
165 Range r = curve.getIncidentPointsRange(); //range
166
168 ConstIterator itEnd (r.end());
169 s.init( r.begin() );
170 while ( (s.end() != itEnd) && (s.extendFront()) ) {}
171
172 double a, b, c;
173 s.getParameters(a,b,c);
174
175 Board2D board;
176 board << r << s;
177 board.saveEPS("StabbingLineComputerdrawingTest.eps");
178 return true;
179}
Aim: This class specializes a 'Board' class so as to display DGtal objects more naturally (with <<)....
Definition Board2D.h:71
Aim: model of CBidirectionalRangeFromPoint that adapts any range of elements bounded by two iterators...
Aim: On-line recognition of a digital straight segment (DSS) defined as a sequence of connected grid ...
void saveEPS(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition Board.cpp:804
MyDigitalSurface::ConstIterator ConstIterator

References LibBoard::Board::saveEPS().

Referenced by main().

◆ main()

int main ( int argc,
char ** argv )

Definition at line 265 of file testStabbingLineComputer.cpp.

266{
267 trace.beginBlock ( "Testing class StabbingLineComputer" );
268 trace.info() << "Args:";
269 for ( int i = 0; i < argc; ++i )
270 trace.info() << " " << argv[ i ];
271 trace.info() << endl;
272
273 bool res;
274
275 {//concept checking
277 }
278
279 {//basic operations
280 std::string filename = testPath + "samples/DSS.dat";
281 ifstream instream; // input stream
282 instream.open (filename.c_str(), ifstream::in);
283
285 GridCurve<KSpace> c; //grid curve
286 c.initFromVectorStream(instream);
287
290 }
291
292 {//segmentations
293 std::string filename = testPath + "samples/sinus2D4.dat";
294 ifstream instream; // input stream
295 instream.open (filename.c_str(), ifstream::in);
296
298 GridCurve<KSpace> c; //grid curve
299 c.initFromVectorStream(instream);
300
301 res = res && testSegmentation(c);
302 }
303
304 trace.emphase() << ( res ? "Passed." : "Error." ) << endl;
305 trace.endBlock();
306 return res ? 0 : 1;
307}
Aim: describes, in a cellular space of dimension n, a closed or open sequence of signed d-cells (or d...
Definition GridCurve.h:173
bool initFromVectorStream(std::istream &in)
Aim: This class is a model of CCellularGridSpaceND. It represents the cubical grid as a cell complex,...
void beginBlock(const std::string &keyword="")
std::ostream & emphase()
std::ostream & info()
double endBlock()
Trace trace
Definition Common.h:153
bool testSegmentation()
void testStabbingLineComputerConceptChecking()
bool drawingTestStabbingLineComputer(const TCurve &curve)
bool testStabbingLineComputer(const TCurve &curve)

References DGtal::Trace::beginBlock(), drawingTestStabbingLineComputer(), DGtal::Trace::emphase(), DGtal::Trace::endBlock(), DGtal::Trace::info(), DGtal::GridCurve< TKSpace >::initFromVectorStream(), testSegmentation(), testStabbingLineComputer(), testStabbingLineComputerConceptChecking(), and DGtal::trace.

◆ testSegmentation()

template<typename TCurve >
bool testSegmentation ( const TCurve & curve)

Definition at line 191 of file testStabbingLineComputer.cpp.

192{
193
194 typedef typename TCurve::IncidentPointsRange Range; //range
195 Range r = curve.getIncidentPointsRange(); //range
196
197 typedef typename Range::ConstIterator ConstIterator; //iterator
198 typedef StabbingLineComputer<ConstIterator> SegmentComputer; //segment computer
199
200 unsigned int nbok = 0;
201 unsigned int nb = 0;
202
203
204 trace.beginBlock ( "Greedy segmentation" );
205 {
207 Segmentation theSegmentation( r.begin(), r.end(), SegmentComputer() );
208
209 Board2D board;
210 board << r;
211
212 typename Segmentation::SegmentComputerIterator it = theSegmentation.begin();
213 typename Segmentation::SegmentComputerIterator itEnd = theSegmentation.end();
214 unsigned int n = 0;
215 unsigned int suml = 0;
216 for ( ; it != itEnd; ++it, ++n) {
217 board << (*it);
218 for (ConstIterator i = it->begin(); i != it->end(); ++i)
219 suml += 1;
220 }
221
222 board.saveEPS("StabbingLineComputerGreedySegmentationTest.eps", Board2D::BoundingBox, 5000 );
223
224 trace.info() << r.size() << ";" << n << ";" << suml << endl;
225 //comparison with the results gave by another program
226 nbok += ((r.size()==85)&&(n==10)&&(suml==94)) ? 1 : 0;
227 nb++;
228 }
229 trace.endBlock();
230
231 trace.beginBlock ( "Saturated segmentation" );
232 {
234 Segmentation theSegmentation( r.begin(), r.end(), SegmentComputer() );
235
236 Board2D board;
237 board << r;
238
239 typename Segmentation::SegmentComputerIterator it = theSegmentation.begin();
240 typename Segmentation::SegmentComputerIterator itEnd = theSegmentation.end();
241 unsigned int n = 0;
242 unsigned int suml = 0;
243 for ( ; it != itEnd; ++it, ++n) {
244 board << (*it);
245 for (ConstIterator i = it->begin(); i != it->end(); ++i)
246 suml += 1;
247 }
248
249 board.saveEPS("StabbingLineComputerSaturatedSegmentationTest.eps", Board2D::BoundingBox, 5000 );
250
251 trace.info() << r.size() << ";" << n << ";" << suml << endl;
252 //comparison with the results gave by another program
253 nbok += ((r.size()==85)&&(n==25)&&(suml==255)) ? 1 : 0;
254 nb++;
255 }
256 trace.endBlock();
257
258
259 trace.info() << "(" << nbok << "/" << nb << ") " << endl;
260 return (nbok == nb);
261}
Aim: This class is a wrapper around ArithmeticalDSS that is devoted to the dynamic recognition of dig...
Aim: Computes the greedy segmentation of a range given by a pair of ConstIterators....
Aim: Specific iterator to visit all the maximal segments of a saturated segmentation.
Aim: Computes the saturated segmentation, that is the whole set of maximal segments within a range gi...
ArithmeticalDSSComputer< std::vector< Z2i::Point >::const_iterator, int, 4 > SegmentComputer
SaturatedSegmentation< SegmentComputer > Segmentation

References DGtal::SaturatedSegmentation< TSegmentComputer >::begin(), DGtal::Trace::beginBlock(), DGtal::SaturatedSegmentation< TSegmentComputer >::end(), DGtal::Trace::endBlock(), DGtal::Trace::info(), LibBoard::Board::saveEPS(), and DGtal::trace.

◆ testStabbingLineComputer()

template<typename TCurve >
bool testStabbingLineComputer ( const TCurve & curve)

Basic methods

Definition at line 61 of file testStabbingLineComputer.cpp.

62{
63
64 typedef typename TCurve::IncidentPointsRange Range; //range
65 typedef typename Range::ConstIterator ConstIterator; //iterator
66 typedef typename Range::ConstReverseIterator ConstReverseIterator; //reverse iterator
67
68 unsigned int nbok = 0;
69 unsigned int nb = 0;
70
71 trace.beginBlock ( "Constructors, copy, assignement" );
72 {
73 Range r = curve.getIncidentPointsRange(); //range
74
76 s2.init(r.begin());
77 s3.init(++r.begin());
80 s3 = s1;
81
82 trace.info() << s1.isValid() << s1 << endl;
83 trace.info() << s2.isValid() << s2 << endl;
84 trace.info() << s3.isValid() << s3 << endl;
85 trace.info() << s4.isValid() << s4 << endl;
86 trace.info() << s5.isValid() << s5 << endl;
87
88 bool myFlag = (!s1.isValid())&&(!s3.isValid())
89 &&(s2.isValid())&&(s4.isValid())&&(s5.isValid())
90 &&(s2 == s4)&&(s3 != s5)&&(s1 == s3)&&(s2 != s5);
91
92 nbok += myFlag ? 1 : 0;
93 nb++;
94 }
96
97 trace.beginBlock ( "Extension operations" );
98 {
99 Range r = curve.getIncidentPointsRange(); //range
100
102
103 trace.info() << "forward extension " << endl;
104 ConstIterator itBegin (r.begin());
105 ConstIterator itEnd (r.end());
106 s.init( itBegin+1 );
107 while ( (s.end() != itEnd) && (s.isExtendableFront()) && (s.extendFront()) ) {}
108 trace.info() << s << endl;
109 double a, b, c;
110 s.getParameters(a,b,c);
111 trace.info() << a << " " << b << " " << c << endl;
112
113 t.init( (itBegin + (itEnd - itBegin)/2) );
114 while ( (t.end() != itEnd) && (t.extendFront())
115 && (t.begin() != itBegin) && (t.extendBack()) ) {}
116 trace.info() << t << endl;
117
118 trace.info() << "backward extension " << endl;
120 ConstReverseIterator ritBegin (t.end());
121 ConstReverseIterator ritEnd (r.rend());
122 rs.init( ritBegin );
123 while ( (rs.end() != ritEnd) && (rs.isExtendableFront()) && (rs.extendFront()) ) {}
124 trace.info() << rs << endl;
125 double ap, bp, cp;
126 rs.getParameters(ap,bp,cp);
127 trace.info() << ap << " " << bp << " " << cp << endl;
128
130 rt.init( (ritBegin + (ritEnd - ritBegin)/2) );
131 while ( (rt.begin() != ritBegin) && (rt.extendBack())
132 && (rt.end() != ritEnd) && (rt.extendFront()) ) {}
133 trace.info() << rt << endl;
134
135 trace.info() << "comparison... " << endl;
136 bool myFlag = ( (s == t)&&(rs == rt) )
137 && ( s.Uf() == rs.Uf() )
138 && ( s.Ul() == rs.Ul() )
139 && ( s.Lf() == rs.Lf() )
140 && ( s.Ll() == rs.Ll() )
141 && (a == ap)
142 && (b == bp)
143 && (c == cp)
144 ;
145
146 nbok += myFlag ? 1 : 0;
147 nb++;
148 }
149 trace.endBlock();
150
151 trace.info() << "(" << nbok << "/" << nb << ") " << endl;
152 return nbok == nb;
153}
std::reverse_iterator< ConstIterator > ConstReverseIterator
Reverse getReverse() const
ConstIterator end() const
ConstIterator begin() const
void init(const ConstIterator &anIt)
void getParameters(double &alpha, double &beta, double &gamma) const

References DGtal::StabbingLineComputer< TConstIterator >::begin(), DGtal::Trace::beginBlock(), DGtal::StabbingLineComputer< TConstIterator >::end(), DGtal::Trace::endBlock(), DGtal::StabbingLineComputer< TConstIterator >::extendBack(), DGtal::StabbingLineComputer< TConstIterator >::extendFront(), DGtal::StabbingLineComputer< TConstIterator >::getParameters(), DGtal::StabbingLineComputer< TConstIterator >::getReverse(), DGtal::Trace::info(), DGtal::StabbingLineComputer< TConstIterator >::init(), DGtal::StabbingLineComputer< TConstIterator >::isExtendableFront(), DGtal::StabbingLineComputer< TConstIterator >::isValid(), DGtal::StabbingLineComputer< TConstIterator >::Lf(), DGtal::StabbingLineComputer< TConstIterator >::Ll(), DGtal::trace, DGtal::StabbingLineComputer< TConstIterator >::Uf(), and DGtal::StabbingLineComputer< TConstIterator >::Ul().

Referenced by main().

◆ testStabbingLineComputerConceptChecking()

void testStabbingLineComputerConceptChecking ( )

Definition at line 181 of file testStabbingLineComputer.cpp.

182{
183 typedef std::pair<PointVector<2,int>, PointVector<2,int> > Pair;
184 typedef std::vector<Pair>::const_iterator ConstIterator;
186 BOOST_CONCEPT_ASSERT(( concepts::CDrawableWithBoard2D<GeomDSS> ));
187 BOOST_CONCEPT_ASSERT(( concepts::CBidirectionalSegmentComputer<GeomDSS> ));
188}
Aim: Implements basic operations that will be used in Point and Vector classes.
Aim: Defines the concept describing a bidirectional segment computer, ie. a model of concepts::CSeg...
Aim: The concept CDrawableWithBoard2D specifies what are the classes that admit an export with Board2...

Referenced by main().