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