42 #include <pcl/pcl_exports.h>
43 #include <vtkRenderer.h>
44 #include <vtkRenderWindow.h>
45 #include <vtkRenderWindowInteractor.h>
46 #include <vtkSmartPointer.h>
47 #include <vtkObjectFactory.h>
48 #include <vtkContext2D.h>
49 #include <vtkTransform2D.h>
50 #include <vtkContextItem.h>
51 #include <vtkContextView.h>
52 #include <vtkContextScene.h>
55 #include <vtkTextProperty.h>
56 #include <vtkOpenGLContextDevice2D.h>
57 #include <vtkPoints2D.h>
58 #include "vtkCommand.h"
62 namespace visualization
76 Figure2D (std::vector<float> info, vtkPen *p, vtkBrush * b, vtkTransform2D *t)
78 this->pen_ = vtkPen::New ();
79 this->brush_ = vtkBrush::New ();
80 this->transform_ = vtkTransform2D::New();
82 this->pen_->DeepCopy (p);
83 this->brush_->DeepCopy (b);
84 this->transform_->SetMatrix (t->GetMatrix());
88 Figure2D (vtkPen *p, vtkBrush * b, vtkTransform2D *t)
90 this->pen_ = vtkPen::New ();
91 this->brush_ = vtkBrush::New ();
92 this->transform_ = vtkTransform2D::New();
94 this->pen_->DeepCopy (p);
95 this->brush_->DeepCopy (b);
96 this->transform_->SetMatrix (t->GetMatrix());
101 painter->ApplyPen (
pen_);
102 painter->ApplyBrush (
brush_);
103 painter->GetDevice ()->SetMatrix (
transform_->GetMatrix());
106 virtual void draw (vtkContext2D *) {}
114 FPolyLine2D (std::vector<float> info, vtkPen *p, vtkBrush * b, vtkTransform2D *t) :
Figure2D (info, p, b, t){}
116 void draw (vtkContext2D * painter)
override
119 painter->DrawPoly (&
info_[0],
static_cast<unsigned int> (
info_.size ()) / 2);
128 FPoints2D (std::vector<float> info, vtkPen *p, vtkBrush * b, vtkTransform2D *t) :
Figure2D (info, p, b, t) {}
130 void draw (vtkContext2D * painter)
override
133 painter->DrawPoints (&
info_[0],
static_cast<unsigned int> (
info_.size ()) / 2);
142 FQuad2D (std::vector<float> info, vtkPen *p, vtkBrush * b, vtkTransform2D *t) :
Figure2D (info, p, b, t) {}
144 void draw (vtkContext2D * painter)
override
147 painter->DrawQuad (&
info_[0]);
156 FPolygon2D (std::vector<float> info, vtkPen *p, vtkBrush * b, vtkTransform2D *t) :
Figure2D (info, p, b, t){}
158 void draw (vtkContext2D * painter)
override
161 painter->DrawPolygon (&
info_[0],
static_cast<unsigned int> (
info_.size ()) / 2);
172 FEllipticArc2D (
float x,
float y,
float rx,
float ry,
float sa,
float ea, vtkPen *p, vtkBrush * b, vtkTransform2D *t) :
Figure2D (p, b, t)
183 void draw (vtkContext2D * painter)
override
211 Paint (vtkContext2D *painter)
override;
220 addLine (
float x1,
float y1,
float x2,
float y2);
226 addLine (std::vector<float> p);
234 addPoint (
float x,
float y);
240 addPoints (std::vector<float> points);
250 addRect (
float x,
float y,
float width,
float height);
256 addQuad (std::vector<float> p);
262 addPolygon (std::vector<float> p);
272 addEllipse (
float x,
float y,
float rx,
float ry);
280 addCircle (
float x,
float y,
float r);
291 addEllipticArc (
float x,
float y,
float rx,
float ry,
float start_angle,
float end_angle);
301 addArc (
float x,
float y,
float r,
float start_angle,
float end_angle);
309 translatePen (
double x,
double y);
315 rotatePen(
double angle);
322 scalePen(
double x,
double y);
328 setTransform(vtkMatrix3x3 *matrix);
347 void setPenColor (
unsigned char r,
unsigned char g,
unsigned char b,
unsigned char a);
348 void setPenWidth (
float w);
349 void setPenType (
int type);
353 unsigned char* getPenColor ();
354 float getPenWidth ();
356 void setPen (vtkPen *pen);
361 void setBrush (vtkBrush *brush);
362 vtkBrush* getBrush ();
363 void setBrushColor (
unsigned char r,
unsigned char g,
unsigned char b,
unsigned char a);
364 unsigned char* getBrushColor ();
372 setBackgroundColor (
const double r,
const double g,
const double b);
378 setBackgroundColor (
const double color[3]);
384 getBackgroundColor ();
392 setWindowSize (
int w,
int h);
398 getWindowSize ()
const;
407 void spinOnce (
const int spin_time = 0 );
417 std::vector<Figure2D *> figures_;
420 vtkPen *current_pen_;
421 vtkBrush *current_brush_;
422 vtkTransform2D *current_transform_;
423 int win_width_, win_height_;
424 double bkg_color_[3];
426 vtkContextView *view_;
429 struct ExitMainLoopTimerCallback :
public vtkCommand
431 static ExitMainLoopTimerCallback* New ()
433 return (
new ExitMainLoopTimerCallback);
436 Execute (vtkObject* vtkNotUsed (caller),
unsigned long event_id,
void* call_data)
override
438 if (event_id != vtkCommand::TimerEvent)
440 int timer_id = *(
reinterpret_cast<int*
> (call_data));
442 if (timer_id != right_timer_id)
446 interactor->TerminateApp ();
449 vtkRenderWindowInteractor *interactor;