33 #include "DGtal/base/Common.h"
34 #include "DGtal/helpers/StdDefs.h"
36 #include "DGtal/io/boards/Board2D.h"
39 #include "DGtal/geometry/curves/ArithmeticalDSL.h"
44 using namespace DGtal;
51 void exampleNaiveDSL()
68 Point bottomLeft( 0, 0 );
69 Point topRight( 10, 5 );
70 Domain domain( bottomLeft, topRight );
75 Point firstPoint( bottomLeft[0], (line.a()*bottomLeft[0]/line.b()) );
76 Point lastPoint( topRight[0], (line.a()*topRight[0]/line.b()) );
81 it = line.
begin(firstPoint),
82 ite = line.end(lastPoint);
85 board <<
SetMode( it->className(),
"Paving" )
101 board.
saveCairo(
"NaiveDSL.png", Board2D::CairoPNG);
111 void exampleStandardDSL()
128 Point bottomLeft( 0, 0 );
129 Point topRight( 10, 5 );
130 Domain domain( bottomLeft, topRight );
135 Point firstPoint( bottomLeft[0], (line.a()*bottomLeft[0]/line.b()) );
136 Point lastPoint( topRight[0], (line.a()*topRight[0]/line.b()) );
140 it = line.
begin(firstPoint),
141 ite = line.end(lastPoint);
144 board <<
SetMode( it->className(),
"Paving" )
157 board.
saveSVG(
"StandardDSL.svg");
159 board.
saveCairo(
"StandardDSL.png", Board2D::CairoPNG);
174 template<
typename DSL>
175 void drawArithmeticalDSL(
typename DSL::Integer a,
176 typename DSL::Integer b,
177 unsigned short octant,
180 std::stringstream ssTitle;
181 ssTitle <<
" Arithmetical DSL "
182 <<
"(" << a <<
", " << b <<
", 0)"
183 <<
" in octant " << octant;
192 Vector v = line.steps().first;
193 Vector w = line.steps().second;
194 Vector s = line.shift();
200 typename DSL::ConstIterator it;
201 it = line.begin( Point(0,0) );
203 for (c = 0; c < n; ++it, ++c )
208 board <<
SetMode( p.className(),
"Paving" )
213 Point topRight, bottomLeft;
214 Point firstPoint(0,0);
215 Point lastPoint = *it;
220 bottomLeft = firstPoint;
221 topRight = lastPoint;
225 bottomLeft = Point( firstPoint[0], lastPoint[1] );
226 topRight = Point( lastPoint[0], firstPoint[1] );
233 bottomLeft = Point( lastPoint[0], firstPoint[1] );
234 topRight = Point( firstPoint[0], lastPoint[1] );
238 bottomLeft = lastPoint;
239 topRight = firstPoint;
242 Domain domain( bottomLeft, topRight );
246 it = line.begin( Point(0,0) );
247 for (c = 0; c < n; ++c )
252 if ( line.remainder( p ) == line.mu() )
255 board.
drawArrow(p[0], p[1], p[0]+s[0], p[1]+s[1]);
265 else if ( (q-p) == w )
284 std::stringstream ssFileName;
285 ssFileName <<
"ArithmeticalDSL"
286 <<
"-" << DSL::foregroundAdjacency
288 <<
"-" << a <<
"-" << b
291 board.
saveCairo(ssFileName.str().c_str(), Board2D::CairoPNG);
303 void exampleArithmeticalDSLOctant()
307 drawArithmeticalDSL<NaiveDSL<Integer> >( 0, 1, 0, 15 );
308 drawArithmeticalDSL<NaiveDSL<Integer> >( 5, 8, 0, 15 );
309 drawArithmeticalDSL<NaiveDSL<Integer> >( 1, 1, 1, 15 );
310 drawArithmeticalDSL<NaiveDSL<Integer> >( 8, 5, 1, 15 );
311 drawArithmeticalDSL<NaiveDSL<Integer> >( 1, 0, 2, 15 );
312 drawArithmeticalDSL<NaiveDSL<Integer> >( 8, -5, 2, 15 );
313 drawArithmeticalDSL<NaiveDSL<Integer> >( 1, -1, 3, 15 );
314 drawArithmeticalDSL<NaiveDSL<Integer> >( 5, -8, 3, 15 );
315 drawArithmeticalDSL<NaiveDSL<Integer> >( 0, -1, 4, 15 );
316 drawArithmeticalDSL<NaiveDSL<Integer> >( -5, -8, 4, 15 );
317 drawArithmeticalDSL<NaiveDSL<Integer> >( -1, -1, 5, 15 );
318 drawArithmeticalDSL<NaiveDSL<Integer> >( -8, -5, 5, 15 );
319 drawArithmeticalDSL<NaiveDSL<Integer> >( -1, 0, 6, 15 );
320 drawArithmeticalDSL<NaiveDSL<Integer> >( -8, 5, 6, 15 );
321 drawArithmeticalDSL<NaiveDSL<Integer> >( -1, 1, 7, 15 );
322 drawArithmeticalDSL<NaiveDSL<Integer> >( -5, 8, 7, 15 );
324 drawArithmeticalDSL<StandardDSL<Integer> >( 0, 1, 0, 21 );
325 drawArithmeticalDSL<StandardDSL<Integer> >( 5, 8, 0, 21 );
326 drawArithmeticalDSL<StandardDSL<Integer> >( 1, 1, 1, 21 );
327 drawArithmeticalDSL<StandardDSL<Integer> >( 8, 5, 1, 21 );
328 drawArithmeticalDSL<StandardDSL<Integer> >( 1, 0, 2, 21 );
329 drawArithmeticalDSL<StandardDSL<Integer> >( 8, -5, 2, 21 );
330 drawArithmeticalDSL<StandardDSL<Integer> >( 1, -1, 3, 21 );
331 drawArithmeticalDSL<StandardDSL<Integer> >( 5, -8, 3, 21 );
332 drawArithmeticalDSL<StandardDSL<Integer> >( 0, -1, 4, 21 );
333 drawArithmeticalDSL<StandardDSL<Integer> >( -5, -8, 4, 21 );
334 drawArithmeticalDSL<StandardDSL<Integer> >( -1, -1, 5, 21 );
335 drawArithmeticalDSL<StandardDSL<Integer> >( -8, -5, 5, 21 );
336 drawArithmeticalDSL<StandardDSL<Integer> >( -1, 0, 6, 21 );
337 drawArithmeticalDSL<StandardDSL<Integer> >( -8, 5, 6, 21 );
338 drawArithmeticalDSL<StandardDSL<Integer> >( -1, 1, 7, 21 );
339 drawArithmeticalDSL<StandardDSL<Integer> >( -5, 8, 7, 21 );
346 void exampleArithmeticalDSLTypes()
361 trace.
info() << line2 << line2.isValid();
374 int main(
int argc,
char** argv )
378 for (
int i = 0; i < argc; ++i )
383 exampleStandardDSL();
384 exampleArithmeticalDSLOctant();
385 exampleArithmeticalDSLTypes();
void beginBlock(const std::string &keyword="")
ConstIterator begin(const Point &aPoint) const
void drawArrow(double x1, double y1, double x2, double y2, bool filled=true, int depthValue=-1)
void saveCairo(const char *filename, CairoType type=CairoPNG, PageSize size=Board::BoundingBox, double margin=10.0) const
std::string className() const
Aim: This class is an alias of ArithmeticalDSS for naive DSL. It represents a naive digital straight ...
Aim: This class is an alias of ArithmeticalDSS for standard DSL. It represents a standard digital str...
DGtal is the top-level namespace which contains all DGtal functions and types.
void saveSVG(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Modifier class in a Board2D stream. Useful to choose your own mode for a given class. Realizes the concept CDrawableWithBoard2D.
Board & setPenColorRGBi(unsigned char red, unsigned char green, unsigned char blue, unsigned char alpha=255)
Aim: This class specializes a 'Board' class so as to display DGtal objects more naturally (with <<)...