1 /*=========================================================================
2
3 Program: Visualization Toolkit
4 Module: TestGPURayCastPositionalLights.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 // This test volume renders a synthetic dataset with four different
16 // positional lights in the scene.
17
18 #include <vtkCamera.h>
19 #include <vtkColorTransferFunction.h>
20 #include <vtkGPUVolumeRayCastMapper.h>
21 #include <vtkImageData.h>
22 #include <vtkLight.h>
23 #include <vtkNew.h>
24 #include <vtkPiecewiseFunction.h>
25 #include <vtkRegressionTestImage.h>
26 #include <vtkRenderer.h>
27 #include <vtkRenderWindow.h>
28 #include <vtkRenderWindowInteractor.h>
29 #include <vtkSmartPointer.h>
30 #include <vtkTestUtilities.h>
31 #include <vtkVolumeProperty.h>
32 #include <vtkXMLImageDataReader.h>
33
34 #include <vtkLightActor.h>
35 #include <vtkContourFilter.h>
36 #include <vtkPolyDataMapper.h>
37 #include <vtkActor.h>
38
TestGPURayCastPositionalLights(int argc,char * argv[])39 int TestGPURayCastPositionalLights(int argc, char *argv[])
40 {
41 double scalarRange[2];
42
43 vtkNew<vtkGPUVolumeRayCastMapper> volumeMapper;
44 vtkNew<vtkXMLImageDataReader> reader;
45 const char* volumeFile = vtkTestUtilities::ExpandDataFileName(
46 argc, argv, "Data/vase_1comp.vti");
47 reader->SetFileName(volumeFile);
48 volumeMapper->SetInputConnection(reader->GetOutputPort());
49
50 volumeMapper->GetInput()->GetScalarRange(scalarRange);
51 volumeMapper->SetBlendModeToComposite();
52 volumeMapper->SetAutoAdjustSampleDistances(0);
53 volumeMapper->SetSampleDistance(0.1);
54
55 vtkNew<vtkRenderWindow> renWin;
56 vtkNew<vtkRenderer> ren;
57 ren->SetBackground(0.0, 0.0, 0.4);
58 ren->AutomaticLightCreationOff();
59 ren->RemoveAllLights();
60
61 vtkNew<vtkLight> light1;
62 light1->SetLightTypeToSceneLight();
63 light1->SetPositional(true);
64 light1->SetDiffuseColor(1,0,0);
65 light1->SetAmbientColor(0,0,0);
66 light1->SetSpecularColor(1,1,1);
67 light1->SetConeAngle(60);
68 light1->SetPosition(0.0, 0.0, 100.0);
69 light1->SetFocalPoint(0.0, 0.0, 0.0);
70 // light1->SetColor(1,0,0);
71 // light1->SetPosition(40,40,301);
72 // light1->SetPosition(-57, -50, -360);
73
74 vtkNew<vtkLightActor> lightActor;
75 lightActor->SetLight(light1.GetPointer());
76 ren->AddViewProp(lightActor.GetPointer());
77 vtkNew<vtkLight> light2;
78 vtkNew<vtkLight> light3;
79 vtkNew<vtkLight> light4;
80
81 renWin->AddRenderer(ren.GetPointer());
82 renWin->SetSize(400, 400);
83
84 vtkNew<vtkRenderWindowInteractor> iren;
85 iren->SetRenderWindow(renWin.GetPointer());
86
87 vtkNew<vtkPiecewiseFunction> scalarOpacity;
88 scalarOpacity->AddPoint(50, 0.0);
89 scalarOpacity->AddPoint(75, 1.0);
90
91 vtkNew<vtkVolumeProperty> volumeProperty;
92 volumeProperty->ShadeOn();
93 volumeProperty->SetInterpolationType(VTK_LINEAR_INTERPOLATION);
94 volumeProperty->SetScalarOpacity(scalarOpacity.GetPointer());
95
96 vtkSmartPointer<vtkColorTransferFunction> colorTransferFunction =
97 volumeProperty->GetRGBTransferFunction(0);
98 colorTransferFunction->RemoveAllPoints();
99 colorTransferFunction->AddRGBPoint(scalarRange[0], 1.0, 1.0, 1.0);
100 colorTransferFunction->AddRGBPoint(scalarRange[1], 1.0, 1.0, 1.0);
101
102 vtkNew<vtkVolume> volume;
103 volume->SetMapper(volumeMapper.GetPointer());
104 volume->SetProperty(volumeProperty.GetPointer());
105
106 ren->AddViewProp(volume.GetPointer());
107
108 vtkNew<vtkPolyDataMapper> pm;
109 vtkNew<vtkActor> ac;
110 vtkNew<vtkContourFilter> cf;
111 ac->SetMapper(pm.GetPointer());
112 pm->SetInputConnection(cf->GetOutputPort());
113 pm->SetScalarVisibility(0);
114 cf->SetValue(0, 60.0);
115 cf->SetInputConnection(reader->GetOutputPort());
116 ac->SetPosition(-89.0, 0.0, 0.0);
117 volume->SetPosition(-30.0, 0.0, 0.0);
118 ren->AddActor(ac.GetPointer());
119 vtkNew<vtkActor> ac1;
120 ac1->SetMapper(pm.GetPointer());
121 ac1->SetPosition(0,0,0);
122 ren->SetTwoSidedLighting(0);
123
124 ren->AddLight(light1.GetPointer());
125 renWin->Render();
126
127 ren->ResetCamera();
128 iren->Initialize();
129
130 int retVal = vtkRegressionTestImage( renWin.GetPointer() );
131 if( retVal == vtkRegressionTester::DO_INTERACTOR)
132 {
133 iren->Start();
134 }
135
136 return !retVal;
137 }
138