Commit fd6e1d2e authored by David Gobbi's avatar David Gobbi Committed by Kitware Robot

Merge topic 'rendering_stereo_background'

18322771 Enabling support for augmented reality via video passthrough
Acked-by: Kitware Robot's avatarKitware Robot <kwrobot@kitware.com>
Acked-by: David Gobbi's avatarDavid Gobbi <david.gobbi@gmail.com>
Acked-by: Jean-Christophe Fillion-Robin's avatarJean-Christophe Fillion-Robin <jchris.fillionr@kitware.com>
Merge-request: !3902
parents c8de5438 18322771
......@@ -71,6 +71,8 @@ vtk_add_test_cxx(vtkRenderingCoreCxxTests tests
TestOffAxisStereo.cxx
TestOrderedTriangulator.cxx
TestOpacity.cxx
TestStereoBackgroundLeft.cxx
TestStereoBackgroundRight.cxx
TestOSConeCxx.cxx
TestPickTextActor.cxx,NO_VALID
TestPointSelection.cxx,NO_VALID
......
#include "vtkConeSource.h"
#include "vtkImageData.h"
#include "vtkJPEGReader.h"
#include "vtkPolyDataMapper.h"
#include "vtkProperty.h"
#include "vtkRegressionTestImage.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkRenderer.h"
#include "vtkSmartPointer.h"
#include "vtkTestUtilities.h"
#include "vtkTexture.h"
#define VTK_CREATE(type,name) \
vtkSmartPointer<type> name = vtkSmartPointer<type>::New()
int TestStereoBackgroundLeft(int argc, char* argv[])
{
VTK_CREATE(vtkRenderWindow, win);
VTK_CREATE(vtkRenderWindowInteractor, iren);
VTK_CREATE(vtkRenderer, ren);
VTK_CREATE(vtkConeSource, cone);
VTK_CREATE(vtkPolyDataMapper, map);
VTK_CREATE(vtkActor, act);
VTK_CREATE(vtkTexture, textr);
VTK_CREATE(vtkJPEGReader, imgReader);
VTK_CREATE(vtkImageData, image);
char* fname = vtkTestUtilities::ExpandDataFileName(
argc, argv, "Data/beach.jpg");
imgReader->SetFileName(fname);
delete[] fname;
imgReader->Update();
textr->SetInputConnection(imgReader->GetOutputPort(0));
map->SetInputConnection(cone->GetOutputPort(0));
act->SetMapper(map);
act->GetProperty()->BackfaceCullingOn();
ren->AddActor(act);
ren->TexturedBackgroundOn();
ren->SetBackgroundTexture(textr);
win->AddRenderer(ren);
win->SetInteractor(iren);
win->SetMultiSamples(0);
win->SetStereoTypeToLeft();
win->SetStereoRender(true);
win->Render();
iren->Initialize();
int retVal = vtkRegressionTestImage(win);
if (retVal == vtkRegressionTester::DO_INTERACTOR)
{
iren->Start();
}
return !retVal;
}
#include "vtkConeSource.h"
#include "vtkImageData.h"
#include "vtkJPEGReader.h"
#include "vtkPolyDataMapper.h"
#include "vtkProperty.h"
#include "vtkRegressionTestImage.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkRenderer.h"
#include "vtkSmartPointer.h"
#include "vtkTestUtilities.h"
#include "vtkTexture.h"
#define VTK_CREATE(type,name) \
vtkSmartPointer<type> name = vtkSmartPointer<type>::New()
int TestStereoBackgroundRight(int argc, char* argv[])
{
VTK_CREATE(vtkRenderWindow, win);
VTK_CREATE(vtkRenderWindowInteractor, iren);
VTK_CREATE(vtkRenderer, ren);
VTK_CREATE(vtkConeSource, cone);
VTK_CREATE(vtkPolyDataMapper, map);
VTK_CREATE(vtkActor, act);
VTK_CREATE(vtkTexture, textr);
VTK_CREATE(vtkJPEGReader, imgReader);
VTK_CREATE(vtkImageData, image);
char* fname = vtkTestUtilities::ExpandDataFileName(
argc, argv, "Data/beach.jpg");
imgReader->SetFileName(fname);
delete[] fname;
imgReader->Update();
textr->SetInputConnection(imgReader->GetOutputPort(0));
map->SetInputConnection(cone->GetOutputPort(0));
act->SetMapper(map);
act->GetProperty()->BackfaceCullingOn();
ren->AddActor(act);
ren->TexturedBackgroundOn();
ren->SetRightBackgroundTexture(textr);
win->AddRenderer(ren);
win->SetInteractor(iren);
win->SetMultiSamples(0);
win->SetStereoTypeToRight();
win->SetStereoRender(true);
win->Render();
iren->Initialize();
int retVal = vtkRegressionTestImage(win);
if (retVal == vtkRegressionTester::DO_INTERACTOR)
{
iren->Start();
}
return !retVal;
}
77d1825332247b808954a25f7ac5ee37794dd1df5d548d2f1c1e30a3a69227b8fd9cb1a8d15ad7b9e61f17000db6406b6a5843b3ab239179a5b8a741b88437c6
5af13fc3ea7b8bb6555dc63294070500ddd610281e57b8f93fbf19cd4aa1c3315b8d8bc6a5eaa6c708ccad5f53f147b71e8d4079db745ad7b17e745347065849
......@@ -49,6 +49,7 @@
vtkCxxSetObjectMacro(vtkRenderer, Information, vtkInformation);
vtkCxxSetObjectMacro(vtkRenderer, Delegate, vtkRendererDelegate);
vtkCxxSetObjectMacro(vtkRenderer, BackgroundTexture, vtkTexture);
vtkCxxSetObjectMacro(vtkRenderer, RightBackgroundTexture, vtkTexture);
vtkCxxSetObjectMacro(vtkRenderer, Pass, vtkRenderPass);
vtkCxxSetObjectMacro(vtkRenderer, FXAAOptions, vtkFXAAOptions);
......@@ -139,6 +140,7 @@ vtkRenderer::vtkRenderer()
this->TexturedBackground = false;
this->BackgroundTexture = nullptr;
this->RightBackgroundTexture = nullptr;
this->Pass = nullptr;
......@@ -190,15 +192,34 @@ vtkRenderer::~vtkRenderer()
this->BackgroundTexture->Delete();
}
if (this->RightBackgroundTexture != nullptr)
{
this->RightBackgroundTexture->Delete();
}
this->SetInformation(nullptr);
}
void vtkRenderer::SetLeftBackgroundTexture(vtkTexture* texture)
{
this->SetBackgroundTexture(texture);
}
vtkTexture* vtkRenderer::GetLeftBackgroundTexture()
{
return this->GetBackgroundTexture();
}
void vtkRenderer::ReleaseGraphicsResources(vtkWindow *renWin)
{
if(this->BackgroundTexture != nullptr)
{
this->BackgroundTexture->ReleaseGraphicsResources(renWin);
}
if (this->RightBackgroundTexture != nullptr)
{
this->RightBackgroundTexture->ReleaseGraphicsResources(renWin);
}
vtkProp *aProp;
vtkCollectionSimpleIterator pit;
this->Props->InitTraversal(pit);
......@@ -1664,6 +1685,16 @@ void vtkRenderer::PrintSelf(ostream& os, vtkIndent indent)
os << "null" << endl;
}
os << indent << "RightBackgroundTexture:";
if (this->RightBackgroundTexture != nullptr)
{
os << "exists" << endl;
}
else
{
os << "null" << endl;
}
os << indent << "Pass:";
if(this->Pass!=nullptr)
{
......
......@@ -662,13 +662,25 @@ public:
//@{
/**
* Set/Get the texture to be used for the background. If set
* and enabled this gets the priority over the gradient background.
* Set/Get the texture to be used for the monocular or stereo left eye
* background. If set and enabled this gets the priority over the gradient
* background.
*/
virtual void SetLeftBackgroundTexture(vtkTexture*);
vtkTexture* GetLeftBackgroundTexture();
virtual void SetBackgroundTexture(vtkTexture*);
vtkGetObjectMacro(BackgroundTexture, vtkTexture);
//@}
//@{
/**
* Set/Get the texture to be used for the right eye background. If set
* and enabled this gets the priority over the gradient background.
*/
virtual void SetRightBackgroundTexture(vtkTexture*);
vtkGetObjectMacro(RightBackgroundTexture, vtkTexture);
//@}
//@{
/**
* Set/Get whether this viewport should have a textured background.
......@@ -955,6 +967,7 @@ protected:
bool TexturedBackground;
vtkTexture* BackgroundTexture;
vtkTexture* RightBackgroundTexture;
friend class vtkRenderPass;
vtkRenderPass *Pass;
......
......@@ -75,7 +75,6 @@ vtkOpenGLRenderer::vtkOpenGLRenderer()
this->ShadowMapPass = nullptr;
this->DepthPeelingHigherLayer=0;
this->BackgroundTexture = nullptr;
this->HaveApplePrimitiveIdBugValue = false;
this->HaveApplePrimitiveIdBugChecked = false;
......@@ -388,6 +387,27 @@ int vtkOpenGLRenderer::UpdateGeometry()
return this->NumberOfPropsRendered;
}
//----------------------------------------------------------------------------
vtkTexture* vtkOpenGLRenderer::GetCurrentTexturedBackground()
{
if (!this->GetRenderWindow()->GetStereoRender() && this->BackgroundTexture)
{
return this->BackgroundTexture;
}
else if (this->GetRenderWindow()->GetStereoRender() && this->GetActiveCamera()->GetLeftEye() == 1 && this->BackgroundTexture)
{
return this->BackgroundTexture;
}
else if (this->GetRenderWindow()->GetStereoRender() && this->RightBackgroundTexture)
{
return this->RightBackgroundTexture;
}
else
{
return nullptr;
}
}
// ----------------------------------------------------------------------------
void vtkOpenGLRenderer::DeviceRenderOpaqueGeometry()
{
......@@ -596,10 +616,10 @@ void vtkOpenGLRenderer::Clear(void)
mapper->SetInputConnection(prod->GetOutputPort());
actor->SetMapper(mapper);
if(this->TexturedBackground && this->BackgroundTexture)
if(this->TexturedBackground && this->GetCurrentTexturedBackground())
{
this->BackgroundTexture->InterpolateOn();
actor->SetTexture(this->BackgroundTexture);
this->GetCurrentTexturedBackground()->InterpolateOn();
actor->SetTexture(this->GetCurrentTexturedBackground());
vtkNew<vtkFloatArray> tcoords;
float tmp[2];
......
......@@ -153,6 +153,13 @@ protected:
*/
int UpdateGeometry() override;
/**
* Check and return the textured background for the current state
* If monocular or stereo left eye, check BackgroundTexture
* If stereo right eye, check RightBackgroundTexture
*/
vtkTexture* GetCurrentTexturedBackground();
friend class vtkOpenGLProperty;
friend class vtkOpenGLTexture;
friend class vtkOpenGLImageSliceMapper;
......
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