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

  Program:   Visualization Toolkit
  Module:    TestChartXYZ.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 "vtkAxis.h"
17
18
19
20
#include "vtkChartXYZ.h"
#include "vtkContextView.h"
#include "vtkContextScene.h"
#include "vtkFloatArray.h"
Zack Galbreath's avatar
Zack Galbreath committed
21
#include "vtkPlotPoints3D.h"
22
23
24
25
26
27

#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkNew.h"
#include "vtkTable.h"
28
#include "vtkCallbackCommand.h"
29

30
31
32
33
34
// Need a timer so that we can animate, and then take a snapshot!
namespace
{
static double angle = 0;

35
void ProcessEvents(vtkObject *caller, unsigned long,
36
                   void *clientData, void *callerData)
37
{
38
39
40
41
42
43
44
45
46
47
48
49
50
  vtkChartXYZ *chart = reinterpret_cast<vtkChartXYZ *>(clientData);
  vtkRenderWindowInteractor *interactor =
      reinterpret_cast<vtkRenderWindowInteractor *>(caller);
  angle += 2;
  chart->SetAngle(angle);
  interactor->Render();
  if (angle >= 90)
    {
    int timerId = *reinterpret_cast<int *>(callerData);
    interactor->DestroyTimer(timerId);
    }
}
} // End of anonymous namespace.
51

52
53
int TestChartXYZ(int , char * [])
{
54
55
  // Now the chart
  vtkNew<vtkChartXYZ> chart;
Zack Galbreath's avatar
Zack Galbreath committed
56
57
58
  chart->SetAutoRotate(true);
  chart->SetFitToScene(false);
  chart->SetDecorateAxes(false);
59
  vtkNew<vtkContextView> view;
60
  view->GetRenderWindow()->SetSize(400, 300);
61
  view->GetScene()->AddItem(chart.GetPointer());
62
  vtkNew<vtkChartXYZ> chart2;
63
  chart2->SetAutoRotate(true);
Zack Galbreath's avatar
Zack Galbreath committed
64
65
  chart2->SetFitToScene(false);
  chart->SetDecorateAxes(false);
66
  view->GetScene()->AddItem(chart2.GetPointer());
67

68
69
  chart->SetGeometry(vtkRectf(75.0, 20.0, 250, 260));
  chart2->SetGeometry(vtkRectf(75.0, 20.0, 250, 260));
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92

  // Create a table with some points in it...
  vtkNew<vtkTable> table;
  vtkNew<vtkFloatArray> arrX;
  arrX->SetName("X Axis");
  table->AddColumn(arrX.GetPointer());
  vtkNew<vtkFloatArray> arrC;
  arrC->SetName("Cosine");
  table->AddColumn(arrC.GetPointer());
  vtkNew<vtkFloatArray> arrS;
  arrS->SetName("Sine");
  table->AddColumn(arrS.GetPointer());
  // Test charting with a few more points...
  int numPoints = 69;
  float inc = 7.5 / (numPoints-1);
  table->SetNumberOfRows(numPoints);
  for (int i = 0; i < numPoints; ++i)
    {
    table->SetValue(i, 0, i * inc);
    table->SetValue(i, 1, cos(i * inc) + 0.0);
    table->SetValue(i, 2, sin(i * inc) + 0.0);
    }

93
  //chart->SetAroundX(true);
94
  // Add the three dimensions we are interested in visualizing.
Zack Galbreath's avatar
Zack Galbreath committed
95
96
97
  vtkNew<vtkPlotPoints3D> plot;
  plot->SetInputData(table.GetPointer(), "X Axis", "Sine", "Cosine");
  chart->AddPlot(plot.GetPointer());
98
99
  const vtkColor4ub axisColor(20, 200, 30);
  chart->SetAxisColor(axisColor);
100
101
102
103
  chart->GetAxis(0)->SetUnscaledRange(-0.1,7.6);
  chart->GetAxis(1)->SetUnscaledRange(-1.1,1.1);
  chart->GetAxis(2)->SetUnscaledRange(-1.1,1.1);
  chart->RecalculateTransform();
104
105

  // We want a duplicate, that does not move.
Zack Galbreath's avatar
Zack Galbreath committed
106
107
108
  vtkNew<vtkPlotPoints3D> plot2;
  plot2->SetInputData(table.GetPointer(), "X Axis", "Sine", "Cosine");
  chart2->AddPlot(plot2.GetPointer());
109
110
111

  view->GetRenderWindow()->SetMultiSamples(0);
  view->GetInteractor()->Initialize();
112
113
114
115
116
117
118
119
120

  // Set up the timer, and be sure to incrememt the angle.
  vtkNew<vtkCallbackCommand> callback;
  callback->SetClientData(chart.GetPointer());
  callback->SetCallback(::ProcessEvents);
  view->GetInteractor()->AddObserver(vtkCommand::TimerEvent, callback.GetPointer(),
                                0);
  view->GetInteractor()->CreateRepeatingTimer(1000 / 25);

121
122
123
124
  view->GetInteractor()->Start();

  return EXIT_SUCCESS;
}