vtkScatterPlotMatrix.h 11.9 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
/*=========================================================================

  Program:   Visualization Toolkit
  Module:    vtkScatterPlotMatrix.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 vtkScatterPlotMatrix - container for a matrix of charts.
//
// .SECTION Description
// This class contains a matrix of charts. These charts will be of type
// vtkChartXY by default, but this can be overridden. The class will manage
// their layout and object lifetime.

#ifndef __vtkScatterPlotMatrix_h
#define __vtkScatterPlotMatrix_h

#include "vtkChartMatrix.h"
#include "vtkSmartPointer.h" // For ivars
28
29
#include "vtkNew.h"          // For ivars
#include "vtkColor.h"        // For member function return
30
#include "vtkStdString.h"    // For ivars
31

32
class vtkStringArray;
33
class vtkTable;
34
class vtkAxis;
35
class vtkAnnotationLink;
36
class vtkTextProperty;
37
class vtkTooltipItem;
38
class vtkRenderWindowInteractor;
39
40
41
42

class VTK_CHARTS_EXPORT vtkScatterPlotMatrix : public vtkChartMatrix
{
public:
43
44
45
46
47
48
49
  enum {
    SCATTERPLOT,
    HISTOGRAM,
    ACTIVEPLOT,
    NOPLOT
  };

50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
  vtkTypeMacro(vtkScatterPlotMatrix, vtkChartMatrix);
  virtual void PrintSelf(ostream &os, vtkIndent indent);

  // Description:
  // Creates a new object.
  static vtkScatterPlotMatrix *New();

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

  // Description:
  // Paint event for the chart matrix.
  virtual bool Paint(vtkContext2D *painter);

65
66
67
68
69
70
71
72
73
74
  // Description:
  // Set the active plot, the one that will be displayed in the top-right.
  // This defaults to (0, n-2), the plot below the first histogram on the left.
  // \return false is the position specified is not valid.
  virtual bool SetActivePlot(const vtkVector2i& position);

  // Description:
  // Get the position of the active plot.
  virtual vtkVector2i GetActivePlot();

75
76
77
  // Description:
  // Get the active AnnotationLink from the big chart, which
  // is the only active AnnotationLink in the matrix.
78
79
80
81
82
83
84
  // @deprecated Replaced by GetAnnotationLink(), never in a VTK release.
  VTK_LEGACY(vtkAnnotationLink* GetActiveAnnotationLink());

  // Description:
  // Get the AnnotationLink for the scatter plot matrix, this gives you access
  // to the currently selected points in the scatter plot matrix.
  vtkAnnotationLink* GetAnnotationLink();
85

86
87
88
89
90
  // Description:
  // Set the input table for the scatter plot matrix. This will cause all
  // columns to be plotted against each other - a square scatter plot matrix.
  virtual void SetInput(vtkTable *table);

91
92
93
94
  // Description:
  // Set the visibility of the specified column.
  void SetColumnVisibility(const vtkStdString& name, bool visible);

95
96
97
98
99
  // Description:
  // Insert the specified column at the index position of
  // the visible columns.
  void InsertVisibleColumn(const vtkStdString& name, int index);

100
101
102
103
104
105
106
107
108
109
110
111
112
  // Description:
  // Get the visibility of the specified column.
  bool GetColumnVisibility(const vtkStdString& name);

  // Description:
  // Set the visibility of all columns (true will make them all visible, false
  // will remove all visible columns).
  void SetColumnVisibilityAll(bool visible);

  // Description:
  // Get a list of the columns, and the order in which they are displayed.
  virtual vtkStringArray* GetVisibleColumns();

113
114
115
116
  // Description:
  // Set the list of visible columns, and the order in which they will be displayed.
  virtual void SetVisibleColumns(vtkStringArray* visColumns);

117
118
119
120
121
122
123
124
125
126
  // Description:
  // Set the number of bins in the histograms along the central diagonal of the
  // scatter plot matrix.
  virtual void SetNumberOfBins(int numberOfBins);

  // Description:
  // Get the number of bins the histograms along the central diagonal scatter
  // plot matrix. The default value is 10.
  virtual int GetNumberOfBins() const { return this->NumberOfBins; }

127
  // Description:
128
129
  // Set the color for the specified plotType.
  void SetPlotColor(int plotType, const vtkColor4ub& color);
130
131

  // Description:
132
133
  // Sets the marker style for the specified plotType.
  void SetPlotMarkerStyle(int plotType, int style);
134
135

  // Description:
136
137
  // Sets the marker size for the specified plotType.
  void SetPlotMarkerSize(int plotType, float size);
138

139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
  // Description:
  // Return true if the supplied x, y coordinate is inside the item.
  bool Hit(const vtkContextMouseEvent &mouse);

  // Description:
  // Mouse move event.
  bool MouseMoveEvent(const vtkContextMouseEvent &mouse);

  // Description:
  // Mouse button down event
  bool MouseButtonPressEvent(const vtkContextMouseEvent &mouse);

  // Description:
  // Mouse button release event.
  bool MouseButtonReleaseEvent(const vtkContextMouseEvent &mouse);

155
156
157
158
159
160
  // Description:
  // Returns the type of the plot at the given position. The return
  // value is one of: SCATTERPLOT, HISTOGRAM, ACTIVEPLOT, or NOPLOT.
  int GetPlotType(const vtkVector2i &pos);
  int GetPlotType(int row, int column);

161
  // Description:
162
163
164
  // Set/get the scatter plot title.
  void SetTitle(const vtkStdString& title);
  vtkStdString GetTitle();
165
166

  // Description:
167
168
169
  // Set/get the text properties for the chart title, i.e. color, font, size.
  void SetTitleProperties(vtkTextProperty *prop);
  vtkTextProperty* GetTitleProperties();
170
171

  // Description:
172
173
  // Sets whether or not the grid for the given axis is visible given a plot
  // type, which refers to
174
175
176
177
178
179
180
  // vtkScatterPlotMatrix::{SCATTERPLOT, HISTOGRAM, ACTIVEPLOT}.
  void SetGridVisibility(int plotType, bool visible);
  bool GetGridVisibility(int plotType);

  // Description:
  // Sets the background color for the chart given a plot type, which refers to
  // vtkScatterPlotMatrix::{SCATTERPLOT, HISTOGRAM, ACTIVEPLOT}.
181
182
  void SetBackgroundColor(int plotType, const vtkColor4ub& color);
  vtkColor4ub GetBackgroundColor(int plotType);
183
184
185
186

  // Description:
  // Sets the color for the axes given a plot type, which refers to
  // vtkScatterPlotMatrix::{SCATTERPLOT, HISTOGRAM, ACTIVEPLOT}.
187
188
  void SetAxisColor(int plotType, const vtkColor4ub& color);
  vtkColor4ub GetAxisColor(int plotType);
189
190
191
192

  // Description:
  // Sets the color for the axes given a plot type, which refers to
  // vtkScatterPlotMatrix::{SCATTERPLOT, HISTOGRAM, ACTIVEPLOT}.
193
194
  void SetGridColor(int plotType, const vtkColor4ub& color);
  vtkColor4ub GetGridColor(int plotType);
195
196

  // Description:
197
198
  // Sets whether or not the labels for the axes are visible, given a plot type,
  // which refers to
199
200
201
202
203
  // vtkScatterPlotMatrix::{SCATTERPLOT, HISTOGRAM, ACTIVEPLOT}.
  void SetAxisLabelVisibility(int plotType, bool visible);
  bool GetAxisLabelVisibility(int plotType);

  // Description:
204
205
206
207
  // Set/get the text property for the axis labels of the given plot type,
  // possible types are vtkScatterPlotMatrix::{SCATTERPLOT, HISTOGRAM, ACTIVEPLOT}.
  void SetAxisLabelProperties(int plotType, vtkTextProperty *prop);
  vtkTextProperty* GetAxisLabelProperties(int plotType);
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228

  // Description:
  // Sets the axis label notation for the axes given a plot type, which refers to
  // vtkScatterPlotMatrix::{SCATTERPLOT, HISTOGRAM, ACTIVEPLOT}.
  void SetAxisLabelNotation(int plotType, int notation);
  int GetAxisLabelNotation(int plotType);

  // Description:
  // Sets the axis label precision for the axes given a plot type, which refers to
  // vtkScatterPlotMatrix::{SCATTERPLOT, HISTOGRAM, ACTIVEPLOT}.
  void SetAxisLabelPrecision(int plotType, int precision);
  int GetAxisLabelPrecision(int plotType);

  // Description:
  // Set chart's tooltip notation and precision, given a plot type, which refers to
  // vtkScatterPlotMatrix::{SCATTERPLOT, HISTOGRAM, ACTIVEPLOT}.
  void SetTooltipNotation(int plotType, int notation);
  void SetTooltipPrecision(int plotType, int precision);
  int GetTooltipNotation(int plotType);
  int GetTooltipPrecision(int plotType);

229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
  // Description:
  // Set the vtkTooltipItem object that will be displayed by the active chart.
  void SetTooltip(vtkTooltipItem *tooltip);

  // Description:
  // Get the vtkTooltipItem object that will be displayed by the active chart.
  vtkTooltipItem* GetTooltip() const;

  // Description:
  // Set indexed labels array.
  void SetIndexedLabels(vtkStringArray *labels);

  // Description:
  // Get the indexed labels array.
  vtkStringArray* GetIndexedLabels() const;

245
246
  // Description:
  // Set the scatter plot selected row/column charts' background color.
247
248
  void SetScatterPlotSelectedRowColumnColor(const vtkColor4ub& color);
  vtkColor4ub GetScatterPlotSelectedRowColumnColor();
249
250
251

  // Description:
  // Set the scatter plot selected active chart background color.
252
253
  void SetScatterPlotSelectedActiveColor(const vtkColor4ub& color);
  vtkColor4ub GetScatterPlotSelectedActiveColor();
254
255
256
257
258
259
260
261
262

  // Description:
  // Convenient method to update all the chart settings
  void UpdateSettings();

  // Description:
  // Update charts based on settings given the plot type
  void UpdateChartSettings(int plotType);

263
264
265
266
267
268
269
  // Description:
  // Set/get the Selection Mode that will be used by the chart while doing
  // selection. The only valid enums are vtkContextScene::SELECTION_NONE,
  // SELECTION_DEFAULT, SELECTION_ADDITION, SELECTION_SUBTRACTION, SELECTION_TOGGLE
  virtual void SetSelectionMode(int);
  vtkGetMacro(SelectionMode, int);

270
271
272
273
274
275
276
277
  // Description:
  // Get the column name for the supplied index.
  vtkStdString GetColumnName(int column);

  // Description:
  // Get the column name for the supplied index.
  vtkStdString GetRowName(int row);

278
279
280
281
protected:
  vtkScatterPlotMatrix();
  ~vtkScatterPlotMatrix();

282
283
284
285
  // Description:
  // Internal helper to do the layout of the charts in the scatter plot matrix.
  void UpdateLayout();

286
287
288
289
290
  // Description:
  // Attach axis range listener so we can forward to dependent axes in matrix.
  void AttachAxisRangeListener(vtkAxis*);
  void AxisRangeForwarderCallback(vtkObject*, unsigned long, void*);

291
292
293
294
295
  // Description:
  // The callback function when SelectionChangedEvent is invoked from
  // the Big chart. This class will just forward the event.
  void BigChartSelectionCallback(vtkObject*, unsigned long, void*);

296
297
298
299
300
301
302
303
304
305
306
  // Description:
  // Given a new position for the active plot, calculate a
  // an animation path from the old active plot to the new
  // active plot.
  virtual void UpdateAnimationPath(const vtkVector2i& newActivePos);

  // Description:
  // Given the render window interactor, start animation of the
  // animation path calculated above.
  virtual void StartAnimation(vtkRenderWindowInteractor* interactor);

307
308
309
310
311
312
313
314
315
  // Description:
  // Advance the animation in response to the timer events.
  virtual void AdvanceAnimation();

  // Description:
  // Process events and dispatch to the appropriate member functions.
  static void ProcessEvents(vtkObject *caller, unsigned long event,
                            void *clientData, void *callerData);

316
317
318
  // The position of the active plot (defaults to 0, 1).
  vtkVector2i ActivePlot;

319
  // Weakly owned input data for the scatter plot matrix.
320
  vtkSmartPointer<vtkTable> Input;
321

322
323
  // Strongly owned internal data for the column visibility.
  vtkNew<vtkStringArray> VisibleColumns;
324

325
326
327
  // The number of bins in the histograms.
  int NumberOfBins;

328
329
330
331
  // The title of the scatter plot matrix.
  vtkStdString Title;
  vtkSmartPointer<vtkTextProperty> TitleProperties;

332
333
334
  // The mode when the chart is doing selection.
  int SelectionMode;

335
336
337
private:
  vtkScatterPlotMatrix(const vtkScatterPlotMatrix &); // Not implemented.
  void operator=(const vtkScatterPlotMatrix &); // Not implemented.
338
339
340
341
342
343
344
345
346

  class PIMPL;
  PIMPL *Private;
  friend class PIMPL;

  // Go through the process of calculating axis ranges, etc...
  void UpdateAxes();
  void ApplyAxisSetting(vtkChart *chart, const vtkStdString &x,
                        const vtkStdString &y);
347
348
349
};

#endif //__vtkScatterPlotMatrix_h