DGtal  0.6.devel
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Display2DFactory.ih
1 
29 
30 // Implementation of inline methods //
31 
32 
34 // Implementation of inline functions and external operators //
35 
36 
37 // AngleLinearMinimizer
38 inline
40  const DGtal::AngleLinearMinimizer & a )
41 {
42  double distance=5.0;
43  board.setLineWidth(3.0);
44  board.setPenColor(Color(20,20,200));
45  // now with accessor
46  for(int i=0; i< (int)a.size(); i++){
47  board.drawArc(0.0, 0.0, distance, a.ro(i).min, a.ro(i).max, false, 1);
48  board.drawDot(cos(a.ro(i).value)*distance, sin(a.ro(i).value)*distance );
49  distance+=a.ro(i).distToNext;
50  }
51  distance=5.0;
52  double distanceNext;
53  // now with accessor
54  for(int i=0; i< (int) (a.size()-1); i++){
55  distanceNext= distance+ a.ro(i).distToNext;
56  board.setPenColor(Color(200,20,20));
57  board.drawLine(cos(a.ro(i).value)*distance, sin(a.ro(i).value)*distance,
58  cos(a.ro(i+1).value)*distanceNext, sin(a.ro(i+1).value)*distanceNext);
59  distance=distanceNext;
60  }
61 }
62 // AngleLinearMinimizer
63 
64 
65 // ArithmeticalDSS
66 template <typename TIterator, typename TInteger, int connectivity>
67 inline
70 {
71  typedef DGtal::PointVector<2,double> PointD;
72 
73  //draw bounding box
74  PointD topLeft = a.project(*a.myF, a.myUf);
75  PointD bottomLeft = a.project(*a.myF, a.myLf);
76  PointD bottomRight = a.project(*a.myL, a.myLf);
77  PointD topRight = a.project(*a.myL, a.myUf);
78 
79 
80  LibBoard::Point topLeftBoard(topLeft[0],topLeft[1]);
81  LibBoard::Point bottomLeftBoard(bottomLeft[0],bottomLeft[1]);
82  LibBoard::Point bottomRightBoard(bottomRight[0],bottomRight[1]);
83  LibBoard::Point topRightBoard(topRight[0],topRight[1]);
84 
85  vector<LibBoard::Point> bb;
86  bb.push_back(topLeftBoard);
87  bb.push_back(bottomLeftBoard);
88  bb.push_back(bottomRightBoard);
89  bb.push_back(topRightBoard);
90 
91  aBoard.drawClosedPolyline(bb);
92 }
93 
94 template <typename TIterator, typename TInteger, int connectivity>
95 inline
98 {
99  typedef TIterator ConstIterator;
101 
102  ConstIterator itend = a.myL; ++itend;
103 
104  // Draw a linking polygonal line if the pixels are drawn as points.
105  if(aBoard.getMode("PointVector")=="Grid" || aBoard.getMode("PointVector")=="")
106  {
107  vector<LibBoard::Point> contour;
108  for (ConstIterator i = a.myF; i != itend; ++i) {
109  Point p = *i;
110  double xp = NumberTraits<TInteger>::castToDouble(p[0]);
111  double yp = NumberTraits<TInteger>::castToDouble(p[1]);
112  contour.push_back(LibBoard::Point(xp,yp));
113  }
114  aBoard.drawPolyline(contour);
115  }
116 
117  // Draw points
118  for (ConstIterator i = a.myF; i != itend; ++i) {
119  Point p = *i;
120  aBoard << p;
121  }
122 }
123 
124 template <typename TIterator, typename TInteger, int connectivity>
125 inline
128 {
129  std::string mode = board.getMode( a.className() );
130  if ( mode == "BoundingBox" )
131  drawAsBoundingBox( board, a );
132  else if ( mode == "Points" )
133  drawAsDigitalPoints( board, a );
134  else if ( ( mode == "" ) )
135  {
136  drawAsDigitalPoints( board, a );
137  drawAsBoundingBox( board, a );
138  }
139  else
140  ASSERT(false && ("draw( DGtal::Board2D & board, const DGtal::ArithmeticalDSS<TIterator,TInteger,connectivity> & a ): Unknown mode "+mode)=="" );
141 
142 }
143 // ArithmeticalDSS
144 
145 
146 // CircleFrom2Points
147 template <typename TPoint>
148 inline
150 {
151  // now with accessor
152  CircleFrom3Points<TPoint> c(cf2p.pole(),cf2p.p(),cf2p.q());
153  drawArc(aBoard,c,cf2p.p(),cf2p.q(),true);
154 }
155 // CircleFrom2Points
156 
157 
158 // CircleFrom3Points
159 template <typename Point>
160 inline
161 void DGtal::Display2DFactory::drawArc(Board2D & aBoard, const DGtal::CircleFrom3Points<Point> & cf3p, const Point& aPoint1, const Point& aPoint2, bool anOrientation)
162 {
163  typedef typename Point::Coordinate Coordinate;
164  typedef Point Vector;
165 
166  double cx = 0, cy = 0, radius = 1;
167  try
168  {
169  //circle parameters
170  cf3p.getParameters(cx, cy, radius);
171  //angle parameters
172  double alpha1 = std::atan2( NumberTraits<Coordinate>::castToDouble(aPoint1[1])-cy,
174  alpha1 = (alpha1<0)?(alpha1+2.0*M_PI):alpha1;
175  double alpha2 = std::atan2( NumberTraits<Coordinate>::castToDouble(aPoint2[1])-cy,
177  alpha2 = (alpha2<0)?(alpha2+2.0*M_PI):alpha2;
178  // now with accessor
179  Vector u(cf3p.p() - cf3p.q());
180  Vector v(cf3p.r() - cf3p.p());
181  bool orientation = ( ( (u[0] * v[1]) - (u[1] * v[0]) ) < 0 )?(!anOrientation):anOrientation;
182  //drawing
183  aBoard.drawArc (cx, cy, radius, alpha1, alpha2, orientation);
184  }
185  catch ( InfiniteNumberException e )
186  {
191  }
192 }
193 
194 template <typename Point>
195 inline
196 void DGtal::Display2DFactory::drawSector(Board2D & aBoard, const DGtal::CircleFrom3Points<Point> & cf3p, const Point& aPoint1, const Point& aPoint2, bool anOrientation)
197 {
198  typedef typename Point::Coordinate Coordinate;
199  typedef Point Vector;
200 
201  double cx = 0, cy = 0, radius = 1;
202  try
203  {
204  //circle parameters
205  cf3p.getParameters(cx, cy, radius);
206  //angle parameters
207  double alpha1 = std::atan2( NumberTraits<Coordinate>::castToDouble(aPoint1[1])-cy,
209  alpha1 = (alpha1<0)?(alpha1+2.0*M_PI):alpha1;
210  double alpha2 = std::atan2( NumberTraits<Coordinate>::castToDouble(aPoint2[1])-cy,
212  alpha2 = (alpha2<0)?(alpha2+2.0*M_PI):alpha2;
213  // now with accessor
214  Vector u(cf3p.p() - cf3p.q());
215  Vector v(cf3p.r() - cf3p.p());
216  bool orientation = ( ( (u[0] * v[1]) - (u[1] * v[0]) ) < 0 )?(!anOrientation):anOrientation;
217  //arc drawing
218  aBoard.drawArc (cx, cy, radius, alpha1, alpha2, orientation);
219  //draw the segments tied to the center
220  double fx = cx + radius*std::cos(alpha1);
221  double fy = cy + radius*std::sin(alpha1);
222  double lx = cx + radius*std::cos(alpha2);
223  double ly = cy + radius*std::sin(alpha2);
224  aBoard.drawLine(fx, fy, cx, cy );
225  aBoard.drawLine(lx, ly, cx, cy );
226 
227  }
228  catch ( InfiniteNumberException e )
229  {
234  }
235 }
236 
237 template <typename Point>
238 inline
239 void DGtal::Display2DFactory::drawAnnulus(Board2D & aBoard, const DGtal::CircleFrom3Points<Point> & cf3p, const Point& aPoint1, const Point& aPoint2, const double& w, bool anOrientation)
240 {
241  typedef typename Point::Coordinate Coordinate;
242  typedef Point Vector;
243 
244  double cx = 0, cy = 0, radius = 1;
245  try
246  {
247  //circle parameters
248  cf3p.getParameters(cx, cy, radius);
249  //angle parameters
250  double alpha1 = std::atan2( NumberTraits<Coordinate>::castToDouble(aPoint1[1])-cy,
252  alpha1 = (alpha1<0)?(alpha1+2.0*M_PI):alpha1;
253  double alpha2 = std::atan2( NumberTraits<Coordinate>::castToDouble(aPoint2[1])-cy,
255  alpha2 = (alpha2<0)?(alpha2+2.0*M_PI):alpha2;
256  // now with accessor
257  Vector u(cf3p.p() - cf3p.q());
258  Vector v(cf3p.r() - cf3p.p());
259  bool orientation = ( ( (u[0] * v[1]) - (u[1] * v[0]) ) < 0 )?(!anOrientation):anOrientation;
260  //inner arc
261  aBoard.drawArc (cx, cy, radius-w, alpha1, alpha2, orientation);
262  //outer arc
263  aBoard.drawArc (cx, cy, radius+w, alpha1, alpha2, orientation);
264  //first segment
265  double ifx = cx + (radius-w)*std::cos(alpha1);
266  double ify = cy + (radius-w)*std::sin(alpha1);
267  double ofx = cx + (radius+w)*std::cos(alpha1);
268  double ofy = cy + (radius+w)*std::sin(alpha1);
269  aBoard.drawLine(ifx, ify, ofx, ofy);
270  //second segment
271  double ilx = cx + (radius-w)*std::cos(alpha2);
272  double ily = cy + (radius-w)*std::sin(alpha2);
273  double olx = cx + (radius+w)*std::cos(alpha2);
274  double oly = cy + (radius+w)*std::sin(alpha2);
275  aBoard.drawLine(ilx, ily, olx, oly);
276  }
277  catch ( InfiniteNumberException e )
278  {
283  }
284 }
285 
286 template <typename Point>
287 inline
288 void DGtal::Display2DFactory::draw(Board2D & aBoard, const DGtal::CircleFrom3Points<Point> & cf3p, const Point& aPoint1, const Point& aPoint2, bool anOrientation)
289 {
290  std::string mode = aBoard.getMode( cf3p.className() );
291  ASSERT( (mode=="Arc" || mode=="" || mode=="Sector"|| mode=="Annulus") ||
292  ("draw(Board2D & aBoard, const DGtal::CircleFrom3Points<Point> & cf3p, const Point& aPoint1, const Point& aPoint2): Unknown mode "+mode)=="" );
293 
294  if ( mode == "Arc" || ( mode == "" ) )
295  drawArc( aBoard, cf3p, aPoint1, aPoint2, anOrientation);
296  else if ( mode == "Sector" )
297  drawSector( aBoard, cf3p, aPoint1, aPoint2, anOrientation);
298  else if ( mode == "Annulus" )
299  drawAnnulus( aBoard, cf3p, aPoint1, aPoint2, anOrientation);
300 }
301 
302 template <typename TPoint>
303 inline
305 {
306  typedef typename TPoint::Coordinate Coordinate;
307 
308  double cx = 0, cy = 0, radius = 1;
309  try
310  {
311  cf3p.getParameters(cx,cy,radius);
312  aBoard.drawCircle (cx,cy,radius);
313  }
314  catch ( InfiniteNumberException e )
315  {
320  }
321 }
322 // CircleFrom3Points
323 
324 
325 // DigitalSetBySTLSet
326 template<typename Domain>
327 inline
330 {
331  typedef typename Domain::Point Point;
332  typedef typename Point::Coordinate Coordinate;
333  typedef typename std::set<Point>::const_iterator ConstIterator;
334 
335  ASSERT(Domain::Space::dimension == 2);
336  for(ConstIterator it = s.begin(); it != s.end(); ++it)
337 // <<<<<<< HEAD
338 // board.drawRectangle( NumberTraits<Coordinate>::castToDouble( (*it)[0] ) - 0.5,
339 // NumberTraits<Coordinate>::castToDouble( (*it)[1] ) + 0.5,
340 // 1,
341 // 1 );
342 // =======
343  draw(board, *it);
344 
345  //>>>>>>> master
346 }
347 // DigitalSetBySTLSet
348 
349 
350 // DigitalSetBySTLVector
351 template<typename Domain>
352 inline
355 {
356  typedef typename Domain::Point Point;
357  typedef typename std::vector<Point>::const_iterator ConstIterator;
358 
359  if (Domain::dimension == 2)
360  {
361  for(ConstIterator it = v.begin(); it != v.end(); ++it)
362  draw(board, *it);
363  }
364  else
365  ASSERT(false && ("draw-NOT-YET-IMPLEMENTED-in-ND"));
366 }
367 // DigitalSetBySTLVector
368 
369 
370 // FP
371 template <typename TIterator, typename TInteger, int connectivity>
372 inline
375 {
377  typedef std::list<Point> Polygon;
378 
379  typedef typename Polygon::const_iterator ConstIterator;
380 
381  //polyline to draw
382  vector<LibBoard::Point> polyline;
383 
384  // now with accessor
385  ConstIterator i = fp.polygon().begin();
386  for ( ;i != fp.polygon().end();++i) {
387  Point p = (*i);
388  double xp = (double)NumberTraits<TInteger>::castToInt64_t(p[0]);
389  double yp = (double)NumberTraits<TInteger>::castToInt64_t(p[1]);
390  polyline.push_back(LibBoard::Point(xp,yp));
391  }
392 
393  // now with accessor
394  if (fp.flagIsClosed()) {
395  Point p = (*fp.polygon().begin());
396  double xp = (double)NumberTraits<TInteger>::castToInt64_t(p[0]);
397  double yp = (double)NumberTraits<TInteger>::castToInt64_t(p[1]);
398  polyline.push_back(LibBoard::Point(xp,yp));
399  }
400  aBoard.drawPolyline(polyline);
401 }
402 
403 template <typename TIterator, typename TInteger, int connectivity>
404 inline
407 {
408  std::string mode = board.getMode( fp.className() );
409  if ( mode == "Polygon" )
410  drawAsPolygon( board, fp );
411  else if ( ( mode == "Both" ) || ( mode == "" ) )
412  {
413  drawAsPolygon( board, fp );
414  }
415  else
416  {
417  mode = "draw( DGtal::Board2D & board, const DGtal::FP<TIterator,TInteger,connectivity> & fp ): Unknown mode "+mode;
418  ASSERT2(false, mode );
419  }
420 }
421 // FP
422 
423 
424 // FreemanChain
425 template <typename TInteger>
426 inline
429 {
430  typedef TInteger Integer;
432 
433  vector<Point> aVContour;
435  TInteger minX, minY, maxX, maxY;
436  f.computeBoundingBox(minX, minY, maxX, maxY);
437 
438  vector<LibBoard::Point> contour;
439  for(unsigned int i=0; i< aVContour.size(); i++){
440  contour.push_back(LibBoard::Point(NumberTraits<TInteger>::castToDouble(aVContour[i][0]),
441  NumberTraits<TInteger>::castToDouble(aVContour[i][1])));
442  }
443  aBoard.drawPolyline(contour);
444 }
445 
446 template <typename TInteger>
447 inline
450 {
451  typedef TInteger Integer;
453 
454  vector<Point> aVContour;
456  TInteger minX, minY, maxX, maxY;
457  f.computeBoundingBox(minX, minY, maxX, maxY);
458 
459  vector<LibBoard::Point> contour;
460  for(unsigned int i=0; i< aVContour.size(); i++){
461  contour.push_back(LibBoard::Point(NumberTraits<TInteger>::castToInt64_t(aVContour[i][0])-0.5,
462  NumberTraits<TInteger>::castToInt64_t(aVContour[i][1])+0.5));
463  }
464  aBoard.drawPolyline(contour);
465 }
466 
467 template <typename TInteger>
468 inline
471 {
472  std::string mode = aBoard.getMode( f.className() );
473  ASSERT( (mode=="Grid" || mode=="" || mode=="InterGrid") ||
474  ("draw( DGtal::Board2D & board, const DGtal::FreemanChain<TInteger> & f ): Unknown mode "+mode)=="" );
475 
476  if ( mode == "Grid" || ( mode == "" ) )
477  drawAsGrid( aBoard, f );
478  else if ( mode == "InterGrid" )
479  drawAsInterGrid( aBoard, f );
480 }
481 // FreemanChain
482 
483 
484 // GeometricalDSS
485 template <typename TConstIterator>
486 inline
489 {
490  typedef TConstIterator ConstIterator;
491  typedef typename IteratorCirculatorTraits<ConstIterator>::Value Pair;
492  typedef typename Pair::first_type Point;
493 
494  double alpha, beta, gamma;
495  g.getParameters(alpha, beta, gamma);
496 
497  typedef typename Point::Coordinate Coordinate;
498 
499  // now with accessor
500  Pair firstPair( *g.begin() );
501  double fx1 = NumberTraits<Coordinate>::castToDouble(firstPair.first[0]);
502  double fx2 = NumberTraits<Coordinate>::castToDouble(firstPair.second[0]);
503  double fy1 = NumberTraits<Coordinate>::castToDouble(firstPair.first[1]);
504  double fy2 = NumberTraits<Coordinate>::castToDouble(firstPair.second[1]);
505  double fx = (fx1+fx2)/2.0;
506  double fy = (fy1+fy2)/2.0;
507  g.projects(fx, fy, alpha, beta, gamma);
508 
509  // now with accessor
510  ConstIterator it (g.end());
511  --it;
512  Pair lastPair( *it );
513  double lx1 = NumberTraits<Coordinate>::castToDouble(lastPair.first[0]);
514  double lx2 = NumberTraits<Coordinate>::castToDouble(lastPair.second[0]);
515  double ly1 = NumberTraits<Coordinate>::castToDouble(lastPair.first[1]);
516  double ly2 = NumberTraits<Coordinate>::castToDouble(lastPair.second[1]);
517  double lx = (lx1+lx2)/2.0;
518  double ly = (ly1+ly2)/2.0;
519  g.projects(lx, ly, alpha, beta, gamma);
520 
521  aBoard.drawLine(fx,fy,lx,ly);
522 }
523 // GeometricalDSS
524 
525 // GeometricalDCA
526 template <typename TConstIterator>
527 inline
530 {
531 
532  typedef TConstIterator ConstIterator;
533  typedef typename IteratorCirculatorTraits<ConstIterator>::Value Pair;
534  typedef typename Pair::first_type Point;
535 
536  if (g.isValid())
537  {
538  if (!g.isStraight())
539  {
540  typedef typename Point::Coordinate Coordinate;
541 
542  //points
543  Pair firstPair( *g.begin() );
544  double fx1 = NumberTraits<Coordinate>::castToDouble(firstPair.first[0]);
545  double fx2 = NumberTraits<Coordinate>::castToDouble(firstPair.second[0]);
546  double fy1 = NumberTraits<Coordinate>::castToDouble(firstPair.first[1]);
547  double fy2 = NumberTraits<Coordinate>::castToDouble(firstPair.second[1]);
548  PointVector<2,double> p1( (fx1+fx2)/2.0, (fy1+fy2)/2.0 );
549 
550  ConstIterator it (g.end());
551  --it;
552  Pair lastPair( *it );
553  double lx1 = NumberTraits<Coordinate>::castToDouble(lastPair.first[0]);
554  double lx2 = NumberTraits<Coordinate>::castToDouble(lastPair.second[0]);
555  double ly1 = NumberTraits<Coordinate>::castToDouble(lastPair.first[1]);
556  double ly2 = NumberTraits<Coordinate>::castToDouble(lastPair.second[1]);
557  PointVector<2,double> p2( (lx1+lx2)/2.0, (ly1+ly2)/2.0 );
558 
559  //circle
560  CircleFrom3Points<Point> separatingCircle = g.getSeparatingCircle();
561  double px = NumberTraits<Coordinate>::castToDouble(separatingCircle.p()[0]);
562  double py = NumberTraits<Coordinate>::castToDouble(separatingCircle.p()[1]);
563  double qx = NumberTraits<Coordinate>::castToDouble(separatingCircle.q()[0]);
564  double qy = NumberTraits<Coordinate>::castToDouble(separatingCircle.q()[1]);
565  double rx = NumberTraits<Coordinate>::castToDouble(separatingCircle.r()[0]);
566  double ry = NumberTraits<Coordinate>::castToDouble(separatingCircle.r()[1]);
568  circleToDraw.init( PointVector<2,double>(px,py),
569  PointVector<2,double>(qx,qy),
570  PointVector<2,double>(rx,ry) );
571 
572  //orientation
573  ASSERT( g.getGeometricalDSSPtr().get() != 0 );
574  bool orientation = g.getGeometricalDSSPtr()->isClockwiseOriented();
575 
576  //mode
577  std::string mode = aBoard.getMode( g.className() );
578  if ( mode == "Sector" )
579  drawSector( aBoard, circleToDraw, p1, p2, orientation );
580  else if ( mode == "Annulus" )
581  drawAnnulus( aBoard, circleToDraw, p1, p2, orientation );
582  else
583  drawArc( aBoard, circleToDraw, p1, p2, orientation );
584  }
585  else
586  {
587  ASSERT( g.getGeometricalDSSPtr().get() != 0 );
588  aBoard << ( *(g.getGeometricalDSSPtr()) );
589  }
590  }
591 
592 }
593 // GeometricalDCA
594 
595 
596 
597 // FrechetShortcut
598 template <typename TIterator,typename TInteger>
599 inline
601 {
602  typedef TIterator Iterator;
604  typedef typename Point::Coordinate Coordinate;
605 
606  // get first point of the shortcut
607  Point p1 = *(f.begin());
608  double px1 = NumberTraits<Coordinate>::castToDouble(p1[0]);
609  double py1 = NumberTraits<Coordinate>::castToDouble(p1[1]);
610 
611  // get last point of the shortcut
612  Iterator it (f.end());
613  --it;
614  Point p2(*it);
615  double px2 = NumberTraits<Coordinate>::castToDouble(p2[0]);
616  double py2 = NumberTraits<Coordinate>::castToDouble(p2[1]);
617 
618  aBoard.drawLine(px1,py1,px2,py2);
619 }
620 // FrechetShortcut
621 
622 
623 
624 // GridCurve
625 template <typename TKSpace>
627  const GridCurve<TKSpace> & object )
628 {
629  typedef typename GridCurve<TKSpace>::ConstIterator ConstIterator;
630  ConstIterator it ( object.begin() );
631  ConstIterator itEnd ( object.end() );
632  for( ; it != itEnd; ++it)
633  {
634  aBoard << *it;
635  }
636 }
637 // GridCurve
638 
639 // SCellsRange
640 template <typename TIterator, typename TSCell>
643 {
645  typedef typename Range::ConstIterator ConstIterator;
646 
647  ConstIterator it ( object.begin() );
648  ConstIterator itEnd ( object.end() );
649  for( ; it != itEnd; ++it)
650  {
651  aBoard << *it;
652  }
653 }
654 // SCellsRange
655 
656 // PointsRange
657 template <typename TIterator, typename TKSpace>
659  const ConstRangeAdapter<TIterator, SCellToPoint<TKSpace>, typename TKSpace::Point> & object )
660 {
661  typedef ConstRangeAdapter<TIterator, SCellToPoint<TKSpace>, typename TKSpace::Point> Range;
662  typedef typename Range::ConstIterator ConstIterator;
663 
664  ConstIterator it ( object.begin() );
665  ConstIterator itEnd ( object.end() );
666  for( ; it != itEnd; ++it)
667  {
668  aBoard << SetMode(it->className(),"Grid");
669  aBoard << *it;
670  }
671 }
672 // PointsRange
673 
674 // MidPointsRange
675 template <typename TIterator, typename TKSpace>
678  typename TKSpace::Space::RealPoint> & object )
679 {
680  typedef typename TKSpace::Space::RealPoint RPoint;
682  typedef typename Range::ConstIterator ConstIterator;
683 
684  ConstIterator it ( object.begin() );
685  ConstIterator itEnd ( object.end() );
686  for( ; it != itEnd; ++it)
687  {
688  RPoint p(*it);
689  double s = 0.1;
690  aBoard.drawLine( p[0]-s, p[1]-s, p[0]+s, p[1]+s );
691  aBoard.drawLine( p[0]-s, p[1]+s, p[0]+s, p[1]-s );
692  }
693 }
694 // MidPointsRange
695 
696 // ArrowsRange
697 template <typename TIterator, typename TKSpace>
699  const ConstRangeAdapter<TIterator, SCellToArrow<TKSpace>,
700  std::pair<typename TKSpace::Point, typename TKSpace::Vector> > & object )
701 {
702  typedef typename TKSpace::Point Point;
703  typedef typename TKSpace::Vector Vector;
704  typedef std::pair<Point, Vector> Arrow;
706  typedef typename Range::ConstIterator ConstIterator;
707 
708  ConstIterator it ( object.begin() );
709  ConstIterator itEnd ( object.end() );
710  for( ; it != itEnd; ++it)
711  {
712  Arrow a(*it);
713  Vector shift( a.second );
714  aBoard << CustomStyle( shift.className(),
715  new CustomPen( Color::Black, Color::Black, 1.0,
719  draw(aBoard, shift, a.first);
720  }
721 }
722 // ArrowsRange
723 
724 // InnerPointsRange
725 template <typename TIterator, typename TKSpace>
728  typename TKSpace::Point > & object )
729 {
730  typedef typename TKSpace::Point Point;
732  typedef typename Range::ConstIterator ConstIterator;
733 
734  ConstIterator it ( object.begin() );
735  ConstIterator itEnd ( object.end() );
736  for( ; it != itEnd; ++it)
737  {
738  aBoard << SetMode( it->className(), "Both" )
739  << CustomStyle( it->className(),
741  << *it;
742  }
743 }
744 // InnerPointsRange
745 
746 // OuterPointsRange
747 template <typename TIterator, typename TKSpace>
750  typename TKSpace::Point > & object )
751 {
752  typedef typename TKSpace::Point Point;
754  typedef typename Range::ConstIterator ConstIterator;
755 
756  ConstIterator it ( object.begin() );
757  ConstIterator itEnd ( object.end() );
758  for( ; it != itEnd; ++it)
759  {
760  aBoard << SetMode( it->className(), "Both" )
761  << CustomStyle( it->className(),
763  << *it;
764  }
765 }
766 // OuterPointsRange
767 
768 // IncidentPointsRange
769 template <typename TIterator, typename TKSpace>
772  std::pair<typename TKSpace::Point, typename TKSpace::Point> > & object )
773 {
774  typedef typename TKSpace::Point Point;
775  typedef std::pair<Point, Point> Pair;
777  typedef typename Range::ConstIterator ConstIterator;
778 
779  ConstIterator it ( object.begin() );
780  ConstIterator itEnd ( object.end() );
781  for( ; it != itEnd; ++it)
782  {
783  Pair pair(*it);
784  aBoard << SetMode( pair.first.className(), "Both" )
785  << CustomStyle( pair.first.className(),
787  << pair.first
788  << CustomStyle( pair.second.className(),
790  << pair.second;
791  }
792 }
793 // IncidentPointsRange
794 
795 // HyperRectDomain
796 template<typename TSpace>
797 inline
800 {
801  typedef typename TSpace::Integer Integer;
802 
803  ASSERT(TSpace::dimension == 2 || "drawAsGrid-NOT-YET-IMPLEMENTED-in-ND");
804 
805  if (TSpace::dimension == 2)
806  {
807  for (double x = NumberTraits<Integer>::castToDouble(h.myLowerBound[0]);
809  aboard.drawLine(x,
811  0.5,
812  x,
814  0.5);
815 
819  0.5,
820  y,
822  0.5,
823  y);
824 
825  for (double x = NumberTraits<Integer>::castToDouble(h.myLowerBound[0]);
829  aboard.fillCircle(x, y, 0.1);
830  }
831 }
832 
833 template<typename TSpace>
834 inline
837 {
838  typedef typename TSpace::Integer Integer;
839 
840  ASSERT(TSpace::dimension==2 || "drawAsPaving-NOT-YET-IMPLEMENTED-in-ND" );
841 
842  if (TSpace::dimension == 2)
843  {
848  aboard.drawRectangle(x - 0.5, y + 0.5, 1, 1);
849  }
850 }
851 
852 template<typename TSpace>
853 inline
856 {
857  std::string mode = board.getMode( h.className() );
858  ASSERT((mode=="" || mode=="Grid" || mode=="Paving") ||
859  ("draw( DGtal::Board2D & board, const DGtal::HyperRectDomain<TSpace> & h ): Unknown mode "+mode)=="");
860 
861  if ( ( mode == "" ) || ( mode == "Grid" ) )
862  drawAsGrid( board, h );
863  else if ( mode == "Paving" )
864  drawAsPaving( board, h );
865 }
866 // HyperRectDomain
867 
868 
869 // ImageContainerByHashTree
870 template <typename C, typename Domain, typename Value, typename HashKey>
871 inline
874  HashKey key,
875  const double p[2],
876  const double len,
877  LibBoard::Board & board,
878  const C& cmap )
879 {
880 
881  ASSERT ( Domain::dimension == 2 );
882 
883  double np[2], nlen;
884 
885  //Node* n = i.getNode ( key );
886  if ( i.getNode ( key ) )
887  {
888  Color c;
889  c = cmap ( i.getNode ( key )->getObject() );
890  board.setFillColorRGBi ( c.red(), c.green(), c.blue() );
891 
892  board.drawRectangle ( p[0], p[1], len, len );
893  }
894  else
895  {
896  HashKey children[4];
897  i.myMorton.childrenKeys ( key, children );
898 
899  nlen = len / 2.0;
900 
901  np[0] = p[0];
902  np[1] = p[1] - nlen;
903  drawImageRecursive<C>( aBoard, i, children[0], np, nlen, board, cmap );
904 
905  np[0] = p[0] + nlen;
906  np[1] = p[1] - nlen;
907  drawImageRecursive<C>( aBoard, i, children[1], np, nlen, board, cmap );
908 
909  np[0] = p[0];
910  np[1] = p[1];
911  drawImageRecursive<C>( aBoard, i, children[2], np, nlen, board, cmap );
912 
913  np[0] = p[0] + nlen;
914  np[1] = p[1];
915  drawImageRecursive<C>( aBoard, i, children[3], np, nlen, board, cmap );
916  }
917 }
918 
919 template <typename C, typename Domain, typename Value, typename HashKey>
920 inline
923  const Value &minV, const Value &maxV )
924 {
925  static const HashKey ROOT_KEY = static_cast<HashKey>(1);
926 
927  ASSERT ( Domain::dimension == 2 );
928 
929  C colormap ( minV, maxV );
930 
931  double p[2];
932  double len;
933 
934  p[0] = i.myOrigin[0];
935  p[1] = i.myOrigin[1] + i.getSpanSize();
936 
937  len = i.getSpanSize();
938 
939  drawImageRecursive<C>( board, i, ROOT_KEY, p, len, board, colormap );
940 }
941 // ImageContainerByHashTree
942 
943 
944 // ImageContainerBySTLVector, ImageContainerByHashTree, Image and ImageAdapter...
945 template <typename Colormap, typename Image>
946 inline
948  const Image & i,
949  const typename Image::Value & minV,
950  const typename Image::Value & maxV )
951 {
952  typedef typename Image::Domain D;
953  typedef typename Image::Value V;
954 
955  ASSERT(D::Space::dimension == 2);
956 
957  Colormap colormap(minV, maxV);
958  Color c;
959  V val;
960  D ldomain(i.domain());
961 
962  for (typename D::ConstIterator it = ldomain.begin();
963  it != ldomain.end(); ++it)
964  {
965  val = i.operator()( (*it) );
966  c = colormap( val );
967  board.setFillColorRGBi( c.red(), c.green(), c.blue());
969  castToInt64_t((*it)[0]) - 0.5,
971  castToInt64_t((*it)[1]) + 0.5, 1, 1);
972  }
973 }
974 // ImageContainerBySTLVector, ImageContainerByHashTree, Image and ImageAdapter...
975 
976 
977 // KhalimskyCell
978 template < Dimension dim, typename TInteger >
979 inline
982 {
983  ASSERT( dim == 2 );
984  float x = (float)
986  float y = (float)
988  float retract = 0.05f;
989  bool xodd = ( k.myCoordinates[ 0 ] & 1 );
990  bool yodd = ( k.myCoordinates[ 1 ] & 1 );
991  float dx = xodd ? 1.0f - 2.0f*retract : 2.0f*retract;
992  float dy = yodd ? 1.0f - 2.0f*retract : 2.0f*retract;
993  board.drawRectangle( !xodd ? x - retract - 0.5 : x + retract - 0.5,
994  !yodd ? y + retract - 0.5 : y - retract + 0.5,
995  dx, dy );
996 }
997 // KhalimskyCell
998 
999 
1000 // Object
1001 template <typename TDigitalTopology, typename TDigitalSet>
1002 inline
1005 {
1006  typedef TDigitalSet DigitalSet;
1007  typedef typename DigitalSet::Point Point;
1008 
1009  typedef TDigitalTopology DigitalTopology;
1010  typedef typename DigitalSet::Domain Domain;
1011  typedef
1012  typename DigitalSetSelector < Domain,
1013  SMALL_DS + HIGH_ITER_DS >::Type SmallSet;
1014  typedef Object<DigitalTopology, SmallSet> SmallObject;
1015 
1016  Point p;
1017 
1018  for (typename TDigitalSet::ConstIterator it = o.pointSet().begin();
1019  it != o.pointSet().end();
1020  ++it)
1021  {
1022  //Brute-force scan of the neighborhood.
1023  SmallObject neig = o.properNeighborhood(*it);
1024  for (typename SmallObject::DigitalSet::ConstIterator it2 = neig.pointSet().begin();
1025  it2 != neig.pointSet().end();
1026  ++it2)
1027  {
1028  p = (*it2) - (*it);
1029  draw(aBoard, p, (*it));
1030  }
1031  }
1032 }
1033 
1034 template <typename TDigitalTopology, typename TDigitalSet>
1035 inline
1038 {
1039  std::string mode = board.getMode( o.className() );
1040  if ( mode == "" )
1041  draw( board, o.pointSet() );
1042  else
1043  if ( mode == "DrawAdjacencies" )
1044  {
1045  draw( board, o.pointSet() );
1046  drawWithAdjacencies( board, o );
1047  }
1048  else
1049  ASSERT(false && (("draw( DGtal::Board2D & board, const DGtal::Object<TDigitalTopology, TDigitalSet> & o ): Unknown mode " + mode) == ""));
1050 }
1051 // Object
1052 
1053 
1054 // PointVector
1055 template<Dimension dim, typename TComponent>
1056 inline
1059 {
1060  ASSERT(dim == 2);
1061  board.drawRectangle( (float) NumberTraits<TComponent>::castToDouble(p.myArray[0]) - 0.5f,
1062  (float) NumberTraits<TComponent>::castToDouble(p.myArray[1]) + 0.5f, 1, 1 );
1063 }
1064 
1065 template<Dimension dim, typename TComponent>
1066 inline
1069 {
1070  ASSERT(dim == 2);
1073 }
1074 
1075 template<Dimension dim, typename TComponent>
1076 inline
1079 {
1080  std::string mode = board.getMode( p.className() );
1081  ASSERT( (mode=="Paving" || mode=="Grid" || mode=="Both" || mode=="") ||
1082  ("draw( DGtal::Board2D & board, const DGtal::PointVector<dim,TComponent> & p ): Unknown mode "+mode)=="" );
1083 
1084  if ( mode == "Paving" || ( mode == "" ) )
1085  drawAsPaving( board, p );
1086  else if ( mode == "Grid" )
1087  drawAsGrid( board, p );
1088  else if ( ( mode == "Both" ))
1089  {
1090  drawAsPaving( board, p );
1091  drawAsGrid( board, p );
1092  }
1093 }
1094 
1095 template<Dimension dim, typename TComponent>
1096 inline
1099  const DGtal::PointVector<dim,TComponent> & apoint )
1100 {
1101  ASSERT(dim == 2);
1102 
1103  board.drawArrow((float)apoint[0], (float) apoint[1],
1104  (float) apoint[0] + p.myArray[0], (float)apoint[1] + p.myArray[1],
1105  true);
1106 }
1107 // PointVector
1108 
1109 
1110 // Preimage2D
1111 template <typename Shape>
1112 inline
1114  const DGtal::Preimage2D<Shape> & p )
1115 {
1116  typedef typename Shape::Point Point;
1117  typedef typename std::list<Point>::const_iterator ConstForwardIterator;
1118 
1119  // now with accessor
1120  Shape s( p.shape() );
1121  ConstForwardIterator i = p.pHull().begin();
1122  Point pt(*i);
1123  ++i;
1124  while ( i != p.pHull().end() ) {
1125  s.init(pt, *i);
1126  draw(aBoard, s); //s.setStyle(aBoard);
1127  pt = Point(*i);
1128  ++i;
1129  }
1130 
1131  i = p.qHull().begin();
1132  pt = Point(*i);
1133  ++i;
1134  while ( i != p.qHull().end() ) {
1135  s.init(pt, *i);
1136  draw(aBoard, s); //s.setStyle(aBoard);
1137  pt = Point(*i);
1138  ++i;
1139  }
1140 
1141  Point Pf(*p.pHull().begin());
1142  Point Pl(*p.pHull().rbegin());
1143  Point Qf(*p.qHull().begin());
1144  Point Ql(*p.qHull().rbegin());
1145 
1146  s.init(Pf, Ql);
1147  draw(aBoard, s); //s.setStyle(aBoard);
1148  s.init(Qf, Pl);
1149  draw(aBoard, s); //s.setStyle(aBoard);
1150 }
1151 // Preimage2D
1152 
1153 
1154 // SignedKhalimskyCell
1155 template < Dimension dim, typename TInteger >
1156 inline
1159 {
1160  ASSERT( dim == 2 );
1161  float x = (float)
1163  float y = (float)
1165  float retract = 0.05f;
1166  bool xodd = ( sk.myCoordinates[ 0 ] & 1 );
1167  bool yodd = ( sk.myCoordinates[ 1 ] & 1 );
1168  float dx = xodd ? 1.0f - 2.0f*retract : 2.0f*retract;
1169  float dy = yodd ? 1.0f - 2.0f*retract : 2.0f*retract;
1170  board.drawRectangle( !xodd ? x - retract - 0.5 : x + retract - 0.5,
1171  !yodd ? y + retract - 0.5 : y - retract + 0.5,
1172  dx, dy );
1173 }
1174 // SignedKhalimskyCell
1175 
1176 
1177 // StraightLineFrom2Points
1178 template <typename TPoint>
1179 inline
1181 {
1182  // now with accessor
1183  aBoard.drawLine(slf2p.p()[0],slf2p.p()[1],slf2p.q()[0],slf2p.q()[1]);
1184 }
1185 // StraightLineFrom2Points
1186 
1187 
1188 //
1189 
1190 
1191 inline
1193  const DGtal::CustomStyle & cs )
1194 {
1195  board.myStyles[ cs.myClassname ] = cs.myStyle;
1196 }
1197 
1198 inline
1200  const DGtal::SetMode & sm )
1201 {
1202  board.myModes[ sm.myClassname ] = sm.myMode;
1203 }
1204 
1205 template <typename TSpace, typename TSequence>
1206 inline
1207 void
1209 ( DGtal::Board2D & aBoard,
1211 {
1212  typedef typename LibBoard::Point BoardPoint;
1213  typedef typename DGtal::LatticePolytope2D<TSpace>::Point CIPPoint;
1214  typedef typename DGtal::LatticePolytope2D<TSpace>::ConstIterator ConstIterator;
1215  typedef typename DGtal::LatticePolytope2D<TSpace>::Integer Integer;
1216  std::string mode = aBoard.getMode( cip.className() );
1217  ASSERT( mode=="Filled" || mode=="" || mode=="Transparent" ||
1218  ("draw(Board2D & aBoard, const DGtal::LatticePolytope2D<Space,Sequence> & cip): Unknown mode "+mode)=="" );
1219 
1220  std::vector<BoardPoint> pts;
1221 
1222  for ( ConstIterator it = cip.begin(), it_end = cip.end(); it != it_end; ++it )
1223  {
1224  CIPPoint p = *it;
1225  pts.push_back( BoardPoint( NumberTraits<Integer>::castToDouble( p[ 0 ] ),
1227  }
1228  aBoard.drawClosedPolyline( pts );
1229  // if ( mode == "Transparent" || ( mode == "" ) )
1230  // {
1231  // aBoard.drawClosedPolyline( pts );
1232  // }
1233  // else
1234  // {
1235  // aBoard.fillPolyline( pts );
1236  // }
1237 }
1238 
1239 
1240 // //
1242 
1243