Commit 4a842da9 authored by Michael Migliore's avatar Michael Migliore

Add a panoramic projection pass

This pass render the scene in all direction and projects those renders
using different types of projection (equirectangular or azimuthal projection)
parent 0857be6f
...@@ -71,6 +71,7 @@ set(Module_SRCS ...@@ -71,6 +71,7 @@ set(Module_SRCS
vtkOpenGLVertexBufferObjectGroup.cxx vtkOpenGLVertexBufferObjectGroup.cxx
vtkOrderIndependentTranslucentPass.cxx vtkOrderIndependentTranslucentPass.cxx
vtkOverlayPass.cxx vtkOverlayPass.cxx
vtkPanoramicProjectionPass.cxx
vtkPixelBufferObject.cxx vtkPixelBufferObject.cxx
vtkPointFillPass.cxx vtkPointFillPass.cxx
vtkRenderPassCollection.cxx vtkRenderPassCollection.cxx
......
...@@ -26,6 +26,7 @@ vtk_add_test_cxx(vtkRenderingOpenGL2CxxTests tests ...@@ -26,6 +26,7 @@ vtk_add_test_cxx(vtkRenderingOpenGL2CxxTests tests
TestMultiTexturing.cxx TestMultiTexturing.cxx
TestOffscreenRenderingResize.cxx TestOffscreenRenderingResize.cxx
TestOrderIndependentTranslucentPass.cxx TestOrderIndependentTranslucentPass.cxx
TestPanoramicProjectionPass.cxx,NO_DATA
TestPointFillPass.cxx TestPointFillPass.cxx
TestPointGaussianSelection.cxx,NO_DATA TestPointGaussianSelection.cxx,NO_DATA
TestPropPicker2Renderers.cxx,NO_DATA TestPropPicker2Renderers.cxx,NO_DATA
......
/*=========================================================================
Program: Visualization Toolkit
Module: TestPanoramicProjectionPass.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 covers the tone mapping post-processing render pass.
// It renders an opaque actor with a lot of lights.
#include "vtkRegressionTestImage.h"
#include "vtkTestUtilities.h"
#include "vtkActor.h"
#include "vtkCamera.h"
#include "vtkCameraPass.h"
#include "vtkCullerCollection.h"
#include "vtkPanoramicProjectionPass.h"
#include "vtkLight.h"
#include "vtkLightsPass.h"
#include "vtkOpaquePass.h"
#include "vtkOpenGLRenderer.h"
#include "vtkPolyDataMapper.h"
#include "vtkProperty.h"
#include "vtkRenderPassCollection.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkSequencePass.h"
#include "vtkSphereSource.h"
int TestPanoramicProjectionPass(int argc, char* argv[])
{
vtkNew<vtkRenderWindow> renWin;
renWin->SetSize(400, 400);
vtkNew<vtkRenderWindowInteractor> iren;
iren->SetRenderWindow(renWin);
vtkNew<vtkSphereSource> sphere;
sphere->SetRadius(1.0);
vtkNew<vtkRenderer> renderer;
renderer->GetCullers()->RemoveAllItems();
renderer->SetBackground(1.0, 1.0, 1.0);
renderer->AutomaticLightCreationOff();
vtkNew<vtkLight> light;
light->SetPosition(0.0, 10.0, 0.0);
light->SetFocalPoint(0.0, 0.0, 0.0);
light->SetLightTypeToSceneLight();
renderer->AddLight(light);
// custom passes
vtkNew<vtkCameraPass> cameraP;
vtkNew<vtkSequencePass> seq;
vtkNew<vtkOpaquePass> opaque;
vtkNew<vtkLightsPass> lights;
vtkNew<vtkRenderPassCollection> passes;
passes->AddItem(lights);
passes->AddItem(opaque);
seq->SetPasses(passes);
cameraP->SetDelegatePass(seq);
vtkNew<vtkPanoramicProjectionPass> projectionP;
projectionP->SetProjectionTypeToAzimuthal();
projectionP->SetAngle(360.0);
projectionP->SetDelegatePass(cameraP);
vtkOpenGLRenderer::SafeDownCast(renderer)->SetPass(projectionP);
renWin->AddRenderer(renderer);
vtkNew<vtkPolyDataMapper> mapper;
mapper->SetInputConnection(sphere->GetOutputPort());
for (int i = 0; i < 4; i++)
{
double f = i & 1 ? -2.0 : 2.0;
double x = i & 2 ? 1.0 : 0.0;
double c[3] = { static_cast<double>((i + 1) & 1),
static_cast<double>(((i + 1) >> 1) & 1),
static_cast<double>(((i + 1) >> 2) & 1) };
vtkNew<vtkActor> actor;
actor->SetMapper(mapper);
actor->SetPosition(f * x, 0.0, f * (1.0 - x));
actor->GetProperty()->SetColor(c);
renderer->AddActor(actor);
}
vtkNew<vtkCamera> camera;
camera->SetPosition(0.0, 0.0, 0.0);
camera->SetFocalPoint(0.0, 0.0, 1.0);
camera->SetViewUp(0.0, 1.0, 0.0);
renderer->SetActiveCamera(camera);
renWin->Render();
int retVal = vtkRegressionTestImage(renWin);
if (retVal == vtkRegressionTester::DO_INTERACTOR)
{
iren->Start();
}
return !retVal;
}
11e1f1020ba1c5681a90095c9cc2415c9d20c0ebff5941c352add3bd93d79404fbe87987aec172dc0e4f8e925c6323836beefcc75988ef912337ad9b2b4ea3a5
This diff is collapsed.
/*=========================================================================
Program: Visualization Toolkit
Module: vtkPanoramicProjectionPass.h
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.
=========================================================================*/
/**
* @class vtkPanoramicProjectionPass
* @brief Render pass that render the scene in a cubemap and project
* these six renderings to a single quad.
* There are currently two differents projections implemented (Equirectangular and Azimuthal).
* This pass can be used to produce images that can be visualize with specific devices that re-maps
* the distorted image to a panoramic view (for instance VR headsets, domes, panoramic screens)
*
* Note that it is often necessary to disable frustum cullers in order to render
* properly objects that are behind the camera.
*
* @sa
* vtkRenderPass
*/
#ifndef vtkPanoramicProjectionPass_h
#define vtkPanoramicProjectionPass_h
#include "vtkImageProcessingPass.h"
#include "vtkRenderingOpenGL2Module.h" // For export macro
class vtkOpenGLFramebufferObject;
class vtkOpenGLQuadHelper;
class vtkTextureObject;
class VTKRENDERINGOPENGL2_EXPORT vtkPanoramicProjectionPass : public vtkImageProcessingPass
{
public:
static vtkPanoramicProjectionPass* New();
vtkTypeMacro(vtkPanoramicProjectionPass, vtkImageProcessingPass);
void PrintSelf(ostream& os, vtkIndent indent) override;
/**
* Perform rendering according to a render state.
*/
void Render(const vtkRenderState* s) override;
/**
* Release graphics resources and ask components to release their own resources.
*/
void ReleaseGraphicsResources(vtkWindow* w) override;
//@{
/**
* Get/Set the cubemap textures resolution used to render (offscreen) all directions.
* Default is 300.
*/
vtkGetMacro(CubeResolution, unsigned int);
vtkSetMacro(CubeResolution, unsigned int);
//@}
/**
* Enumeration of projection types.
*/
enum : int
{
Equirectangular = 1, /**< Equirectangular projection */
Azimuthal = 2 /**< Azimuthal equidistant projection */
};
//@{
/**
* Get/Set the type of projection.
* Equirectangular projection maps meridians to vertical straight lines and circles of latitude to
* horizontal straight lines.
* Azimuthal equidistant projection maps all points of the scene based on their distance to the
* view direction. This projection produces a fisheye effect.
* Default is Equirectangular.
*/
vtkGetMacro(ProjectionType, int);
vtkSetClampMacro(ProjectionType, int, Equirectangular, Azimuthal);
void SetProjectionTypeToEquirectangular() { this->SetProjectionType(Equirectangular); }
void SetProjectionTypeToAzimuthal() { this->SetProjectionType(Azimuthal); }
//@}
//@{
/**
* Get/Set the vertical angle of projection.
* 180 degrees is a half sphere, 360 degrees is a full sphere,
* but any values in the range (90;360) can be set.
* Default is 180 degrees.
*/
vtkGetMacro(Angle, double);
vtkSetClampMacro(Angle, double, 90.0, 360.0);
//@}
protected:
vtkPanoramicProjectionPass() = default;
~vtkPanoramicProjectionPass() override = default;
void RenderOnFace(const vtkRenderState* s, int index);
void Project(vtkOpenGLRenderWindow* renWin);
void InitOpenGLResources(vtkOpenGLRenderWindow* renWin);
/**
* Graphics resources.
*/
vtkOpenGLFramebufferObject* FrameBufferObject = nullptr;
vtkTextureObject* CubeMapTexture = nullptr;
vtkOpenGLQuadHelper* QuadHelper = nullptr;
unsigned int CubeResolution = 300;
int ProjectionType = Equirectangular;
double Angle = 180.0;
private:
vtkPanoramicProjectionPass(const vtkPanoramicProjectionPass&) = delete;
void operator=(const vtkPanoramicProjectionPass&) = delete;
};
#endif
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