10 #include <vtkSphereSource.h> 11 #include <vtkSmartPointer.h> 12 #include <vtkAppendPolyData.h> 13 #include <vtkCamera.h> 14 #include <vtkPolyDataMapper.h> 16 #include <vtkRenderer.h> 17 #include <vtkRenderWindow.h> 18 #include <vtkProperty.h> 19 #include <vtkRenderWindowInteractor.h> 20 #include <vtkTimerLog.h> 21 #include <vtkTransform.h> 22 #include <vtkDepthSortPolyData.h> 35 vtkSmartPointer<vtkAppendPolyData> appendData =
36 vtkSmartPointer<vtkAppendPolyData>::New();
38 for (
int i = 0; i < 5; i++)
40 vtkSmartPointer<vtkSphereSource> sphereSource =
41 vtkSmartPointer<vtkSphereSource>::New();
42 sphereSource->SetThetaResolution(theta);
43 sphereSource->SetPhiResolution(phi);
44 sphereSource->SetRadius(0.5);
49 sphereSource->SetRadius(1);
50 sphereSource->SetCenter(0, 0, 0);
break;
52 sphereSource->SetCenter(1, 0, 0);
break;
54 sphereSource->SetCenter(-1, 0, 0);
break;
56 sphereSource->SetCenter(0, 1, 0);
break;
58 sphereSource->SetCenter(0, -1, 0);
break;
60 sphereSource->Update();
61 appendData->AddInputConnection(sphereSource->GetOutputPort());
79 vtkSmartPointer<vtkRenderWindow> renderWindow,
80 vtkSmartPointer<vtkRenderer> renderer,
int maxNoOfPeels,
81 double occlusionRatio)
83 if (!renderWindow || !renderer)
87 renderWindow->SetAlphaBitPlanes(
true);
91 renderWindow->SetMultiSamples(0);
94 renderer->SetUseDepthPeeling(
true);
98 renderer->SetMaximumNumberOfPeels(maxNoOfPeels);
100 renderer->SetOcclusionRatio(occlusionRatio);
117 vtkSmartPointer<vtkRenderer> renderer,
120 if (!renderWindow || !renderer)
128 bool origOffScreenRendering = renderWindow->GetOffScreenRendering() == 1;
129 bool origAlphaBitPlanes = renderWindow->GetAlphaBitPlanes() == 1;
130 int origMultiSamples = renderWindow->GetMultiSamples();
131 bool origUseDepthPeeling = renderer->GetUseDepthPeeling() == 1;
132 int origMaxPeels = renderer->GetMaximumNumberOfPeels();
133 double origOcclusionRatio = renderer->GetOcclusionRatio();
136 renderWindow->SetOffScreenRendering(doItOffScreen);
143 renderWindow->Render();
146 success = success && renderer->GetLastRenderingUsedDepthPeeling();
149 renderWindow->SetOffScreenRendering(origOffScreenRendering);
150 renderWindow->SetAlphaBitPlanes(origAlphaBitPlanes);
151 renderWindow->SetMultiSamples(origMultiSamples);
152 renderer->SetUseDepthPeeling(origUseDepthPeeling);
153 renderer->SetMaximumNumberOfPeels(origMaxPeels);
154 renderer->SetOcclusionRatio(origOcclusionRatio);
180 int main (
int argc,
char *argv[])
184 cerr <<
"Usage: " << argv[0] <<
" Theta Phi MaximumPeels " <<
185 "OcclusionRatio ForceDepthSortingFlag " <<
186 "DoNotUseAnyDepthRelatedAlgorithmFlag" << std::endl;
190 int theta = atoi(argv[1]);
191 int phi = atoi(argv[2]);
192 int maxPeels = atoi(argv[3]);
193 double occulusionRatio = atof(argv[4]);
194 bool forceDepthSort = atoi(argv[5]) == 1;
195 bool withoutAnyDepthThings = atoi(argv[6]) == 1;
198 vtkSmartPointer<vtkAppendPolyData> translucentGeometry =
202 vtkSmartPointer<vtkPolyDataMapper> mapper =
203 vtkSmartPointer<vtkPolyDataMapper>::New();
204 mapper->SetInputConnection(translucentGeometry->GetOutputPort());
206 vtkSmartPointer<vtkActor> actor =
207 vtkSmartPointer<vtkActor>::New();
208 actor->SetMapper(mapper);
209 actor->GetProperty()->SetOpacity(0.5);
210 actor->GetProperty()->SetColor(1, 0, 0);
215 vtkSmartPointer<vtkRenderer> renderer =
216 vtkSmartPointer<vtkRenderer>::New();
217 vtkSmartPointer<vtkRenderWindow> renderWindow =
218 vtkSmartPointer<vtkRenderWindow>::New();
219 renderWindow->AddRenderer(renderer);
220 vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =
221 vtkSmartPointer<vtkRenderWindowInteractor>::New();
222 renderWindowInteractor->SetRenderWindow(renderWindow);
225 renderer->AddActor(actor);
226 renderer->SetBackground(1, 1, 1);
227 renderWindow->SetSize(600, 400);
230 renderer->ResetCamera();
231 renderer->GetActiveCamera()->Zoom(2.2);
235 std::cout <<
"DEPTH PEELING SUPPORT: " << (useDepthPeeling ?
"YES" :
"NO") << std::endl;
237 int success = EXIT_SUCCESS;
241 std::cout << std::endl <<
"CHOSEN MODE: ";
242 if (useDepthPeeling && !forceDepthSort && !withoutAnyDepthThings)
244 std::cout <<
"*** DEPTH PEELING ***" << std::endl;
247 maxPeels, occulusionRatio);
249 else if (!withoutAnyDepthThings)
251 std::cout <<
"*** DEPTH SORTING ***" << std::endl;
253 vtkSmartPointer<vtkDepthSortPolyData> depthSort =
254 vtkSmartPointer<vtkDepthSortPolyData>::New();
255 depthSort->SetInputConnection(translucentGeometry->GetOutputPort());
256 depthSort->SetDirectionToBackToFront();
257 depthSort->SetVector(1, 1, 1);
258 depthSort->SetCamera(renderer->GetActiveCamera());
259 depthSort->SortScalarsOff();
261 mapper->SetInputConnection(depthSort->GetOutputPort());
266 std::cout <<
"*** NEITHER DEPTH PEELING NOR DEPTH SORTING ***" << std::endl;
270 renderWindowInteractor->Initialize();
274 vtkSmartPointer<vtkTimerLog> clock =
275 vtkSmartPointer<vtkTimerLog>::New();
277 vtkSmartPointer<vtkTransform>
transform =
278 vtkSmartPointer<vtkTransform>::New();
279 transform->Identity();
280 transform->RotateY(2.0);
281 vtkSmartPointer<vtkCamera> camera = renderer->GetActiveCamera();
285 for (
int i = 0; i < endCount; i++)
287 camera->GetPosition(camPos);
288 transform->TransformPoint(camPos, camPos);
289 camera->SetPosition(camPos);
290 renderWindow->Render();
293 double frameRate = (double)endCount / clock->GetElapsedTime();
294 std::cout <<
"AVERAGE FRAME RATE: " << frameRate <<
" fps" << std::endl;
bool SetupEnvironmentForDepthPeeling(vtkSmartPointer< vtkRenderWindow > renderWindow, vtkSmartPointer< vtkRenderer > renderer, int maxNoOfPeels, double occlusionRatio)
vtkSmartPointer< vtkAppendPolyData > GenerateOverlappingBunchOfSpheres(int theta, int phi)
int main(int argc, char *argv[])
bool IsDepthPeelingSupported(vtkSmartPointer< vtkRenderWindow > renderWindow, vtkSmartPointer< vtkRenderer > renderer, bool doItOffScreen)
float4 transform(float16 matrix, float4 voxel)