Whiteboard
An interface and tools for visualizing large and complex datasets
Whiteboard.h
Go to the documentation of this file.
1 #ifndef WHITEBOARD_H
2 #define WHITEBOARD_H
3 
4 #include "visual/Color.h"
5 #include "visual/Eps.h"
6 
7 #include "base/SVector.h"
8 #include <string>
9 
26 namespace ns_whiteboard {
27 
30  typedef pair<double,double> xy_coords;
31 
36 
41 
47 {
48  public:
52  virtual void DrawPoint( const xy_coords &coord ) = 0;
56  virtual void DrawPoint( double x,
57  double y ) = 0;
58 
62  virtual void DrawLine( const xy_coords &startCoord,
63  const xy_coords &stopCoord ) = 0;
64 
68  virtual void DrawRect( const xy_coords &topLeftCoord,
69  const xy_coords &bottomRightCoord ) = 0;
73  virtual void DrawText( const xy_coords& coords,
74  const string& chars,
75  double rot_angle,
76  double point_size,
77  const vert_align vAlign,
79  const horiz_align hAlign ) = 0;
84  virtual void DrawArc( const xy_coords &coords,
85  const double radius,
86  const double startAngle,
87  const double stopAngle ) = 0;
88 
92  virtual const color& GetColor() const = 0;
93 
97  virtual void SetColor( const color& C ) = 0;
98 
102  virtual double GetLineWidth() const = 0;
103 
107  virtual void SetLineWidth( const double width ) = 0;
108 
112  virtual const string& GetFontName() const = 0;
113 
117  virtual double GetFontSize() const = 0;
118 
122  virtual void SetFont( const string& font, const double size ) = 0;
123 
127  virtual void Finish() = 0;
128 public:
129  virtual ~display_type(){}
130 };
131 
132 
136 class graphic
137 {
138  public:
139  graphic() {}
140 
144  virtual void Draw( display_type *d ) = 0;
145 public:
146  virtual ~graphic(){}
147 };
148 
149 
155 {
156  public:
158 
162  void Add( graphic *g )
163  {
164  m_graphics.push_back(g);
165  }
166 
171  {
172  for ( int i=0; i<(int) m_graphics.size(); ++i )
173  m_graphics[i]->Draw( d );
174  d->Finish();
175  }
176 
178  void DeletePointers() {
179  for (int i=0; i != m_graphics.isize(); ++i) {
180  delete m_graphics[i];
181  }
182  m_graphics.clear();
183  }
184 
186  int size() const { return m_graphics.size(); }
187 
190  void clear() { m_graphics.clear(); }
191 
192  private:
193 
195 };
196 
197 
204 class point : public graphic
205 {
206  public:
207  point( const xy_coords& coords,
208  const double size = 1.0,
209  const color& c = black )
210  : m_coords(coords),
211  m_size(size),
212  m_color(c) {}
213 
217  void Draw( display_type *d )
218  {
219  d->SetLineWidth(m_size);
220  d->SetColor(m_color);
221  d->DrawPoint(m_coords);
222  }
223 
224  protected:
225  xy_coords m_coords;
226  double m_size;
228 public:
229  virtual ~point(){}
230 };
231 
232 
237 class dpoint : public graphic
238 {
239  public:
240 
241  dpoint( double x,
242  double y,
243  const double size = 1.0,
244  const color& c = black )
245  : x_(x), y_(y),
246  m_size(size),
247  m_color(c) {}
248 
252  void Draw( display_type *d )
253  {
254  d->SetLineWidth(m_size);
255  d->SetColor(m_color);
256  d->DrawPoint(x_,y_);
257  }
258 
259  protected:
260  double x_;
261  double y_;
262  double m_size;
264 public:
265  virtual ~dpoint(){}
266 };
267 
268 
276 class line : public graphic
277 {
278  public:
279  line( const xy_coords& startCoords,
280  const xy_coords& stopCoords,
281  const double width = 1.0,
282  const color& c = black )
283  : m_startCoords(startCoords),
284  m_stopCoords(stopCoords),
285  m_width(width),
286  m_color(c)
287  {}
288 
292  void Draw( display_type *d )
293  {
294  d->SetLineWidth(m_width);
295  d->SetColor(m_color);
297  }
298 
299 
300 xy_coords StartCoords() const { return m_startCoords; }
301 xy_coords StopCoords() const { return m_stopCoords; }
302 double GetWidth() const { return m_width; }
303 
304  protected:
306  double m_width;
308 public:
309  virtual ~line(){}
310 };
311 
312 
319 class rect : public graphic
320 {
321  public:
322  rect( const xy_coords& topLeftCoords,
323  const xy_coords& bottomRightCoords,
324  const color& c = black )
325  : m_topLeftCoords(topLeftCoords),
326  m_bottomRightCoords(bottomRightCoords),
327  m_color(c)
328  {}
329 
333  void Draw( display_type *d )
334  {
335  d->SetColor(m_color);
337  }
338 
339  protected:
342 public:
343  virtual ~rect(){}
344 };
345 
346 
355 class arc : public graphic
356 {
357  public:
358  arc( const xy_coords & coords,
359  const double radius,
360  const double startAngle,
361  const double stopAngle,
362  const double width = 1.0,
363  const color &c = black )
364  : m_coords(coords),
365  m_radius(radius),
366  m_startAngle(startAngle),
367  m_stopAngle(stopAngle),
368  m_width(width),
369  m_color(c)
370  {}
371 
375  void Draw( display_type *d )
376  {
377  d->SetLineWidth(m_width);
378  d->SetColor(m_color);
380  }
381 
382  protected:
383  xy_coords m_coords;
386 public:
387  virtual ~arc(){}
388 };
389 
390 
394 class text : public graphic
395 {
396  public:
397  text( const xy_coords& coords,
398  const string& chars,
399  const color& c = black,
400  const double fontSize = 12.0,
401  const string& fontName = "Times-Roman",
402  const double rotAngle = 0.0,
404  bool alignLeft = false )
405  : m_coords(coords),
406  m_chars(chars),
407  m_color(c),
408  m_fontSize(fontSize),
409  m_fontName(fontName),
410  m_rotAngle(rotAngle),
413  {
414  if (alignLeft)
416  }
417 
421  void SetVertAlign( const vert_align a ) { m_vertAlign = a; }
422 
426  void SetHorizAlign( const horiz_align a ) { m_horizAlign = a; }
427 
428  virtual ~text() {}
429 
433  void Draw( display_type *d )
434  {
436  d->SetColor(m_color);
438  }
439 
440  protected:
441  xy_coords m_coords;
442  string m_chars;
444  double m_fontSize;
445  string m_fontName;
446  double m_rotAngle;
449 };
450 
451 
452 
453 
454 class decorator : public graphic
455 {
456  public:
458 
459  virtual void Draw( display_type *d )
460  {
461  mp_graphic->Draw(d);
462  }
463 
464  protected:
466 
467 public:
468  virtual ~decorator(){}
469 };
470 
471 
476 class ps_display : public display_type
477 {
478  public:
479 
480  // constructor
481  // ostrm (ostream): stream to write EPS code to
482  // horizSize, vertSize (double): length and height of display page.
483  // border (double): size of border around display page (def. 0.0, i.e. no border)
484  ps_display( ostream &ostrm,
485  double horizSize,
486  double vertSize,
487  double border = 0.0 )
488  : m_outstrm(ostrm),
489  m_color(white),
490  m_lineWidth(0.0)
491  {
492  PrintEpsHeader( m_outstrm, horizSize, vertSize, border );
493  }
494 
495  virtual ~ps_display() {}
496 
500  void DrawPoint( const xy_coords& coords )
501  {
502  m_outstrm <<coords.first-m_lineWidth/2<<" "<<coords.second<<" moveto" << "\n";
503  m_outstrm <<m_lineWidth<<" 0 rlineto"<< "\n";
504  m_outstrm <<"stroke" << "\n";
505  }
506 
510  void DrawPoint( double x,
511  double y )
512  {
513  m_outstrm << x - m_lineWidth/2<<" "<< y <<" moveto" << "\n";
514  m_outstrm << m_lineWidth << " 0 rlineto"<< "\n";
515  m_outstrm << "stroke" << "\n";
516  }
517 
520  void DrawLine( const xy_coords& startCoords,
521  const xy_coords& stopCoords )
522  {
523  m_outstrm <<startCoords.first<<" "<<startCoords.second<<" moveto" << "\n";
524  m_outstrm <<stopCoords.first<<" "<<stopCoords.second<<" lineto" << "\n";
525  m_outstrm <<"stroke" << "\n";
526  }
527 
531  void DrawText( const xy_coords& coords,
532  const string& chars,
533  double rot_angle,
535  double point_size, /*<! size of text (pts) */
536  const vert_align vAlign,
537  const horiz_align hAlign )
538  {
539  m_outstrm <<"("<<chars<<") newpath" << "\n";
540  m_outstrm <<coords.first<<" "<<coords.second<<" moveto" << "\n";
541 
542  if( rot_angle != 0 )
543  m_outstrm << "gsave " << rot_angle << " rotate ";
544 
545  switch( hAlign ) {
546  case align_left:
547  // do nothing
548  break;
549  case align_center:
550  m_outstrm <<"("<<chars<<") stringwidth pop 2 div neg 0 rmoveto ";
551  break;
552  case align_right:
553  m_outstrm <<"("<<chars<<") stringwidth pop neg 0 rmoveto ";
554  break;
555  }
556 
557  switch ( vAlign ) {
558  case align_top:
559  // move down 80% of the font size
560  m_outstrm << "0 " << point_size << " 0.8 mul neg rmoveto ";
561  break;
562  case align_middle:
563  // move down 40% of the font size
564  m_outstrm << "0 " << point_size << " 0.4 mul neg rmoveto ";
565  break;
566  case align_bottom:
567  // do nothing
568  break;
569  }
570 
571  m_outstrm << "show ";
572 
573  if( rot_angle != 0 )
574  m_outstrm << " grestore";
575 
576  m_outstrm << "\n";
577  }
578 
582  void DrawArc( const xy_coords &coords,
583  const double radius,
584  const double startAngle,
585  const double stopAngle )
586  {
587  m_outstrm <<"newpath" << "\n";
588  m_outstrm << coords.first <<" "<<coords.second<<" "<<radius<<" "<<startAngle<<" "
589  << stopAngle<<" arc"<< "\n";
590  m_outstrm <<"stroke" << "\n";
591  }
592 
596  void DrawRect( const xy_coords &topLeftCoords,
597  const xy_coords &bottomRightCoords )
598  {
599  m_outstrm <<"newpath" << "\n";
600  m_outstrm << topLeftCoords.first <<" "<< topLeftCoords.second << " moveto" << "\n";
601  m_outstrm << bottomRightCoords.first <<" "<< topLeftCoords.second << " lineto" << "\n";
602  m_outstrm << bottomRightCoords.first <<" "<< bottomRightCoords.second << " lineto" << "\n";
603  m_outstrm << topLeftCoords.first <<" "<< bottomRightCoords.second << " lineto" << "\n";
604  m_outstrm << topLeftCoords.first <<" "<< topLeftCoords.second << " lineto" << "\n";
605  m_outstrm <<"fill" << "\n";
606  }
607 
611  const color& GetColor() const { return m_color; }
615  void SetColor( const color& C )
616  {
617  if ( C != m_color )
618  {
619  m_outstrm <<C.R()<<" "<<C.G()<<" "<<C.B()<<" setrgbcolor" << "\n";
620  m_color = C;
621  }
622  }
623 
627  double GetLineWidth() const { return m_lineWidth; }
628 
632  void SetLineWidth( const double width )
633  {
634  if ( width != m_lineWidth )
635  {
636  m_outstrm << width << " setlinewidth" << "\n";
637  m_lineWidth = width;
638  }
639  }
640 
644  const string& GetFontName() const { return m_fontName; }
648  double GetFontSize() const { return m_fontSize; }
651  void SetFont( const string& font,
652  const double size )
653  {
654  if ( font != m_fontName || size != m_fontSize )
655  {
656  m_outstrm << "/"<<font<<" findfont "<<size<<" scalefont setfont" << "\n";
657  m_fontName = font;
658  m_fontSize = size;
659  }
660  }
661 
664  void Finish() { m_outstrm << flush; }
665 
666  protected:
667  ostream& m_outstrm;
669  double m_lineWidth;
670  string m_fontName;
671  double m_fontSize;
672 };
673 
674 }
675 
676 #endif
virtual void SetColor(const color &C)=0
double GetFontSize() const
Definition: Whiteboard.h:648
void DisplayOn(display_type *d)
Definition: Whiteboard.h:170
Definition: Whiteboard.h:276
double m_lineWidth
Definition: Whiteboard.h:669
virtual ~ps_display()
Definition: Whiteboard.h:495
Definition: Whiteboard.h:35
void Draw(display_type *d)
Definition: Whiteboard.h:433
color m_color
Definition: Whiteboard.h:668
virtual void DrawText(const xy_coords &coords, const string &chars, double rot_angle, double point_size, const vert_align vAlign, const horiz_align hAlign)=0
virtual ~dpoint()
Definition: Whiteboard.h:265
Definition: Whiteboard.h:40
float B() const
Definition: Color.h:39
Definition: Whiteboard.h:394
horiz_align m_horizAlign
Definition: Whiteboard.h:448
color m_color
Definition: Whiteboard.h:263
virtual ~decorator()
Definition: Whiteboard.h:468
double y_
Definition: Whiteboard.h:261
color m_color
Definition: Whiteboard.h:385
double m_fontSize
Definition: Whiteboard.h:444
void Draw(display_type *d)
Definition: Whiteboard.h:333
line(const xy_coords &startCoords, const xy_coords &stopCoords, const double width=1.0, const color &c=black)
Definition: Whiteboard.h:279
Definition: SVector.h:15
double m_size
Definition: Whiteboard.h:262
Definition: Whiteboard.h:35
Definition: Whiteboard.h:154
float R() const
Definition: Color.h:29
text(const xy_coords &coords, const string &chars, const color &c=black, const double fontSize=12.0, const string &fontName="Times-Roman", const double rotAngle=0.0, bool alignLeft=false)
Definition: Whiteboard.h:397
virtual double GetFontSize() const =0
int size() const
Number of graphics pointers contained.
Definition: Whiteboard.h:186
virtual void DrawArc(const xy_coords &coords, const double radius, const double startAngle, const double stopAngle)=0
The whiteboard namespace.
Definition: Axes.h:10
xy_coords m_coords
Definition: Whiteboard.h:383
graphic()
Definition: Whiteboard.h:139
xy_coords m_coords
Definition: Whiteboard.h:441
virtual void Draw(display_type *d)
Definition: Whiteboard.h:459
graphic * mp_graphic
Definition: Whiteboard.h:465
float G() const
Definition: Color.h:34
void Draw(display_type *d)
Definition: Whiteboard.h:375
void DeletePointers()
Clear all data, deleting all added pointers.
Definition: Whiteboard.h:178
void Finish()
Definition: Whiteboard.h:664
void Draw(display_type *d)
Definition: Whiteboard.h:292
arc(const xy_coords &coords, const double radius, const double startAngle, const double stopAngle, const double width=1.0, const color &c=black)
Definition: Whiteboard.h:358
virtual const color & GetColor() const =0
virtual void SetFont(const string &font, const double size)=0
xy_coords m_bottomRightCoords
Definition: Whiteboard.h:340
double GetWidth() const
Definition: Whiteboard.h:302
ostream & m_outstrm
Definition: Whiteboard.h:667
dpoint(double x, double y, const double size=1.0, const color &c=black)
Definition: Whiteboard.h:241
double m_width
Definition: Whiteboard.h:306
const color black(0, 0, 0)
Definition: Whiteboard.h:136
void DrawText(const xy_coords &coords, const string &chars, double rot_angle, double point_size, const vert_align vAlign, const horiz_align hAlign)
Definition: Whiteboard.h:531
Definition: Whiteboard.h:355
void DrawLine(const xy_coords &startCoords, const xy_coords &stopCoords)
Definition: Whiteboard.h:520
void Draw(display_type *d)
Definition: Whiteboard.h:252
void Add(graphic *g)
Definition: Whiteboard.h:162
ps_display(ostream &ostrm, double horizSize, double vertSize, double border=0.0)
Definition: Whiteboard.h:484
Definition: Whiteboard.h:204
pair< double, double > xy_coords
Definition: Whiteboard.h:30
virtual ~graphic()
Definition: Whiteboard.h:146
double m_fontSize
Definition: Whiteboard.h:671
string m_fontName
Definition: Whiteboard.h:445
void PrintEpsHeader(ostream &out, const float horizSize, const float vertSize, const float border)
Definition: Eps.cc:6
void DrawRect(const xy_coords &topLeftCoords, const xy_coords &bottomRightCoords)
Definition: Whiteboard.h:596
double m_width
Definition: Whiteboard.h:384
virtual ~point()
Definition: Whiteboard.h:229
const color & GetColor() const
Definition: Whiteboard.h:611
virtual double GetLineWidth() const =0
Definition: Whiteboard.h:237
horiz_align
Definition: Whiteboard.h:40
Definition: Whiteboard.h:46
void SetColor(const color &C)
Definition: Whiteboard.h:615
double m_stopAngle
Definition: Whiteboard.h:384
void Draw(display_type *d)
Definition: Whiteboard.h:217
virtual void Draw(display_type *d)=0
whiteboard()
Definition: Whiteboard.h:157
virtual const string & GetFontName() const =0
svec< graphic * > m_graphics
Definition: Whiteboard.h:194
string m_chars
Definition: Whiteboard.h:442
xy_coords StartCoords() const
Definition: Whiteboard.h:300
virtual void SetLineWidth(const double width)=0
decorator(graphic *g)
Definition: Whiteboard.h:457
xy_coords m_topLeftCoords
Definition: Whiteboard.h:340
Definition: Whiteboard.h:319
void Draw(const string &o, double x, double y)
Definition: Plot3D.cc:16
void DrawPoint(const xy_coords &coords)
Definition: Whiteboard.h:500
double x_
Definition: Whiteboard.h:260
virtual ~text()
Definition: Whiteboard.h:428
void SetHorizAlign(const horiz_align a)
Definition: Whiteboard.h:426
void SetVertAlign(const vert_align a)
Definition: Whiteboard.h:421
double m_rotAngle
Definition: Whiteboard.h:446
virtual ~arc()
Definition: Whiteboard.h:387
Definition: Whiteboard.h:454
color m_color
Definition: Whiteboard.h:443
virtual void DrawLine(const xy_coords &startCoord, const xy_coords &stopCoord)=0
virtual void DrawPoint(const xy_coords &coord)=0
color m_color
Definition: Whiteboard.h:307
virtual ~display_type()
Definition: Whiteboard.h:129
double GetLineWidth() const
Definition: Whiteboard.h:627
Definition: Whiteboard.h:476
double m_radius
Definition: Whiteboard.h:384
void DrawArc(const xy_coords &coords, const double radius, const double startAngle, const double stopAngle)
Definition: Whiteboard.h:582
virtual void DrawRect(const xy_coords &topLeftCoord, const xy_coords &bottomRightCoord)=0
void DrawPoint(double x, double y)
Definition: Whiteboard.h:510
void clear()
Definition: Whiteboard.h:190
xy_coords m_coords
Definition: Whiteboard.h:225
Definition: Whiteboard.h:40
color m_color
Definition: Whiteboard.h:341
Definition: Whiteboard.h:40
const string & GetFontName() const
Definition: Whiteboard.h:644
Definition: Whiteboard.h:35
color m_color
Definition: Whiteboard.h:227
Definition: Color.h:12
point(const xy_coords &coords, const double size=1.0, const color &c=black)
Definition: Whiteboard.h:207
xy_coords m_startCoords
Definition: Whiteboard.h:305
double m_size
Definition: Whiteboard.h:226
string m_fontName
Definition: Whiteboard.h:670
rect(const xy_coords &topLeftCoords, const xy_coords &bottomRightCoords, const color &c=black)
Definition: Whiteboard.h:322
xy_coords StopCoords() const
Definition: Whiteboard.h:301
vert_align
Definition: Whiteboard.h:35
void SetFont(const string &font, const double size)
Definition: Whiteboard.h:651
virtual ~rect()
Definition: Whiteboard.h:343
xy_coords m_stopCoords
Definition: Whiteboard.h:305
void SetLineWidth(const double width)
Definition: Whiteboard.h:632
const color white(1, 1, 1)
virtual ~line()
Definition: Whiteboard.h:309
vert_align m_vertAlign
Definition: Whiteboard.h:447
double m_startAngle
Definition: Whiteboard.h:384