1 /*========================================================================= 2 3 Program: Visualization Toolkit 4 Module: vtkPlotPoints.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 /** 17 * @class vtkPlotStacked 18 * @brief Class for drawing an stacked polygon plot 19 * given an X, Ybase, Yextent in a vtkTable. 20 * 21 * 22 * 23 */ 24 25 #ifndef vtkPlotStacked_h 26 #define vtkPlotStacked_h 27 28 #include "vtkChartsCoreModule.h" // For export macro 29 #include "vtkPlot.h" 30 31 class vtkChartXY; 32 class vtkContext2D; 33 class vtkTable; 34 class vtkPoints2D; 35 class vtkStdString; 36 class vtkImageData; 37 class vtkColorSeries; 38 39 class vtkPlotStackedPrivate; 40 41 class VTKCHARTSCORE_EXPORT vtkPlotStacked : public vtkPlot 42 { 43 public: 44 vtkTypeMacro(vtkPlotStacked, vtkPlot); 45 void PrintSelf(ostream& os, vtkIndent indent) override; 46 47 /** 48 * Creates a Stacked Plot Object 49 */ 50 static vtkPlotStacked* New(); 51 52 ///@{ 53 /** 54 * Set the plot color 55 */ 56 void SetColor(unsigned char r, unsigned char g, unsigned char b, unsigned char a) override; 57 void SetColor(double r, double g, double b) override; 58 void GetColor(double rgb[3]) override; 59 ///@} 60 61 /** 62 * Perform any updates to the item that may be necessary before rendering. 63 * The scene should take care of calling this on all items before their 64 * Paint function is invoked. 65 */ 66 void Update() override; 67 68 /** 69 * Paint event for the Stacked plot, called whenever the chart needs to be drawn 70 */ 71 bool Paint(vtkContext2D* painter) override; 72 73 /** 74 * Paint legend event for the Stacked plot, called whenever the legend needs the 75 * plot items symbol/mark/line drawn. A rect is supplied with the lower left 76 * corner of the rect (elements 0 and 1) and with width x height (elements 2 77 * and 3). The plot can choose how to fill the space supplied. 78 */ 79 bool PaintLegend(vtkContext2D* painter, const vtkRectf& rect, int legendIndex) override; 80 81 /** 82 * Get the bounds for this mapper as (Xmin,Xmax,Ymin,Ymax). 83 */ 84 void GetBounds(double bounds[4]) override; 85 86 /** 87 * Get the unscaled input bounds for this mapper as (Xmin,Xmax,Ymin,Ymax). 88 * See vtkPlot for more information. 89 */ 90 void GetUnscaledInputBounds(double bounds[4]) override; 91 92 /** 93 * When used to set additional arrays, stacked bars are created. 94 */ 95 void SetInputArray(int index, const vtkStdString& name) override; 96 97 /** 98 * Set the color series to use if this becomes a stacked bar plot. 99 */ 100 void SetColorSeries(vtkColorSeries* colorSeries); 101 102 /** 103 * Get the color series used if when this is a stacked bar plot. 104 */ 105 vtkColorSeries* GetColorSeries(); 106 107 /** 108 * Get the plot labels. 109 */ 110 vtkStringArray* GetLabels() override; 111 112 /** 113 * Function to query a plot for the nearest point to the specified coordinate. 114 * Returns the index of the data series with which the point is associated or 115 * -1. 116 */ 117 vtkIdType GetNearestPoint(const vtkVector2f& point, const vtkVector2f& tolerance, 118 vtkVector2f* location, vtkIdType* segmentId) override; 119 using vtkPlot::GetNearestPoint; 120 121 /** 122 * Select all points in the specified rectangle. 123 */ 124 bool SelectPoints(const vtkVector2f& min, const vtkVector2f& max) override; 125 126 protected: 127 vtkPlotStacked(); 128 ~vtkPlotStacked() override; 129 130 /** 131 * Update the table cache. 132 */ 133 bool UpdateTableCache(vtkTable* table); 134 135 // Descript: 136 // For stacked plots the Extent data must be greater than (or equal to) the 137 // base data. Ensure that this is true 138 void FixExtent(); 139 140 /** 141 * Handle calculating the log of the x or y series if necessary. Should be 142 * called by UpdateTableCache once the data has been updated in Points. 143 */ 144 void CalculateLogSeries(); 145 146 /** 147 * An array containing the indices of all the "bad base points", meaning any x, y 148 * pair that has an infinity, -infinity or not a number value. 149 */ 150 vtkIdTypeArray* BaseBadPoints; 151 152 /** 153 * An array containing the indices of all the "bad extent points", meaning any x, y 154 * pair that has an infinity, -infinity or not a number value. 155 */ 156 vtkIdTypeArray* ExtentBadPoints; 157 158 /** 159 * The point cache is marked dirty until it has been initialized. 160 */ 161 vtkTimeStamp BuildTime; 162 163 bool LogX, LogY; 164 165 /** 166 * The color series to use for each series. 167 */ 168 vtkSmartPointer<vtkColorSeries> ColorSeries; 169 170 private: 171 vtkPlotStacked(const vtkPlotStacked&) = delete; 172 void operator=(const vtkPlotStacked&) = delete; 173 174 vtkPlotStackedPrivate* Private; 175 }; 176 177 #endif // vtkPlotStacked_h 178