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());
103 transform_->Delete();
108 painter->ApplyPen (pen_);
109 painter->ApplyBrush (brush_);
110 painter->GetDevice ()->SetMatrix (transform_->GetMatrix());
113 virtual void draw (vtkContext2D *) {}
121 FPolyLine2D (std::vector<float> info, vtkPen *p, vtkBrush * b, vtkTransform2D *t) :
Figure2D (info, p, b, t){}
123 void draw (vtkContext2D * painter)
override
126 painter->DrawPoly (
info_.data(),
static_cast<unsigned int> (
info_.size ()) / 2);
135 FPoints2D (std::vector<float> info, vtkPen *p, vtkBrush * b, vtkTransform2D *t) :
Figure2D (info, p, b, t) {}
137 void draw (vtkContext2D * painter)
override
140 painter->DrawPoints (
info_.data(),
static_cast<unsigned int> (
info_.size ()) / 2);
149 FQuad2D (std::vector<float> info, vtkPen *p, vtkBrush * b, vtkTransform2D *t) :
Figure2D (info, p, b, t) {}
151 void draw (vtkContext2D * painter)
override
154 painter->DrawQuad (
info_.data());
163 FPolygon2D (std::vector<float> info, vtkPen *p, vtkBrush * b, vtkTransform2D *t) :
Figure2D (info, p, b, t){}
165 void draw (vtkContext2D * painter)
override
168 painter->DrawPolygon (
info_.data(),
static_cast<unsigned int> (
info_.size ()) / 2);
179 FEllipticArc2D (
float x,
float y,
float rx,
float ry,
float sa,
float ea, vtkPen *p, vtkBrush * b, vtkTransform2D *t) :
Figure2D (p, b, t)
190 void draw (vtkContext2D * painter)
override
218 Paint (vtkContext2D *painter)
override;
227 addLine (
float x1,
float y1,
float x2,
float y2);
233 addLine (std::vector<float> p);
241 addPoint (
float x,
float y);
247 addPoints (std::vector<float> points);
257 addRect (
float x,
float y,
float width,
float height);
263 addQuad (std::vector<float> p);
269 addPolygon (std::vector<float> p);
279 addEllipse (
float x,
float y,
float rx,
float ry);
287 addCircle (
float x,
float y,
float r);
298 addEllipticArc (
float x,
float y,
float rx,
float ry,
float start_angle,
float end_angle);
308 addArc (
float x,
float y,
float r,
float start_angle,
float end_angle);
316 translatePen (
double x,
double y);
322 rotatePen(
double angle);
329 scalePen(
double x,
double y);
335 setTransform(vtkMatrix3x3 *matrix);
354 void setPenColor (
unsigned char r,
unsigned char g,
unsigned char b,
unsigned char a);
355 void setPenWidth (
float w);
356 void setPenType (
int type);
360 unsigned char* getPenColor ();
361 float getPenWidth ();
363 void setPen (vtkPen *pen);
368 void setBrush (vtkBrush *brush);
369 vtkBrush* getBrush ();
370 void setBrushColor (
unsigned char r,
unsigned char g,
unsigned char b,
unsigned char a);
371 unsigned char* getBrushColor ();
379 setBackgroundColor (
const double r,
const double g,
const double b);
385 setBackgroundColor (
const double color[3]);
391 getBackgroundColor ();
399 setWindowSize (
int w,
int h);
405 getWindowSize ()
const;
414 void spinOnce (
const int spin_time = 0 );
424 std::vector<Figure2D *> figures_;
427 vtkPen *current_pen_;
428 vtkBrush *current_brush_;
429 vtkTransform2D *current_transform_;
430 int win_width_, win_height_;
431 double bkg_color_[3];
433 vtkContextView *view_;
436 struct ExitMainLoopTimerCallback :
public vtkCommand
438 static ExitMainLoopTimerCallback* New ()
440 return (
new ExitMainLoopTimerCallback);
443 Execute (vtkObject* vtkNotUsed (caller),
unsigned long event_id,
void* call_data)
override
445 if (event_id != vtkCommand::TimerEvent)
447 int timer_id = *(
reinterpret_cast<int*
> (call_data));
449 if (timer_id != right_timer_id)
453 interactor->TerminateApp ();
456 vtkRenderWindowInteractor *interactor;
FQuad2D(std::vector< float > info, vtkPen *p, vtkBrush *b, vtkTransform2D *t)
PCL Painter2D main class.
void draw(vtkContext2D *painter) override
FPolyLine2D(std::vector< float > info, vtkPen *p, vtkBrush *b, vtkTransform2D *t)
Class for storing Points.
FPoints2D(std::vector< float > info, vtkPen *p, vtkBrush *b, vtkTransform2D *t)
void draw(vtkContext2D *painter) override
FEllipticArc2D(float x, float y, float rx, float ry, float sa, float ea, vtkPen *p, vtkBrush *b, vtkTransform2D *t)
void draw(vtkContext2D *painter) override
FEllipticArc2D(std::vector< float > info, vtkPen *p, vtkBrush *b, vtkTransform2D *t)
void draw(vtkContext2D *painter) override
Class for storing EllipticArc; every ellipse , circle are covered by this.
void draw(vtkContext2D *painter) override
FPolygon2D(std::vector< float > info, vtkPen *p, vtkBrush *b, vtkTransform2D *t)