1 /*========================================================================= 2 3 Program: Visualization Toolkit 4 Module: vtkSpiderPlotActor.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 vtkSpiderPlotActor - create a spider plot from input field 16 // .SECTION Description 17 // vtkSpiderPlotActor generates a spider plot from an input field (i.e., 18 // vtkDataObject). A spider plot represents N-dimensional data by using a set 19 // of N axes that originate from the center of a circle, and form the spokes 20 // of a wheel (like a spider web). Each N-dimensional point is plotted as a 21 // polyline that forms a closed polygon; the vertices of the polygon 22 // are plotted against the radial axes. 23 // 24 // To use this class, you must specify an input data object. You'll probably 25 // also want to specify the position of the plot be setting the Position and 26 // Position2 instance variables, which define a rectangle in which the plot 27 // lies. Another important parameter is the IndependentVariables ivar, which 28 // tells the instance how to interpret the field data (independent variables 29 // as the rows or columns of the field). There are also many other instance 30 // variables that control the look of the plot includes its title and legend. 31 // 32 // Set the text property/attributes of the title and the labels through the 33 // vtkTextProperty objects associated with these components. 34 35 // .SECTION Caveats 36 // Field data is not necessarily "rectangular" in shape. In these cases, some 37 // of the data may not be plotted. 38 // 39 // Field data can contain non-numeric arrays (i.e. arrays not subclasses of 40 // vtkDataArray). Such arrays are skipped. 41 // 42 // .SECTION See Also 43 // vtkParallelCoordinatesActor vtkXYPlotActor2D 44 45 #ifndef vtkSpiderPlotActor_h 46 #define vtkSpiderPlotActor_h 47 48 #include "vtkRenderingAnnotationModule.h" // For export macro 49 #include "vtkActor2D.h" 50 51 class vtkAlgorithmOutput; 52 class vtkAxisActor2D; 53 class vtkDataObject; 54 class vtkPolyData; 55 class vtkPolyDataMapper2D; 56 class vtkTextMapper; 57 class vtkTextProperty; 58 class vtkLegendBoxActor; 59 class vtkGlyphSource2D; 60 class vtkAxisLabelArray; 61 class vtkAxisRanges; 62 class vtkSpiderPlotActorConnection; 63 64 65 #define VTK_IV_COLUMN 0 66 #define VTK_IV_ROW 1 67 68 class VTKRENDERINGANNOTATION_EXPORT vtkSpiderPlotActor : public vtkActor2D 69 { 70 public: 71 // Description: 72 // Standard methods for type information and printing. 73 vtkTypeMacro(vtkSpiderPlotActor,vtkActor2D); 74 void PrintSelf(ostream& os, vtkIndent indent); 75 76 // Description: 77 // Instantiate this class. 78 static vtkSpiderPlotActor *New(); 79 80 // Description: 81 // Set the input to the pie chart actor. SetInputData() 82 // does not connect the pipeline whereas SetInputConnection() 83 // does. 84 virtual void SetInputData(vtkDataObject*); 85 virtual void SetInputConnection(vtkAlgorithmOutput*); 86 87 // Description: 88 // Get the input data object to this actor. 89 virtual vtkDataObject* GetInput(); 90 91 // Description: 92 // Specify whether to use the rows or columns as independent variables. 93 // If columns, then each row represents a separate point. If rows, then 94 // each column represents a separate point. 95 vtkSetClampMacro(IndependentVariables,int,VTK_IV_COLUMN, VTK_IV_ROW); 96 vtkGetMacro(IndependentVariables,int); SetIndependentVariablesToColumns()97 void SetIndependentVariablesToColumns() 98 {this->SetIndependentVariables(VTK_IV_COLUMN);}; SetIndependentVariablesToRows()99 void SetIndependentVariablesToRows() 100 {this->SetIndependentVariables(VTK_IV_ROW);}; 101 102 // Description: 103 // Enable/Disable the display of a plot title. 104 vtkSetMacro(TitleVisibility, int); 105 vtkGetMacro(TitleVisibility, int); 106 vtkBooleanMacro(TitleVisibility, int); 107 108 // Description: 109 // Set/Get the title of the spider plot. 110 vtkSetStringMacro(Title); 111 vtkGetStringMacro(Title); 112 113 // Description: 114 // Set/Get the title text property. 115 virtual void SetTitleTextProperty(vtkTextProperty *p); 116 vtkGetObjectMacro(TitleTextProperty,vtkTextProperty); 117 118 // Enable/Disable the display axes titles. These are arranged on the end 119 // of each radial axis on the circumference of the spider plot. The label 120 // text strings are derived from the names of the data object arrays 121 // associated with the input. 122 vtkSetMacro(LabelVisibility, int); 123 vtkGetMacro(LabelVisibility, int); 124 vtkBooleanMacro(LabelVisibility, int); 125 126 // Description: 127 // Enable/Disable the creation of a legend. If on, the legend labels will 128 // be created automatically unless the per plot legend symbol has been 129 // set. 130 virtual void SetLabelTextProperty(vtkTextProperty *p); 131 vtkGetObjectMacro(LabelTextProperty,vtkTextProperty); 132 133 // Description: 134 // Specify the number of circumferential rings. If set to zero, then 135 // none will be shown; otherwise the specified number will be shown. 136 vtkSetClampMacro(NumberOfRings,int,0,VTK_INT_MAX); 137 vtkGetMacro(NumberOfRings,int); 138 139 // Description: 140 // Specify the names of the radial spokes (i.e., the radial axes). If 141 // not specified, then an integer number is automatically generated. 142 void SetAxisLabel(const int i, const char *); 143 const char* GetAxisLabel(int i); 144 145 // Description: 146 // Specify the range of data on each radial axis. If not specified, 147 // then the range is computed automatically. 148 void SetAxisRange(int i, double min, double max); 149 void SetAxisRange(int i, double range[2]); 150 void GetAxisRange(int i, double range[2]); 151 152 // Description: 153 // Specify colors for each plot. If not specified, they are automatically generated. 154 void SetPlotColor(int i, double r, double g, double b); SetPlotColor(int i,const double color[3])155 void SetPlotColor(int i, const double color[3]) 156 { this->SetPlotColor(i, color[0], color[1], color[2]); } 157 double *GetPlotColor(int i); 158 159 // Description: 160 // Enable/Disable the creation of a legend. If on, the legend labels will 161 // be created automatically unless the per plot legend symbol has been 162 // set. 163 vtkSetMacro(LegendVisibility, int); 164 vtkGetMacro(LegendVisibility, int); 165 vtkBooleanMacro(LegendVisibility, int); 166 167 // Description: 168 // Retrieve handles to the legend box. This is useful if you would like 169 // to manually control the legend appearance. 170 vtkGetObjectMacro(LegendActor,vtkLegendBoxActor); 171 172 // Description: 173 // Draw the spider plot. 174 int RenderOverlay(vtkViewport*); 175 int RenderOpaqueGeometry(vtkViewport*); RenderTranslucentPolygonalGeometry(vtkViewport *)176 virtual int RenderTranslucentPolygonalGeometry(vtkViewport* ) {return 0;} 177 178 // Description: 179 // Does this prop have some translucent polygonal geometry? 180 virtual int HasTranslucentPolygonalGeometry(); 181 182 // Description: 183 // Release any graphics resources that are being consumed by this actor. 184 // The parameter window could be used to determine which graphic 185 // resources to release. 186 void ReleaseGraphicsResources(vtkWindow *); 187 188 protected: 189 vtkSpiderPlotActor(); 190 ~vtkSpiderPlotActor(); 191 192 private: 193 194 vtkSpiderPlotActorConnection* ConnectionHolder; 195 196 int IndependentVariables; // Use column or row 197 int TitleVisibility; // Should I see the title? 198 char *Title; // The title string 199 vtkTextProperty *TitleTextProperty; 200 int LabelVisibility; 201 vtkTextProperty *LabelTextProperty; 202 vtkAxisLabelArray *Labels; 203 int LegendVisibility; 204 vtkLegendBoxActor *LegendActor; 205 vtkGlyphSource2D *GlyphSource; 206 int NumberOfRings; 207 int AutomaticRangeComputation; 208 209 // Local variables needed to plot 210 vtkIdType N; // The number of independent variables 211 double *Mins; // Minimum data value along this row/column 212 double *Maxs; // Maximum data value along this row/column 213 vtkAxisRanges *Ranges; 214 215 vtkTextMapper **LabelMappers; //a label for each radial spoke 216 vtkActor2D **LabelActors; 217 218 vtkTextMapper *TitleMapper; 219 vtkActor2D *TitleActor; 220 221 vtkPolyData *WebData; // The web of the spider plot 222 vtkPolyDataMapper2D *WebMapper; 223 vtkActor2D *WebActor; 224 225 vtkPolyData *PlotData; // The lines drawn within the axes 226 vtkPolyDataMapper2D *PlotMapper; 227 vtkActor2D *PlotActor; 228 229 vtkTimeStamp BuildTime; 230 231 double Center[3]; 232 double Radius; 233 double Theta; 234 235 int LastPosition[2]; 236 int LastPosition2[2]; 237 double P1[3]; 238 double P2[3]; 239 240 void Initialize(); 241 int PlaceAxes(vtkViewport *viewport, int *size); 242 int BuildPlot(vtkViewport*); 243 244 private: 245 vtkSpiderPlotActor(const vtkSpiderPlotActor&); // Not implemented. 246 void operator=(const vtkSpiderPlotActor&); // Not implemented. 247 }; 248 249 250 #endif 251 252