1 /*=========================================================================
2
3 Program: Visualization Toolkit
4 Module: TestGPURayCastDataTypesMIP.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 // This test volume renders the same dataset using 8 different data types
17 // (unsigned char, signed char, unsigned short, signed short, unsigned int
18 // int, float, and double). It uses compositing and no shading. The extents of
19 // the dataset are (0, 114, 0, 100, 0, 74).
20
21
22 #include "vtkGPUVolumeRayCastMapper.h"
23 #include "vtkTestUtilities.h"
24 #include "vtkXMLImageDataReader.h"
25 #include "vtkImageShiftScale.h"
26 #include "vtkColorTransferFunction.h"
27 #include "vtkPiecewiseFunction.h"
28 #include "vtkTransform.h"
29 #include "vtkRenderer.h"
30 #include "vtkRenderWindow.h"
31 #include "vtkRenderWindowInteractor.h"
32 #include "vtkVolumeProperty.h"
33 #include "vtkCamera.h"
34 #include "vtkTextActor.h"
35 #include "vtkTextProperty.h"
36 #include "vtkRegressionTestImage.h"
37
TestGPURayCastDataTypesMIP(int argc,char * argv[])38 int TestGPURayCastDataTypesMIP(int argc,
39 char *argv[])
40 {
41 cout << "CTEST_FULL_OUTPUT (Avoid ctest truncation of output)" << endl;
42 char *cfname=
43 vtkTestUtilities::ExpandDataFileName(argc, argv, "Data/vase_1comp.vti");
44
45 vtkXMLImageDataReader *reader=vtkXMLImageDataReader::New();
46 reader->SetFileName(cfname);
47 delete [] cfname;
48
49 vtkImageShiftScale *shiftScale[4][2];
50 vtkColorTransferFunction *color[4][2];
51 vtkPiecewiseFunction *opacity[4][2];
52
53 // unsigned char
54 shiftScale[0][0]=vtkImageShiftScale::New();
55 shiftScale[0][0]->SetInputConnection(reader->GetOutputPort());
56
57 color[0][0]=vtkColorTransferFunction::New();
58 color[0][0]->AddRGBPoint(0,0,0,1);
59 color[0][0]->AddRGBPoint(255,0,1,0);
60
61 opacity[0][0]=vtkPiecewiseFunction::New();
62 opacity[0][0]->AddPoint(0,0);
63 opacity[0][0]->AddPoint(255,1);
64
65 // signed char
66 shiftScale[0][1]=vtkImageShiftScale::New();
67 shiftScale[0][1]->SetInputConnection(shiftScale[0][0]->GetOutputPort());
68 shiftScale[0][1]->SetShift(-128);
69 shiftScale[0][1]->SetOutputScalarType(15);
70
71 color[0][1]=vtkColorTransferFunction::New();
72 color[0][1]->AddRGBPoint(-128,0,0,1);
73 color[0][1]->AddRGBPoint(127,0,1,0);
74
75 opacity[0][1]=vtkPiecewiseFunction::New();
76 opacity[0][1]->AddPoint(-128,0);
77 opacity[0][1]->AddPoint(127,1);
78
79 // unsigned short
80 shiftScale[1][0]=vtkImageShiftScale::New();
81 shiftScale[1][0]->SetInputConnection(reader->GetOutputPort());
82 shiftScale[1][0]->SetScale(256);
83 shiftScale[1][0]->SetOutputScalarTypeToUnsignedShort();
84
85 color[1][0]=vtkColorTransferFunction::New();
86 color[1][0]->AddRGBPoint(0,0,0,1);
87 color[1][0]->AddRGBPoint(65535,0,1,0);
88
89 opacity[1][0]=vtkPiecewiseFunction::New();
90 opacity[1][0]->AddPoint(0,0);
91 opacity[1][0]->AddPoint(65535,1);
92
93 // short
94 shiftScale[1][1]=vtkImageShiftScale::New();
95 shiftScale[1][1]->SetInputConnection(shiftScale[1][0]->GetOutputPort());
96 shiftScale[1][1]->SetShift(-32768);
97 shiftScale[1][1]->SetOutputScalarTypeToShort();
98
99 color[1][1]=vtkColorTransferFunction::New();
100 color[1][1]->AddRGBPoint(-32768,0,0,1);
101 color[1][1]->AddRGBPoint(32767,0,1,0);
102
103 opacity[1][1]=vtkPiecewiseFunction::New();
104 opacity[1][1]->AddPoint(-32768,0);
105 opacity[1][1]->AddPoint(32767,1);
106
107 // unsigned int
108 shiftScale[2][0]=vtkImageShiftScale::New();
109 shiftScale[2][0]->SetInputConnection (reader->GetOutputPort());
110 shiftScale[2][0]->SetScale(16777216);
111 shiftScale[2][0]->SetOutputScalarTypeToUnsignedInt();
112
113 color[2][0]=vtkColorTransferFunction::New();
114 color[2][0]->AddRGBPoint(0,0,0,1);
115 color[2][0]->AddRGBPoint(VTK_UNSIGNED_INT_MAX,0,1,0);
116
117 opacity[2][0]=vtkPiecewiseFunction::New();
118 opacity[2][0]->AddPoint(0,0);
119 opacity[2][0]->AddPoint(VTK_UNSIGNED_INT_MAX,1);
120
121 // int
122 shiftScale[2][1]=vtkImageShiftScale::New();
123 shiftScale[2][1]->SetInputConnection(shiftScale[2][0]->GetOutputPort());
124 shiftScale[2][1]->SetShift(VTK_INT_MIN);
125 shiftScale[2][1]->SetOutputScalarTypeToInt();
126
127 color[2][1]=vtkColorTransferFunction::New();
128 color[2][1]->AddRGBPoint(VTK_INT_MIN,0,0,1);
129 color[2][1]->AddRGBPoint(VTK_INT_MAX,0,1,0);
130
131 opacity[2][1]=vtkPiecewiseFunction::New();
132
133 opacity[2][1]->AddPoint(VTK_INT_MIN,0);
134 opacity[2][1]->AddPoint(VTK_INT_MAX,1);
135
136 // float [-1 1]
137 vtkImageShiftScale *shiftScale_3_0_pre=vtkImageShiftScale::New();
138 shiftScale_3_0_pre->SetInputConnection(reader->GetOutputPort());
139 shiftScale_3_0_pre->SetScale(0.0078125);
140 shiftScale_3_0_pre->SetOutputScalarTypeToFloat();
141
142 shiftScale[3][0]=vtkImageShiftScale::New();
143 shiftScale[3][0]->SetInputConnection(shiftScale_3_0_pre->GetOutputPort());
144 shiftScale[3][0]->SetShift(-1.0);
145 shiftScale[3][0]->SetOutputScalarTypeToFloat();
146
147 color[3][0]=vtkColorTransferFunction::New();
148 color[3][0]->AddRGBPoint(-1.0,0,0,1);
149 color[3][0]->AddRGBPoint(1.0,0,1,0);
150
151 opacity[3][0]=vtkPiecewiseFunction::New();
152 opacity[3][0]->AddPoint(-1.0,0);
153 opacity[3][0]->AddPoint(1.0,1);
154
155 // double [-1000 3000]
156 vtkImageShiftScale *shiftScale_3_1_pre=vtkImageShiftScale::New();
157 shiftScale_3_1_pre->SetInputConnection(reader->GetOutputPort());
158 shiftScale_3_1_pre->SetScale(15.625);
159 shiftScale_3_1_pre->SetOutputScalarTypeToDouble();
160
161 shiftScale[3][1]=vtkImageShiftScale::New();
162 shiftScale[3][1]->SetInputConnection(shiftScale_3_1_pre->GetOutputPort());
163 shiftScale[3][1]->SetShift(-1000);
164 shiftScale[3][1]->SetOutputScalarTypeToDouble();
165
166 color[3][1]=vtkColorTransferFunction::New();
167 color[3][1]->AddRGBPoint(-1000,0,0,1);
168 color[3][1]->AddRGBPoint(3000,0,1,0);
169
170 opacity[3][1]=vtkPiecewiseFunction::New();
171 opacity[3][1]->AddPoint(-1000,0);
172 opacity[3][1]->AddPoint(3000,1);
173
174 vtkRenderer *ren1=vtkRenderer::New();
175 vtkRenderWindow *renWin=vtkRenderWindow::New();
176 renWin->AddRenderer(ren1);
177 renWin->SetSize(600,300);
178 vtkRenderWindowInteractor *iren=vtkRenderWindowInteractor::New();
179 iren->SetRenderWindow(renWin);
180
181 renWin->Render();
182
183 vtkGPUVolumeRayCastMapper *volumeMapper[4][2];
184 vtkVolumeProperty *volumeProperty[4][2];
185 vtkVolume *volume[4][2];
186 vtkTransform *userMatrix[4][2];
187
188 int i=0;
189 while(i<4)
190 {
191 int j=0;
192 while(j<2)
193 {
194 volumeMapper[i][j]=vtkGPUVolumeRayCastMapper::New();
195 volumeMapper[i][j]->SetBlendModeToMaximumIntensity();
196 volumeMapper[i][j]->SetInputConnection(
197 shiftScale[i][j]->GetOutputPort());
198
199 volumeProperty[i][j]=vtkVolumeProperty::New();
200 volumeProperty[i][j]->SetColor(color[i][j]);
201 volumeProperty[i][j]->SetScalarOpacity(opacity[i][j]);
202 volumeProperty[i][j]->SetInterpolationType(VTK_LINEAR_INTERPOLATION);
203
204 volume[i][j]=vtkVolume::New();
205 volume[i][j]->SetMapper(volumeMapper[i][j]);
206 volume[i][j]->SetProperty(volumeProperty[i][j]);
207
208 userMatrix[i][j]=vtkTransform::New();
209 userMatrix[i][j]->PostMultiply();
210 userMatrix[i][j]->Identity();
211 userMatrix[i][j]->Translate(i*120,j*120,0);
212
213 volume[i][j]->SetUserTransform(userMatrix[i][j]);
214 ren1->AddViewProp(volume[i][j]);
215 ++j;
216 }
217 ++i;
218 }
219
220 int valid=volumeMapper[0][1]->IsRenderSupported(renWin,volumeProperty[0][1]);
221
222 int retVal;
223 if(valid)
224 {
225 iren->Initialize();
226 ren1->SetBackground(0.1,0.4,0.2);
227 ren1->ResetCamera();
228 ren1->GetActiveCamera()->Zoom(2.0);
229 renWin->Render();
230
231 retVal = vtkTesting::Test(argc, argv, renWin, 75);
232 if (retVal == vtkRegressionTester::DO_INTERACTOR)
233 {
234 iren->Start();
235 }
236 }
237 else
238 {
239 retVal=vtkTesting::PASSED;
240 cout << "Required extensions not supported." << endl;
241 }
242
243 iren->Delete();
244 renWin->Delete();
245 ren1->Delete();
246 shiftScale_3_1_pre->Delete();
247 shiftScale_3_0_pre->Delete();
248 i=0;
249 while(i<4)
250 {
251 int j=0;
252 while(j<2)
253 {
254 volumeMapper[i][j]->Delete();
255 volumeProperty[i][j]->Delete();
256 volume[i][j]->Delete();
257 userMatrix[i][j]->Delete();
258 shiftScale[i][j]->Delete();
259 color[i][j]->Delete();
260 opacity[i][j]->Delete();
261 ++j;
262 }
263 ++i;
264 }
265 reader->Delete();
266
267 if ((retVal == vtkTesting::PASSED) || (retVal == vtkTesting::DO_INTERACTOR))
268 {
269 return 0;
270 }
271 else
272 {
273 return 1;
274 }
275 }
276