31#include <visp3/ar/vpPanda3DGeometryRenderer.h>
32#include <visp3/rbt/vpPanda3DDepthFilters.h>
33#if defined(VISP_HAVE_PANDA3D)
35#include "graphicsOutput.h"
36#include "graphicsEngine.h"
37#include "windowFramework.h"
39#include <visp3/gui/vpDisplayFactory.h>
42#define VP_STRINGIFY(x) #x
43#define VP_TOSTRING(x) VP_STRINGIFY(x)
45const std::string vpPanda3DDepthGaussianBlur::FRAGMENT_SHADER =
50"uniform sampler2D p3d_Texture0;\n"
51"uniform vec2 dp; // 1 divided by number of pixels\n"
53"const float kernel[25] = float[25](\n"
60"const float normalize = 1 / 159.0;\n"
62"vec2 offset[25] = vec2[25](\n"
63" 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"
64" 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"
65" 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"
66" 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"
67" 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"
70"out vec4 p3d_FragData;\n"
75" for(int i = 0; i < 25; ++i) {\n"
76" v += kernel[i] * texture(p3d_Texture0, texcoords + offset[i]).a;\n"
78" p3d_FragData.a = v * normalize;\n"
88 FrameBufferProperties fbp;
89 fbp.set_depth_bits(0);
90 fbp.set_rgba_bits(0, 0, 0, 32);
91 fbp.set_float_color(
true);
100const std::string vpPanda3DDepthCannyFilter::FRAGMENT_SHADER =
106"in vec2 texcoords;\n"
108"uniform sampler2D p3d_Texture0;\n"
109"uniform vec2 dp; // 1 divided by number of pixels\n"
110"uniform float edgeThreshold;\n"
112"const float kernel[9] = float[9](\n"
118"const float kernel_h[9] = float[9](\n"
124"const float kernel_v[9] = float[9](\n"
125" -1.0, -2.0, -1.0,\n"
130"vec2 offset[9] = vec2[9](\n"
131" vec2(-dp.x, -dp.y), vec2(0.0, -dp.y), vec2(dp.x, -dp.y),\n"
132" vec2(-dp.x, 0.0), vec2(0.0, 0.0), vec2(dp.x, 0.0),\n"
133" vec2(-dp.x, dp.y), vec2(0.0, dp.y), vec2(dp.x, dp.y)\n"
136"float textureValues[9];\n"
138"out vec3 p3d_FragData;\n"
141" if(texture(p3d_Texture0, texcoords).a == 0) {\n"
142" p3d_FragData = vec3(0.f, 0.f, 0.f);\n"
145" for(int i = 0; i < 9; ++i) {\n"
146" float pix = texture(p3d_Texture0, texcoords + offset[i]).a;\n"
147" pix = (pix < 1e-5f ? 1000.f: pix);\n"
148" textureValues[i] = pix;\n"
149" sum += pix * kernel[i];\n"
151" if(abs(sum) > edgeThreshold) {\n"
152" float sum_h = 0.f;\n"
153" float sum_v = 0.f;\n"
154" for(int i = 0; i < 9; ++i) {\n"
155" float pix = textureValues[i];\n"
156" sum_h += pix * kernel_h[i];\n"
157" sum_v += pix * kernel_v[i];\n"
159" vec2 orientationAndValid = (sum_h != 0.f) ? vec2(atan(sum_v, -sum_h), 1.f) : vec2(0.f, 0.f);\n"
160" float orientation = (orientationAndValid.x + PI) / (PI * 2);\n"
161" p3d_FragData = vec3(orientation, orientationAndValid.y, orientation);\n"
163" p3d_FragData = vec3(0.f, 0.f, 0.f);\n"
175 m_renderRoot.set_shader_input(
"edgeThreshold", LVector2f(m_edgeThreshold));
181 m_edgeThreshold = edgeThreshold;
182 float shaderValue = m_inputIsFast ? m_edgeThreshold /
m_renderParameters.getFarClippingDistance() : m_edgeThreshold;
183 m_renderRoot.set_shader_input(
"edgeThreshold", LVector2f(shaderValue));
188 FrameBufferProperties fbp;
189 fbp.set_depth_bits(0);
190 fbp.set_rgba_bits(8, 8, 8, 0);
191 fbp.set_alpha_bits(0);
193 fbp.set_rgb_color(
false);
195 fbp.set_float_color(
false);
201 PointerTo<Texture> tex =
new Texture();
202 fbp.setup_color_texture(tex);
203 tex->set_format(Texture::F_rgb);
204 tex->set_component_type(Texture::T_unsigned_byte);
216 valid.
resize(I.getHeight(), I.getWidth());
217 const unsigned numComponents =
m_texture->get_num_components();
218 int rowIncrement = I.getWidth() * numComponents;
219 uint8_t *data = (uint8_t *)(&(
m_texture->get_ram_image().front()));
221 data += rowIncrement * (I.getHeight() - 1);
222 rowIncrement = -rowIncrement;
223 if (numComponents != 3) {
226 for (
unsigned int i = 0; i < I.getHeight(); ++i) {
227 float *colorRow = I[i];
228 unsigned char *validRow = valid[i];
229 for (
unsigned int j = 0; j < I.getWidth(); ++j) {
230 colorRow[j] =
static_cast<float>(data[j * numComponents]) / std::numeric_limits<uint8_t>::max() * M_PI * 2 - M_PI;
231 validRow[j] =
static_cast<unsigned char>((data[j * numComponents + 1] > 0) * 255);
233 data += rowIncrement;
244 valid.
resize(I.getHeight(), I.getWidth(), 0);
245 const unsigned top =
static_cast<unsigned int>(std::max(0.0, bb.getTop()));
246 const unsigned left =
static_cast<unsigned int>(std::max(0.0, bb.getLeft()));
247 const unsigned numComponents =
m_texture->get_num_components();
250 const uint8_t *data = (uint8_t *)(&(
m_texture->get_ram_image().front()));
252 if (numComponents != 3) {
256 const uint8_t *rowData = data - i * rowIncrement;
257 float *colorRow = I[top + i];
258 unsigned char *validRow = valid[top + i];
260 colorRow[left + j] =
static_cast<float>(rowData[j * numComponents]) / std::numeric_limits<uint8_t>::max() * M_PI * 2 - M_PI;
261 validRow[left + j] =
static_cast<unsigned char>((rowData[j * numComponents + 1] > 0) * 255);
error that can be emitted by ViSP classes.
@ dimensionError
Bad dimension.
Definition of the vpImage class member functions.
void resize(unsigned int h, unsigned int w)
resize the image : Image initialization
NodePath m_renderRoot
Rendering parameters.
vpPanda3DRenderParameters m_renderParameters
Pointer to owning window, which can create buffers etc. It is not necessarily visible.
FrameBufferProperties getBufferProperties() const VP_OVERRIDE
vpPanda3DDepthCannyFilter(const std::string &name, std::shared_ptr< vpPanda3DGeometryRenderer > inputRenderer, bool isOutput, float edgeThreshold)
PointerTo< Texture > setupTexture(const FrameBufferProperties &fbp) const VP_OVERRIDE
void setEdgeThreshold(float edgeThreshold)
void getRender(vpImage< float > &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
void getRenderBasic(vpImage< unsigned char > &I) const
virtual void setupScene() VP_OVERRIDE
Initialize the scene for this specific renderer.
PointerTo< Texture > m_texture
vpPanda3DPostProcessFilter(const std::string &name, std::shared_ptr< vpPanda3DBaseRenderer > inputRenderer, bool isOutput, std::string fragmentShader)
Defines a rectangle in the plane.