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());
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);
257 addRect (
float x,
float y,
float width,
float height);
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);
354 void setPenColor (
unsigned char r,
unsigned char g,
unsigned char b,
unsigned char a);
370 void setBrushColor (
unsigned char r,
unsigned char g,
unsigned char b,
unsigned char a);
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;
PCL Painter2D main class.
void clearTransform()
Clears all the transformation applied.
void setPenType(int type)
unsigned char * getBrushColor()
void addCircle(float x, float y, float r)
Draw a circle based on the inputs.
void spin()
spins (runs the event loop) the interactor indefinitely.
void addRect(float x, float y, float width, float height)
Draw a rectangle based on the given points.
PCLPainter2D(char const *name="PCLPainter2D")
Constructor of the class.
void setBrushColor(unsigned char r, unsigned char g, unsigned char b, unsigned char a)
void rotatePen(double angle)
Create a rotation matrix and concatenate it with the current transformation.
void addEllipticArc(float x, float y, float rx, float ry, float start_angle, float end_angle)
Draw an elliptic arc based on the inputs.
void scalePen(double x, double y)
Create a scale matrix and concatenate it with the current transformation.
void addPoints(std::vector< float > points)
Draw specified point(s).
vtkMatrix3x3 * getTransform()
Returns the current transformation matrix.
void setBackgroundColor(const double r, const double g, const double b)
set/get method for the viewport's background color.
void display()
displays all the figures added in a window.
void setPenWidth(float w)
void addEllipse(float x, float y, float rx, float ry)
Draw an ellipse based on the inputs.
bool Paint(vtkContext2D *painter) override
Paint event for the chart, called whenever the chart needs to be drawn.
void setBackgroundColor(const double color[3])
set/get method for the viewport's background color.
void translatePen(double x, double y)
Create a translation matrix and concatenate it with the current transformation.
vtkTypeMacro(PCLPainter2D, vtkContextItem)
void addLine(std::vector< float > p)
Draw line(s) between the specified points.
void clearFigures()
remove all the figures from the window
void addPolygon(std::vector< float > p)
Draw a polygon between the specified points.
void addQuad(std::vector< float > p)
Draw a quadrilateral based on the given points.
void setTransform(vtkMatrix3x3 *matrix)
Create a translation matrix and concatenate it with the current transformation.
unsigned char * getPenColor()
set/get methods for current working vtkPen
void addPoint(float x, float y)
Draw specified point(s).
void setBrush(vtkBrush *brush)
set/get methods for current working vtkBrush
void addArc(float x, float y, float r, float start_angle, float end_angle)
Draw an arc based on the inputs.
void spinOnce(const int spin_time=0)
spins (runs the event loop) the interactor for spin_time amount of time.
double * getBackgroundColor()
set/get method for the viewport's background color.
void addLine(float x1, float y1, float x2, float y2)
Draw a line between the specified points.
void setPenColor(unsigned char r, unsigned char g, unsigned char b, unsigned char a)
set/get methods for current working vtkPen
int * getWindowSize() const
set/get method for the window size.
void setWindowSize(int w, int h)
set/get method for the window size.
Class for storing EllipticArc; every ellipse , circle are covered by this.
void draw(vtkContext2D *painter) override
FEllipticArc2D(float x, float y, float rx, float ry, float sa, float ea, vtkPen *p, vtkBrush *b, vtkTransform2D *t)
FEllipticArc2D(std::vector< float > info, vtkPen *p, vtkBrush *b, vtkTransform2D *t)
Class for storing Points.
void draw(vtkContext2D *painter) override
FPoints2D(std::vector< float > info, vtkPen *p, vtkBrush *b, vtkTransform2D *t)
FPolyLine2D(std::vector< float > info, vtkPen *p, vtkBrush *b, vtkTransform2D *t)
void draw(vtkContext2D *painter) override
void draw(vtkContext2D *painter) override
FPolygon2D(std::vector< float > info, vtkPen *p, vtkBrush *b, vtkTransform2D *t)
FQuad2D(std::vector< float > info, vtkPen *p, vtkBrush *b, vtkTransform2D *t)
void draw(vtkContext2D *painter) override