vtkBoundingRectContextDevice2D.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (c) Kitware Inc.
2 // SPDX-License-Identifier: BSD-3-Clause
3 /*
4  * @class vtkBoundingRectContextDevice2D
5  * @brief Utility class for computing the bounds of items drawn by a
6  * vtkContext2D.
7 
8  * vtkBoundingRectContextDevice2D is a utility class that can be used to
9  * determine the bounding box of items drawn in a vtkContext2D. It overrides all
10  * the member functions for drawing primitives, and instead of drawing anything,
11  * it expands a running bounding box so that the bounding box contains the
12  * rendered primitive. The running bounding box can be reset using Reset(), and
13  * it can be queried with GetBoundingRect().
14  *
15  * This class delegates the task of computing the bounds of some primitives,
16  * such as text strings, to a delegate device using SetDelegateDevice().
17  *
18  * Example usage:
19  * \code{.cpp}
20  * vtkContextScene* scene = ...;
21  * vtkViewport* viewport = ...;
22  * vtkNew<vtkContextDevice2D> contextDevice;
23  * vtkNew<vtkBoundingRectContextDevice2D> bbDevice;
24  * bbDevice->SetDelegateDevice(contextDevice.Get());
25  * bbDevice->Begin(viewport);
26  * vtkNew<vtkContextDevice2D> context;
27  * context->Begin(bbDevice.Get());
28  * scene->Paint(context.Get());
29  * context->End();
30  * bbDevice->End();
31  *
32  * \warning Currently ignores transformation matrices.
33  * \endcode
34  */
35 
36 #ifndef vtkBoundingRectContextDevice2D_h
37 #define vtkBoundingRectContextDevice2D_h
38 
39 #include "vtkRemotingViewsModule.h" // needed for export macro
40 
41 #include "vtkContextDevice2D.h"
42 
44 
46 {
47 public:
49  void PrintSelf(ostream& os, vtkIndent indent) override;
51 
55  vtkSetObjectMacro(DelegateDevice, vtkContextDevice2D);
56  vtkGetObjectMacro(DelegateDevice, vtkContextDevice2D);
57 
61  void Reset();
62 
66  static vtkRectf GetBoundingRect(vtkAbstractContextItem* item, vtkViewport* viewport);
67 
72  vtkRectf GetBoundingRect();
73 
77  void DrawString(float* point, const vtkStdString& string) override;
78 
82  void DrawMathTextString(float* point, const vtkStdString& string) override;
83 
87  void DrawImage(float p[2], float scale, vtkImageData* image) override;
88 
92  void DrawImage(const vtkRectf& pos, vtkImageData* image) override;
93 
99  void DrawPolyData(float vtkNotUsed(p)[2], float vtkNotUsed(scale),
100  vtkPolyData* vtkNotUsed(polyData), vtkUnsignedCharArray* vtkNotUsed(colors),
101  int vtkNotUsed(scalarMode)) override
102  {
103  }
104 
108  void SetColor4(unsigned char color[4]) override;
109 
113  void SetTexture(vtkImageData* image, int properties) override;
114 
118  void SetPointSize(float size) override;
119 
124  void SetLineWidth(float width) override;
125 
130  void SetLineType(int type) override;
131 
135  void SetMatrix(vtkMatrix3x3* m) override;
136 
140  void GetMatrix(vtkMatrix3x3* m) override;
141 
145  void MultiplyMatrix(vtkMatrix3x3* m) override;
146 
150  void PushMatrix() override;
151 
155  void PopMatrix() override;
156 
160  void EnableClipping(bool enable) override;
161 
165  void SetClipping(int* x) override;
166 
170  void ApplyPen(vtkPen* pen) override;
171 
175  vtkPen* GetPen() override;
176 
180  void ApplyBrush(vtkBrush* brush) override;
181 
185  vtkBrush* GetBrush() override;
186 
190  void ApplyTextProp(vtkTextProperty* prop) override;
191 
195  vtkTextProperty* GetTextProp() override;
196 
200  void DrawPoly(float* points, int n, unsigned char* colors = nullptr, int nc_comps = 0) override;
201 
205  void DrawLines(float* f, int n, unsigned char* colors = nullptr, int nc_comps = 0) override;
206 
210  void DrawPoints(float* points, int n, unsigned char* colors = nullptr, int nc_comps = 0) override;
211 
215  void DrawPointSprites(vtkImageData* sprite, float* points, int n, unsigned char* colors = nullptr,
216  int nc_comps = 0) override;
217 
221  void DrawMarkers(int shape, bool highlight, float* points, int n, unsigned char* colors = nullptr,
222  int nc_comps = 0) override;
223 
227  void DrawEllipseWedge(float x, float y, float outRx, float outRy, float inRx, float inRy,
228  float startAngle, float stopAngle) override;
229 
233  void DrawEllipticArc(
234  float x, float y, float rX, float rY, float startAngle, float stopAngle) override;
235 
239  void ComputeStringBounds(const vtkStdString& string, float bounds[4]) override;
240 
244  void ComputeJustifiedStringBounds(const char* string, float bounds[4]) override;
245 
249  void Begin(vtkViewport*) override;
250 
254  void End() override;
255 
259  bool GetBufferIdMode() const override;
260 
264  void BufferIdModeBegin(vtkAbstractContextBufferId* bufferId) override;
265 
269  void BufferIdModeEnd() override;
270 
271 protected:
273  ~vtkBoundingRectContextDevice2D() override;
274 
279 
284 
289 
293  void AddPoint(float x, float y);
294  void AddPoint(float point[2]);
295 
299  void AddRect(const vtkRectf& rect);
300 
301 private:
303  void operator=(const vtkBoundingRectContextDevice2D&) = delete;
304 };
305 
306 #endif // vtkBoundingRectContextDevice2D_h
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()