31 #include <visp3/ar/vpPanda3DCommonFilters.h>
32 #include <visp3/ar/vpPanda3DRGBRenderer.h>
34 #if defined(VISP_HAVE_PANDA3D)
37 const std::string vpPanda3DLuminanceFilter::FRAGMENT_SHADER =
39 "in vec2 texcoords;\n"
40 "uniform sampler2D p3d_Texture0;\n"
41 "out vec4 p3d_FragData;\n"
43 " vec4 v = texture(p3d_Texture0, texcoords);\n"
44 " p3d_FragData.b = 0.299 * v.r + 0.587 * v.g + 0.114 * v.b;\n"
52 FrameBufferProperties fbp;
53 fbp.set_depth_bits(0);
54 fbp.set_rgba_bits(0, 0, 8, 0);
55 fbp.set_float_color(
false);
63 const std::string vpPanda3DGaussianBlur::FRAGMENT_SHADER =
65 "in vec2 texcoords;\n"
66 "uniform sampler2D p3d_Texture0;\n"
67 "uniform vec2 dp; // 1 divided by number of pixels\n"
68 "const float kernel[25] = float[25](\n"
71 " 5, 12, 15, 12, 5,\n"
75 "const float normalize = 1 / 159.0;\n"
76 "vec2 offset[25] = vec2[25](\n"
77 " vec2(-2*dp.x,-2*dp.y), vec2(-dp.x,-2*dp.y), vec2(0,-2*dp.y), vec2(dp.x,-2*dp.y), vec2(2*dp.x,-2*dp.y),\n"
78 " vec2(-2*dp.x,-dp.y), vec2(-dp.x, -dp.y), vec2(0.0, -dp.y), vec2(dp.x, -dp.y), vec2(2*dp.x,-dp.y),\n"
79 " vec2(-2*dp.x,0.0), vec2(-dp.x, 0.0), vec2(0.0, 0.0), vec2(dp.x, 0.0), vec2(2*dp.x,0.0),\n"
80 " vec2(-2*dp.x, dp.y), vec2(-dp.x, dp.y), vec2(0.0, dp.y), vec2(dp.x, dp.y), vec2(2*dp.x, dp.y),\n"
81 " vec2(-2*dp.x, 2*dp.y), vec2(-dp.x, 2*dp.y), vec2(0.0, 2*dp.y), vec2(dp.x, 2*dp.y), vec2(2*dp.x, 2*dp.y)\n"
83 "out vec4 p3d_FragData;\n"
86 " for(int i = 0; i < 25; ++i) {\n"
87 " v += kernel[i] * texture(p3d_Texture0, texcoords + offset[i]).b;\n"
89 " p3d_FragData.b = v * normalize;\n"
98 FrameBufferProperties fbp;
99 fbp.set_depth_bits(0);
100 fbp.set_rgba_bits(0, 0, 8, 0);
101 fbp.set_float_color(
false);
110 const std::string vpPanda3DCanny::FRAGMENT_SHADER =
112 "in vec2 texcoords;\n"
113 "uniform sampler2D p3d_Texture0;\n"
114 "uniform vec2 dp; // 1 divided by number of pixels\n"
115 "uniform float edgeThreshold;\n"
116 "const float kernel[9] = float[9](\n"
121 "const float kernel_h[9] = float[9](\n"
126 "const float kernel_v[9] = float[9](\n"
127 " -1.0, -2.0, -1.0,\n"
131 "vec2 offset[9] = vec2[9](\n"
132 " vec2(-dp.x, -dp.y), vec2(0.0, -dp.y), vec2(dp.x, -dp.y),\n"
133 " vec2(-dp.x, 0.0), vec2(0.0, 0.0), vec2(dp.x, 0.0),\n"
134 " vec2(-dp.x, dp.y), vec2(0.0, dp.y), vec2(dp.x, dp.y)\n"
136 "out vec4 p3d_FragData;\n"
138 " float sum = 0.f;\n"
139 " for(int i = 0; i < 9; ++i) {\n"
140 " float pix = texture(p3d_Texture0, texcoords + offset[i]).b;\n"
141 " sum += pix * kernel[i];\n"
143 " if(abs(sum * 255.f) > edgeThreshold) {\n"
144 " float sum_h = 0.f;\n"
145 " float sum_v = 0.f;\n"
146 " for(int i = 0; i < 9; ++i) {\n"
147 " float pix = texture(p3d_Texture0, texcoords + offset[i]).b;\n"
148 " sum_h += pix * kernel_h[i];\n"
149 " sum_v += pix * kernel_v[i];\n"
151 " vec2 orientationAndValid = sum_h * sum_h + sum_v * sum_v > 0 ? vec2(-atan(sum_v/sum_h), 1.f) : vec2(0.f, 0.f);\n"
152 " p3d_FragData = vec4(sum_h, sum_v, orientationAndValid.x, orientationAndValid.y);\n"
154 " p3d_FragData = vec4(0.f, 0.f, 0.f, 0.f);\n"
165 m_renderRoot.set_shader_input(
"edgeThreshold", LVector2f(m_edgeThreshold));
170 m_edgeThreshold = edgeThreshold;
171 m_renderRoot.set_shader_input(
"edgeThreshold", LVector2f(m_edgeThreshold));
176 FrameBufferProperties fbp;
177 fbp.set_depth_bits(0);
178 fbp.set_rgba_bits(32, 32, 32, 32);
179 fbp.set_float_color(
true);
190 #elif !defined(VISP_BUILD_SHARED_LIBS)
192 void dummy_vpPanda3DCanny() { };
NodePath m_renderRoot
Rendering parameters.
Implementation of canny filtering, using Sobel kernels.
void setupScene() VP_OVERRIDE
Initialize the scene for this specific renderer.
void getRender(vpImage< vpRGBf > &I) const
void setEdgeThreshold(float edgeThreshold)
FrameBufferProperties getBufferProperties() const VP_OVERRIDE
vpPanda3DCanny(const std::string &name, std::shared_ptr< vpPanda3DBaseRenderer > inputRenderer, bool isOutput, float edgeThreshold)
Class that implements a gaussian filter on a grayscale image. The grayscale image should be contained...
FrameBufferProperties getBufferProperties() const VP_OVERRIDE
void getRender(vpImage< unsigned char > &I) const
vpPanda3DGaussianBlur(const std::string &name, std::shared_ptr< vpPanda3DBaseRenderer > inputRenderer, bool isOutput)
Class that implements an RGB to grayscale conversion.
FrameBufferProperties getBufferProperties() const VP_OVERRIDE
void getRender(vpImage< unsigned char > &I) const
vpPanda3DLuminanceFilter(const std::string &name, std::shared_ptr< vpPanda3DRGBRenderer > inputRenderer, bool isOutput)
Base class for postprocessing filters that map the result of a vpPanda3DBaseRenderer to a new image.
void getRenderBasic(vpImage< unsigned char > &I) const
virtual void setupScene() VP_OVERRIDE
Initialize the scene for this specific renderer.