1 /*=========================================================================
2 
3   Program:   Visualization Toolkit
4   Module:    TestGPURayCastVolumeRotation.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 covers additive method.
16 // This test volume renders a synthetic dataset with unsigned char values,
17 // with the additive method.
18 
19 #include <vtkCamera.h>
20 #include <vtkColorTransferFunction.h>
21 #include <vtkDataArray.h>
22 #include <vtkGPUVolumeRayCastMapper.h>
23 #include <vtkImageData.h>
24 #include <vtkImageReader.h>
25 #include <vtkImageShiftScale.h>
26 #include <vtkLightKit.h>
27 #include <vtkNew.h>
28 #include <vtkOutlineFilter.h>
29 #include <vtkPiecewiseFunction.h>
30 #include <vtkPointData.h>
31 #include <vtkPolyDataMapper.h>
32 #include <vtkRegressionTestImage.h>
33 #include <vtkRenderWindow.h>
34 #include <vtkRenderWindowInteractor.h>
35 #include <vtkRenderer.h>
36 #include <vtkSmartPointer.h>
37 #include <vtkStructuredPointsReader.h>
38 #include <vtkTestUtilities.h>
39 #include <vtkTimerLog.h>
40 #include <vtkVolumeProperty.h>
41 #include <vtkXMLImageDataReader.h>
42 
TestGPURayCastVolumeLightKit(int argc,char * argv[])43 int TestGPURayCastVolumeLightKit(int argc, char *argv[])
44 {
45   double scalarRange[2];
46 
47   vtkNew<vtkGPUVolumeRayCastMapper> volumeMapper;
48   vtkNew<vtkXMLImageDataReader> reader;
49   const char* volumeFile = vtkTestUtilities::ExpandDataFileName(
50                             argc, argv, "Data/vase_1comp.vti");
51   reader->SetFileName(volumeFile);
52   volumeMapper->SetInputConnection(reader->GetOutputPort());
53 
54   volumeMapper->GetInput()->GetScalarRange(scalarRange);
55   volumeMapper->SetBlendModeToComposite();
56   volumeMapper->SetAutoAdjustSampleDistances(0);
57   volumeMapper->SetSampleDistance(0.1);
58 
59   vtkNew<vtkLightKit> lightKit;
60   vtkNew<vtkRenderWindow> renWin;
61   vtkNew<vtkRenderer> ren;
62   ren->SetBackground(0.0, 0.0, 0.0);
63   ren->SetTwoSidedLighting(0);
64 
65   lightKit->SetKeyLightWarmth(1.0);
66   lightKit->SetFillLightWarmth(0.0);
67   lightKit->SetBackLightWarmth(0.0);
68   lightKit->AddLightsToRenderer(ren.GetPointer());
69 
70   renWin->AddRenderer(ren.GetPointer());
71   renWin->SetSize(400, 400);
72 
73   vtkNew<vtkRenderWindowInteractor> iren;
74   iren->SetRenderWindow(renWin.GetPointer());
75 
76   vtkNew<vtkPiecewiseFunction> scalarOpacity;
77   scalarOpacity->AddPoint(55, 0.0);
78   scalarOpacity->AddPoint(65, 1.0);
79 
80   vtkNew<vtkVolumeProperty> volumeProperty;
81   volumeProperty->ShadeOn();
82   volumeProperty->SetAmbient(0.0);
83   volumeProperty->SetDiffuse(1.0);
84   volumeProperty->SetSpecular(0.0);
85   volumeProperty->SetInterpolationType(VTK_LINEAR_INTERPOLATION);
86   volumeProperty->SetScalarOpacity(scalarOpacity.GetPointer());
87 
88   vtkSmartPointer<vtkColorTransferFunction> colorTransferFunction =
89     volumeProperty->GetRGBTransferFunction(0);
90   colorTransferFunction->RemoveAllPoints();
91   colorTransferFunction->AddRGBPoint(scalarRange[0], 1.0, 1.0, 1.0);
92 
93   vtkNew<vtkVolume> volume;
94   volume->SetMapper(volumeMapper.GetPointer());
95   volume->SetProperty(volumeProperty.GetPointer());
96   ren->AddViewProp(volume.GetPointer());
97 
98   renWin->Render();
99   ren->ResetCamera();
100 
101   iren->Initialize();
102 
103   int retVal = vtkRegressionTestImage( renWin.GetPointer() );
104   if( retVal == vtkRegressionTester::DO_INTERACTOR)
105     {
106     iren->Start();
107     }
108 
109   return !retVal;
110 }
111