1 /*=========================================================================
2 
3   Program:   Visualization Toolkit
4   Module:    TestOSPRayPass.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 // This test verifies that we can hot swap ospray and GL backends.
16 //
17 // The command line arguments are:
18 // -I        => run in interactive mode; unless this is used, the program will
19 //              not allow interaction and exit
20 //              In interactive mode it responds to the keys listed
21 //              vtkOSPRayTestInteractor.h
22 
23 //TODO: dragon.ply crashes, and removing normals is black (ADS 0..255 instead of 0..1)
24 
25 #include "vtkTestUtilities.h"
26 
27 #include "vtkActor.h"
28 #include "vtkCamera.h"
29 #include "vtkOpenGLRenderer.h"
30 #include "vtkOSPRayPass.h"
31 #include "vtkPolyDataMapper.h"
32 #include "vtkPolyDataNormals.h"
33 #include "vtkPLYReader.h"
34 #include "vtkRenderer.h"
35 #include "vtkRenderWindow.h"
36 #include "vtkRenderWindowInteractor.h"
37 #include "vtkSmartPointer.h"
38 
39 #include "vtkOSPRayTestInteractor.h"
40 
TestOSPRayPass(int argc,char * argv[])41 int TestOSPRayPass(int argc, char* argv[])
42 {
43   vtkSmartPointer<vtkRenderWindowInteractor> iren = vtkSmartPointer<vtkRenderWindowInteractor>::New();
44   vtkSmartPointer<vtkRenderWindow> renWin = vtkSmartPointer<vtkRenderWindow>::New();
45   iren->SetRenderWindow(renWin);
46   vtkSmartPointer<vtkRenderer> renderer = vtkSmartPointer<vtkRenderer>::New();
47   renWin->AddRenderer(renderer);
48 
49   const char* fileName =
50     vtkTestUtilities::ExpandDataFileName(argc, argv, "Data/bunny.ply");
51   vtkSmartPointer<vtkPLYReader> polysource = vtkSmartPointer<vtkPLYReader>::New();
52   polysource->SetFileName(fileName);
53 
54   //TODO: ospray acts strangely without these such that Diff and Spec are not 0..255 instead of 0..1
55   vtkSmartPointer<vtkPolyDataNormals> normals = vtkSmartPointer<vtkPolyDataNormals>::New();
56   normals->SetInputConnection(polysource->GetOutputPort());
57   //normals->ComputePointNormalsOn();
58   //normals->ComputeCellNormalsOff();
59 
60   vtkSmartPointer<vtkPolyDataMapper> mapper=vtkSmartPointer<vtkPolyDataMapper>::New();
61   mapper->SetInputConnection(normals->GetOutputPort());
62   vtkSmartPointer<vtkActor> actor=vtkSmartPointer<vtkActor>::New();
63   renderer->AddActor(actor);
64   actor->SetMapper(mapper);
65   renderer->SetBackground(0.1,0.1,1.0);
66   renWin->SetSize(400,400);
67   renWin->Render();
68 
69   vtkSmartPointer<vtkOSPRayPass> ospray=vtkSmartPointer<vtkOSPRayPass>::New();
70 
71   for (int i = 1; i<10; i++)
72   {
73     if (i%2)
74     {
75       cerr << "Render via OSPRAY" << endl;
76       renderer->SetPass(ospray);
77     }
78     else
79     {
80       cerr << "Render via GL" << endl;
81       renderer->SetPass(nullptr);
82     }
83     renWin->Render();
84   }
85 
86   vtkSmartPointer<vtkOSPRayTestInteractor> style =
87     vtkSmartPointer<vtkOSPRayTestInteractor>::New();
88   style->SetPipelineControlPoints(renderer, ospray, nullptr);
89   iren->SetInteractorStyle(style);
90   style->SetCurrentRenderer(renderer);
91 
92   iren->Start();
93 
94   return 0;
95 }
96