vtkPlotBar.h 7.58 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
/*=========================================================================

  Program:   Visualization Toolkit
  Module:    vtkPlotBar.h

  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
  All rights reserved.
  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.

     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
     PURPOSE.  See the above copyright notice for more information.

=========================================================================*/

// .NAME vtkPlotBar - Class for drawing an XY plot given two columns from a
// vtkTable.
//
// .SECTION Description
//

22 23
#ifndef vtkPlotBar_h
#define vtkPlotBar_h
24

25
#include "vtkChartsCoreModule.h" // For export macro
26
#include "vtkPlot.h"
Keith Fieldhouse's avatar
Keith Fieldhouse committed
27
#include "vtkSmartPointer.h" // Needed to hold ColorSeries
28 29 30 31 32

class vtkContext2D;
class vtkTable;
class vtkPoints2D;
class vtkStdString;
Keith Fieldhouse's avatar
Keith Fieldhouse committed
33
class vtkColorSeries;
34 35
class vtkUnsignedCharArray;
class vtkScalarsToColors;
Keith Fieldhouse's avatar
Keith Fieldhouse committed
36 37

class vtkPlotBarPrivate;
38

39
class VTKCHARTSCORE_EXPORT vtkPlotBar : public vtkPlot
40 41
{
public:
42
  vtkTypeMacro(vtkPlotBar, vtkPlot);
43 44
  virtual void PrintSelf(ostream &os, vtkIndent indent);

45 46 47 48 49 50 51
  // Description:
  // Enum of bar chart oritentation types
  enum {
    VERTICAL = 0,
    HORIZONTAL
  };

52 53 54 55
  // Description:
  // Creates a 2D Chart object.
  static vtkPlotBar *New();

56 57 58 59
  // Description:
  // Perform any updates to the item that may be necessary before rendering.
  virtual void Update();

60 61 62 63 64 65 66 67 68
  // Description:
  // Paint event for the XY plot, called whenever the chart needs to be drawn
  virtual bool Paint(vtkContext2D *painter);

  // Description:
  // Paint legend event for the XY plot, called whenever the legend needs the
  // plot items symbol/mark/line drawn. A rect is supplied with the lower left
  // corner of the rect (elements 0 and 1) and with width x height (elements 2
  // and 3). The plot can choose how to fill the space supplied.
69 70
  virtual bool PaintLegend(vtkContext2D *painter, const vtkRectf& rect,
                           int legendIndex);
71 72 73 74 75 76 77 78 79 80

  // Description:
  // Set the plot color
  virtual void SetColor(unsigned char r, unsigned char g, unsigned char b,
                        unsigned char a);
  virtual void SetColor(double r,  double g, double b);
  virtual void GetColor(double rgb[3]);

  // Description:
  // Set the width of the line.
81
  vtkSetMacro(Width, float);
82 83 84

  // Description:
  // Get the width of the line.
85
  vtkGetMacro(Width, float);
86

87 88 89 90 91
  // Description:
  // Set/get the horizontal offset of the bars.
  // Positive values move the bars leftward.
  // For HORIZONTAL orientation, offsets bars vertically,
  // with a positive value moving bars downward.
92 93 94
  vtkSetMacro(Offset, float);
  vtkGetMacro(Offset, float);

95 96 97 98 99 100
  // Description:
  // Set/get the orientation of the bars.
  // Valid orientations are VERTICAL (default) and HORIZONTAL.
  virtual void SetOrientation(int orientation);
  vtkGetMacro(Orientation, int);

101 102 103 104
  // Description:
  // A helper used by both GetUnscaledBounds and GetBounds(double[4]).
  virtual void GetBounds(double bounds[4], bool unscaled);

105
  // Description:
Keith Fieldhouse's avatar
Keith Fieldhouse committed
106
  // Get the bounds for this mapper as (Xmin,Xmax,Ymin,Ymax).
107 108
  virtual void GetBounds(double bounds[4]);

109 110 111 112
  // Description:
  // Get un-log-scaled bounds for this mapper as (Xmin,Xmax,Ymin,Ymax).
  virtual void GetUnscaledInputBounds(double bounds[4]);

Keith Fieldhouse's avatar
Keith Fieldhouse committed
113 114
  // Description:
  // When used to set additional arrays, stacked bars are created.
115
  virtual void SetInputArray(int index, const vtkStdString &name);
Keith Fieldhouse's avatar
Keith Fieldhouse committed
116 117 118 119 120 121 122 123 124

  // Description:
  // Set the color series to use if this becomes a stacked bar plot.
  void SetColorSeries(vtkColorSeries *colorSeries);

  // Description:
  // Get the color series used if when this is a stacked bar plot.
  vtkColorSeries *GetColorSeries();

125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151
  // Description:
  // Specify a lookup table for the mapper to use.
  virtual void SetLookupTable(vtkScalarsToColors *lut);
  virtual vtkScalarsToColors *GetLookupTable();

  // Description:
  // Create default lookup table. Generally used to create one when none
  // is available with the scalar data.
  virtual void CreateDefaultLookupTable();

  // Description:
  // Turn on/off flag to control whether scalar data is used to color objects.
  vtkSetMacro(ScalarVisibility, bool);
  vtkGetMacro(ScalarVisibility, bool);
  vtkBooleanMacro(ScalarVisibility, bool);

  // Description:
  // When ScalarMode is set to UsePointFieldData or UseCellFieldData,
  // you can specify which array to use for coloring using these methods.
  // The lookup table will decide how to convert vectors to colors.
  void SelectColorArray(vtkIdType arrayNum);
  void SelectColorArray(const vtkStdString& arrayName);

  // Description:
  // Get the array name to color by.
  vtkStdString GetColorArrayName();

Keith Fieldhouse's avatar
Keith Fieldhouse committed
152 153 154 155
  // Description
  // Get the plot labels.
  virtual vtkStringArray *GetLabels();

156 157 158 159 160 161
  // Description:
  // Set the group name of the bar chart - can be displayed on the X axis.
  virtual void SetGroupName(const vtkStdString& name);

  // Description:
  // Get the group name of the bar char - can be displayed on the X axis.
162
  virtual vtkStdString GetGroupName();
163

164 165 166
  // Description:
  // Generate and return the tooltip label string for this plot
  // The segmentIndex is implemented here.
167
  virtual vtkStdString GetTooltipLabel(const vtkVector2d &plotPos,
168 169 170
                                       vtkIdType seriesIndex,
                                       vtkIdType segmentIndex);

171 172 173 174
  // Description:
  // Select all points in the specified rectangle.
  virtual bool SelectPoints(const vtkVector2f& min, const vtkVector2f& max);

Keith Fieldhouse's avatar
Keith Fieldhouse committed
175 176
  // Description:
  // Function to query a plot for the nearest point to the specified coordinate.
177
  // Returns the index of the data series with which the point is associated or
Keith Fieldhouse's avatar
Keith Fieldhouse committed
178
  // -1.
179 180 181
  virtual vtkIdType GetNearestPoint(const vtkVector2f& point,
                                    const vtkVector2f& tolerance,
                                    vtkVector2f* location);
182 183 184 185 186 187 188

  // Description:
  // Function to query a plot for the nearest point to the specified coordinate.
  // Returns the index of the data series with which the point is associated or
  // -1.
  // If a vtkIdType* is passed, its referent will be set to index of the bar
  // segment with which a point is associated, or -1.
189 190 191 192
  virtual vtkIdType GetNearestPoint(const vtkVector2f& point,
                                    const vtkVector2f&,
                                    vtkVector2f* location,
                                    vtkIdType* segmentIndex);
193

194 195 196 197 198 199 200 201
  // Description:
  // Get amount of plotted bars.
  int GetBarsCount();

  // Description:
  // Get the data bounds for this mapper as (Xmin,Xmax).
  void GetDataBounds(double bounds[2]);

202 203 204 205 206 207 208 209 210 211 212 213 214
protected:
  vtkPlotBar();
  ~vtkPlotBar();

  // Description:
  // Update the table cache.
  bool UpdateTableCache(vtkTable *table);

  // Description:
  // Store a well packed set of XY coordinates for this data series.
  vtkPoints2D *Points;

  float Width;
215
  float Offset;
216

217 218
  int Orientation;

219 220 221 222
  // Description:
  // The point cache is marked dirty until it has been initialized.
  vtkTimeStamp BuildTime;

Keith Fieldhouse's avatar
Keith Fieldhouse committed
223 224 225 226
  // Description:
  // The color series to use if this becomes a stacked bar
  vtkSmartPointer<vtkColorSeries> ColorSeries;

227 228 229 230 231 232 233 234 235 236
  // Description:
  // Lookup Table for coloring bars by scalar value
  vtkSmartPointer<vtkScalarsToColors> LookupTable;
  vtkSmartPointer<vtkUnsignedCharArray> Colors;
  bool ScalarVisibility;
  vtkStdString ColorArrayName;

  bool LogX;
  bool LogY;

237
private:
238
  vtkPlotBar(const vtkPlotBar &) VTK_DELETE_FUNCTION;
239
  void operator=(const vtkPlotBar &) VTK_DELETE_FUNCTION;
240

Keith Fieldhouse's avatar
Keith Fieldhouse committed
241 242
  vtkPlotBarPrivate *Private;

243 244
};

245
#endif //vtkPlotBar_h