1 /*=========================================================================
2
3 Program: Visualization Toolkit
4 Module: TestGPURayCastAdditive.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 cropping on volume datasets.
16
17 #include <vtkActor.h>
18 #include <vtkColorTransferFunction.h>
19 #include <vtkCommand.h>
20 #include <vtkGPUVolumeRayCastMapper.h>
21 #include <vtkImageData.h>
22 #include <vtkNew.h>
23 #include <vtkOutlineFilter.h>
24 #include <vtkPiecewiseFunction.h>
25 #include <vtkPolyDataMapper.h>
26 #include <vtkRegressionTestImage.h>
27 #include <vtkRenderWindow.h>
28 #include <vtkRenderWindowInteractor.h>
29 #include <vtkRenderer.h>
30 #include <vtkSmartPointer.h>
31 #include <vtkSphereSource.h>
32 #include <vtkTestUtilities.h>
33 #include <vtkTimerLog.h>
34 #include <vtkVolumeProperty.h>
35 #include <vtkXMLImageDataReader.h>
36
TestGPURayCastCropping1(int argc,char * argv[])37 int TestGPURayCastCropping1(int argc, char *argv[])
38 {
39 double scalarRange[2];
40
41 vtkNew<vtkActor> outlineActor;
42 vtkNew<vtkPolyDataMapper> outlineMapper;
43 vtkNew<vtkGPUVolumeRayCastMapper> volumeMapper;
44 volumeMapper->AutoAdjustSampleDistancesOff();
45 volumeMapper->SetSampleDistance(0.05);
46
47 vtkNew<vtkXMLImageDataReader> reader;
48 const char* volumeFile = vtkTestUtilities::ExpandDataFileName(
49 argc, argv, "Data/vase_1comp.vti");
50 reader->SetFileName(volumeFile);
51 volumeMapper->SetInputConnection(reader->GetOutputPort());
52
53 // Add outline filter
54 vtkNew<vtkOutlineFilter> outlineFilter;
55 outlineFilter->SetInputConnection(reader->GetOutputPort());
56 outlineMapper->SetInputConnection(outlineFilter->GetOutputPort());
57 outlineActor->SetMapper(outlineMapper.GetPointer());
58
59 volumeMapper->GetInput()->GetScalarRange(scalarRange);
60 volumeMapper->SetBlendModeToComposite();
61
62 // Testing prefers image comparison with small images
63 vtkNew<vtkRenderWindow> renWin;
64 renWin->SetSize(400, 400);
65
66 // Intentional odd and NPOT width/height
67 vtkNew<vtkRenderer> ren;
68 renWin->AddRenderer(ren.GetPointer());
69
70 vtkNew<vtkRenderWindowInteractor> iren;
71 iren->SetRenderWindow(renWin.GetPointer());
72
73 // Make sure we have an OpenGL context.
74 renWin->Render();
75
76 vtkNew<vtkPiecewiseFunction> scalarOpacity;
77 scalarOpacity->AddPoint(scalarRange[0], 0.0);
78 scalarOpacity->AddPoint(scalarRange[1], 1.0);
79
80 vtkNew<vtkVolumeProperty> volumeProperty;
81 volumeProperty->ShadeOff();
82 volumeProperty->SetInterpolationType(VTK_LINEAR_INTERPOLATION);
83 volumeProperty->SetScalarOpacity(scalarOpacity.GetPointer());
84
85 vtkSmartPointer<vtkColorTransferFunction> colorTransferFunction =
86 volumeProperty->GetRGBTransferFunction(0);
87 colorTransferFunction->RemoveAllPoints();
88 colorTransferFunction->AddRGBPoint(scalarRange[0], 0.0, 0.0, 0.0);
89 colorTransferFunction->AddRGBPoint(scalarRange[1], 1.0, 1.0, 1.0);
90
91 // Test cropping now
92 volumeMapper->SetCroppingRegionPlanes(10.0, 20.0, 10.0, 20.0, 10.0, 20.0);
93 volumeMapper->SetCroppingRegionFlagsToFence();
94 volumeMapper->CroppingOn();
95
96 // Setup volume actor
97 vtkNew<vtkVolume> volume;
98 volume->SetMapper(volumeMapper.GetPointer());
99 volume->SetProperty(volumeProperty.GetPointer());
100
101 ren->AddViewProp(volume.GetPointer());
102 ren->AddActor(outlineActor.GetPointer());
103 ren->ResetCamera();
104
105 renWin->Render();
106 iren->Initialize();
107
108 int retVal = vtkRegressionTestImage( renWin.GetPointer() );
109 if( retVal == vtkRegressionTester::DO_INTERACTOR)
110 {
111 iren->Start();
112 }
113
114 return !retVal;
115 }
116