Commit 44b2711e authored by Michael Fogleman's avatar Michael Fogleman Committed by Kitware Robot

Merge topic 'ospray-renderer-type'

55282449 Add TestOSPRayRendererType; add 't' command for OSPRay tests
36878f3d Doxygen comments and other cleanup
5388c05a Allow selecting scivis vs pathtracer for OSPRay
Acked-by: Kitware Robot's avatarKitware Robot <kwrobot@kitware.com>
Reviewed-by: David E. DeMarle's avatarDavid E DeMarle <dave.demarle@kitware.com>
Merge-request: !1889
parents babcc816 55282449
......@@ -11,6 +11,7 @@ vtk_add_test_cxx(${vtk-module}CxxTests tests
TestOSPRayOrthographic.cxx,
TestOSPRayPass.cxx,
TestOSPRayRenderMesh.cxx,
TestOSPRayRendererType.cxx,
TestOSPRayScalarBar.cxx
TestOSPRayTime.cxx,
TestOSPRayWindow.cxx
......
/*=========================================================================
Program: Visualization Toolkit
Module: TestOSPRayRendererType.cxx
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
// This test verifies that we can switch between scivis and pathtracer modes
//
// The command line arguments are:
// -I => run in interactive mode; unless this is used, the program will
// not allow interaction and exit
// In interactive mode it responds to the keys listed
// vtkOSPRayTestInteractor.h
#include "vtkTestUtilities.h"
#include "vtkActor.h"
#include "vtkCamera.h"
#include "vtkOpenGLRenderer.h"
#include "vtkOSPRayPass.h"
#include "vtkOSPRayRendererNode.h"
#include "vtkPolyDataMapper.h"
#include "vtkPolyDataNormals.h"
#include "vtkPLYReader.h"
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkSmartPointer.h"
#include "vtkOSPRayTestInteractor.h"
int TestOSPRayRendererType(int argc, char* argv[])
{
vtkSmartPointer<vtkRenderWindowInteractor> iren = vtkSmartPointer<vtkRenderWindowInteractor>::New();
vtkSmartPointer<vtkRenderWindow> renWin = vtkSmartPointer<vtkRenderWindow>::New();
iren->SetRenderWindow(renWin);
vtkSmartPointer<vtkRenderer> renderer = vtkSmartPointer<vtkRenderer>::New();
renWin->AddRenderer(renderer);
const char* fileName =
vtkTestUtilities::ExpandDataFileName(argc, argv, "Data/bunny.ply");
vtkSmartPointer<vtkPLYReader> polysource = vtkSmartPointer<vtkPLYReader>::New();
polysource->SetFileName(fileName);
//TODO: ospray acts strangely without these such that Diff and Spec are not 0..255 instead of 0..1
vtkSmartPointer<vtkPolyDataNormals> normals = vtkSmartPointer<vtkPolyDataNormals>::New();
normals->SetInputConnection(polysource->GetOutputPort());
//normals->ComputePointNormalsOn();
//normals->ComputeCellNormalsOff();
vtkSmartPointer<vtkPolyDataMapper> mapper=vtkSmartPointer<vtkPolyDataMapper>::New();
mapper->SetInputConnection(normals->GetOutputPort());
vtkSmartPointer<vtkActor> actor=vtkSmartPointer<vtkActor>::New();
renderer->AddActor(actor);
actor->SetMapper(mapper);
renderer->SetBackground(0.1,0.1,1.0);
renWin->SetSize(400,400);
renWin->Render();
vtkSmartPointer<vtkOSPRayPass> ospray=vtkSmartPointer<vtkOSPRayPass>::New();
vtkOSPRayRendererNode *ren = ospray->GetSceneGraph();
renderer->SetPass(ospray);
for (int i = 1; i<9; i++)
{
if (i%2)
{
cerr << "Render via scivis" << endl;
ren->SetRendererType("scivis", renderer);
}
else
{
cerr << "Render via pathtracer" << endl;
ren->SetRendererType("pathtracer", renderer);
}
renWin->Render();
}
vtkSmartPointer<vtkOSPRayTestInteractor> style =
vtkSmartPointer<vtkOSPRayTestInteractor>::New();
style->SetPipelineControlPoints((vtkOpenGLRenderer*)renderer.Get(), ospray, NULL);
iren->SetInteractorStyle(style);
style->SetCurrentRenderer(renderer);
iren->Start();
return 0;
}
......@@ -173,6 +173,20 @@ void vtkOSPRayTestInteractor::OnKeyPress()
this->GLRenderer->GetRenderWindow()->Render();
}
if(key == "t")
{
std::string type = vtkOSPRayRendererNode::GetRendererType(this->GLRenderer);
if (type == std::string("scivis"))
{
vtkOSPRayRendererNode::SetRendererType("pathtracer", this->GLRenderer);
}
else
{
vtkOSPRayRendererNode::SetRendererType("scivis", this->GLRenderer);
}
this->GLRenderer->GetRenderWindow()->Render();
}
if(key == "2")
{
int spp = vtkOSPRayRendererNode::GetSamplesPerPixel(this->GLRenderer);
......
......@@ -23,6 +23,7 @@
// l => turns on each light in the scene in turn
// I/i => increase/decrease the global light intensity scale
// D/d => increase/decrease the number of ambient occlusion samples
// t => change renderer type: scivis, pathtracer
#ifndef vtkOSPRayTestInteractor_h
#define vtkOSPRayTestInteractor_h
......
......@@ -64,6 +64,14 @@ void vtkOSPRayCompositePolyDataMapper2Node::PrintSelf(ostream& os, vtkIndent ind
this->Superclass::PrintSelf(os, indent);
}
//----------------------------------------------------------------------------
void vtkOSPRayCompositePolyDataMapper2Node::Invalidate(bool prepass)
{
if (prepass)
{
this->RenderTime = 0;
}
}
//----------------------------------------------------------------------------
void vtkOSPRayCompositePolyDataMapper2Node::Render(bool prepass)
......
......@@ -40,6 +40,10 @@ public:
//Make ospray calls to render me.
virtual void Render(bool prepass);
//Description:
//Invalidates cached rendering data.
virtual void Invalidate(bool prepass);
protected:
vtkOSPRayCompositePolyDataMapper2Node();
~vtkOSPRayCompositePolyDataMapper2Node();
......
......@@ -914,6 +914,15 @@ void vtkOSPRayPolyDataMapperNode::CreateNewMeshes()
this->OSPMeshes = myMeshes;
}
//----------------------------------------------------------------------------
void vtkOSPRayPolyDataMapperNode::Invalidate(bool prepass)
{
if (prepass)
{
this->RenderTime = 0;
}
}
//----------------------------------------------------------------------------
void vtkOSPRayPolyDataMapperNode::Render(bool prepass)
{
......
......@@ -37,6 +37,10 @@ public:
//Make ospray calls to render me.
virtual void Render(bool prepass);
//Description:
//Invalidates cached rendering data.
virtual void Invalidate(bool prepass);
protected:
vtkOSPRayPolyDataMapperNode();
~vtkOSPRayPolyDataMapperNode();
......
......@@ -18,6 +18,7 @@
#include "vtkCollectionIterator.h"
#include "vtkInformation.h"
#include "vtkInformationIntegerKey.h"
#include "vtkInformationStringKey.h"
#include "vtkObjectFactory.h"
#include "vtkOSPRayActorNode.h"
#include "vtkOSPRayCameraNode.h"
......@@ -161,6 +162,7 @@ vtkInformationKeyMacro(vtkOSPRayRendererNode, SAMPLES_PER_PIXEL, Integer);
vtkInformationKeyMacro(vtkOSPRayRendererNode, MAX_FRAMES, Integer);
vtkInformationKeyMacro(vtkOSPRayRendererNode, AMBIENT_SAMPLES, Integer);
vtkInformationKeyMacro(vtkOSPRayRendererNode, COMPOSITE_ON_GL, Integer);
vtkInformationKeyMacro(vtkOSPRayRendererNode, RENDERER_TYPE, String);
//============================================================================
vtkStandardNewMacro(vtkOSPRayRendererNode);
......@@ -251,6 +253,32 @@ int vtkOSPRayRendererNode::GetMaxFrames(vtkRenderer *renderer)
return 1;
}
//----------------------------------------------------------------------------
void vtkOSPRayRendererNode::SetRendererType(std::string name, vtkRenderer *renderer)
{
if (!renderer)
{
return;
}
vtkInformation *info = renderer->GetInformation();
info->Set(vtkOSPRayRendererNode::RENDERER_TYPE(), name);
}
//----------------------------------------------------------------------------
std::string vtkOSPRayRendererNode::GetRendererType(vtkRenderer *renderer)
{
if (!renderer)
{
return std::string("scivis");
}
vtkInformation *info = renderer->GetInformation();
if (info && info->Has(vtkOSPRayRendererNode::RENDERER_TYPE()))
{
return (info->Get(vtkOSPRayRendererNode::RENDERER_TYPE()));
}
return std::string("scivis");
}
//----------------------------------------------------------------------------
void vtkOSPRayRendererNode::SetAmbientSamples(int value, vtkRenderer *renderer)
{
......@@ -427,6 +455,15 @@ void vtkOSPRayRendererNode::Traverse(int operation)
this->Apply(operation,false);
}
//----------------------------------------------------------------------------
void vtkOSPRayRendererNode::Invalidate(bool prepass)
{
if (prepass)
{
this->RenderTime = 0;
}
}
//----------------------------------------------------------------------------
void vtkOSPRayRendererNode::Build(bool prepass)
{
......@@ -454,11 +491,15 @@ void vtkOSPRayRendererNode::Render(bool prepass)
if (prepass)
{
OSPRenderer oRenderer = NULL;
if (!this->ORenderer)
static std::string previousType;
std::string type = this->GetRendererType(static_cast<vtkRenderer*>(this->Renderable));
if (!this->ORenderer || previousType != type)
{
this->Traverse(invalidate);
ospRelease((osp::Renderer*)this->ORenderer);
oRenderer = (osp::Renderer*)ospNewRenderer("scivis");
oRenderer = (osp::Renderer*)ospNewRenderer(type.c_str());
this->ORenderer = oRenderer;
previousType = type;
}
else
{
......
......@@ -25,6 +25,7 @@
class vtkRenderer;
class vtkInformationIntegerKey;
class vtkInformationStringKey;
// ospray forward decs so that someone does not need to include ospray.h
namespace osp {
struct Model;
......@@ -56,6 +57,10 @@ public:
//Traverse graph in ospray's prefered order and render
virtual void Render(bool prepass);
//Description:
//Invalidates cached rendering data.
virtual void Invalidate(bool prepass);
//Description:
//Put my results into the correct place in the provided pixel buffer.
virtual void WriteLayer(unsigned char *buffer, float *zbuffer,
......@@ -83,6 +88,13 @@ public:
static void SetMaxFrames(int, vtkRenderer *renderer);
static int GetMaxFrames(vtkRenderer *renderer);
//Description:
//Set the OSPRay renderer type to use (e.g. scivis vs. pathtracer)
//default is scivis
static vtkInformationStringKey* RENDERER_TYPE();
static void SetRendererType(std::string name, vtkRenderer *renderer);
static std::string GetRendererType(vtkRenderer *renderer);
//Description:
//When present on renderer, controls the number of ambient occlusion
//samples shot per hit.
......
......@@ -254,6 +254,9 @@ void vtkViewNode::Apply(int operation, bool prepass)
case render:
this->Render(prepass);
break;
case invalidate:
this->Invalidate(prepass);
break;
default:
cerr << "UNKNOWN OPERATION" << operation << endl;
}
......
......@@ -54,6 +54,10 @@ public:
//Makes calls to make self visible.
virtual void Render(bool /*prepass*/) {};
//Description:
//Clear any cached data.
virtual void Invalidate(bool /*prepass*/) {};
//Description:
//Access the node that owns this one.
virtual void SetParent(vtkViewNode*);
......@@ -96,7 +100,7 @@ public:
//Description:
//internal mechanics of graph traversal and actions
enum operation_type{noop, build, synchronize, render};
enum operation_type{noop, build, synchronize, render, invalidate};
protected:
vtkViewNode();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment