1 /*=========================================================================
2
3 Program: Visualization Toolkit
4 Module: TestLinePlot.cxx
5
6 Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7 All rights reserved.
8 See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9
10 This software is distributed WITHOUT ANY WARRANTY; without even
11 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12 PURPOSE. See the above copyright notice for more information.
13
14 =========================================================================*/
15
16 #include "vtkChartXY.h"
17 #include "vtkColorTransferFunction.h"
18 #include "vtkCompositeControlPointsItem.h"
19 #include "vtkCompositeTransferFunctionItem.h"
20 #include "vtkContext2D.h"
21 #include "vtkContextDevice2D.h"
22 #include "vtkContextScene.h"
23 #include "vtkContextView.h"
24 #include "vtkLookupTable.h"
25 #include "vtkPiecewiseControlPointsItem.h"
26 #include "vtkPiecewiseFunction.h"
27 #include "vtkRenderWindow.h"
28 #include "vtkRenderWindowInteractor.h"
29 #include "vtkRenderer.h"
30 #include "vtkSmartPointer.h"
31
32 //----------------------------------------------------------------------------
TestScalarsToColors(int,char * [])33 int TestScalarsToColors(int , char * [])
34 {
35 // Set up a 2D scene, add an XY chart to it
36 vtkSmartPointer<vtkContextView> view =
37 vtkSmartPointer<vtkContextView>::New();
38 view->GetRenderer()->SetBackground(1.0, 1.0, 1.0);
39 view->GetRenderWindow()->SetSize(400, 300);
40 vtkSmartPointer<vtkChartXY> chart = vtkSmartPointer<vtkChartXY>::New();
41 chart->SetTitle("Chart");
42 chart->ForceAxesToBoundsOn();
43 view->GetScene()->AddItem(chart);
44
45 vtkSmartPointer<vtkLookupTable> lookupTable =
46 vtkSmartPointer<vtkLookupTable>::New();
47 lookupTable->Build();
48
49 vtkSmartPointer<vtkColorTransferFunction> colorTransferFunction =
50 vtkSmartPointer<vtkColorTransferFunction>::New();
51 colorTransferFunction->AddHSVSegment(0.,0.,1.,1.,0.3333,0.3333,1.,1.);
52 colorTransferFunction->AddHSVSegment(0.3333,0.3333,1.,1.,0.6666,0.6666,1.,1.);
53 colorTransferFunction->AddHSVSegment(0.6666,0.6666,1.,1.,1.,0.,1.,1.);
54
55 colorTransferFunction->Build();
56
57 vtkSmartPointer<vtkPiecewiseFunction> opacityFunction =
58 vtkSmartPointer<vtkPiecewiseFunction>::New();
59 opacityFunction->AddPoint(0.2, 0.);
60 opacityFunction->AddPoint(0.5,0.5);
61 opacityFunction->AddPoint(1.,1.);
62
63 vtkSmartPointer<vtkCompositeTransferFunctionItem> item3 =
64 vtkSmartPointer<vtkCompositeTransferFunctionItem>::New();
65 item3->SetColorTransferFunction(colorTransferFunction);
66 item3->SetOpacityFunction(opacityFunction);
67 item3->SetMaskAboveCurve(true);
68 chart->AddPlot(item3);
69
70 vtkSmartPointer<vtkCompositeControlPointsItem> item5 =
71 vtkSmartPointer<vtkCompositeControlPointsItem>::New();
72 item5->SetOpacityFunction(opacityFunction);
73 item5->SetColorTransferFunction(colorTransferFunction);
74 chart->AddPlot(item5);
75
76 // Finally render the scene and compare the image to a reference image
77 view->GetRenderWindow()->SetMultiSamples(1);
78 if (view->GetContext()->GetDevice()->IsA("vtkOpenGL2ContextDevice2D"))
79 {
80 view->GetInteractor()->Initialize();
81 view->GetInteractor()->Start();
82 }
83 else
84 {
85 cout << "GL version 2 or higher is required." << endl;
86 }
87
88 return EXIT_SUCCESS;
89 }
90