1 /*=========================================================================
2
3 Program: Visualization Toolkit
4 Module: TestGPURayCastRenderToTexture.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 // Description
17 // Test the GPU volume mapper low level API to render color and depth buffers to
18 // the frame buffer.
19
20 #include "vtkActor.h"
21 #include "vtkCamera.h"
22 #include "vtkColorTransferFunction.h"
23 #include "vtkGPUVolumeRayCastMapper.h"
24 #include "vtkImageActor.h"
25 #include "vtkImageData.h"
26 #include "vtkImageMapper3D.h"
27 #include "vtkNew.h"
28 #include "vtkPiecewiseFunction.h"
29 #include "vtkRegressionTestImage.h"
30 #include "vtkRenderer.h"
31 #include "vtkRenderWindow.h"
32 #include "vtkRenderWindowInteractor.h"
33 #include "vtkTesting.h"
34 #include "vtkTestUtilities.h"
35 #include "vtkVolume16Reader.h"
36 #include "vtkVolumeProperty.h"
37
TestGPURayCastRenderToTexture(int argc,char * argv[])38 int TestGPURayCastRenderToTexture(int argc, char *argv[])
39 {
40 cout << "CTEST_FULL_OUTPUT (Avoid ctest truncation of output)" << endl;
41
42 char* fname = vtkTestUtilities::ExpandDataFileName(argc, argv, "Data/headsq/quarter");
43
44 vtkNew<vtkVolume16Reader> reader;
45 reader->SetDataDimensions( 64, 64);
46 reader->SetDataByteOrderToLittleEndian();
47 reader->SetImageRange( 1, 93);
48 reader->SetDataSpacing( 3.2, 3.2, 1.5);
49 reader->SetFilePrefix( fname );
50 reader->SetDataMask( 0x7fff);
51
52 delete[] fname;
53
54 vtkNew<vtkGPUVolumeRayCastMapper> volumeMapper;
55 volumeMapper->SetInputConnection(reader->GetOutputPort());
56 volumeMapper->RenderToImageOn();
57
58 vtkNew<vtkColorTransferFunction> colorFunction;
59 colorFunction->AddRGBPoint(900.0, 198/255.0, 134/255.0, 66/255.0);
60
61 vtkNew<vtkPiecewiseFunction> scalarOpacity;
62 scalarOpacity->AddPoint(0, 0.0);
63 scalarOpacity->AddPoint(70, 0.0);
64 scalarOpacity->AddPoint(449, 0.0);
65 scalarOpacity->AddPoint(900, 0.15);
66 scalarOpacity->AddPoint(1120, 0.25);
67 scalarOpacity->AddPoint(1404, 0.35);
68 scalarOpacity->AddPoint(4095, 0.5);
69
70 vtkNew<vtkVolumeProperty> volumeProperty;
71 volumeProperty->ShadeOn();
72 volumeProperty->SetInterpolationType(VTK_LINEAR_INTERPOLATION);
73 volumeProperty->SetColor(colorFunction);
74 volumeProperty->SetScalarOpacity(scalarOpacity);
75
76 // Setup volume actor
77 vtkNew<vtkVolume> volume;
78 volume->SetMapper(volumeMapper);
79 volume->SetProperty(volumeProperty);
80
81 // Testing prefers image comparison with small images
82 vtkNew<vtkRenderWindow> renWin;
83 // Intentional odd and NPOT width/height
84 renWin->SetSize(401, 399);
85
86 vtkNew<vtkRenderer> ren;
87 renWin->AddRenderer(ren);
88
89 vtkNew<vtkRenderWindowInteractor> iren;
90 iren->SetRenderWindow(renWin);
91
92 ren->AddVolume(volume);
93 ren->GetActiveCamera()->Azimuth(90);
94 ren->GetActiveCamera()->Roll(90);
95 ren->GetActiveCamera()->Azimuth(-90);
96 ren->ResetCamera();
97 ren->GetActiveCamera()->Zoom(1.8);
98 renWin->Render();
99
100 vtkNew<vtkImageData> im;
101
102 // Get color texture as image
103 volumeMapper->GetColorImage(im);
104
105 ren->RemoveVolume(volume);
106
107 vtkNew<vtkImageActor> ia;
108 ia->GetMapper()->SetInputData(im);
109 ren->AddActor(ia);
110 ren->GetActiveCamera()->SetPosition(0, 0, -1);
111 ren->GetActiveCamera()->SetFocalPoint(0, 0, 1);
112 ren->GetActiveCamera()->SetViewUp(0, 1, 0);
113 ren->ResetCamera();
114 renWin->Render();
115 iren->Initialize();
116
117 int retVal = vtkRegressionTestImage( renWin );
118 if( retVal == vtkRegressionTester::DO_INTERACTOR)
119 {
120 iren->Start();
121 }
122
123 return !retVal;
124 }
125