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