TestScatterPlotMatrix.cxx 3.01 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
/*=========================================================================

  Program:   Visualization Toolkit
  Module:    TestScatterPlotMatrix.cxx

  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
#include "vtkMath.h"
17 18 19 20 21 22 23 24 25
#include "vtkScatterPlotMatrix.h"
#include "vtkRenderWindow.h"
#include "vtkChart.h"
#include "vtkPlot.h"
#include "vtkTable.h"
#include "vtkFloatArray.h"
#include "vtkContextView.h"
#include "vtkContextScene.h"
#include "vtkRenderWindowInteractor.h"
26
#include "vtkContextMouseEvent.h"
27 28 29 30 31
#include "vtkNew.h"

//----------------------------------------------------------------------------
int TestScatterPlotMatrix(int, char * [])
{
32
  // Set up a 2D scene, add a chart to it
33
  vtkNew<vtkContextView> view;
34
  view->GetRenderWindow()->SetSize(800, 600);
35 36 37 38 39 40
  vtkNew<vtkScatterPlotMatrix> matrix;
  view->GetScene()->AddItem(matrix.GetPointer());

  // Create a table with some points in it...
  vtkNew<vtkTable> table;
  vtkNew<vtkFloatArray> arrX;
41
  arrX->SetName("x");
42 43
  table->AddColumn(arrX.GetPointer());
  vtkNew<vtkFloatArray> arrC;
44
  arrC->SetName("cos(x)");
45 46
  table->AddColumn(arrC.GetPointer());
  vtkNew<vtkFloatArray> arrS;
47
  arrS->SetName("sin(x)");
48 49
  table->AddColumn(arrS.GetPointer());
  vtkNew<vtkFloatArray> arrS2;
50
  arrS2->SetName("sin(x + 0.5)");
51 52
  table->AddColumn(arrS2.GetPointer());
  vtkNew<vtkFloatArray> tangent;
53
  tangent->SetName("tan(x)");
54
  table->AddColumn(tangent.GetPointer());
55
  // Test the chart scatter plot matrix
56
  int numPoints = 100;
57
  float inc = 4.0 * vtkMath::Pi() / (numPoints-1);
58 59 60 61 62 63 64 65 66 67
  table->SetNumberOfRows(numPoints);
  for (int i = 0; i < numPoints; ++i)
    {
    table->SetValue(i, 0, i * inc);
    table->SetValue(i, 1, cos(i * inc));
    table->SetValue(i, 2, sin(i * inc));
    table->SetValue(i, 3, sin(i * inc) + 0.5);
    table->SetValue(i, 4, tan(i * inc));
    }

68
  // Set the scatter plot matrix up to analyze all columns in the table.
69 70
  matrix->SetInput(table.GetPointer());

71 72
  matrix->SetNumberOfBins(7);

73 74 75 76
  view->Render();
  matrix->GetMainChart()->SetActionToButton(vtkChart::SELECT_POLYGON,
                                            vtkContextMouseEvent::RIGHT_BUTTON);

Zack Galbreath's avatar
Zack Galbreath committed
77 78 79 80 81 82 83 84 85 86
  // Test animation by releasing a right click on subchart (1,2)
  vtkContextMouseEvent mouseEvent;
  mouseEvent.SetInteractor(view->GetInteractor());
  vtkVector2f pos;

  mouseEvent.SetButton(vtkContextMouseEvent::RIGHT_BUTTON);
  pos.Set(245, 301);
  mouseEvent.SetPos(pos);
  matrix->MouseButtonReleaseEvent(mouseEvent);

87 88 89 90 91 92
  //Finally render the scene and compare the image to a reference image
  view->GetRenderWindow()->SetMultiSamples(0);
  view->GetInteractor()->Initialize();
  view->GetInteractor()->Start();
  return EXIT_SUCCESS;
}