TestHistogram2D.cxx 2.44 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
/*=========================================================================

  Program:   Visualization Toolkit
  Module:    TestLinePlot.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.

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

#include "vtkRenderWindow.h"
#include "vtkSmartPointer.h"
18
19
#include "vtkChartHistogram2D.h"
#include "vtkPlotHistogram2D.h"
20
21
22
23
24
25
#include "vtkImageData.h"
#include "vtkColorTransferFunction.h"
#include "vtkContextView.h"
#include "vtkContextScene.h"
#include "vtkMath.h"
#include "vtkRenderWindowInteractor.h"
26
#include "vtkNew.h"
27
28

//----------------------------------------------------------------------------
29
int TestHistogram2D(int, char * [])
30
31
{
  // Set up a 2D scene, add an XY chart to it
32
  int size = 400;
33
  vtkNew<vtkContextView> view;
34
  view->GetRenderWindow()->SetSize(size, size);
35
  vtkNew<vtkChartHistogram2D> chart;
36

37
  view->GetScene()->AddItem(chart.GetPointer());
38

39
  vtkNew<vtkImageData> data;
40
  data->SetExtent(0, size-1, 0, size-1, 0, 0);
41
  data->AllocateScalars(VTK_DOUBLE, 1);
42
43
44
45
46
47
48
49
50
51
52
53
54

  data->SetOrigin(100.0, 0.0, 0.0);
  data->SetSpacing(2.0, 1.0, 1.0);

  double *dPtr = static_cast<double *>(data->GetScalarPointer(0, 0, 0));
  for (int i = 0; i < size; ++i)
    {
    for (int j = 0; j < size; ++j)
      {
      dPtr[i * size + j] = sin(vtkMath::RadiansFromDegrees(double(2*i))) *
          cos(vtkMath::RadiansFromDegrees(double(j)));
      }
    }
55
  chart->SetInputData(data.GetPointer());
56

57
  vtkNew<vtkColorTransferFunction> transferFunction;
58
59
60
61
62
  transferFunction->AddHSVSegment(0.0, 0.0, 1.0, 1.0,
                                  0.3333, 0.3333, 1.0, 1.0);
  transferFunction->AddHSVSegment(0.3333, 0.3333, 1.0, 1.0,
                                  0.6666, 0.6666, 1.0, 1.0);
  transferFunction->AddHSVSegment(0.6666, 0.6666, 1.0, 1.0,
63
                                  1.0, 0.2, 1.0, 0.3);
64
  transferFunction->Build();
65
  chart->SetTransferFunction(transferFunction.GetPointer());
66
67
68
69
70
71
72

  //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;
}