vtkScatterPlotMatrix.h 13.9 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
/*=========================================================================

  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.

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

16 17 18 19 20 21 22 23 24
/**
 * @class   vtkScatterPlotMatrix
 * @brief   container for a matrix of charts.
 *
 *
 * 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.
*/
25

26 27
#ifndef vtkScatterPlotMatrix_h
#define vtkScatterPlotMatrix_h
28

29
#include "vtkChartsCoreModule.h" // For export macro
30 31
#include "vtkChartMatrix.h"
#include "vtkSmartPointer.h" // For ivars
32 33
#include "vtkNew.h"          // For ivars
#include "vtkColor.h"        // For member function return
34
#include "vtkStdString.h"    // For ivars
35
#include "vtkWeakPointer.h"  // For currentPainter
36

37
class vtkStringArray;
38
class vtkTable;
39
class vtkAxis;
40
class vtkAnnotationLink;
41
class vtkTextProperty;
42
class vtkTooltipItem;
43
class vtkRenderWindowInteractor;
44

45
class VTKCHARTSCORE_EXPORT vtkScatterPlotMatrix : public vtkChartMatrix
46 47
{
public:
48 49 50 51 52 53 54
  enum {
    SCATTERPLOT,
    HISTOGRAM,
    ACTIVEPLOT,
    NOPLOT
  };

55
  vtkTypeMacro(vtkScatterPlotMatrix, vtkChartMatrix);
56
  void PrintSelf(ostream &os, vtkIndent indent) override;
57

58 59 60
  /**
   * Creates a new object.
   */
61 62
  static vtkScatterPlotMatrix *New();

63 64 65
  /**
   * Perform any updates to the item that may be necessary before rendering.
   */
66
  void Update() override;
67

68 69 70
  /**
   * Paint event for the chart matrix.
   */
71
  bool Paint(vtkContext2D *painter) override;
72

73
  void SetScene(vtkContextScene *scene) override;
74

75 76 77 78 79
  /**
   * 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.
   */
80 81
  virtual bool SetActivePlot(const vtkVector2i& position);

82 83 84
  /**
   * Reset ActivePlotSet flag and call superclass method
   */
85
  void SetSize(const vtkVector2i& size) override;
86

87 88 89
  /**
   * Get the position of the active plot.
   */
90 91
  virtual vtkVector2i GetActivePlot();

92 93 94 95
  /**
   * Get the AnnotationLink for the scatter plot matrix, this gives you access
   * to the currently selected points in the scatter plot matrix.
   */
96
  vtkAnnotationLink* GetAnnotationLink();
97

98 99 100 101
  /**
   * 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.
   */
102 103
  virtual void SetInput(vtkTable *table);

104 105 106
  /**
   * Set the visibility of the specified column.
   */
107 108
  void SetColumnVisibility(const vtkStdString& name, bool visible);

109 110 111 112
  /**
   * Insert the specified column at the index position of
   * the visible columns.
   */
113 114
  void InsertVisibleColumn(const vtkStdString& name, int index);

115 116 117
  /**
   * Get the visibility of the specified column.
   */
118 119
  bool GetColumnVisibility(const vtkStdString& name);

120 121 122 123
  /**
   * Set the visibility of all columns (true will make them all visible, false
   * will remove all visible columns).
   */
124 125
  void SetColumnVisibilityAll(bool visible);

126 127 128
  /**
   * Get a list of the columns, and the order in which they are displayed.
   */
129 130
  virtual vtkStringArray* GetVisibleColumns();

131 132 133
  /**
   * Set the list of visible columns, and the order in which they will be displayed.
   */
134 135
  virtual void SetVisibleColumns(vtkStringArray* visColumns);

136 137 138 139
  /**
   * Set the number of bins in the histograms along the central diagonal of the
   * scatter plot matrix.
   */
140 141
  virtual void SetNumberOfBins(int numberOfBins);

142 143 144 145
  /**
   * Get the number of bins the histograms along the central diagonal scatter
   * plot matrix. The default value is 10.
   */
146 147
  virtual int GetNumberOfBins() const { return this->NumberOfBins; }

148 149 150
  /**
   * Set the color for the specified plotType.
   */
151
  void SetPlotColor(int plotType, const vtkColor4ub& color);
152

153 154 155
  /**
   * Sets the marker style for the specified plotType.
   */
156
  void SetPlotMarkerStyle(int plotType, int style);
157

158 159 160
  /**
   * Sets the marker size for the specified plotType.
   */
161
  void SetPlotMarkerSize(int plotType, float size);
162

163 164 165
  /**
   * Return true if the supplied x, y coordinate is inside the item.
   */
166
  bool Hit(const vtkContextMouseEvent &mouse) override;
167

168 169 170
  /**
   * Mouse move event.
   */
171
  bool MouseMoveEvent(const vtkContextMouseEvent &mouse) override;
172

173 174 175
  /**
   * Mouse button down event
   */
176
  bool MouseButtonPressEvent(const vtkContextMouseEvent &mouse) override;
177

178 179 180
  /**
   * Mouse button release event.
   */
181
  bool MouseButtonReleaseEvent(const vtkContextMouseEvent &mouse) override;
182

183 184 185 186 187
  //@{
  /**
   * Returns the type of the plot at the given position. The return
   * value is one of: SCATTERPLOT, HISTOGRAM, ACTIVEPLOT, or NOPLOT.
   */
188 189
  int GetPlotType(const vtkVector2i &pos);
  int GetPlotType(int row, int column);
190
  //@}
191

192 193 194 195
  //@{
  /**
   * Set/get the scatter plot title.
   */
196 197
  void SetTitle(const vtkStdString& title);
  vtkStdString GetTitle();
198
  //@}
199

200 201 202 203
  //@{
  /**
   * Set/get the text properties for the chart title, i.e. color, font, size.
   */
204 205
  void SetTitleProperties(vtkTextProperty *prop);
  vtkTextProperty* GetTitleProperties();
206 207 208 209 210 211 212 213
  //@}

  //@{
  /**
   * Sets whether or not the grid for the given axis is visible given a plot
   * type, which refers to
   * vtkScatterPlotMatrix::{SCATTERPLOT, HISTOGRAM, ACTIVEPLOT}.
   */
214 215
  void SetGridVisibility(int plotType, bool visible);
  bool GetGridVisibility(int plotType);
216
  //@}
217

218 219 220 221 222
  //@{
  /**
   * Sets the background color for the chart given a plot type, which refers to
   * vtkScatterPlotMatrix::{SCATTERPLOT, HISTOGRAM, ACTIVEPLOT}.
   */
223 224
  void SetBackgroundColor(int plotType, const vtkColor4ub& color);
  vtkColor4ub GetBackgroundColor(int plotType);
225
  //@}
226

227 228 229 230 231
  //@{
  /**
   * Sets the color for the axes given a plot type, which refers to
   * vtkScatterPlotMatrix::{SCATTERPLOT, HISTOGRAM, ACTIVEPLOT}.
   */
232 233
  void SetAxisColor(int plotType, const vtkColor4ub& color);
  vtkColor4ub GetAxisColor(int plotType);
234
  //@}
235

236 237 238 239 240
  //@{
  /**
   * Sets the color for the axes given a plot type, which refers to
   * vtkScatterPlotMatrix::{SCATTERPLOT, HISTOGRAM, ACTIVEPLOT}.
   */
241 242
  void SetGridColor(int plotType, const vtkColor4ub& color);
  vtkColor4ub GetGridColor(int plotType);
243 244 245 246 247 248 249 250
  //@}

  //@{
  /**
   * Sets whether or not the labels for the axes are visible, given a plot type,
   * which refers to
   * vtkScatterPlotMatrix::{SCATTERPLOT, HISTOGRAM, ACTIVEPLOT}.
   */
251 252
  void SetAxisLabelVisibility(int plotType, bool visible);
  bool GetAxisLabelVisibility(int plotType);
253
  //@}
254

255 256 257 258 259
  //@{
  /**
   * Set/get the text property for the axis labels of the given plot type,
   * possible types are vtkScatterPlotMatrix::{SCATTERPLOT, HISTOGRAM, ACTIVEPLOT}.
   */
260 261
  void SetAxisLabelProperties(int plotType, vtkTextProperty *prop);
  vtkTextProperty* GetAxisLabelProperties(int plotType);
262
  //@}
263

264 265 266 267 268
  //@{
  /**
   * Sets the axis label notation for the axes given a plot type, which refers to
   * vtkScatterPlotMatrix::{SCATTERPLOT, HISTOGRAM, ACTIVEPLOT}.
   */
269 270
  void SetAxisLabelNotation(int plotType, int notation);
  int GetAxisLabelNotation(int plotType);
271
  //@}
272

273 274 275 276 277
  //@{
  /**
   * Sets the axis label precision for the axes given a plot type, which refers to
   * vtkScatterPlotMatrix::{SCATTERPLOT, HISTOGRAM, ACTIVEPLOT}.
   */
278 279
  void SetAxisLabelPrecision(int plotType, int precision);
  int GetAxisLabelPrecision(int plotType);
280
  //@}
281

282 283 284 285 286
  //@{
  /**
   * Set chart's tooltip notation and precision, given a plot type, which refers to
   * vtkScatterPlotMatrix::{SCATTERPLOT, HISTOGRAM, ACTIVEPLOT}.
   */
287 288 289 290
  void SetTooltipNotation(int plotType, int notation);
  void SetTooltipPrecision(int plotType, int precision);
  int GetTooltipNotation(int plotType);
  int GetTooltipPrecision(int plotType);
291
  //@}
292

293 294 295
  /**
   * Set the vtkTooltipItem object that will be displayed by the active chart.
   */
296 297
  void SetTooltip(vtkTooltipItem *tooltip);

298 299 300
  /**
   * Get the vtkTooltipItem object that will be displayed by the active chart.
   */
301 302
  vtkTooltipItem* GetTooltip() const;

303 304 305
  /**
   * Set indexed labels array.
   */
306 307
  void SetIndexedLabels(vtkStringArray *labels);

308 309 310
  /**
   * Get the indexed labels array.
   */
311 312
  vtkStringArray* GetIndexedLabels() const;

313 314 315 316
  //@{
  /**
   * Set the scatter plot selected row/column charts' background color.
   */
317 318
  void SetScatterPlotSelectedRowColumnColor(const vtkColor4ub& color);
  vtkColor4ub GetScatterPlotSelectedRowColumnColor();
319
  //@}
320

321 322 323 324
  //@{
  /**
   * Set the scatter plot selected active chart background color.
   */
325 326
  void SetScatterPlotSelectedActiveColor(const vtkColor4ub& color);
  vtkColor4ub GetScatterPlotSelectedActiveColor();
327
  //@}
328

329 330 331
  /**
   * Convenient method to update all the chart settings
   */
332 333
  void UpdateSettings();

334 335 336
  /**
   * Update charts based on settings given the plot type
   */
337 338
  void UpdateChartSettings(int plotType);

339 340 341 342 343 344
  //@{
  /**
   * 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
   */
345 346
  virtual void SetSelectionMode(int);
  vtkGetMacro(SelectionMode, int);
347
  //@}
348

349 350 351
  /**
   * Get the column name for the supplied index.
   */
352 353
  vtkStdString GetColumnName(int column);

354 355 356
  /**
   * Get the column name for the supplied index.
   */
357 358
  vtkStdString GetRowName(int row);

359 360 361 362
  /**
   * Set the number of animation frames in each transition. Default is 25,
   * and 0 means to animations between axes.
   */
363 364
  void SetNumberOfFrames(int frames);

365 366 367 368
  /**
   * Get the number of animation frames in each transition. Default is 25,
   * and 0 means to animations between axes.
   */
369 370
  int GetNumberOfFrames();

371 372 373
  /**
   * Clear the animation path.
   */
374 375
  void ClearAnimationPath();

376 377 378 379 380
  /**
   * Add a move to the animation path. Note that a move can only change i or j,
   * not both. If the proposed move does not satisfy those criteria it will
   * be rejected and the animation path will not be extended.
   */
381 382
  bool AddAnimationPath(const vtkVector2i &move);

383 384 385
  /**
   * Get the number of elements (transitions) in the animation path.
   */
386 387
  vtkIdType GetNumberOfAnimationPathElements();

388 389 390
  /**
   * Get the element specified from the animation path.
   */
391 392
  vtkVector2i GetAnimationPathElement(vtkIdType i);

393 394 395
  /**
   * Trigger the animation of the scatter plot matrix to begin.
   */
396 397
  bool BeginAnimationPath(vtkRenderWindowInteractor* interactor);

398 399 400 401
  /**
   * Advance the animation in response to the timer events. This is public to
   * allow the animation to be manually advanced when timers are not a
   */
402 403
  virtual void AdvanceAnimation();

404 405 406
  /**
   * Get the main plot (the one in the top-right of the matrix.
   */
407 408
  virtual vtkChart * GetMainChart();

409 410
protected:
  vtkScatterPlotMatrix();
411
  ~vtkScatterPlotMatrix() override;
412

413 414 415
  /**
   * Internal helper to do the layout of the charts in the scatter plot matrix.
   */
416 417
  void UpdateLayout();

418 419 420 421 422
  /**
   * Compute and set big chart resize
   */
  void ResizeBigChart();

423 424 425 426
  //@{
  /**
   * Attach axis range listener so we can forward to dependent axes in matrix.
   */
427 428
  void AttachAxisRangeListener(vtkAxis*);
  void AxisRangeForwarderCallback(vtkObject*, unsigned long, void*);
429
  //@}
430

431 432 433 434
  /**
   * The callback function when SelectionChangedEvent is invoked from
   * the Big chart. This class will just forward the event.
   */
435 436
  void BigChartSelectionCallback(vtkObject*, unsigned long, void*);

437 438 439 440 441
  /**
   * Given a new position for the active plot, calculate a
   * an animation path from the old active plot to the new
   * active plot.
   */
442 443
  virtual void UpdateAnimationPath(const vtkVector2i& newActivePos);

444 445 446 447
  /**
   * Given the render window interactor, start animation of the
   * animation path calculated above.
   */
448 449
  virtual void StartAnimation(vtkRenderWindowInteractor* interactor);

450 451 452
  /**
   * Process events and dispatch to the appropriate member functions.
   */
453 454 455
  static void ProcessEvents(vtkObject *caller, unsigned long event,
                            void *clientData, void *callerData);

Mathieu Westphal's avatar
Mathieu Westphal committed
456 457 458 459 460 461 462
  /**
   * Called when drawing a chart, does nothing at this level.
   */
  virtual void AddSupplementaryPlot(vtkChart* vtkNotUsed(chart), int vtkNotUsed(plotType),
                                    vtkStdString vtkNotUsed(row), vtkStdString vtkNotUsed(column),
                                    int vtkNotUsed(plotCorner) = 0){}

463 464 465
  // The position of the active plot (defaults to 0, 1).
  vtkVector2i ActivePlot;

466 467 468
  // A flag to show if the ActivePlot vector is valid or not
  bool ActivePlotValid;

469
  // Weakly owned input data for the scatter plot matrix.
470
  vtkSmartPointer<vtkTable> Input;
471

472 473
  // Strongly owned internal data for the column visibility.
  vtkNew<vtkStringArray> VisibleColumns;
474

475 476 477
  // The number of bins in the histograms.
  int NumberOfBins;

478 479 480 481
  // The title of the scatter plot matrix.
  vtkStdString Title;
  vtkSmartPointer<vtkTextProperty> TitleProperties;

482 483 484
  // The mode when the chart is doing selection.
  int SelectionMode;

485 486 487
  // How many frames should animations consist of, 0 means no transitions.
  int NumberOfFrames;

Mathieu Westphal's avatar
Mathieu Westphal committed
488 489 490
  // A flag to know if we are animating the scatter plot along an animation path
  bool Animating;

491
private:
492 493
  vtkScatterPlotMatrix(const vtkScatterPlotMatrix &) = delete;
  void operator=(const vtkScatterPlotMatrix &) = delete;
494 495 496 497 498

  class PIMPL;
  PIMPL *Private;
  friend class PIMPL;

499
  vtkWeakPointer<vtkContext2D> CurrentPainter;
500
  vtkMTimeType LayoutUpdatedTime;
501

502 503 504 505
  // Go through the process of calculating axis ranges, etc...
  void UpdateAxes();
  void ApplyAxisSetting(vtkChart *chart, const vtkStdString &x,
                        const vtkStdString &y);
506 507
};

508
#endif //vtkScatterPlotMatrix_h