1 /*========================================================================= 2 3 Program: Visualization Toolkit 4 Module: vtkLegendBoxActor.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 // .NAME vtkLegendBoxActor - draw symbols with text 16 // .SECTION Description 17 // vtkLegendBoxActor is used to associate a symbol with a text string. 18 // The user specifies a vtkPolyData to use as the symbol, and a string 19 // associated with the symbol. The actor can then be placed in the scene 20 // in the same way that any other vtkActor2D can be used. 21 // 22 // To use this class, you must define the position of the legend box by using 23 // the superclasses' vtkActor2D::Position coordinate and 24 // Position2 coordinate. Then define the set of symbols and text strings that 25 // make up the menu box. The font attributes of the entries can be set through 26 // the vtkTextProperty associated to this actor. The class will 27 // scale the symbols and text to fit in the legend box defined by 28 // (Position,Position2). Optional features like turning on a border line and 29 // setting the spacing between the border and the symbols/text can also be 30 // set. 31 32 // .SECTION See Also 33 // vtkXYPlotActor vtkActor2D vtkGlyphSource2D 34 35 #ifndef vtkLegendBoxActor_h 36 #define vtkLegendBoxActor_h 37 38 #include "vtkRenderingAnnotationModule.h" // For export macro 39 #include "vtkActor2D.h" 40 41 class vtkActor; 42 class vtkDoubleArray; 43 class vtkImageData; 44 class vtkPolyData; 45 class vtkPolyDataMapper2D; 46 class vtkPolyDataMapper; 47 class vtkPlaneSource; 48 class vtkTextMapper; 49 class vtkTextProperty; 50 class vtkTexturedActor2D; 51 class vtkTransform; 52 class vtkTransformPolyDataFilter; 53 class vtkProperty2D; 54 55 class VTKRENDERINGANNOTATION_EXPORT vtkLegendBoxActor : public vtkActor2D 56 { 57 public: 58 vtkTypeMacro(vtkLegendBoxActor,vtkActor2D); 59 void PrintSelf(ostream& os, vtkIndent indent); 60 61 // Description: 62 // Instantiate object with a rectangle in normaled view coordinates 63 // of (0.2,0.85, 0.8, 0.95). 64 static vtkLegendBoxActor *New(); 65 66 // Description: 67 // Specify the number of entries in the legend box. 68 void SetNumberOfEntries(int num); GetNumberOfEntries()69 int GetNumberOfEntries() 70 {return this->NumberOfEntries;} 71 72 // Description: 73 // Add an entry to the legend box. You must supply a vtkPolyData to be 74 // used as a symbol (it can be NULL) and a text string (which also can 75 // be NULL). The vtkPolyData is assumed to be defined in the x-y plane, 76 // and the text is assumed to be a single line in height. Note that when 77 // this method is invoked previous entries are deleted. Also supply a text 78 // string and optionally a color. (If a color is not specified, then the 79 // entry color is the same as this actor's color.) (Note: use the set 80 // methods when you use SetNumberOfEntries().) 81 void SetEntry(int i, vtkPolyData *symbol, const char* string, double color[3]); 82 void SetEntry(int i, vtkImageData *symbol, const char* string, double color[3]); 83 void SetEntry(int i, vtkPolyData *symbol, vtkImageData *icon, 84 const char* string, double color[3]); 85 86 void SetEntrySymbol (int i, vtkPolyData *symbol); 87 void SetEntryIcon (int i, vtkImageData *icon); 88 void SetEntryString (int i, const char* string); 89 void SetEntryColor (int i, double color[3]); 90 void SetEntryColor (int i, double r, double g, double b); 91 92 vtkPolyData* GetEntrySymbol(int i); 93 vtkImageData* GetEntryIcon(int i); 94 const char* GetEntryString(int i); 95 double* GetEntryColor(int i); 96 97 // Description: 98 // Set/Get the text property. 99 virtual void SetEntryTextProperty(vtkTextProperty *p); 100 vtkGetObjectMacro(EntryTextProperty,vtkTextProperty); 101 102 // Description: 103 // Set/Get the flag that controls whether a border will be drawn 104 // around the legend box. 105 vtkSetMacro(Border, int); 106 vtkGetMacro(Border, int); 107 vtkBooleanMacro(Border, int); 108 109 // Description: 110 // Set/Get the flag that controls whether the border and legend 111 // placement is locked into the rectangle defined by (Position,Position2). 112 // If off, then the legend box will adjust its size so that the border 113 // fits nicely around the text and symbols. (The ivar is off by default.) 114 // Note: the legend box is guaranteed to lie within the original border 115 // definition. 116 vtkSetMacro(LockBorder, int); 117 vtkGetMacro(LockBorder, int); 118 vtkBooleanMacro(LockBorder, int); 119 120 // Description: 121 // Set/Get the flag that controls whether a box will be drawn/filled 122 // corresponding to the legend box. 123 vtkSetMacro(Box, int); 124 vtkGetMacro(Box, int); 125 vtkBooleanMacro(Box, int); 126 127 // Description: 128 // Get the box vtkProperty2D. GetBoxProperty()129 vtkProperty2D* GetBoxProperty() { return this->BoxActor->GetProperty(); }; 130 131 // Description: 132 // Set/Get the padding between the legend entries and the border. The value 133 // is specified in pixels. 134 vtkSetClampMacro(Padding, int, 0, 50); 135 vtkGetMacro(Padding, int); 136 137 // Description: 138 // Turn on/off flag to control whether the symbol's scalar data 139 // is used to color the symbol. If off, the color of the 140 // vtkLegendBoxActor is used. 141 vtkSetMacro(ScalarVisibility,int); 142 vtkGetMacro(ScalarVisibility,int); 143 vtkBooleanMacro(ScalarVisibility,int); 144 145 // Description: 146 // Turn on/off background. 147 vtkSetMacro(UseBackground, int); 148 vtkGetMacro(UseBackground, int); 149 vtkBooleanMacro(UseBackground, int); 150 151 // Description: 152 // Set/Get background color. 153 // Default is: (0.3, 0.3, 0.3). 154 vtkSetVector3Macro(BackgroundColor, double); 155 vtkGetVector3Macro(BackgroundColor, double); 156 157 // Description: 158 // Set/Get background opacity. 159 // Default is: 1.0 160 vtkSetClampMacro(BackgroundOpacity, double, 0.0, 1.0); 161 vtkGetMacro(BackgroundOpacity, double); 162 163 // Description: 164 // Shallow copy of this scaled text actor. Overloads the virtual 165 // vtkProp method. 166 void ShallowCopy(vtkProp *prop); 167 168 //BTX 169 // Description: 170 // WARNING: INTERNAL METHOD - NOT INTENDED FOR GENERAL USE 171 // DO NOT USE THIS METHOD OUTSIDE OF THE RENDERING PROCESS. 172 // Release any graphics resources that are being consumed by this actor. 173 // The parameter window could be used to determine which graphic 174 // resources to release. 175 virtual void ReleaseGraphicsResources(vtkWindow *); 176 177 // Description: 178 // WARNING: INTERNAL METHOD - NOT INTENDED FOR GENERAL USE 179 // DO NOT USE THIS METHOD OUTSIDE OF THE RENDERING PROCESS. 180 // Draw the legend box to the screen. 181 int RenderOpaqueGeometry(vtkViewport* viewport); RenderTranslucentPolygonalGeometry(vtkViewport *)182 virtual int RenderTranslucentPolygonalGeometry(vtkViewport* ) {return 0;}; 183 int RenderOverlay(vtkViewport* viewport); 184 185 // Description: 186 // Does this prop have some translucent polygonal geometry? 187 virtual int HasTranslucentPolygonalGeometry(); 188 //ETX 189 190 protected: 191 vtkLegendBoxActor(); 192 ~vtkLegendBoxActor(); 193 194 void InitializeEntries(); 195 196 vtkPolyData createTexturedPlane(); 197 198 int Border; 199 int Box; 200 int Padding; 201 int LockBorder; 202 int ScalarVisibility; 203 double BoxOpacity; 204 205 // Internal actors, mappers, data to represent the legend 206 int NumberOfEntries; 207 int Size; //allocation size 208 vtkDoubleArray *Colors; 209 vtkTextMapper **TextMapper; 210 vtkActor2D **TextActor; 211 212 vtkPolyData **Symbol; 213 vtkTransform **Transform; 214 vtkTransformPolyDataFilter **SymbolTransform; 215 vtkPolyDataMapper2D **SymbolMapper; 216 vtkActor2D **SymbolActor; 217 218 vtkPlaneSource **Icon; 219 vtkTransform **IconTransform; 220 vtkTransformPolyDataFilter **IconTransformFilter; 221 vtkPolyDataMapper2D **IconMapper; 222 vtkTexturedActor2D **IconActor; 223 vtkImageData **IconImage; 224 225 vtkPolyData *BorderPolyData; 226 vtkPolyDataMapper2D *BorderMapper; 227 vtkActor2D *BorderActor; 228 vtkPolyData *BoxPolyData; 229 vtkPolyDataMapper2D *BoxMapper; 230 vtkActor2D *BoxActor; 231 vtkTextProperty *EntryTextProperty; 232 233 // Background plane. 234 int UseBackground; 235 double BackgroundOpacity; 236 double BackgroundColor[3]; 237 vtkPlaneSource *Background; 238 239 // May use texture. 240 vtkTexturedActor2D *BackgroundActor; 241 vtkPolyDataMapper2D *BackgroundMapper; 242 243 // Used to control whether the stuff is recomputed 244 int LegendEntriesVisible; 245 int CachedSize[2]; 246 vtkTimeStamp BuildTime; 247 248 private: 249 vtkLegendBoxActor(const vtkLegendBoxActor&); // Not implemented. 250 void operator=(const vtkLegendBoxActor&); // Not implemented. 251 }; 252 253 254 #endif 255 256