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

Go to the source code of this file.

Functions

void exampleNaiveDSL ()
 Function that illustrates the basic usage of a naive DSL. More...
 
void exampleStandardDSL ()
 Function that illustrates the basic usage of a standard DSL. More...
 
template<typename DSL >
void drawArithmeticalDSL (typename DSL::Integer a, typename DSL::Integer b, unsigned short octant, unsigned int n)
 Function that draws the steps and the shift vector of a DSL of slope a / b and intercept 0. More...
 
void exampleArithmeticalDSLOctant ()
 Function that draws the steps and the shift vector of a naive and a standard DSL in each octant. More...
 
void exampleArithmeticalDSLTypes ()
 Function that creates a naive DSL with different types. More...
 
int main (int argc, char **argv)
 Program that illustrates the basic usages of instances of ArithmeticalDSL. More...
 

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/11/09

An example file named exampleArithmeticalDSL.

This file is part of the DGtal library.

Definition in file exampleArithmeticalDSL.cpp.

Function Documentation

◆ drawArithmeticalDSL()

template<typename DSL >
void drawArithmeticalDSL ( typename DSL::Integer  a,
typename DSL::Integer  b,
unsigned short  octant,
unsigned int  n 
)

Function that draws the steps and the shift vector of a DSL of slope a / b and intercept 0.

Parameters
aa-parameter of the DSL
bb-parameter of the DSL
octantoctant index for tracing (from 0 to 7).
nnumber of points to draw
Template Parameters
DSLtype of a naive or standard DSL
Examples
geometry/curves/exampleArithmeticalDSL.cpp.

Definition at line 185 of file exampleArithmeticalDSL.cpp.

189{
190 std::stringstream ssTitle;
191 ssTitle << " Arithmetical DSL "
192 << "(" << a << ", " << b << ", 0)"
193 << " in octant " << octant;
194 trace.beginBlock ( ssTitle.str().c_str() );
195
196 using namespace Z2i;
197
198 // Construct the DSL to draw
199 DSL line( a, b, 0 );
200
201 // Vectors to draw
202 Vector v = line.steps().first;
203 Vector w = line.steps().second;
204 Vector s = line.shift();
205
206 // Display the DSL points within the domain with Board2D
207 Board2D board;
208
209 // Draw the DSL points of the DSS
210 typename DSL::ConstIterator it;
211 it = line.begin( Point(0,0) );
212 unsigned int c;
213 for (c = 0; c < n; ++it, ++c )
214 {
215 Point p = *it;
216
217 // Draw the point
218 board << SetMode( p.className(), "Paving" )
219 << p;
220 }
221
222 // Construct the domain
223 Point topRight, bottomLeft;
224 Point firstPoint(0,0);
225 Point lastPoint = *it;
226 if (b > 0)
227 {
228 if (a > 0)
229 {
230 bottomLeft = firstPoint;
231 topRight = lastPoint;
232 }
233 else
234 {
235 bottomLeft = Point( firstPoint[0], lastPoint[1] );
236 topRight = Point( lastPoint[0], firstPoint[1] );
237 }
238 }
239 else
240 {
241 if (a > 0)
242 {
243 bottomLeft = Point( lastPoint[0], firstPoint[1] );
244 topRight = Point( firstPoint[0], lastPoint[1] );
245 }
246 else
247 {
248 bottomLeft = lastPoint;
249 topRight = firstPoint;
250 }
251 }
252 Domain domain( bottomLeft, topRight );
253
254
255 // Draw the vectors
256 it = line.begin( Point(0,0) );
257 for (c = 0; c < n; ++c )
258 {
259 Point p = *it;
260
261 // Draw the shift vector
262 if ( line.remainder( p ) == line.mu() )
263 {
264 board.setPenColorRGBi(250, 0, 0);
265 board.drawArrow(p[0], p[1], p[0]+s[0], p[1]+s[1]);
266 }
267
268 // Draw the steps
269 ++it;
270 if (c < (n-1))
271 {
272 Point q = *it;
273 if ( (q-p) == v )
274 board.setPenColorRGBi(0, 0, 250);
275 else if ( (q-p) == w )
276 board.setPenColorRGBi(0, 250, 0);
277 else
278 board.setPenColorRGBi(0, 0, 0);
279
280 board.drawArrow(p[0], p[1], q[0], q[1]);
281 }
282 }
283
284 // Draw the grid
285 board << SetMode(domain.className(), "Grid")
286 << domain;
287
288 // Draw the orthonormal base
289 board.setPenColorRGBi(0, 0, 0);
290 board.drawArrow(0.0, 0.0, 1.0, 0.0);
291 board.drawArrow(0.0, 0.0, 0.0, 1.0);
292
293 // Save
294 std::stringstream ssFileName;
295 ssFileName << "ArithmeticalDSL"
296 << "-" << DSL::foregroundAdjacency
297 << "-" << octant
298 << "-" << a << "-" << b
299 << ".png";
300 #ifdef WITH_CAIRO
301 board.saveCairo(ssFileName.str().c_str(), Board2D::CairoPNG);
302 #endif
303
304 trace.endBlock();
305
306}
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 beginBlock(const std::string &keyword="")
double endBlock()
Board & setPenColorRGBi(unsigned char red, unsigned char green, unsigned char blue, unsigned char alpha=255)
Definition: Board.cpp:278
void drawArrow(double x1, double y1, double x2, double y2, bool filled=true, int depthValue=-1)
Definition: Board.cpp:400
void saveCairo(const char *filename, CairoType type=CairoPNG, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:1139
Trace trace
Definition: Common.h:154
Modifier class in a Board2D stream. Useful to choose your own mode for a given class....
Definition: Board2D.h:247
MyPointD Point
Definition: testClone2.cpp:383
FreemanChain< int >::Vector Vector
Domain domain

References DGtal::Trace::beginBlock(), DGtal::HyperRectDomain< TSpace >::className(), domain, LibBoard::Board::drawArrow(), DGtal::Trace::endBlock(), LibBoard::Board::saveCairo(), LibBoard::Board::setPenColorRGBi(), and DGtal::trace.

◆ exampleArithmeticalDSLOctant()

void exampleArithmeticalDSLOctant ( )

Function that draws the steps and the shift vector of a naive and a standard DSL in each octant.

See also
drawArithmeticalDSL
Examples
geometry/curves/exampleArithmeticalDSL.cpp.

Definition at line 313 of file exampleArithmeticalDSL.cpp.

314{
315 using namespace Z2i;
316
317 drawArithmeticalDSL<NaiveDSL<Integer> >( 0, 1, 0, 15 );
318 drawArithmeticalDSL<NaiveDSL<Integer> >( 5, 8, 0, 15 );
319 drawArithmeticalDSL<NaiveDSL<Integer> >( 1, 1, 1, 15 );
320 drawArithmeticalDSL<NaiveDSL<Integer> >( 8, 5, 1, 15 );
321 drawArithmeticalDSL<NaiveDSL<Integer> >( 1, 0, 2, 15 );
322 drawArithmeticalDSL<NaiveDSL<Integer> >( 8, -5, 2, 15 );
323 drawArithmeticalDSL<NaiveDSL<Integer> >( 1, -1, 3, 15 );
324 drawArithmeticalDSL<NaiveDSL<Integer> >( 5, -8, 3, 15 );
325 drawArithmeticalDSL<NaiveDSL<Integer> >( 0, -1, 4, 15 );
326 drawArithmeticalDSL<NaiveDSL<Integer> >( -5, -8, 4, 15 );
327 drawArithmeticalDSL<NaiveDSL<Integer> >( -1, -1, 5, 15 );
328 drawArithmeticalDSL<NaiveDSL<Integer> >( -8, -5, 5, 15 );
329 drawArithmeticalDSL<NaiveDSL<Integer> >( -1, 0, 6, 15 );
330 drawArithmeticalDSL<NaiveDSL<Integer> >( -8, 5, 6, 15 );
331 drawArithmeticalDSL<NaiveDSL<Integer> >( -1, 1, 7, 15 );
332 drawArithmeticalDSL<NaiveDSL<Integer> >( -5, 8, 7, 15 );
333
334 drawArithmeticalDSL<StandardDSL<Integer> >( 0, 1, 0, 21 );
335 drawArithmeticalDSL<StandardDSL<Integer> >( 5, 8, 0, 21 );
336 drawArithmeticalDSL<StandardDSL<Integer> >( 1, 1, 1, 21 );
337 drawArithmeticalDSL<StandardDSL<Integer> >( 8, 5, 1, 21 );
338 drawArithmeticalDSL<StandardDSL<Integer> >( 1, 0, 2, 21 );
339 drawArithmeticalDSL<StandardDSL<Integer> >( 8, -5, 2, 21 );
340 drawArithmeticalDSL<StandardDSL<Integer> >( 1, -1, 3, 21 );
341 drawArithmeticalDSL<StandardDSL<Integer> >( 5, -8, 3, 21 );
342 drawArithmeticalDSL<StandardDSL<Integer> >( 0, -1, 4, 21 );
343 drawArithmeticalDSL<StandardDSL<Integer> >( -5, -8, 4, 21 );
344 drawArithmeticalDSL<StandardDSL<Integer> >( -1, -1, 5, 21 );
345 drawArithmeticalDSL<StandardDSL<Integer> >( -8, -5, 5, 21 );
346 drawArithmeticalDSL<StandardDSL<Integer> >( -1, 0, 6, 21 );
347 drawArithmeticalDSL<StandardDSL<Integer> >( -8, 5, 6, 21 );
348 drawArithmeticalDSL<StandardDSL<Integer> >( -1, 1, 7, 21 );
349 drawArithmeticalDSL<StandardDSL<Integer> >( -5, 8, 7, 21 );
350
351}

Referenced by main().

◆ exampleArithmeticalDSLTypes()

void exampleArithmeticalDSLTypes ( )

Function that creates a naive DSL with different types.

[ArithmeticalDSLNaiveCtorTypes]

[ArithmeticalDSLNaiveCtorTypes]

Examples
geometry/curves/exampleArithmeticalDSL.cpp.

Definition at line 356 of file exampleArithmeticalDSL.cpp.

357{
358 trace.beginBlock ( "Naive DSLs" );
359
360 // // Do not use the default type for the intercepts !
361 // NaiveDSL<DGtal::int16_t> line1( 17711, 28657, 1607895256 );
362 // //NB: 1 607 895 256 is not representable by the type DGtal::int16_t,
363 // //even if it is the remainder of the point (32 767,-32 767)
364 // //whose coordinates are representable by the type DGtal::int16_t
365 // trace.info() << line1; //KO
366
368 NaiveDSL<DGtal::int16_t, DGtal::int32_t> line2( 17711, 28657, 1607895256 );
369 //NB: 1 607 895 256 is the remainder of the point (32 767,-32 767),
370 //whose coordinates are representable by the type DGtal::int16_t
371 trace.info() << line2 << line2.isValid(); //ok
373
374 trace.endBlock();
375}
Aim: This class is an alias of ArithmeticalDSS for naive DSL. It represents a naive digital straight ...
std::ostream & info()

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

Referenced by main().

◆ exampleNaiveDSL()

void exampleNaiveDSL ( )

Function that illustrates the basic usage of a naive DSL.

[ArithmeticalDSLNaiveCtor]

[ArithmeticalDSLNaiveCtor]

[ArithmeticalDSLIteration]

[ArithmeticalDSLIteration]

Examples
geometry/curves/exampleArithmeticalDSL.cpp.

Definition at line 61 of file exampleArithmeticalDSL.cpp.

62{
63 trace.beginBlock ( "Naive DSL" );
64
65 using namespace Z2i;
66
68 // Construct a naive DSL from a, b, mu
69 NaiveDSL<Integer> line( 2, 5, 0 );
71
72 // Trace to the standard output
73 // the two representations
74 // corresponding to the same set of points
75 trace.info() << line << line.negate();
76
77 // Construct a (rectangular) domain
78 Point bottomLeft( 0, 0 );
79 Point topRight( 10, 5 );
80 Domain domain( bottomLeft, topRight );
81
82 // Display the DSL points within the domain with Board2D
83 Board2D board;
84
85 Point firstPoint( bottomLeft[0], (line.a()*bottomLeft[0]/line.b()) );
86 Point lastPoint( topRight[0], (line.a()*topRight[0]/line.b()) );
87
89 // Draw the DSL points between firstPoint and lastPoint
91 it = line.begin(firstPoint),
92 ite = line.end(lastPoint);
93 it != ite; ++it )
94 {
95 board << SetMode( it->className(), "Paving" )
96 << *it; //Draw the point
97 }
99
100 // Draw the grid
101 board << SetMode(domain.className(), "Grid")
102 << domain;
103
104 // Draw the orthonormal base
105 board.drawArrow(0.0, 0.0, 1.0, 0.0);
106 board.drawArrow(0.0, 0.0, 0.0, 1.0);
107
108 // Save
109 board.saveSVG("NaiveDSL.svg");
110 #ifdef WITH_CAIRO
111 board.saveCairo("NaiveDSL.png", Board2D::CairoPNG);
112 #endif
113
114 trace.endBlock();
115}
ConstIterator begin(const Point &aPoint) const
void saveSVG(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:1012

References DGtal::ArithmeticalDSL< TCoordinate, TInteger, adjacency >::a(), DGtal::ArithmeticalDSL< TCoordinate, TInteger, adjacency >::b(), DGtal::ArithmeticalDSL< TCoordinate, TInteger, adjacency >::begin(), DGtal::Trace::beginBlock(), DGtal::HyperRectDomain< TSpace >::className(), domain, LibBoard::Board::drawArrow(), DGtal::ArithmeticalDSL< TCoordinate, TInteger, adjacency >::end(), DGtal::Trace::endBlock(), DGtal::Trace::info(), DGtal::ArithmeticalDSL< TCoordinate, TInteger, adjacency >::negate(), LibBoard::Board::saveCairo(), LibBoard::Board::saveSVG(), and DGtal::trace.

Referenced by main().

◆ exampleStandardDSL()

void exampleStandardDSL ( )

Function that illustrates the basic usage of a standard DSL.

[ArithmeticalDSLStandardCtor]

[ArithmeticalDSLStandardCtor]

Examples
geometry/curves/exampleArithmeticalDSL.cpp.

Definition at line 121 of file exampleArithmeticalDSL.cpp.

122{
123 trace.beginBlock ( "Standard DSL" );
124
125 using namespace Z2i;
126
128 // Construct a standard DSL from a, b, mu
129 StandardDSL<Integer> line( 2, 5, 0 );
131
132 // Trace to the standard output
133 // the two representations
134 // corresponding to the same set of points
135 trace.info() << line << line.negate();
136
137 // Construct a (rectangular) domain
138 Point bottomLeft( 0, 0 );
139 Point topRight( 10, 5 );
140 Domain domain( bottomLeft, topRight );
141
142 // Display the DSL points within the domain with Board2D
143 Board2D board;
144
145 Point firstPoint( bottomLeft[0], (line.a()*bottomLeft[0]/line.b()) );
146 Point lastPoint( topRight[0], (line.a()*topRight[0]/line.b()) );
147
148 // Draw the DSL points between firstPoint and lastPoint
150 it = line.begin(firstPoint),
151 ite = line.end(lastPoint);
152 it != ite; ++it )
153 {
154 board << SetMode( it->className(), "Paving" )
155 << *it; //Draw the point
156 }
157
158 // Draw the grid
159 board << SetMode(domain.className(), "Grid")
160 << domain;
161
162 // Draw the orthonormal base
163 board.drawArrow(0.0, 0.0, 1.0, 0.0);
164 board.drawArrow(0.0, 0.0, 0.0, 1.0);
165
166 // Save
167 board.saveSVG("StandardDSL.svg");
168 #ifdef WITH_CAIRO
169 board.saveCairo("StandardDSL.png", Board2D::CairoPNG);
170 #endif
171
172 trace.endBlock();
173}
Aim: This class is an alias of ArithmeticalDSS for standard DSL. It represents a standard digital str...

References DGtal::ArithmeticalDSL< TCoordinate, TInteger, adjacency >::a(), DGtal::ArithmeticalDSL< TCoordinate, TInteger, adjacency >::b(), DGtal::ArithmeticalDSL< TCoordinate, TInteger, adjacency >::begin(), DGtal::Trace::beginBlock(), DGtal::HyperRectDomain< TSpace >::className(), domain, LibBoard::Board::drawArrow(), DGtal::ArithmeticalDSL< TCoordinate, TInteger, adjacency >::end(), DGtal::Trace::endBlock(), DGtal::Trace::info(), DGtal::ArithmeticalDSL< TCoordinate, TInteger, adjacency >::negate(), LibBoard::Board::saveCairo(), LibBoard::Board::saveSVG(), and DGtal::trace.

Referenced by main().

◆ main()

int main ( int  argc,
char **  argv 
)

Program that illustrates the basic usages of instances of ArithmeticalDSL.

Parameters
argcnumber of arguments
argvlist of arguments

Definition at line 384 of file exampleArithmeticalDSL.cpp.

385{
386 trace.beginBlock ( "Example exampleArithmeticalDSL" );
387 trace.info() << "Args:";
388 for ( int i = 0; i < argc; ++i )
389 trace.info() << " " << argv[ i ];
390 trace.info() << endl;
391
396
397 trace.endBlock();
398 return 0;
399}
void exampleStandardDSL()
Function that illustrates the basic usage of a standard DSL.
void exampleNaiveDSL()
Function that illustrates the basic usage of a naive DSL.
void exampleArithmeticalDSLTypes()
Function that creates a naive DSL with different types.
void exampleArithmeticalDSLOctant()
Function that draws the steps and the shift vector of a naive and a standard DSL in each octant.

References DGtal::Trace::beginBlock(), DGtal::Trace::endBlock(), exampleArithmeticalDSLOctant(), exampleArithmeticalDSLTypes(), exampleNaiveDSL(), exampleStandardDSL(), DGtal::Trace::info(), and DGtal::trace.