DGtal  0.9.4beta
Board2D.h
1 
17 #pragma once
18 
31 #if defined(Board2D_RECURSES)
32 #error Recursive header files inclusion detected in Board2D.h
33 #else // defined(Board2D_RECURSES)
34 
35 #define Board2D_RECURSES
36 
37 #if !defined Board2D_h
38 
39 #define Board2D_h
40 
42 // Inclusions
43 #include <iostream>
44 #include "Board/Board.h"
45 #include "DGtal/base/Common.h"
46 #include "DGtal/base/CountedPtr.h"
47 #include "DGtal/io/Color.h"
49 
50 
51 
52 namespace DGtal
53 {
57  enum DomainDrawMode { GRID = 0, PAVING = 1 };
58 
59 
61  // class Board2D
70  class Board2D : public LibBoard::Board
71  {
72  // ----------------------- local types ------------------------------
73  public:
78  typedef std::map< std::string,CountedPtr<DrawableWithBoard2D> > StyleMapping;
79 
84  typedef std::map< std::string, std::string > ModeMapping;
85 
87 
88  // ----------------------- Standard services ------------------------------
89  public:
90 
94  ~Board2D();
95 
101  Board2D( const Color & aBackgroundColor = Color::None );
102 
108  Board2D( const Board2D & other );
109 
115  Board2D & operator= ( const Board2D & other );
116 
124  std::string getMode( const std::string & objectName ) const;
125 
134  template <typename TDrawableWithBoard2D>
135  Board2D & operator<<( const TDrawableWithBoard2D & object );
136 
137 
138  // ----------------------- Interface --------------------------------------
139  public:
140 
145  void selfDisplay ( std::ostream & out ) const;
146 
151  bool isValid() const;
152 
153  // ------------------------- Public Datas ------------------------------
154  public:
165  StyleMapping myStyles;
166 
175  ModeMapping myModes;
176  // ------------------------- Private Datas --------------------------------
177  private:
178 
179  }; // end of class Board2D
180 
181 
188  std::ostream&
189  operator<< ( std::ostream & out, const Board2D & object );
190 
197  std::string className() const
198  {
199  return "DrawWithBoardModifier";
200  }
201 
202  /*DrawableWithBoard2D* defaultStyle( std::string = "" ) const
203  {
204  return 0;
205  }*/
206 
207  /*virtual void setStyle( Board2D & ) const
208  {}*/
209  };
210 
211 
224  CustomStyle( std::string classname, DrawableWithBoard2D* style )
225  : myClassname( classname ), myStyle( style )
226  {}
227 
228  std::string className() const
229  {
230  return "CustomStyle";
231  }
232 
233  /*void setStyle( Board2D & board ) const
234  {
235  board.myStyles[ myClassname ] = myStyle;
236  }*/
237 
238  std::string myClassname;
240  };
241 
247  struct SetMode : public DrawWithBoardModifier {
254  SetMode( std::string classname, std::string mode )
255  : myClassname( classname ), myMode( mode )
256  {}
257 
258  /*void setStyle( Board2D & board ) const
259  {
260  board.myModes[ myClassname ] = myMode;
261  }*/
262 
263  std::string myClassname;
264  std::string myMode;
265  };
266 
279  {
282 
289  CustomColors( const Color & penColor,
290  const Color & fillColor )
291  : myPenColor( penColor ), myFillColor( fillColor )
292  {}
293 
294  virtual void setStyle( Board2D & aboard) const
295  {
296  aboard.setFillColor( myFillColor);
297  aboard.setPenColor( myPenColor );
298  }
299  };
300 
313  {
315 
321  CustomPenColor( const Color & penColor )
322  : myPenColor( penColor )
323  {}
324 
325  virtual void setStyle( Board2D & aboard) const
326  {
327  aboard.setPenColor( myPenColor );
328  }
329  };
330 
343  {
345 
351  CustomFillColor( const Color & fillColor )
352  : myFillColor( fillColor )
353  {}
354 
355  virtual void setStyle( Board2D & aboard) const
356  {
357  aboard.setFillColor( myFillColor );
358  }
359  };
360 
374  {
377  double myLineWidth;
381  int myDepth;
400  CustomPen( const Color & penColor,
401  const Color & fillColor,
402  double lineWidth = 1.0,
406  : myPenColor( penColor ), myFillColor( fillColor ),
407  myLineWidth( lineWidth ),
408  myLineStyle( lineStyle ), myLineCap ( lineCap ), myLineJoin( lineJoin )
409  {}
410 
411  virtual void setStyle( Board2D & aboard) const
412  {
413  aboard.setPenColor( myPenColor );
414  aboard.setFillColor( myFillColor );
415  aboard.setLineWidth( myLineWidth );
416  aboard.setLineStyle( myLineStyle );
417  aboard.setLineCap( myLineCap );
418  aboard.setLineJoin( myLineJoin );
419  }
420  };
421 
422 } // namespace DGtal
423 
424 
426 // Includes inline functions.
427 
428 #include "DGtal/io/Display2DFactory.h"
429 #include "DGtal/io/Style2DFactory.h"
430 #include "DGtal/io/boards/Board2D.ih"
431 
432 // //
434 
435 #endif // !defined Board2D_h
436 
437 #undef Board2D_RECURSES
438 #endif // else defined(Board2D_RECURSES)
Abstract structure for a 2D shape.
Definition: Board/Shapes.h:58
std::map< std::string, std::string > ModeMapping
Definition: Board2D.h:84
Board & setLineWidth(double width)
Definition: Board.cpp:329
void selfDisplay(std::ostream &out) const
Definition: Board2D.cpp:97
Custom style class redefining the pen attributes. You may use Board2D::Color::None for transparent co...
Definition: Board2D.h:373
CustomPenColor(const Color &penColor)
Definition: Board2D.h:321
std::string className() const
Definition: Board2D.h:228
bool isValid() const
Definition: Board2D.cpp:107
Class for EPS, FIG or SVG drawings.
Definition: Board.h:35
Custom style class redefining the fill color. You may use Board2D::Color::None for transparent color...
Definition: Board2D.h:342
LibBoard::Shape Shape
Definition: Board2D.h:86
Board & setLineJoin(Shape::LineJoin join)
Board2D(const Color &aBackgroundColor=Color::None)
Definition: Board2D.cpp:54
double myLineWidth
Definition: Board2D.h:377
DomainDrawMode
Definition: Board2D.h:57
CustomFillColor(const Color &fillColor)
Definition: Board2D.h:351
virtual void setStyle(Board2D &aboard) const
Definition: Board2D.h:411
std::string myClassname
Definition: Board2D.h:263
virtual void setStyle(Board2D &aboard) const
Definition: Board2D.h:325
Custom style class redefining the pen color and the fill color. You may use Board2D::Color::None for ...
Definition: Board2D.h:278
CountedPtr< DrawableWithBoard2D > myStyle
Definition: Board2D.h:239
std::string myMode
Definition: Board2D.h:264
CustomPen(const Color &penColor, const Color &fillColor, double lineWidth=1.0, Board2D::Shape::LineStyle lineStyle=Board2D::Shape::SolidStyle, Board2D::Shape::LineCap lineCap=Board2D::Shape::ButtCap, Board2D::Shape::LineJoin lineJoin=Board2D::Shape::MiterJoin)
Definition: Board2D.h:400
std::string myClassname
Definition: Board2D.h:238
static const Color None
Definition: Color.h:387
CustomStyle(std::string classname, DrawableWithBoard2D *style)
Definition: Board2D.h:224
std::ostream & operator<<(std::ostream &out, const ClosedIntegerHalfPlane< TSpace > &object)
std::string getMode(const std::string &objectName) const
Board & setLineStyle(Shape::LineStyle style)
virtual void setStyle(Board2D &aboard) const
Definition: Board2D.h:294
StyleMapping myStyles
Definition: Board2D.h:165
DGtal is the top-level namespace which contains all DGtal functions and types.
Board2D & operator<<(const TDrawableWithBoard2D &object)
Board & setFillColor(const DGtal::Color &color)
Definition: Board.cpp:322
Board2D::Shape::LineCap myLineCap
Definition: Board2D.h:379
std::string className() const
Definition: Board2D.h:197
Board2D::Shape::LineStyle myLineStyle
Definition: Board2D.h:378
CustomColors(const Color &penColor, const Color &fillColor)
Definition: Board2D.h:289
std::map< std::string, CountedPtr< DrawableWithBoard2D > > StyleMapping
Definition: Board2D.h:78
virtual void setStyle(Board2D &aboard) const
Definition: Board2D.h:355
Modifier class in a Board2D stream. Useful to choose your own mode for a given class. Realizes the concept CDrawableWithBoard2D.
Definition: Board2D.h:247
Color myFillColor
Definition: Board2D.h:376
Color myPenColor
Definition: Board2D.h:375
Board2D::Shape::LineJoin myLineJoin
Definition: Board2D.h:380
Structure representing an RGB triple with alpha component.
Definition: Color.h:66
Board & setPenColor(const DGtal::Color &color)
Definition: Board.cpp:298
Board & setLineCap(Shape::LineCap cap)
SetMode(std::string classname, std::string mode)
Definition: Board2D.h:254
Custom style class redefining the pen color. You may use Board2D::Color::None for transparent color...
Definition: Board2D.h:312
ModeMapping myModes
Definition: Board2D.h:175
Board2D & operator=(const Board2D &other)
Definition: Board2D.cpp:78
Aim: This class specializes a 'Board' class so as to display DGtal objects more naturally (with <<)...
Definition: Board2D.h:70