DGtal 1.3.0
Loading...
Searching...
No Matches
Functions
exampleArithmeticalDSS.cpp File Reference
#include <iostream>
#include <exception>
#include "DGtal/base/Common.h"
#include "DGtal/helpers/StdDefs.h"
#include "DGtal/io/boards/Board2D.h"
#include "DGtal/geometry/curves/ArithmeticalDSS.h"

Go to the source code of this file.

Functions

void exampleNaiveDSS ()
 Function that illustrates the basic usage of a naive DSS. More...
 
void exampleStandardDSS ()
 Function that illustrates the basic usage of a standard DSS. More...
 
void exampleConstructors ()
 Function showing the different ways of constructing DSSs. More...
 
void exampleUpdate ()
 Function showing how a DSS can be extended and retracted. More...
 
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
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
2013/07/08

An example file named exampleArithmeticalDSS.

This file is part of the DGtal library.

Definition in file exampleArithmeticalDSS.cpp.

Function Documentation

◆ exampleConstructors()

void exampleConstructors ( )

Function showing the different ways of constructing DSSs.

[ArithmeticalDSSNaiveCtorUpperPoints]

[ArithmeticalDSSNaiveCtorUpperPoints]

[ArithmeticalDSSNaiveCtorLowerPoints]

[ArithmeticalDSSNaiveCtorLowerPoints]

[ArithmeticalDSSNaiveCtorDSL]

[ArithmeticalDSSNaiveCtorDSL]

[ArithmeticalDSSNaiveCtorDSS]

[ArithmeticalDSSNaiveCtorDSS]

[ArithmeticalDSSNaiveCtorParam]

[ArithmeticalDSSNaiveCtorParam]

[ArithmeticalDSSNaiveCtorRange]

[ArithmeticalDSSNaiveCtorRange]

Examples
geometry/curves/exampleArithmeticalDSS.cpp.

Definition at line 197 of file exampleArithmeticalDSS.cpp.

198{
199 trace.beginBlock ( "DSSs constructions" );
200
201 using namespace Z2i;
202
203 {
205 // Construct a naive DSS from two upper leaning points
206 NaiveDSS8<Integer> segment( Point(0,0), Point(8,5), true );
207 //or simply NaiveDSS8<Integer> segment( Point(0,0), Point(8,5) );
209 trace.info() << segment << std::endl;
210 }
211
212 {
214 // Construct a naive DSS from two lower leaning points
215 NaiveDSS8<Integer> segment( Point(0,0), Point(8,5), false );
217 trace.info() << segment << std::endl;
218 }
219
220 {
222 // Construct a naive DSS as a DSL subsegment
223 NaiveDSS8<Integer> segment( NaiveDSL<Integer>(5,8,0), Point(0,0), Point(8,5) );
225 trace.info() << segment << std::endl;
226 }
227
228 {
229 NaiveDSS8<Integer> bigDSS( NaiveDSL<Integer>(5,8,0), Point(-8,-5), Point(16,10) );
231 // Construct a naive DSS as a subsegment of a greater DSS
232 NaiveDSS8<Integer> segment( bigDSS, Point(0,0), Point(8,5) );
234 trace.info() << segment << std::endl;
235 }
236
237 std::vector<Point> r; //container for DSS points
238 {
240 // Custom a naive DSS
241 NaiveDSS8<Integer> segment( 5, 8, //slope
242 Point(0,0), Point(8,5), //ending points
243 Point(0,0), Point(8,5), //upper points
244 Point(3,1), Point(3,1) //lower points
245 );
246 //You should be sure that your object is valid before using it
247 if (!segment.isValid()) throw std::exception();
249 trace.info() << segment << std::endl;
250
251 //copy the DSS points into the container r
252 std::copy( segment.begin(), segment.end(), std::back_inserter(r) );
253 }
254
255 {
257 // Construct a DSS from a range of points
258 NaiveDSS8<Integer> segment( r.begin(), r.end() );
260 trace.info() << segment << std::endl;
261 }
262
263
264 trace.endBlock();
265}
Aim: This class is an alias of ArithmeticalDSS for naive DSL. It represents a naive digital straight ...
Aim: This class represents a standard digital straight segment (DSS), ie. the sequence of simply 8-co...
void beginBlock(const std::string &keyword="")
std::ostream & info()
double endBlock()
Space::Point Point
Definition: StdDefs.h:95
Trace trace
Definition: Common.h:154

References DGtal::ArithmeticalDSS< TCoordinate, TInteger, adjacency >::begin(), DGtal::Trace::beginBlock(), DGtal::ArithmeticalDSS< TCoordinate, TInteger, adjacency >::end(), DGtal::Trace::endBlock(), DGtal::Trace::info(), DGtal::ArithmeticalDSS< TCoordinate, TInteger, adjacency >::isValid(), and DGtal::trace.

Referenced by main().

◆ exampleNaiveDSS()

void exampleNaiveDSS ( )

Function that illustrates the basic usage of a naive DSS.

[ArithmeticalDSSNaiveCtor]

[ArithmeticalDSSNaiveCtor]

[ArithmeticalDSSIteration]

[ArithmeticalDSSIteration]

[NaiveDSS8DrawingUsage]

[NaiveDSS8DrawingUsage]

Examples
geometry/curves/exampleArithmeticalDSS.cpp.

Definition at line 60 of file exampleArithmeticalDSS.cpp.

61{
62 trace.beginBlock ( "Naive DSS" );
63
64 using namespace Z2i;
65
67 // Construct a naive DSS
68 NaiveDSS8<Integer> segment( 5, 8, //slope
69 Point(0,0), Point(8,5), //ending points
70 Point(0,0), Point(8,5), //upper points
71 Point(3,1), Point(3,1) //lower points
72 );
74
75 // Trace to the standard output
76 trace.info() << segment << std::endl;
77
79 // Trace the position and remainder of each point
81 it = segment.begin(),
82 ite = segment.end();
83 it != ite; ++it )
84 {
85 trace.info() << "("
86 << segment.position( *it ) << ","
87 << segment.remainder( *it )
88 << ") ";
89 }
91 trace.info() << std::endl;
92
94 Board2D board;
95
96 // Draw the grid
97 Domain domain( Point(0,0), Point(8,5) );
98 board << SetMode(domain.className(), "Grid")
99 << domain;
100
101 //Draw the points of the DSS
102 board << SetMode("PointVector", "Both");
103 board << SetMode(segment.className(), "Points")
104 << segment;
105
106 // Draw the bounding box
107 board << SetMode(segment.className(), "BoundingBox")
108 << segment;
110
111
112 // Save
113 board.saveSVG("NaiveDSS8.svg");
114#ifdef WITH_CAIRO
115 board.saveCairo("NaiveDSS8.png", Board2D::CairoPNG);
116#endif
117
118 trace.endBlock();
119}
ConstIterator begin() const
Aim: This class specializes a 'Board' class so as to display DGtal objects more naturally (with <<)....
Definition: Board2D.h:71
std::string className() const
void saveSVG(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:1012
void saveCairo(const char *filename, CairoType type=CairoPNG, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:1139
Modifier class in a Board2D stream. Useful to choose your own mode for a given class....
Definition: Board2D.h:247
Domain domain

References DGtal::ArithmeticalDSS< TCoordinate, TInteger, adjacency >::begin(), DGtal::Trace::beginBlock(), DGtal::ArithmeticalDSS< TCoordinate, TInteger, adjacency >::className(), DGtal::HyperRectDomain< TSpace >::className(), domain, DGtal::ArithmeticalDSS< TCoordinate, TInteger, adjacency >::end(), DGtal::Trace::endBlock(), DGtal::Trace::info(), DGtal::ArithmeticalDSS< TCoordinate, TInteger, adjacency >::position(), DGtal::ArithmeticalDSS< TCoordinate, TInteger, adjacency >::remainder(), LibBoard::Board::saveCairo(), LibBoard::Board::saveSVG(), and DGtal::trace.

Referenced by main().

◆ exampleStandardDSS()

void exampleStandardDSS ( )

Function that illustrates the basic usage of a standard DSS.

[ArithmeticalDSSStandardCtor]

[ArithmeticalDSSStandardCtor]

[StandardDSS4DrawingUsage]

[StandardDSS4DrawingUsage]

[ArithmeticalDSSDrawingUsage]

[ArithmeticalDSSDrawingUsage]

Examples
geometry/curves/exampleArithmeticalDSS.cpp.

Definition at line 126 of file exampleArithmeticalDSS.cpp.

127{
128 trace.beginBlock ( "Standard DSS" );
129
130 using namespace Z2i;
131
133 // Construct a standard DSS
134 StandardDSS4<Integer> segment( 5, 8, //slope
135 Point(0,0), Point(8,5), //ending points
136 Point(0,0), Point(8,5), //upper points
137 Point(4,1), Point(4,1) //lower points
138 );
140
141 // Trace to the standard output
142 trace.info() << segment << std::endl;
143
144 // Display the DSS with a domain on a board
145 Domain domain( Point(0,0), Point(8,5) );
146 Board2D board;
147
149 // Draw the grid
150 board << SetMode(domain.className(), "Grid")
151 << domain;
152
153 // Draw the points of the DSS
154 board << SetMode("PointVector", "Grid")
155 << SetMode(segment.className(), "Points")
156 << segment;
157
158 // Draw the bounding box
159 board << SetMode(segment.className(), "BoundingBox")
160 << segment;
162
163 // Save
164 board.saveSVG("StandardDSS4.svg");
165#ifdef WITH_CAIRO
166 board.saveCairo("StandardDSS4.png", Board2D::CairoPNG);
167#endif
168
169 board.clear();
171 // Draw the pixels
172 board << SetMode(domain.className(), "Paving")
173 << domain;
174
175 //Draw the points of the DSS
176 board << SetMode("PointVector", "Both");
177 board << SetMode(segment.className(), "Points")
178 << segment;
179
180 // Draw the bounding box
181 board << SetMode(segment.className(), "BoundingBox")
182 << segment;
184
185 board.saveSVG("StandardDSS4bis.svg");
186#ifdef WITH_CAIRO
187 board.saveCairo("StandardDSS4bis.png", Board2D::CairoPNG);
188#endif
189
190 trace.endBlock();
191}
Aim: This class represents a standard digital straight segment (DSS), ie. the sequence of simply 4-co...
void clear(const DGtal::Color &color=DGtal::Color::None)
Definition: Board.cpp:152

References DGtal::Trace::beginBlock(), DGtal::ArithmeticalDSS< TCoordinate, TInteger, adjacency >::className(), DGtal::HyperRectDomain< TSpace >::className(), LibBoard::Board::clear(), domain, DGtal::Trace::endBlock(), DGtal::Trace::info(), LibBoard::Board::saveCairo(), LibBoard::Board::saveSVG(), and DGtal::trace.

Referenced by main().

◆ exampleUpdate()

void exampleUpdate ( )

Function showing how a DSS can be extended and retracted.

[ArithmeticalDSSUpdateInit]

[ArithmeticalDSSUpdateInit]

[ArithmeticalDSSUpdateExtension]

[ArithmeticalDSSUpdateExtension]

[ArithmeticalDSSUpdateRetraction]

[ArithmeticalDSSUpdateRetraction]

[ArithmeticalDSSUpdateConclu]

[ArithmeticalDSSUpdateConclu]

Examples
geometry/curves/exampleArithmeticalDSS.cpp.

Definition at line 270 of file exampleArithmeticalDSS.cpp.

271{
272 trace.beginBlock ( "DSS update" );
273
274 using namespace Z2i;
275
276 //Construction --------------------------------------------------
278 Point M(11, 7);
279 NaiveDSS8<Integer> S( 5, 8, //slope
280 Point(0,0), Point(10,6), //ending points
281 Point(0,0), Point(8,5), //upper points
282 Point(3,1), Point(3,1) //lower points
283 );
285
286 //this segment should be valid:
287 if (!S.isValid()) throw std::exception();
288 // Store a copy before any operation
289 NaiveDSS8<Integer> copyOfS = S;
290
291 trace.info() << S << std::endl;
292
293
294 //Display ------------------------------------------------------
295 {
296 Board2D board;
297
298 // Draw the grid
299 Domain domain( Point(0,0), M );
300 board << SetMode(domain.className(), "Grid")
301 << domain;
302 // Draw the points of the DSS and its bounding box
303 board << SetMode("PointVector", "Both");
304 board << SetMode(S.className(), "Points")
305 << S
306 << SetMode(S.className(), "BoundingBox")
307 << S;
308 // Draw the orthonormal base
309 board.drawArrow(0.0, 0.0, 1.0, 0.0);
310 board.drawArrow(0.0, 0.0, 0.0, 1.0);
311 // Draw M
312 board << SetMode(M.className(), "Both")
313 << CustomStyle( M.className(), new CustomColors( Color(255,0,0), Color(192, 0, 0)) )
314 << M;
315
316
317 // Save
318 board.saveSVG("NaiveDSS8ExtInit.svg");
319#ifdef WITH_CAIRO
320 board.saveCairo("NaiveDSS8ExtInit.png", Board2D::CairoPNG);
321#endif
322 }
323
324 // Extension -----------------------------------------------------
326 bool resExtention = S.extendFront( M );
328 //this segment should be extended:
329 if (!resExtention) throw std::exception();
330
331 trace.info() << S << std::endl;
332
333 //Display ------------------------------------------------------
334 {
335 Board2D board;
336
337 // Draw the grid
338 Domain domain( Point(0,0), M );
339 board << SetMode(domain.className(), "Grid")
340 << domain;
341 // Draw the points of the DSS and its bounding box
342 board << SetMode("PointVector", "Both");
343 board << SetMode(S.className(), "Points")
344 << S
345 << SetMode(S.className(), "BoundingBox")
346 << S;
347 // Draw the orthonormal base
348 board.drawArrow(0.0, 0.0, 1.0, 0.0);
349 board.drawArrow(0.0, 0.0, 0.0, 1.0);
350
351 // Save
352 board.saveSVG("NaiveDSS8ExtDone.svg");
353#ifdef WITH_CAIRO
354 board.saveCairo("NaiveDSS8ExtDone.png", Board2D::CairoPNG);
355#endif
356 }
357
358 // Retraction ----------------------------------------------------
360 bool resRetraction = S.retractFront();
362 //this segment should be retracted:
363 if (!resRetraction) throw std::exception();
364
365 trace.info() << S << std::endl;
366
367 // Comparaison ----------------------------------------------------
369 //this segment and the previous copy should be equal:
370 if ( !S.equalsTo(copyOfS) ) throw std::exception();
372
373 trace.endBlock();
374}
Structure representing an RGB triple with alpha component.
Definition: Color.h:68
void drawArrow(double x1, double y1, double x2, double y2, bool filled=true, int depthValue=-1)
Definition: Board.cpp:400
Custom style class redefining the pen color and the fill color. You may use Board2D::Color::None for ...
Definition: Board2D.h:279

References DGtal::Trace::beginBlock(), DGtal::ArithmeticalDSS< TCoordinate, TInteger, adjacency >::className(), DGtal::HyperRectDomain< TSpace >::className(), DGtal::PointVector< dim, TEuclideanRing, TContainer >::className(), domain, LibBoard::Board::drawArrow(), DGtal::Trace::endBlock(), DGtal::ArithmeticalDSS< TCoordinate, TInteger, adjacency >::equalsTo(), DGtal::ArithmeticalDSS< TCoordinate, TInteger, adjacency >::extendFront(), DGtal::Trace::info(), DGtal::ArithmeticalDSS< TCoordinate, TInteger, adjacency >::isValid(), DGtal::ArithmeticalDSS< TCoordinate, TInteger, adjacency >::retractFront(), LibBoard::Board::saveCairo(), LibBoard::Board::saveSVG(), and DGtal::trace.

Referenced by main().

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 378 of file exampleArithmeticalDSS.cpp.

379{
380 trace.beginBlock ( "Example exampleArithmeticalDSS" );
381 trace.info() << "Args:";
382 for ( int i = 0; i < argc; ++i )
383 trace.info() << " " << argv[ i ];
384 trace.info() << endl;
385
389 exampleUpdate();
390
391 trace.endBlock();
392 return 0;
393}
void exampleUpdate()
Function showing how a DSS can be extended and retracted.
void exampleNaiveDSS()
Function that illustrates the basic usage of a naive DSS.
void exampleStandardDSS()
Function that illustrates the basic usage of a standard DSS.
void exampleConstructors()
Function showing the different ways of constructing DSSs.

References DGtal::Trace::beginBlock(), DGtal::Trace::endBlock(), exampleConstructors(), exampleNaiveDSS(), exampleStandardDSS(), exampleUpdate(), DGtal::Trace::info(), and DGtal::trace.