31 #include <visp3/rbt/vpPanda3DDepthFilters.h>
33 #if defined(VISP_HAVE_PANDA3D)
35 #include "graphicsOutput.h"
36 #include "graphicsEngine.h"
37 #include "windowFramework.h"
41 const std::string vpPanda3DDepthGaussianBlur::FRAGMENT_SHADER =
44 "in vec2 texcoords;\n"
46 "uniform sampler2D p3d_Texture0;\n"
47 "uniform vec2 dp; // 1 divided by number of pixels\n"
49 "const float kernel[25] = float[25](\n"
52 " 5, 12, 15, 12, 5,\n"
56 "const float normalize = 1 / 159.0;\n"
58 "vec2 offset[25] = vec2[25](\n"
59 " 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"
60 " 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"
61 " 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"
62 " 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"
63 " 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"
66 "out vec4 p3d_FragData;\n"
71 " for(int i = 0; i < 25; ++i) {\n"
72 " v += kernel[i] * texture(p3d_Texture0, texcoords + offset[i]).a;\n"
74 " p3d_FragData.a = v * normalize;\n"
84 FrameBufferProperties fbp;
85 fbp.set_depth_bits(0);
86 fbp.set_rgba_bits(0, 0, 0, 32);
87 fbp.set_float_color(
true);
96 const std::string vpPanda3DDepthCannyFilter::FRAGMENT_SHADER =
99 "in vec2 texcoords;\n"
101 "uniform sampler2D p3d_Texture0;\n"
102 "uniform vec2 dp; // 1 divided by number of pixels\n"
103 "uniform float edgeThreshold;\n"
105 "const float kernel[9] = float[9](\n"
111 "const float kernel_h[9] = float[9](\n"
117 "const float kernel_v[9] = float[9](\n"
118 " -1.0, -2.0, -1.0,\n"
123 "vec2 offset[9] = vec2[9](\n"
124 " vec2(-dp.x, -dp.y), vec2(0.0, -dp.y), vec2(dp.x, -dp.y),\n"
125 " vec2(-dp.x, 0.0), vec2(0.0, 0.0), vec2(dp.x, 0.0),\n"
126 " vec2(-dp.x, dp.y), vec2(0.0, dp.y), vec2(dp.x, dp.y)\n"
129 "float textureValues[9];\n"
131 "out vec4 p3d_FragData;\n"
134 " if(texture(p3d_Texture0, texcoords).a == 0) {\n"
135 " p3d_FragData = vec4(0.f, 0.f, 0.f, 0.f);\n"
137 " float sum = 0.f;\n"
138 " for(int i = 0; i < 9; ++i) {\n"
139 " float pix = texture(p3d_Texture0, texcoords + offset[i]).a;\n"
140 " pix = (pix < 1e-5f ? 1000.f: pix);\n"
141 " textureValues[i] = pix;\n"
142 " sum += pix * kernel[i];\n"
144 " if(abs(sum) > edgeThreshold) {\n"
145 " float sum_h = 0.f;\n"
146 " float sum_v = 0.f;\n"
147 " for(int i = 0; i < 9; ++i) {\n"
148 " float pix = textureValues[i];\n"
149 " sum_h += pix * kernel_h[i];\n"
150 " sum_v += pix * kernel_v[i];\n"
152 " float norm = sqrt(sum_v * sum_v + sum_h * sum_h);\n"
153 " vec2 orientationAndValid = (sum_h != 0.f) ? vec2(atan(sum_v, -sum_h), 1.f) : vec2(0.f, 0.f);\n"
154 " p3d_FragData.bgra = vec4(sum_h, sum_v, orientationAndValid.x, orientationAndValid.y);\n"
156 " p3d_FragData = vec4(0.f, 0.f, 0.f, 0.f);\n"
168 m_renderRoot.set_shader_input(
"edgeThreshold", LVector2f(m_edgeThreshold));
173 m_edgeThreshold = edgeThreshold;
174 m_renderRoot.set_shader_input(
"edgeThreshold", LVector2f(m_edgeThreshold));
180 FrameBufferProperties fbp;
181 fbp.set_depth_bits(0);
182 fbp.set_rgba_bits(32, 32, 32, 32);
183 fbp.set_float_color(
true);
196 const unsigned numComponents =
m_texture->get_num_components();
197 int rowIncrement = I.
getWidth() * numComponents;
198 float *data = (
float *)(&(
m_texture->get_ram_image().front()));
200 data += rowIncrement * (I.
getHeight() - 1);
201 rowIncrement = -rowIncrement;
202 if (numComponents != 4) {
205 for (
unsigned int i = 0; i < I.
getHeight(); ++i) {
207 unsigned char *validRow = valid[i];
208 for (
unsigned int j = 0; j < I.
getWidth(); ++j) {
209 colorRow[j].
R = data[j * numComponents];
210 colorRow[j].
G = data[j * numComponents + 1];
211 colorRow[j].
B = data[j * numComponents + 2];
212 validRow[j] =
static_cast<unsigned char>(data[j * numComponents + 3]);
214 data += rowIncrement;
227 const unsigned top =
static_cast<unsigned int>(std::max(0.0, bb.
getTop()));
228 const unsigned left =
static_cast<unsigned int>(std::max(0.0, bb.
getLeft()));
229 const unsigned numComponents =
m_texture->get_num_components();
232 const float *data = (
float *)(&(
m_texture->get_ram_image().front()));
234 if (numComponents != 4) {
238 const float *rowData = data - i * rowIncrement;
239 vpRGBf *colorRow = I[top + i];
240 unsigned char *validRow = valid[top + i];
242 colorRow[left + j].
R = rowData[j * numComponents];
243 colorRow[left + j].
G = rowData[j * numComponents + 1];
244 colorRow[left + j].
B = rowData[j * numComponents + 2];
245 validRow[left + j] =
static_cast<unsigned char>(rowData[j * numComponents + 3]);
error that can be emitted by ViSP classes.
@ dimensionError
Bad dimension.
unsigned int getWidth() const
void resize(unsigned int h, unsigned int w)
resize the image : Image initialization
unsigned int getHeight() const
NodePath m_renderRoot
Rendering parameters.
vpPanda3DRenderParameters m_renderParameters
Pointer to owning window, which can create buffers etc. It is not necessarily visible.
Implementation of canny filtering, using Sobel kernels.
FrameBufferProperties getBufferProperties() const VP_OVERRIDE
vpPanda3DDepthCannyFilter(const std::string &name, std::shared_ptr< vpPanda3DBaseRenderer > inputRenderer, bool isOutput, float edgeThreshold)
void setEdgeThreshold(float edgeThreshold)
void getRender(vpImage< vpRGBf > &I, vpImage< unsigned char > &valid) const
void setupScene() VP_OVERRIDE
Initialize the scene for this specific renderer.
vpPanda3DDepthGaussianBlur(const std::string &name, std::shared_ptr< vpPanda3DBaseRenderer > inputRenderer, bool isOutput)
void getRender(vpImage< unsigned char > &I) const
FrameBufferProperties getBufferProperties() const VP_OVERRIDE
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.
PointerTo< Texture > m_texture
unsigned int getImageWidth() const
unsigned int getImageHeight() const
Defines a rectangle in the plane.