Commit bbf9b115 authored by Michael Fogleman's avatar Michael Fogleman Committed by Kitware Robot

Merge topic 'ospray-orthographic'

f84ff950 add TestOSPRayOrthographic
6924a334 Support parallel project in 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: !1827
parents 88ce5bfd f84ff950
......@@ -8,6 +8,7 @@ vtk_add_test_cxx(${vtk-module}CxxTests tests
TestOSPRayLights.cxx,
TestOSPRayMultiBlock.cxx
TestOSPRayMultiBlockPartialArrayFieldData.cxx,
TestOSPRayOrthographic.cxx,
TestOSPRayPass.cxx,
TestOSPRayRenderMesh.cxx,
TestOSPRayScalarBar.cxx
......
/*=========================================================================
Program: Visualization Toolkit
Module: TestOSPRayOrthographic.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 TestOSPRayOrthographic(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);
vtkCamera *camera = renderer->GetActiveCamera();
camera->SetParallelProjection(1);
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;
}
......@@ -54,23 +54,31 @@ void vtkOSPRayCameraNode::Render(bool prepass)
vtkRenderer *ren = vtkRenderer::SafeDownCast(orn->GetRenderable());
int tiledSize[2];
int tiledOrigin[2];
ren->GetTiledSizeAndOrigin(&tiledSize[0], &tiledSize[1],
&tiledOrigin[0], &tiledOrigin[1]);
OSPCamera ospCamera = ospNewCamera("perspective");
ospSetObject(orn->GetORenderer(),"camera", ospCamera);
ren->GetTiledSizeAndOrigin(
&tiledSize[0], &tiledSize[1], &tiledOrigin[0], &tiledOrigin[1]);
vtkCamera *cam = static_cast<vtkCamera *>(this->Renderable);
ospSetf(ospCamera,"aspect", float(tiledSize[0])/float(tiledSize[1]));
ospSetf(ospCamera,"fovy",cam->GetViewAngle());
OSPCamera ospCamera;
if (cam->GetParallelProjection())
{
ospCamera = ospNewCamera("orthographic");
ospSetf(ospCamera, "height", cam->GetParallelScale() * 2);
}
else
{
ospCamera = ospNewCamera("perspective");
ospSetf(ospCamera, "fovy", cam->GetViewAngle());
}
ospSetObject(orn->GetORenderer(), "camera", ospCamera);
ospSetf(ospCamera, "aspect", float(tiledSize[0]) / float(tiledSize[1]));
double *pos = cam->GetPosition();
ospSet3f(ospCamera,"pos",pos[0], pos[1], pos[2]);
ospSet3f(ospCamera,"up",
cam->GetViewUp()[0], cam->GetViewUp()[1], cam->GetViewUp()[2]);
ospSet3f(ospCamera, "pos", pos[0], pos[1], pos[2]);
double *up = cam->GetViewUp();
ospSet3f(ospCamera, "up", up[0], up[1], up[2]);
double *dop = cam->GetDirectionOfProjection();
ospSet3f(ospCamera,"dir", dop[0], dop[1], dop[2]);
ospSet3f(ospCamera, "dir", dop[0], dop[1], dop[2]);
ospCommit(ospCamera);
ospRelease(ospCamera);
}
......
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