Commit 7294a6b1 authored by Francois Bertel's avatar Francois Bertel

ENH:Re-factor common code of vtkGaussianBlurPass and...

ENH:Re-factor common code of vtkGaussianBlurPass and vtkSobelGradientMagnitudePass into a new abstract class vtkImageProcessingPass.
parent cf5e8eb3
......@@ -12,6 +12,11 @@ SET(KIT_LIBS vtkGraphics vtkImaging vtkIO
vtkftgl
${VTK_FREETYPE_LIBRARIES}
)
#INCLUDE(${VTK_CMAKE_DIR}/vtkTestGL.cmake)
#INCLUDE(${VTK_CMAKE_DIR}/vtkTestGLX.cmake)
# Fix for bug#1026 moved out of the common section. This should be
# changed to add the flag only in the right places (CMAKE_CXX_FLAGS?).
......@@ -201,6 +206,7 @@ SET( KitOpenGL_SRCS
vtkDefaultPass.cxx
vtkDepthPeelingPass.cxx
vtkGaussianBlurPass.cxx
vtkImageProcessingPass.cxx
vtkLightsPass.cxx
vtkGLSLShaderDeviceAdapter2.cxx
vtkOpaquePass.cxx
......@@ -254,6 +260,7 @@ SET_SOURCE_FILES_PROPERTIES(
vtkAbstractPropPicker
vtkCuller
vtkExporter
vtkImageProcessingPass
vtkImporter
vtkInteractorObserver
vtkMapper
......@@ -278,6 +285,7 @@ SET_SOURCE_FILES_PROPERTIES(
vtkDefaultPass
vtkDepthPeelingPass
vtkGaussianBlurPass
vtkImageProcessingPass
vtkLightsPass
vtkOpaquePass
vtkRenderPass
......
......@@ -37,10 +37,11 @@
#include "vtkPixelBufferObject.h"
#include "vtkPixelBufferObject.h"
#include "vtkImageExtractComponents.h"
#include "vtkCamera.h"
#include "vtkMath.h"
vtkCxxRevisionMacro(vtkGaussianBlurPass, "1.5");
vtkCxxRevisionMacro(vtkGaussianBlurPass, "1.6");
vtkStandardNewMacro(vtkGaussianBlurPass);
vtkCxxSetObjectMacro(vtkGaussianBlurPass,DelegatePass,vtkRenderPass);
extern const char *vtkGaussianBlurPassShader_fs;
......@@ -48,8 +49,6 @@ extern const char *vtkGaussianBlurPassShader_fs;
// ----------------------------------------------------------------------------
vtkGaussianBlurPass::vtkGaussianBlurPass()
{
this->DelegatePass=0;
this->FrameBufferObject=0;
this->Pass1=0;
this->Pass2=0;
......@@ -59,10 +58,6 @@ vtkGaussianBlurPass::vtkGaussianBlurPass()
// ----------------------------------------------------------------------------
vtkGaussianBlurPass::~vtkGaussianBlurPass()
{
if(this->DelegatePass!=0)
{
this->DelegatePass->Delete();
}
if(this->FrameBufferObject!=0)
{
vtkErrorMacro(<<"FrameBufferObject should have been deleted in ReleaseGraphicsResources().");
......@@ -85,16 +80,6 @@ vtkGaussianBlurPass::~vtkGaussianBlurPass()
void vtkGaussianBlurPass::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os,indent);
os << indent << "DelegatePass:";
if(this->DelegatePass!=0)
{
this->DelegatePass->PrintSelf(os,indent);
}
else
{
os << "(none)" <<endl;
}
}
// ----------------------------------------------------------------------------
......@@ -151,70 +136,33 @@ void vtkGaussianBlurPass::Render(const vtkRenderState *s)
// 1. Create a new render state with an FBO.
int width=0;
int height=0;
vtkFrameBufferObject *fbo=s->GetFrameBuffer();
if(fbo==0)
{
r->GetTiledSize(&width,&height);
}
else
{
int size[2];
fbo->GetLastSize(size);
width=size[0];
height=size[1];
}
int width;
int height;
int size[2];
s->GetWindowSize(size);
width=size[0];
height=size[1];
const int extraPixels=2; // two on each side, as the kernel is 5x5
int w=width+extraPixels*2;
int h=height+extraPixels*2;
vtkRenderState s2(r);
s2.SetPropArrayAndCount(s->GetPropArray(),s->GetPropArrayCount());
if(this->FrameBufferObject==0)
{
this->FrameBufferObject=vtkFrameBufferObject::New();
this->FrameBufferObject->SetContext(r->GetRenderWindow());
}
s2.SetFrameBuffer(this->FrameBufferObject);
if(this->Pass1==0)
{
this->Pass1=vtkTextureObject::New();
this->Pass1->SetContext(this->FrameBufferObject->GetContext());
this->Pass1->SetContext(r->GetRenderWindow());
}
if(this->Pass1->GetWidth()!=static_cast<unsigned int>(w) ||
this->Pass1->GetHeight()!=static_cast<unsigned int>(h))
if(this->FrameBufferObject==0)
{
this->Pass1->Create2D(w,h,4,VTK_UNSIGNED_CHAR,false);
this->FrameBufferObject=vtkFrameBufferObject::New();
this->FrameBufferObject->SetContext(r->GetRenderWindow());
}
this->FrameBufferObject->SetColorBuffer(0,this->Pass1);
this->FrameBufferObject->SetDepthBufferNeeded(true);
this->FrameBufferObject->StartNonOrtho(w,h,false);
#ifdef VTK_GAUSSIAN_BLUR_PASS_DEBUG
cout << "gauss finish0" << endl;
glFinish();
#endif
// 2. Delegate render in FBO
glEnable(GL_DEPTH_TEST);
this->DelegatePass->Render(&s2);
this->NumberOfRenderedProps+=
this->DelegatePass->GetNumberOfRenderedProps();
#ifdef VTK_GAUSSIAN_BLUR_PASS_DEBUG
cout << "gauss finish1" << endl;
glFinish();
#endif
this->RenderDelegate(s,width,height,w,h,this->FrameBufferObject,
this->Pass1);
#ifdef VTK_GAUSSIAN_BLUR_PASS_DEBUG
// Save first pass in file for debugging.
vtkPixelBufferObject *pbo=this->Pass1->Download();
......@@ -478,10 +426,8 @@ void vtkGaussianBlurPass::Render(const vtkRenderState *s)
void vtkGaussianBlurPass::ReleaseGraphicsResources(vtkWindow *w)
{
assert("pre: w_exists" && w!=0);
if(this->DelegatePass!=0)
{
this->DelegatePass->ReleaseGraphicsResources(w);
}
this->Superclass::ReleaseGraphicsResources(w);
if(this->BlurProgram!=0)
{
......
......@@ -46,7 +46,7 @@
#ifndef __vtkGaussianBlurPass_h
#define __vtkGaussianBlurPass_h
#include "vtkRenderPass.h"
#include "vtkImageProcessingPass.h"
class vtkOpenGLRenderWindow;
class vtkDepthPeelingPassLayerList; // Pimpl
......@@ -55,11 +55,11 @@ class vtkShader2;
class vtkFrameBufferObject;
class vtkTextureObject;
class VTK_RENDERING_EXPORT vtkGaussianBlurPass : public vtkRenderPass
class VTK_RENDERING_EXPORT vtkGaussianBlurPass : public vtkImageProcessingPass
{
public:
static vtkGaussianBlurPass *New();
vtkTypeRevisionMacro(vtkGaussianBlurPass,vtkRenderPass);
vtkTypeRevisionMacro(vtkGaussianBlurPass,vtkImageProcessingPass);
void PrintSelf(ostream& os, vtkIndent indent);
// Description:
......@@ -73,14 +73,6 @@ public:
// \pre w_exists: w!=0
void ReleaseGraphicsResources(vtkWindow *w);
// Description:
// Delegate for rendering the image to be blurred.
// If it is NULL, nothing will be rendered and a warning will be emitted.
// It is usually set to a vtkCameraPass or to a post-processing pass.
// Initial value is a NULL pointer.
vtkGetObjectMacro(DelegatePass,vtkRenderPass);
virtual void SetDelegatePass(vtkRenderPass *delegatePass);
protected:
// Description:
// Default constructor. DelegatePass is set to NULL.
......@@ -89,8 +81,6 @@ public:
// Description:
// Destructor.
virtual ~vtkGaussianBlurPass();
vtkRenderPass *DelegatePass;
// Description:
// Graphics resources.
......
......@@ -38,9 +38,8 @@
#include "vtkPixelBufferObject.h"
#include "vtkImageExtractComponents.h"
vtkCxxRevisionMacro(vtkSobelGradientMagnitudePass, "1.5");
vtkCxxRevisionMacro(vtkSobelGradientMagnitudePass, "1.6");
vtkStandardNewMacro(vtkSobelGradientMagnitudePass);
vtkCxxSetObjectMacro(vtkSobelGradientMagnitudePass,DelegatePass,vtkRenderPass);
extern const char *vtkSobelGradientMagnitudePassShader1_fs;
extern const char *vtkSobelGradientMagnitudePassShader2_fs;
......@@ -48,9 +47,7 @@ extern const char *vtkSobelGradientMagnitudePassShader2_fs;
// ----------------------------------------------------------------------------
vtkSobelGradientMagnitudePass::vtkSobelGradientMagnitudePass()
{
this->DelegatePass=0;
{
this->FrameBufferObject=0;
this->Pass1=0;
this->Gx1=0;
......@@ -62,10 +59,6 @@ vtkSobelGradientMagnitudePass::vtkSobelGradientMagnitudePass()
// ----------------------------------------------------------------------------
vtkSobelGradientMagnitudePass::~vtkSobelGradientMagnitudePass()
{
if(this->DelegatePass!=0)
{
this->DelegatePass->Delete();
}
if(this->FrameBufferObject!=0)
{
vtkErrorMacro(<<"FrameBufferObject should have been deleted in ReleaseGraphicsResources().");
......@@ -96,16 +89,6 @@ vtkSobelGradientMagnitudePass::~vtkSobelGradientMagnitudePass()
void vtkSobelGradientMagnitudePass::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os,indent);
os << indent << "DelegatePass:";
if(this->DelegatePass!=0)
{
this->DelegatePass->PrintSelf(os,indent);
}
else
{
os << "(none)" <<endl;
}
}
// ----------------------------------------------------------------------------
......@@ -164,72 +147,31 @@ void vtkSobelGradientMagnitudePass::Render(const vtkRenderState *s)
int width=0;
int height=0;
vtkFrameBufferObject *fbo=s->GetFrameBuffer();
if(fbo==0)
{
r->GetTiledSize(&width,&height);
}
else
{
int size[2];
fbo->GetLastSize(size);
width=size[0];
height=size[1];
}
int size[2];
s->GetWindowSize(size);
width=size[0];
height=size[1];
const int extraPixels=1; // one on each side
int w=width+2*extraPixels;
int h=height+2*extraPixels;
vtkRenderState s2(r);
s2.SetPropArrayAndCount(s->GetPropArray(),s->GetPropArrayCount());
if(this->FrameBufferObject==0)
{
this->FrameBufferObject=vtkFrameBufferObject::New();
this->FrameBufferObject->SetContext(r->GetRenderWindow());
}
s2.SetFrameBuffer(this->FrameBufferObject);
if(this->Pass1==0)
{
this->Pass1=vtkTextureObject::New();
this->Pass1->SetContext(this->FrameBufferObject->GetContext());
this->Pass1->SetContext(r->GetRenderWindow());
}
if(this->Pass1->GetWidth()!=static_cast<unsigned int>(w) ||
this->Pass1->GetHeight()!=static_cast<unsigned int>(h))
if(this->FrameBufferObject==0)
{
this->Pass1->Create2D(w,h,4,VTK_UNSIGNED_CHAR,false);
this->FrameBufferObject=vtkFrameBufferObject::New();
this->FrameBufferObject->SetContext(r->GetRenderWindow());
}
this->FrameBufferObject->SetNumberOfRenderTargets(1);
this->FrameBufferObject->SetColorBuffer(0,this->Pass1);
// because the same FBO is used in the second pass but with 2 color
// buffers. for the first pass to use 1, to avoid sideeffects from the
// render of the previous frame.
this->FrameBufferObject->SetActiveBuffer(0);
this->FrameBufferObject->SetDepthBufferNeeded(true);
this->FrameBufferObject->StartNonOrtho(w,h,false);
#ifdef VTK_SOBEL_PASS_DEBUG
cout << "sobel finish0" << endl;
glFinish();
#endif
// 2. Delegate render in FBO
glEnable(GL_DEPTH_TEST);
this->DelegatePass->Render(&s2);
this->NumberOfRenderedProps+=
this->DelegatePass->GetNumberOfRenderedProps();
#ifdef VTK_SOBEL_PASS_DEBUG
cout << "sobel finish1" << endl;
glFinish();
#endif
this->RenderDelegate(s,width,height,w,h,this->FrameBufferObject,
this->Pass1);
#ifdef VTK_SOBEL_PASS_DEBUG
// Save first pass in file for debugging.
vtkPixelBufferObject *pbo=this->Pass1->Download();
......@@ -582,10 +524,7 @@ void vtkSobelGradientMagnitudePass::ReleaseGraphicsResources(vtkWindow *w)
{
assert("pre: w_exists" && w!=0);
if(this->DelegatePass!=0)
{
this->DelegatePass->ReleaseGraphicsResources(w);
}
this->Superclass::ReleaseGraphicsResources(w);
if(this->Program1!=0)
{
......
......@@ -56,7 +56,7 @@
#ifndef __vtkSobelGradientMagnitudePass_h
#define __vtkSobelGradientMagnitudePass_h
#include "vtkRenderPass.h"
#include "vtkImageProcessingPass.h"
class vtkOpenGLRenderWindow;
class vtkDepthPeelingPassLayerList; // Pimpl
......@@ -65,11 +65,11 @@ class vtkShader2;
class vtkFrameBufferObject;
class vtkTextureObject;
class VTK_RENDERING_EXPORT vtkSobelGradientMagnitudePass : public vtkRenderPass
class VTK_RENDERING_EXPORT vtkSobelGradientMagnitudePass : public vtkImageProcessingPass
{
public:
static vtkSobelGradientMagnitudePass *New();
vtkTypeRevisionMacro(vtkSobelGradientMagnitudePass,vtkRenderPass);
vtkTypeRevisionMacro(vtkSobelGradientMagnitudePass,vtkImageProcessingPass);
void PrintSelf(ostream& os, vtkIndent indent);
// Description:
......@@ -83,14 +83,6 @@ public:
// \pre w_exists: w!=0
void ReleaseGraphicsResources(vtkWindow *w);
// Description:
// Delegate for rendering the image to be blurred.
// If it is NULL, nothing will be rendered and a warning will be emitted.
// It is usually set to a vtkCameraPass or to a post-processing pass.
// Initial value is a NULL pointer.
vtkGetObjectMacro(DelegatePass,vtkRenderPass);
virtual void SetDelegatePass(vtkRenderPass *delegatePass);
protected:
// Description:
// Default constructor. DelegatePass is set to NULL.
......@@ -99,8 +91,6 @@ public:
// Description:
// Destructor.
virtual ~vtkSobelGradientMagnitudePass();
vtkRenderPass *DelegatePass;
// Description:
// Graphics resources.
......
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