1 /*========================================================================= 2 3 Program: Visualization Toolkit 4 Module: vtkBarChartActor.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 * @class vtkBarChartActor 17 * @brief create a bar chart from an array 18 * 19 * vtkBarChartActor generates a bar chart from an array of numbers defined in 20 * field data (a vtkDataObject). To use this class, you must specify an input 21 * data object. You'll probably also want to specify the position of the plot 22 * be setting the Position and Position2 instance variables, which define a 23 * rectangle in which the plot lies. There are also many other instance 24 * variables that control the look of the plot includes its title and legend. 25 * 26 * Set the text property/attributes of the title and the labels through the 27 * vtkTextProperty objects associated with these components. 28 * 29 * @sa 30 * vtkParallelCoordinatesActor vtkXYPlotActor vtkSpiderPlotActor 31 * vtkPieChartActor 32 */ 33 34 #ifndef vtkBarChartActor_h 35 #define vtkBarChartActor_h 36 37 #include "vtkRenderingAnnotationModule.h" // For export macro 38 #include "vtkActor2D.h" 39 40 class vtkAxisActor2D; 41 class vtkDataObject; 42 class vtkPolyData; 43 class vtkPolyDataMapper2D; 44 class vtkTextMapper; 45 class vtkTextProperty; 46 class vtkLegendBoxActor; 47 class vtkGlyphSource2D; 48 class vtkBarLabelArray; 49 50 class VTKRENDERINGANNOTATION_EXPORT vtkBarChartActor : public vtkActor2D 51 { 52 public: 53 //@{ 54 /** 55 * Standard methods for type information and printing. 56 */ 57 vtkTypeMacro(vtkBarChartActor,vtkActor2D); 58 void PrintSelf(ostream& os, vtkIndent indent) override; 59 //@} 60 61 /** 62 * Instantiate this class. 63 */ 64 static vtkBarChartActor *New(); 65 66 /** 67 * Set the input to the bar chart actor. 68 */ 69 virtual void SetInput(vtkDataObject*); 70 71 //@{ 72 /** 73 * Get the input data object to this actor. 74 */ 75 vtkGetObjectMacro(Input,vtkDataObject); 76 //@} 77 78 //@{ 79 /** 80 * Enable/Disable the display of a plot title. 81 */ 82 vtkSetMacro(TitleVisibility, vtkTypeBool); 83 vtkGetMacro(TitleVisibility, vtkTypeBool); 84 vtkBooleanMacro(TitleVisibility, vtkTypeBool); 85 //@} 86 87 //@{ 88 /** 89 * Set/Get the title of the bar chart. 90 */ 91 vtkSetStringMacro(Title); 92 vtkGetStringMacro(Title); 93 //@} 94 95 //@{ 96 /** 97 * Set/Get the title text property. The property controls the 98 * appearance of the plot title. 99 */ 100 virtual void SetTitleTextProperty(vtkTextProperty *p); 101 vtkGetObjectMacro(TitleTextProperty,vtkTextProperty); 102 //@} 103 104 //@{ 105 /** 106 * Enable/Disable the display of bar labels. 107 */ 108 vtkSetMacro(LabelVisibility, vtkTypeBool); 109 vtkGetMacro(LabelVisibility, vtkTypeBool); 110 vtkBooleanMacro(LabelVisibility, vtkTypeBool); 111 //@} 112 113 //@{ 114 /** 115 * Set/Get the labels text property. This controls the appearance 116 * of all bar bar labels. 117 */ 118 virtual void SetLabelTextProperty(vtkTextProperty *p); 119 vtkGetObjectMacro(LabelTextProperty,vtkTextProperty); 120 //@} 121 122 //@{ 123 /** 124 * Specify colors for each bar. If not specified, they are 125 * automatically generated. 126 */ 127 void SetBarColor(int i, double r, double g, double b); SetBarColor(int i,const double color[3])128 void SetBarColor(int i, const double color[3]) 129 { this->SetBarColor(i, color[0], color[1], color[2]); } 130 double *GetBarColor(int i); 131 //@} 132 133 //@{ 134 /** 135 * Specify the names of each bar. If 136 * not specified, then an integer number is automatically generated. 137 */ 138 void SetBarLabel(const int i, const char *); 139 const char* GetBarLabel(int i); 140 //@} 141 142 //@{ 143 /** 144 * Specify the title of the y-axis. 145 */ 146 vtkSetStringMacro(YTitle); 147 vtkGetStringMacro(YTitle); 148 //@} 149 150 //@{ 151 /** 152 * Enable/Disable the creation of a legend. If on, the legend labels will 153 * be created automatically unless the per plot legend symbol has been 154 * set. 155 */ 156 vtkSetMacro(LegendVisibility, vtkTypeBool); 157 vtkGetMacro(LegendVisibility, vtkTypeBool); 158 vtkBooleanMacro(LegendVisibility, vtkTypeBool); 159 //@} 160 161 //@{ 162 /** 163 * Retrieve handles to the legend box. This is useful if you would like 164 * to manually control the legend appearance. 165 */ 166 vtkGetObjectMacro(LegendActor,vtkLegendBoxActor); 167 //@} 168 169 //@{ 170 /** 171 * Draw the bar plot. 172 */ 173 int RenderOverlay(vtkViewport*) override; 174 int RenderOpaqueGeometry(vtkViewport*) override; RenderTranslucentPolygonalGeometry(vtkViewport *)175 int RenderTranslucentPolygonalGeometry(vtkViewport* ) override {return 0;} 176 //@} 177 178 /** 179 * Does this prop have some translucent polygonal geometry? 180 */ 181 vtkTypeBool HasTranslucentPolygonalGeometry() override; 182 183 /** 184 * Release any graphics resources that are being consumed by this actor. 185 * The parameter window could be used to determine which graphic 186 * resources to release. 187 */ 188 void ReleaseGraphicsResources(vtkWindow *) override; 189 190 protected: 191 vtkBarChartActor(); 192 ~vtkBarChartActor() override; 193 194 private: 195 vtkDataObject *Input; // List of data sets to plot 196 vtkIdType ArrayNumber; 197 vtkIdType ComponentNumber; 198 vtkTypeBool TitleVisibility; // Should I see the title? 199 char *Title; // The title string 200 vtkTextProperty *TitleTextProperty; 201 vtkTypeBool LabelVisibility; 202 vtkTextProperty *LabelTextProperty; 203 vtkBarLabelArray *Labels; 204 vtkTypeBool LegendVisibility; 205 vtkLegendBoxActor *LegendActor; 206 vtkGlyphSource2D *GlyphSource; 207 208 // Local variables needed to plot 209 vtkIdType N; // The number of values 210 double *Heights; // The heights of each bar 211 double MinHeight; //The maximum and minimum height 212 double MaxHeight; 213 double LowerLeft[2]; 214 double UpperRight[2]; 215 216 vtkTextMapper **BarMappers; //a label for each bar 217 vtkActor2D **BarActors; 218 219 vtkTextMapper *TitleMapper; 220 vtkActor2D *TitleActor; 221 222 vtkPolyData *PlotData; // The actual bars plus the x-axis 223 vtkPolyDataMapper2D *PlotMapper; 224 vtkActor2D *PlotActor; 225 226 vtkAxisActor2D *YAxis; //The y-axis 227 char *YTitle; 228 229 vtkTimeStamp BuildTime; 230 231 int LastPosition[2]; 232 int LastPosition2[2]; 233 double P1[3]; 234 double P2[3]; 235 236 void Initialize(); 237 int PlaceAxes(vtkViewport *viewport, int *size); 238 int BuildPlot(vtkViewport*); 239 240 private: 241 vtkBarChartActor(const vtkBarChartActor&) = delete; 242 void operator=(const vtkBarChartActor&) = delete; 243 }; 244 245 246 #endif 247 248