1 /*=========================================================================
2 
3   Program:   Visualization Toolkit
4   Module:    vtkQtTreeRingLabelMapper.h
5 
6   Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7   All rights reserved.
8   See Copyright.txt or http://www.kitware.com/Copyright.htm 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   Copyright 2008 Sandia Corporation.
17   Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
18   the U.S. Government retains certain rights in this software.
19 -------------------------------------------------------------------------*/
20 /**
21  * @class   vtkQtTreeRingLabelMapper
22  * @brief   draw text labels on a tree map
23  *
24  *
25  * vtkQtTreeRingLabelMapper is a mapper that renders text on a tree map.
26  * A tree map is a vtkTree with an associated 4-tuple array
27  * used for storing the boundary rectangle for each vertex in the tree.
28  * The user must specify the array name used for storing the rectangles.
29  *
30  * The mapper iterates through the tree and attempts and renders a label
31  * inside the vertex's rectangle as long as the following conditions hold:
32  * 1. The vertex level is within the range of levels specified for labeling.
33  * 2. The label can fully fit inside its box.
34  * 3. The label does not overlap an ancestor's label.
35  *
36  * @sa
37  * vtkLabeledDataMapper
38  *
39  * @par Thanks:
40  * Thanks to Jason Shepherd from
41  * Sandia National Laboratories for help in developing this class.
42  */
43 
44 #ifndef vtkQtTreeRingLabelMapper_h
45 #define vtkQtTreeRingLabelMapper_h
46 
47 #include "vtkDeprecation.h" // for deprecation macros
48 #include "vtkLabeledDataMapper.h"
49 #include "vtkRenderingQtModule.h" // For export macro
50 
51 class QImage;
52 
53 class vtkQImageToImageSource;
54 class vtkCoordinate;
55 class vtkDoubleArray;
56 class vtkPlaneSource;
57 class vtkPolyDataMapper2D;
58 class vtkRenderer;
59 class vtkStringArray;
60 class vtkTexture;
61 class vtkTextureMapToPlane;
62 class vtkTree;
63 class vtkUnicodeStringArray;
64 
65 class VTKRENDERINGQT_EXPORT vtkQtTreeRingLabelMapper : public vtkLabeledDataMapper
66 {
67 public:
68   static vtkQtTreeRingLabelMapper* New();
69   vtkTypeMacro(vtkQtTreeRingLabelMapper, vtkLabeledDataMapper);
70   void PrintSelf(ostream& os, vtkIndent indent) override;
71 
72   ///@{
73   /**
74    * Draw the text to the screen at each input point.
75    */
76   void RenderOpaqueGeometry(vtkViewport* viewport, vtkActor2D* actor) override;
77   void RenderOverlay(vtkViewport* viewport, vtkActor2D* actor) override;
78   ///@}
79 
80   /**
81    * The input to this filter.
82    */
83   virtual vtkTree* GetInputTree();
84 
85   /**
86    * The name of the 4-tuple array used for
87    */
88   virtual void SetSectorsArrayName(const char* name);
89 
90   ///@{
91   /**
92    * Set/Get the text property. Note that multiple type text properties
93    * (set with a second integer parameter) are not currently supported,
94    * but are provided to avoid compiler warnings.
95    */
96   void SetLabelTextProperty(vtkTextProperty* p) override;
GetLabelTextProperty()97   vtkTextProperty* GetLabelTextProperty() override { return this->LabelTextProperty; }
SetLabelTextProperty(vtkTextProperty * p,int type)98   void SetLabelTextProperty(vtkTextProperty* p, int type) override
99   {
100     this->Superclass::SetLabelTextProperty(p, type);
101   }
GetLabelTextProperty(int type)102   vtkTextProperty* GetLabelTextProperty(int type) override
103   {
104     return this->Superclass::GetLabelTextProperty(type);
105   }
106   ///@}
107 
108   ///@{
109   /**
110    * Set/Get the name of the text rotation array.
111    */
112   vtkSetStringMacro(TextRotationArrayName);
113   vtkGetStringMacro(TextRotationArrayName);
114   ///@}
115 
116   /**
117    * Return the object's MTime. This is overridden to include
118    * the timestamp of its internal class.
119    */
120   vtkMTimeType GetMTime() override;
121 
SetRenderer(vtkRenderer * ren)122   void SetRenderer(vtkRenderer* ren)
123   {
124     if (this->Renderer != ren)
125     {
126       this->Renderer = ren;
127       this->Modified();
128     }
129   }
GetRenderer()130   vtkRenderer* GetRenderer() { return this->Renderer; }
131 
132 protected:
133   vtkQtTreeRingLabelMapper();
134   ~vtkQtTreeRingLabelMapper() override;
135   void LabelTree(vtkTree* tree, vtkDataArray* sectorInfo, vtkDataArray* numericData,
136     vtkStringArray* stringData, int activeComp, int numComps, vtkViewport* viewport);
137   VTK_DEPRECATED_IN_9_1_0(
138     "Use void LabelTree(vtkTree* tree, vtkDataArray* sectorInfo, vtkDataArray* numericData, "
139     "vtkStringArray* stringData, int activeComp, int numComps, vtkViewport* viewport)")
140   void LabelTree(vtkTree* tree, vtkDataArray* sectorInfo, vtkDataArray* numericData,
141     vtkStringArray* stringData, vtkUnicodeStringArray* uStringData, int activeComp, int numComps,
142     vtkViewport* viewport);
143   void GetVertexLabel(vtkIdType vertex, vtkDataArray* numericData, vtkStringArray* stringData,
144     int activeComp, int numComps, char* string, size_t stringSize);
145   VTK_DEPRECATED_IN_9_1_0(
146     "Use void GetVertexLabel(vtkIdType vertex, vtkDataArray* numericData, vtkStringArray* "
147     "stringData, int activeComp, int numComps, char* string, size_t stringSize)")
148   void GetVertexLabel(vtkIdType vertex, vtkDataArray* numericData, vtkStringArray* stringData,
149     vtkUnicodeStringArray* uStringData, int activeComp, int numComps, char* string,
150     size_t stringSize);
151 
152   // Returns true if the center of the sector is in the window
153   // along with the pixel dimensions (width, height)  of the sector
154   bool PointInWindow(double* sinfo, double* newDim, double* textPosDC, vtkViewport* viewport);
155 
156   vtkViewport* CurrentViewPort;
157   vtkCoordinate* VCoord;
158   vtkQImageToImageSource* QtImageSource;
159   vtkPlaneSource* PlaneSource;
160   vtkRenderer* Renderer;
161   vtkTextProperty* LabelTextProperty;
162   vtkTexture* LabelTexture;
163   vtkTextureMapToPlane* TextureMapToPlane;
164   char* TextRotationArrayName;
165   vtkPolyDataMapper2D* polyDataMapper;
166   QImage* QtImage;
167   int WindowSize[2];
168 
169 private:
170   vtkQtTreeRingLabelMapper(const vtkQtTreeRingLabelMapper&) = delete;
171   void operator=(const vtkQtTreeRingLabelMapper&) = delete;
172 };
173 
174 #endif
175