39 #ifndef PCL_VISUALUALIZATION_PCL_PAINTER2D_H_
40 #define PCL_VISUALUALIZATION_PCL_PAINTER2D_H_
45 #include <vtkRenderer.h>
46 #include <vtkRenderWindow.h>
47 #include <vtkRenderWindowInteractor.h>
48 #include <vtkSmartPointer.h>
49 #include <vtkObjectFactory.h>
50 #include <vtkContext2D.h>
51 #include <vtkTransform2D.h>
52 #include <vtkContextItem.h>
53 #include <vtkContextView.h>
54 #include <vtkContextScene.h>
57 #include <vtkTextProperty.h>
58 #include <vtkOpenGLContextDevice2D.h>
59 #include <vtkPoints2D.h>
60 #include "vtkCommand.h"
62 #include <vtkRegressionTestImage.h>
66 namespace visualization
80 Figure2D (std::vector<float> info, vtkPen *p, vtkBrush * b, vtkTransform2D *t)
82 this->
pen_ = vtkPen::New ();
83 this->
brush_ = vtkBrush::New ();
86 this->
pen_->DeepCopy (p);
87 this->
brush_->DeepCopy (b);
92 Figure2D (vtkPen *p, vtkBrush * b, vtkTransform2D *t)
94 this->
pen_ = vtkPen::New ();
95 this->
brush_ = vtkBrush::New ();
98 this->
pen_->DeepCopy (p);
99 this->
brush_->DeepCopy (b);
105 painter->ApplyPen (
pen_);
106 painter->ApplyBrush (
brush_);
107 painter->GetDevice ()->SetMatrix (
transform_->GetMatrix());
110 virtual void draw (vtkContext2D *) {}
118 FPolyLine2D (std::vector<float> info, vtkPen *p, vtkBrush * b, vtkTransform2D *t) :
Figure2D (info, p, b, t){}
120 void draw (vtkContext2D * painter)
123 painter->DrawPoly (&
info_[0], static_cast<unsigned int> (
info_.size ()) / 2);
132 FPoints2D (std::vector<float> info, vtkPen *p, vtkBrush * b, vtkTransform2D *t) :
Figure2D (info, p, b, t) {}
134 void draw (vtkContext2D * painter)
137 painter->DrawPoints (&
info_[0], static_cast<unsigned int> (
info_.size ()) / 2);
146 FQuad2D (std::vector<float> info, vtkPen *p, vtkBrush * b, vtkTransform2D *t) :
Figure2D (info, p, b, t) {}
148 void draw (vtkContext2D * painter)
151 painter->DrawQuad (&
info_[0]);
160 FPolygon2D (std::vector<float> info, vtkPen *p, vtkBrush * b, vtkTransform2D *t) :
Figure2D (info, p, b, t){}
162 void draw (vtkContext2D * painter)
165 painter->DrawPolygon (&
info_[0], static_cast<unsigned int> (
info_.size ()) / 2);
176 FEllipticArc2D (
float x,
float y,
float rx,
float ry,
float sa,
float ea, vtkPen *p, vtkBrush * b, vtkTransform2D *t) :
Figure2D (p, b, t)
187 void draw (vtkContext2D * painter)
215 Paint (vtkContext2D *painter);
224 addLine (
float x1,
float y1,
float x2,
float y2);
230 addLine (std::vector<float> p);
254 addRect (
float x,
float y,
float width,
float height);
260 addQuad (std::vector<float> p);
276 addEllipse (
float x,
float y,
float rx,
float ry);
295 addEllipticArc (
float x,
float y,
float rx,
float ry,
float start_angle,
float end_angle);
305 addArc (
float x,
float y,
float r,
float start_angle,
float end_angle);
352 void setPenColor (
unsigned char r,
unsigned char g,
unsigned char b,
unsigned char a);
361 void setPen (vtkPen *pen);
368 void setBrushColor (
unsigned char r,
unsigned char g,
unsigned char b,
unsigned char a);
412 void spinOnce (
const int spin_time = 0 );
422 std::vector<Figure2D *> figures_;
425 vtkPen *current_pen_;
426 vtkBrush *current_brush_;
427 vtkTransform2D *current_transform_;
428 int win_width_, win_height_;
429 double bkg_color_[3];
431 vtkContextView *view_;
434 struct ExitMainLoopTimerCallback :
public vtkCommand
436 static ExitMainLoopTimerCallback* New ()
438 return (
new ExitMainLoopTimerCallback);
441 Execute (vtkObject* vtkNotUsed (caller),
unsigned long event_id,
void* call_data)
443 if (event_id != vtkCommand::TimerEvent)
445 int timer_id = *(
reinterpret_cast<int*
> (call_data));
447 if (timer_id != right_timer_id)
451 #if ((VTK_MAJOR_VERSION == 5) && (VTK_MINOR_VERSION <= 4))
452 interactor->stopLoop ();
454 interactor->TerminateApp ();
458 #if ((VTK_MAJOR_VERSION == 5) && (VTK_MINOR_VERSION <= 4))
461 vtkRenderWindowInteractor *interactor;
void draw(vtkContext2D *painter)
void applyInternals(vtkContext2D *painter)
The PCLVisualizer interactor.
Class for storing Points.
double * getBackgroundColor()
set/get method for the viewport's background color.
PCL Painter2D main class.
FPolyLine2D(std::vector< float > info, vtkPen *p, vtkBrush *b, vtkTransform2D *t)
unsigned char * getPenColor()
set/get methods for current working vtkPen
PCLPainter2D(char const *name="PCLPainter2D")
Constructor of the class.
void addCircle(float x, float y, float r)
Draw a circle based on the inputs.
void setBackgroundColor(const double r, const double g, const double b)
set/get method for the viewport's background color.
void addPoint(float x, float y)
Draw specified point(s).
virtual bool Paint(vtkContext2D *painter)
Paint event for the chart, called whenever the chart needs to be drawn.
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 setBrushColor(unsigned char r, unsigned char g, unsigned char b, unsigned char a)
void translatePen(double x, double y)
Create a translation matrix and concatenate it with the current transformation.
void scalePen(double x, double y)
Create a scale matrix and concatenate it with the current transformation.
void setBrush(vtkBrush *brush)
set/get methods for current working vtkBrush
void addEllipse(float x, float y, float rx, float ry)
Draw an ellipse based on the inputs.
vtkTypeRevisionMacro(PCLPainter2D, vtkContextItem)
FEllipticArc2D(std::vector< float > info, vtkPen *p, vtkBrush *b, vtkTransform2D *t)
void draw(vtkContext2D *painter)
void addQuad(std::vector< float > p)
Draw a quadrilateral based on the given points.
void setPenWidth(float w)
void draw(vtkContext2D *painter)
void clearTransform()
Clears all the transformation applied.
void addArc(float x, float y, float r, float start_angle, float end_angle)
Draw an arc based on the inputs.
FQuad2D(std::vector< float > info, vtkPen *p, vtkBrush *b, vtkTransform2D *t)
Figure2D(std::vector< float > info, vtkPen *p, vtkBrush *b, vtkTransform2D *t)
unsigned char * getBrushColor()
void spin()
spins (runs the event loop) the interactor indefinitely.
vtkTransform2D * transform_
void clearFigures()
remove all the figures from the window
void draw(vtkContext2D *painter)
virtual void draw(vtkContext2D *)
int * getWindowSize()
set/get method for the window size.
FEllipticArc2D(float x, float y, float rx, float ry, float sa, float ea, vtkPen *p, vtkBrush *b, vtkTransform2D *t)
void setPenType(int type)
Class for storing EllipticArc; every ellipse , circle are covered by this.
void setTransform(vtkMatrix3x3 *matrix)
Create a translation matrix and concatenate it with the current transformation.
Figure2D(vtkPen *p, vtkBrush *b, vtkTransform2D *t)
void draw(vtkContext2D *painter)
void setWindowSize(int w, int h)
set/get method for the window size.
void spinOnce(const int spin_time=0)
spins (runs the event loop) the interactor for spin_time amount of time.
Abstract class for storing figure information.
void rotatePen(double angle)
Create a rotation matrix and concatenate it with the current transformation.
FPolygon2D(std::vector< float > info, vtkPen *p, vtkBrush *b, vtkTransform2D *t)
vtkMatrix3x3 * getTransform()
Returns the current transformation matrix.
void addPoints(std::vector< float > points)
Draw specified point(s).
void addLine(float x1, float y1, float x2, float y2)
Draw a line between the specified points.
void addPolygon(std::vector< float > p)
Draw a polygon 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
void display()
displays all the figures added in a window.
FPoints2D(std::vector< float > info, vtkPen *p, vtkBrush *b, vtkTransform2D *t)
void addRect(float x, float y, float width, float height)
Draw a rectangle based on the given points.
std::vector< float > info_