1 /*=========================================================================
2 
3   Program:   Visualization Toolkit
4   Module:    vtkSobelGradientMagnitudePass.h
5 
6   Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7   All rights reserved.
8   See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10      This software is distributed WITHOUT ANY WARRANTY; without even
11      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12      PURPOSE.  See the above copyright notice for more information.
13 
14 =========================================================================*/
15 // .NAME vtkSobelGradientMagnitudePass - Implement a post-processing edge
16 // detection with a Sobel gradient magnitude render pass.
17 // .SECTION Description
18 // Detect the edges of the image renderered by its delegate. Edge-detection
19 // uses a Sobel high-pass filter (3x3 kernel).
20 //
21 // This pass expects an initialized depth buffer and color buffer.
22 // Initialized buffers means they have been cleared with farest z-value and
23 // background color/gradient/transparent color.
24 // An opaque pass may have been performed right after the initialization.
25 //
26 // The delegate is used once.
27 //
28 // Its delegate is usually set to a vtkCameraPass or to a post-processing pass.
29 //
30 // This pass requires a OpenGL context that supports texture objects (TO),
31 // framebuffer objects (FBO) and GLSL. If not, it will emit an error message
32 // and will render its delegate and return.
33 //
34 // .SECTION Implementation
35 // To compute the gradient magnitude, the x and y components of the gradient
36 // (Gx and Gy) have to be computed first. Each computation of Gx and Gy uses
37 // a separable filter.
38 // The first pass takes the image from the delegate as the single input
39 // texture.
40 // The first pass has two outputs, one for the first part of Gx, Gx1, result of
41 // a convolution with (-1 0 1), one for the first part of Gy, Gy1, result of a
42 // convolution with (1 2 1).
43 // The second pass has two inputs, Gx1 and Gy1. Kernel (1 2 1)^T is applied
44 // to Gx1 and kernel (-1 0 1)^T is applied to Gx2. It gives the values for
45 // Gx and Gy. Thoses values are then used to compute the magnitude of the
46 // gradient which is stored in the render target.
47 // The gradient computation happens per component (R,G,B). A is arbitrarly set
48 // to 1 (full opacity).
49 //
50 // \image html vtkSobelGradientMagnitudePassFigure.png
51 // \image latex vtkSobelGradientMagnitudePassFigure.eps
52 
53 // .SECTION See Also
54 // vtkRenderPass
55 
56 #ifndef vtkSobelGradientMagnitudePass_h
57 #define vtkSobelGradientMagnitudePass_h
58 
59 #include "vtkRenderingOpenGLModule.h" // For export macro
60 #include "vtkImageProcessingPass.h"
61 
62 class vtkOpenGLRenderWindow;
63 class vtkDepthPeelingPassLayerList; // Pimpl
64 class vtkShaderProgram2;
65 class vtkShader2;
66 class vtkFrameBufferObject;
67 class vtkTextureObject;
68 
69 class VTKRENDERINGOPENGL_EXPORT vtkSobelGradientMagnitudePass : public vtkImageProcessingPass
70 {
71 public:
72   static vtkSobelGradientMagnitudePass *New();
73   vtkTypeMacro(vtkSobelGradientMagnitudePass,vtkImageProcessingPass);
74   void PrintSelf(ostream& os, vtkIndent indent);
75 
76   //BTX
77   // Description:
78   // Perform rendering according to a render state \p s.
79   // \pre s_exists: s!=0
80   virtual void Render(const vtkRenderState *s);
81   //ETX
82 
83   // Description:
84   // Release graphics resources and ask components to release their own
85   // resources.
86   // \pre w_exists: w!=0
87   void ReleaseGraphicsResources(vtkWindow *w);
88 
89  protected:
90   // Description:
91   // Default constructor. DelegatePass is set to NULL.
92   vtkSobelGradientMagnitudePass();
93 
94   // Description:
95   // Destructor.
96   virtual ~vtkSobelGradientMagnitudePass();
97 
98   // Description:
99   // Graphics resources.
100   vtkFrameBufferObject *FrameBufferObject;
101   vtkTextureObject *Pass1; // render target for the scene
102   vtkTextureObject *Gx1; // render target 0 for the first shader
103   vtkTextureObject *Gy1; // render target 1 for the first shader
104   vtkShaderProgram2 *Program1; // shader to compute Gx1 and Gy1
105   vtkShaderProgram2 *Program2; // shader to compute |G| from Gx1 and Gy1
106 
107  private:
108   vtkSobelGradientMagnitudePass(const vtkSobelGradientMagnitudePass&);  // Not implemented.
109   void operator=(const vtkSobelGradientMagnitudePass&);  // Not implemented.
110 };
111 
112 #endif
113