VTK/2DAPI: Difference between revisions

From KitwarePublic
< VTK
Jump to navigationJump to search
(Added some notes about the 2D API)
 
m (Added a couple of comments)
Line 65: Line 65:
   static vtk2DPainter *New();
   static vtk2DPainter *New();
    
    
  // Begin painting, a valid paint device is required
   bool Begin(vtk2DPaintDevice *device);
   bool Begin(vtk2DPaintDevice *device);
  // Perform any cleanup that might be necessary
   bool End();
   bool End();



Revision as of 17:29, 21 October 2009

The 2D API is currently composed of two levels, a concreate class called vtk2DPainter that is called by the paint functions of components operating within the 2D API, and a vtk2DPaintDevice which is called by the vtk2DPainter to actually draw to a context. The vtk2DPainter contains a pointer to the derived class of the vtk2DPaintDevice to do low level painting. This is the class that must be implemented for a new backend to be supported. The vtk2DPainter builds up more complex 2D constructs on top of the basic constructs implemented in the device.

2D API

The class relationship diagram is shown above. The headers for the two classes look as follows.

vtk2DPainter

<source lang="cpp"> class VTK_CHARTS_EXPORT vtk2DPainter : public vtkObject { public:

 vtkTypeRevisionMacro(vtk2DPainter, vtkObject);
 virtual void PrintSelf(ostream &os, vtkIndent indent);
 static vtk2DPainter *New();
 
 // Begin painting, a valid paint device is required
 bool Begin(vtk2DPaintDevice *device);
 // Perform any cleanup that might be necessary
 bool End();
 // Line drawing functions
 void DrawLine(float x1, float y1, float x2, float y2);
 void DrawLine(vtkPoints2D *points);
 void DrawPoly(float *x, float *y, int n);
 void DrawPoly(vtkPoints2D *points);
 void DrawRectangle(float x, float y, float width, float height);
 void DrawRectangle(float *p);
 void DrawRectangle(vtkPoints2D *points);
 // Point drawing functions
 void DrawPoint(float x, float y);
 void DrawPoints(float *x, float *y, int n);
 void DrawPoints(vtkPoints2D *points);
 // Manage the state of the painter
 void SetColor(int r, int g, int b, int a);
 void SetPointSize(float size);
 void SetLineWidth(float width);

protected:

 vtk2DPainter();
 ~vtk2DPainter();

}; </source>

vtk2DPaintDevice (Abstract)

While the vtk2DPaintDevice class is an abstract class. The header for the equivalent functionality is,

<source lang="cpp"> class VTK_CHARTS_EXPORT vtk2DPaintDevice : public vtkObject { public:

 vtkTypeRevisionMacro(vtk2DPaintDevice, vtkObject);
 virtual void PrintSelf(ostream &os, vtkIndent indent);
 static vtk2DPaintDevice *New();
 
 // Set up the paint device context
 virtual void Begin(vtkRenderer* renderer) { }
 
 // Clean anything up once rendering has been completed
 virtual void End() { }
 // Line drawing functions
 virtual void DrawPoly(vtkPoints2D *points) = 0;
 // Point drawing functions
 virtual void DrawPoints(vtkPoints2D *points) = 0;
 // Manage the state of the painter
 void SetColor(int r, int g, int b, int a);
 void SetPointSize(float size);
 void SetLineWidth(float width);

protected:

 vtk2DPaintDevice();
 ~vtk2DPaintDevice();

}; </source>