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