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 "vtkRenderingOpenGLConfigure.h"
28 #include "vtkRenderWindow.h"
29 #include "vtkRenderWindowInteractor.h"
30 #include "vtkRenderer.h"
31 #include "vtkSmartPointer.h"
32
33 //----------------------------------------------------------------------------
TestScalarsToColors(int,char * [])34 int TestScalarsToColors(int , char * [])
35 {
36 // Set up a 2D scene, add an XY chart to it
37 vtkSmartPointer<vtkContextView> view =
38 vtkSmartPointer<vtkContextView>::New();
39 view->GetRenderer()->SetBackground(1.0, 1.0, 1.0);
40 view->GetRenderWindow()->SetSize(400, 300);
41 vtkSmartPointer<vtkChartXY> chart = vtkSmartPointer<vtkChartXY>::New();
42 chart->SetTitle("Chart");
43 chart->ForceAxesToBoundsOn();
44 view->GetScene()->AddItem(chart);
45
46 vtkSmartPointer<vtkLookupTable> lookupTable =
47 vtkSmartPointer<vtkLookupTable>::New();
48 lookupTable->Build();
49
50 vtkSmartPointer<vtkColorTransferFunction> colorTransferFunction =
51 vtkSmartPointer<vtkColorTransferFunction>::New();
52 colorTransferFunction->AddHSVSegment(0.,0.,1.,1.,0.3333,0.3333,1.,1.);
53 colorTransferFunction->AddHSVSegment(0.3333,0.3333,1.,1.,0.6666,0.6666,1.,1.);
54 colorTransferFunction->AddHSVSegment(0.6666,0.6666,1.,1.,1.,0.,1.,1.);
55
56 colorTransferFunction->Build();
57
58 vtkSmartPointer<vtkPiecewiseFunction> opacityFunction =
59 vtkSmartPointer<vtkPiecewiseFunction>::New();
60 opacityFunction->AddPoint(0.2, 0.);
61 opacityFunction->AddPoint(0.5,0.5);
62 opacityFunction->AddPoint(1.,1.);
63
64 vtkSmartPointer<vtkCompositeTransferFunctionItem> item3 =
65 vtkSmartPointer<vtkCompositeTransferFunctionItem>::New();
66 item3->SetColorTransferFunction(colorTransferFunction);
67 item3->SetOpacityFunction(opacityFunction);
68 item3->SetMaskAboveCurve(true);
69 chart->AddPlot(item3);
70
71 vtkSmartPointer<vtkCompositeControlPointsItem> item5 =
72 vtkSmartPointer<vtkCompositeControlPointsItem>::New();
73 item5->SetOpacityFunction(opacityFunction);
74 item5->SetColorTransferFunction(colorTransferFunction);
75 chart->AddPlot(item5);
76
77 // Finally render the scene and compare the image to a reference image
78 view->GetRenderWindow()->SetMultiSamples(1);
79
80 if (view->GetContext()->GetDevice()->IsA("vtkOpenGL2ContextDevice2D"))
81 {
82 view->GetInteractor()->Initialize();
83 view->GetInteractor()->Start();
84 }
85
86 return EXIT_SUCCESS;
87 }
88