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  void PrintSelf(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 DrawMathTextString(float* point, const vtkStdString& string) override;
95 
99  void DrawImage(float p[2], float scale, vtkImageData* image) override;
100 
104  void DrawImage(const vtkRectf& pos, vtkImageData* image) override;
105 
111  void DrawPolyData(float vtkNotUsed(p)[2], float vtkNotUsed(scale),
112  vtkPolyData* vtkNotUsed(polyData), vtkUnsignedCharArray* vtkNotUsed(colors),
113  int vtkNotUsed(scalarMode)) override
114  {
115  }
116 
120  void SetColor4(unsigned char color[4]) override;
121 
125  void SetTexture(vtkImageData* image, int properties) override;
126 
130  void SetPointSize(float size) override;
131 
136  void SetLineWidth(float width) override;
137 
142  void SetLineType(int type) override;
143 
147  void SetMatrix(vtkMatrix3x3* m) override;
148 
152  void GetMatrix(vtkMatrix3x3* m) override;
153 
157  void MultiplyMatrix(vtkMatrix3x3* m) override;
158 
162  void PushMatrix() override;
163 
167  void PopMatrix() override;
168 
172  void EnableClipping(bool enable) override;
173 
177  void SetClipping(int* x) override;
178 
182  void ApplyPen(vtkPen* pen) override;
183 
187  vtkPen* GetPen() override;
188 
192  void ApplyBrush(vtkBrush* brush) override;
193 
197  vtkBrush* GetBrush() override;
198 
202  void ApplyTextProp(vtkTextProperty* prop) override;
203 
207  vtkTextProperty* GetTextProp() override;
208 
212  void DrawPoly(float* points, int n, unsigned char* colors = nullptr, int nc_comps = 0) override;
213 
217  void DrawLines(float* f, int n, unsigned char* colors = nullptr, int nc_comps = 0) override;
218 
222  void DrawPoints(float* points, int n, unsigned char* colors = nullptr, int nc_comps = 0) override;
223 
227  void DrawPointSprites(vtkImageData* sprite, float* points, int n, unsigned char* colors = nullptr,
228  int nc_comps = 0) override;
229 
233  void DrawMarkers(int shape, bool highlight, float* points, int n, unsigned char* colors = nullptr,
234  int nc_comps = 0) override;
235 
239  void DrawEllipseWedge(float x, float y, float outRx, float outRy, float inRx, float inRy,
240  float startAngle, float stopAngle) override;
241 
245  void DrawEllipticArc(
246  float x, float y, float rX, float rY, float startAngle, float stopAngle) override;
247 
251  void ComputeStringBounds(const vtkStdString& string, float bounds[4]) override;
252 
256  void ComputeJustifiedStringBounds(const char* string, float bounds[4]) override;
257 
261  void Begin(vtkViewport*) override;
262 
266  void End() override;
267 
271  bool GetBufferIdMode() const override;
272 
276  void BufferIdModeBegin(vtkAbstractContextBufferId* bufferId) override;
277 
281  void BufferIdModeEnd() override;
282 
283 protected:
285  ~vtkBoundingRectContextDevice2D() override;
286 
291 
296 
301 
305  void AddPoint(float x, float y);
306  void AddPoint(float point[2]);
307 
311  void AddRect(const vtkRectf& rect);
312 
313 private:
315  void operator=(const vtkBoundingRectContextDevice2D&) = delete;
316 };
317 
318 #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()