vtkBoundingRectContextDevice2D.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: ParaView
4  Module: vtkBoundingRectContextDevice2D.h
5 
6  Copyright (c) Kitware, Inc.
7  All rights reserved.
8  See Copyright.txt or http://www.paraview.org/HTML/Copyright.html for details.
9 
10  This software is distributed WITHOUT ANY WARRANTY; without even
11  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12  PURPOSE. See the above copyright notice for more information.
13 
14 =========================================================================*/
15 /*
16  * @class vtkBoundingRectContextDevice2D
17  * @brief Utility class for computing the bounds of items drawn by a
18  * vtkContext2D.
19 
20  * vtkBoundingRectContextDevice2D is a utility class that can be used to
21  * determine the bounding box of items drawn in a vtkContext2D. It overrides all
22  * the member functions for drawing primitives, and instead of drawing anything,
23  * it expands a running bounding box so that the bounding box contains the
24  * rendered primitive. The running bounding box can be reset using Reset(), and
25  * it can be queried with GetBoundingRect().
26  *
27  * This class delegates the task of computing the bounds of some primitives,
28  * such as text strings, to a delegate device using SetDelegateDevice().
29  *
30  * Example usage:
31  * \code{.cpp}
32  * vtkContextScene* scene = ...;
33  * vtkViewport* viewport = ...;
34  * vtkNew<vtkContextDevice2D> contextDevice;
35  * vtkNew<vtkBoundingRectContextDevice2D> bbDevice;
36  * bbDevice->SetDelegateDevice(contextDevice.Get());
37  * bbDevice->Begin(viewport);
38  * vtkNew<vtkContextDevice2D> context;
39  * context->Begin(bbDevice.Get());
40  * scene->Paint(context.Get());
41  * context->End();
42  * bbDevice->End();
43  *
44  * \warning Currently ignores transformation matrices.
45  * \endcode
46  */
47 
48 #ifndef vtkBoundingRectContextDevice2D_h
49 #define vtkBoundingRectContextDevice2D_h
50 
51 #include "vtkRemotingViewsModule.h" // needed for export macro
52 
53 #include "vtkContextDevice2D.h"
54 
56 
58 {
59 public:
61  ostream& os, vtkIndent indent) override;
63 
67  vtkSetObjectMacro(DelegateDevice, vtkContextDevice2D);
68  vtkGetObjectMacro(DelegateDevice, vtkContextDevice2D);
69 
73  void Reset();
74 
78  static vtkRectf GetBoundingRect(vtkAbstractContextItem* item, vtkViewport* viewport);
79 
84  vtkRectf GetBoundingRect();
85 
89  void DrawString(float* point, const vtkStdString& string) override;
90 
94  void DrawString(float* point, const vtkUnicodeString& string) override;
95 
99  void DrawMathTextString(float* point, const vtkStdString& string) override;
100 
104  void DrawImage(float p[2], float scale, vtkImageData* image) override;
105 
109  void DrawImage(const vtkRectf& pos, vtkImageData* image) override;
110 
116  void DrawPolyData(float vtkNotUsed(p)[2], float vtkNotUsed(scale),
117  vtkPolyData* vtkNotUsed(polyData), vtkUnsignedCharArray* vtkNotUsed(colors),
118  int vtkNotUsed(scalarMode)) override
119  {
120  }
121 
125  void SetColor4(unsigned char color[4]) override;
126 
130  void SetTexture(vtkImageData* image, int properties) override;
131 
135  void SetPointSize(float size) override;
136 
141  void SetLineWidth(float width) override;
142 
147  void SetLineType(int type) override;
148 
152  void SetMatrix(vtkMatrix3x3* m) override;
153 
157  void GetMatrix(vtkMatrix3x3* m) override;
158 
162  void MultiplyMatrix(vtkMatrix3x3* m) override;
163 
167  void PushMatrix() override;
168 
172  void PopMatrix() override;
173 
177  void EnableClipping(bool enable) override;
178 
182  void SetClipping(int* x) override;
183 
187  void ApplyPen(vtkPen* pen) override;
188 
192  vtkPen* GetPen() override;
193 
197  void ApplyBrush(vtkBrush* brush) override;
198 
202  vtkBrush* GetBrush() override;
203 
207  void ApplyTextProp(vtkTextProperty* prop) override;
208 
212  vtkTextProperty* GetTextProp() override;
213 
217  void DrawPoly(float* points, int n, unsigned char* colors = 0, int nc_comps = 0) override;
218 
222  void DrawLines(float* f, int n, unsigned char* colors = 0, int nc_comps = 0) override;
223 
227  void DrawPoints(float* points, int n, unsigned char* colors = 0, int nc_comps = 0) override;
228 
232  void DrawPointSprites(vtkImageData* sprite, float* points, int n, unsigned char* colors = 0,
233  int nc_comps = 0) override;
234 
238  void DrawMarkers(int shape, bool highlight, float* points, int n, unsigned char* colors = 0,
239  int nc_comps = 0) override;
240 
244  void DrawEllipseWedge(float x, float y, float outRx, float outRy, float inRx, float inRy,
245  float startAngle, float stopAngle) override;
246 
250  void DrawEllipticArc(
251  float x, float y, float rX, float rY, float startAngle, float stopAngle) override;
252 
256  void ComputeStringBounds(const vtkStdString& string, float bounds[4]) override;
257 
261  void ComputeStringBounds(const vtkUnicodeString& string, float bounds[4]) override;
262 
266  void ComputeJustifiedStringBounds(const char* string, float bounds[4]) override;
267 
271  void Begin(vtkViewport*) override;
272 
276  void End() override;
277 
281  bool GetBufferIdMode() const override;
282 
286  void BufferIdModeBegin(vtkAbstractContextBufferId* bufferId) override;
287 
291  void BufferIdModeEnd() override;
292 
293 protected:
295  ~vtkBoundingRectContextDevice2D() override;
296 
301 
306 
311 
315  void AddPoint(float x, float y);
316  void AddPoint(float point[2]);
317 
321  void AddRect(const vtkRectf& rect);
322 
323 private:
325  void operator=(const vtkBoundingRectContextDevice2D&) = delete;
326 };
327 
328 #endif // vtkBoundingRectContextDevice2D
bool Initialized
Is the bounding rect initialized?
color
virtual void SetMatrix(vtkMatrix3x3 *m)=0
virtual void SetClipping(int *x)=0
type
virtual void BufferIdModeEnd()
virtual void ComputeJustifiedStringBounds(const char *string, float bounds[4])=0
virtual void ApplyTextProp(vtkTextProperty *prop)
#define VTKREMOTINGVIEWS_EXPORT
vtkContextDevice2D * DelegateDevice
Delegate ContextDevice2D to handle certain computations.
startAngle
vtkRectf BoundingRect
Cumulative rect holding the bounds of the primitives rendered by the device.
virtual void BufferIdModeBegin(vtkAbstractContextBufferId *bufferId)
static vtkContextDevice2D * New()
virtual void DrawPoints(float *points, int n, unsigned char *colors=0, int nc_comps=0)=0
virtual vtkPen * GetPen()
virtual vtkTextProperty * GetTextProp()
virtual void Begin(vtkViewport *)
virtual void DrawMarkers(int shape, bool highlight, float *points, int n, unsigned char *colors=0, int nc_comps=0)
virtual void SetColor4(unsigned char color[4])=0
virtual void EnableClipping(bool enable)=0
virtual void SetLineWidth(float width)=0
virtual void ApplyBrush(vtkBrush *brush)
virtual void DrawPoly(float *points, int n, unsigned char *colors=0, int nc_comps=0)=0
virtual void PopMatrix()=0
virtual void SetTexture(vtkImageData *image, int properties)=0
points
virtual void DrawMathTextString(float *point, const vtkStdString &string)=0
size
virtual bool GetBufferIdMode() const
virtual void SetPointSize(float size)=0
virtual void DrawEllipticArc(float x, float y, float rX, float rY, float startAngle, float stopAngle)=0
virtual void MultiplyMatrix(vtkMatrix3x3 *m)=0
virtual void DrawString(float *point, const vtkStdString &string)=0
virtual void End()
virtual void DrawEllipseWedge(float x, float y, float outRx, float outRy, float inRx, float inRy, float startAngle, float stopAngle)=0
image
virtual void GetMatrix(vtkMatrix3x3 *m)=0
virtual void PrintSelf(ostream &os, vtkIndent indent)
virtual void ComputeStringBounds(const vtkStdString &string, float bounds[4])=0
virtual void PushMatrix()=0
virtual void DrawImage(float p[2], float scale, vtkImageData *image)=0
virtual void ApplyPen(vtkPen *pen)
void DrawPolyData(float vtkNotUsed(p)[2], float vtkNotUsed(scale), vtkPolyData *vtkNotUsed(polyData), vtkUnsignedCharArray *vtkNotUsed(colors), int vtkNotUsed(scalarMode)) override
Draw the supplied PolyData at the given x, y (p[0], p[1]) (bottom corner), scaled by scale (1...
virtual void SetLineType(int type)=0
void operator=(const vtkObjectBase &)
virtual void DrawLines(float *f, int n, unsigned char *colors=0, int nc_comps=0)=0
virtual void DrawPointSprites(vtkImageData *sprite, float *points, int n, unsigned char *colors=0, int nc_comps=0)=0
virtual vtkBrush * GetBrush()