3#include <visp3/core/vpConfig.h>
5#if defined(VISP_HAVE_PANDA3D) && defined(VISP_HAVE_DISPLAY) && defined(VISP_HAVE_MODULE_IO)
7#include <visp3/core/vpException.h>
8#include <visp3/core/vpExponentialMap.h>
10#include <visp3/gui/vpDisplayX.h>
11#include <visp3/gui/vpDisplayGDI.h>
12#include <visp3/gui/vpDisplayD3D.h>
13#include <visp3/gui/vpDisplayOpenCV.h>
14#include <visp3/gui/vpDisplayGTK.h>
16#include <visp3/io/vpParseArgv.h>
17#include <visp3/io/vpImageIo.h>
19#include <visp3/ar/vpPanda3DRGBRenderer.h>
20#include <visp3/ar/vpPanda3DGeometryRenderer.h>
21#include <visp3/ar/vpPanda3DRendererSet.h>
22#include <visp3/ar/vpPanda3DCommonFilters.h>
23#include <visp3/ar/vpPanda3DFrameworkManager.h>
25#ifdef ENABLE_VISP_NAMESPACE
33#pragma omp parallel for
35 for (
int i = 0; i < static_cast<int>(normalsImage.
getSize()); ++
i) {
36 normalDisplayImage.
bitmap[
i].R =
static_cast<unsigned char>((normalsImage.
bitmap[
i].R + 1.0) * 127.5f);
37 normalDisplayImage.
bitmap[
i].G =
static_cast<unsigned char>((normalsImage.
bitmap[
i].G + 1.0) * 127.5f);
38 normalDisplayImage.
bitmap[
i].B =
static_cast<unsigned char>((normalsImage.
bitmap[
i].B + 1.0) * 127.5f);
49#pragma omp parallel for
51 for (
int i = 0; i < static_cast<int>(depthImage.
getSize()); ++
i) {
52 float val = std::max(0.f, (depthImage.
bitmap[i] - nearV) / (farV - nearV));
53 depthDisplayImage.
bitmap[
i] =
static_cast<unsigned char>(val * 255.f);
62#pragma omp parallel for
64 for (
int i = 0; i < static_cast<int>(colorImage.
getSize()); ++
i) {
65 float I1 = 0.299 * colorImage.
bitmap[
i].R + 0.587 * colorImage.
bitmap[
i].G + 0.114 * colorImage.
bitmap[
i].B;
66 float I2 = 0.299 * colorDiffuseOnly.
bitmap[
i].R + 0.587 * colorDiffuseOnly.
bitmap[
i].G + 0.114 * colorDiffuseOnly.
bitmap[
i].B;
67 lightDifference.
bitmap[
i] =
static_cast<unsigned char>(round(abs(I1 - I2)));
77#pragma omp parallel for
79 for (
int i = 0; i < static_cast<int>(cannyRawData.
getSize()); ++
i) {
81 canny.
bitmap[
i] = 255 * (px.
R * px.
R + px.
G * px.
G > 0);
86 for (
unsigned int i = 0;
i < canny.
getHeight();
i += 8) {
87 for (
unsigned int j = 0;
j < canny.
getWidth();
j += 8) {
88 bool valid = (pow(cannyRawData[i][j].R, 2.f) + pow(cannyRawData[i][j].G, 2.f)) > 0;
90 float angle = cannyRawData[
i][
j].B;
91 unsigned x =
j + 10 * cos(angle);
92 unsigned y =
i + 10 * sin(angle);
99int main(
int argc,
const char **argv)
101 bool stepByStep =
false;
103 bool showLightContrib =
false;
104 bool showCanny =
false;
105 char *modelPathCstr =
nullptr;
107 char *backgroundPathCstr =
nullptr;
108 vpParseArgv::vpArgvInfo argTable[] =
111 "Path to the model to load."},
114 "Path to the background image to load for the rgb renderer."},
116 "Show frames step by step."},
118 "Show frames step by step."},
120 "Show frames step by step."},
122 "Show Opengl/Panda3D debug message."},
135 if (PStatClient::is_connected()) {
136 PStatClient::disconnect();
139 std::string host =
"";
141 if (!PStatClient::connect(host, port)) {
142 std::cout <<
"Could not connect to PStat server." << std::endl;
145 std::string modelPath;
147 modelPath = modelPathCstr;
150 modelPath =
"data/suzanne.bam";
153 std::string backgroundPath;
154 if (backgroundPathCstr) {
155 backgroundPath = backgroundPathCstr;
157 const std::string objectName =
"object";
162 unsigned h = renderParams.getImageHeight(),
w = renderParams.getImageWidth();
175 std::shared_ptr<vpPanda3DRGBRenderer> rgbRenderer = std::make_shared<vpPanda3DRGBRenderer>();
176 std::shared_ptr<vpPanda3DRGBRenderer> rgbDiffuseRenderer = std::make_shared<vpPanda3DRGBRenderer>(
false);
177 std::shared_ptr<vpPanda3DLuminanceFilter> grayscaleFilter = std::make_shared<vpPanda3DLuminanceFilter>(
"toGrayscale", rgbRenderer,
false);
178 std::shared_ptr<vpPanda3DCanny> cannyFilter = std::make_shared<vpPanda3DCanny>(
"canny", grayscaleFilter,
true, 10.f);
185 if (showLightContrib) {
192 std::cout <<
"Initializing Panda3D rendering framework" << std::endl;
197 NodePath
object = renderer.
loadObject(objectName, modelPath);
209 if (!backgroundPath.empty()) {
212 rgbRenderer->setBackgroundImage(background);
215 rgbRenderer->printStructure();
220 std::cout <<
"Creating display and data images" << std::endl;
234#if defined(VISP_HAVE_GTK)
236#elif defined(VISP_HAVE_X11)
238#elif defined(HAVE_OPENCV_HIGHGUI)
240#elif defined(VISP_HAVE_GDI)
242#elif defined(VISP_HAVE_D3D9)
245 unsigned int padding = 80;
246 DisplayCls dNormals(normalDisplayImage, 0, 0,
"normals in object space");
247 DisplayCls dNormalsCamera(cameraNormalDisplayImage, 0, h + padding,
"normals in camera space");
248 DisplayCls
dDepth(depthDisplayImage, w + padding, 0,
"depth");
249 DisplayCls dColor(colorImage, w + padding, h + padding,
"color");
251 DisplayCls dImageDiff;
252 if (showLightContrib) {
253 dImageDiff.init(lightDifference, w * 2 + padding, 0,
"Specular/reflectance contribution");
257 dCanny.init(cannyImage, w * 2 + padding, h + padding,
"Canny");
261 std::vector<double> renderTime, fetchTime, displayTime;
264 float nearV = 0, farV = 0;
265 geometryRenderer->computeNearAndFarPlanesFromNode(objectName, nearV, farV,
true);
266 renderParams.setClippingDistance(nearV, farV);
279 if (showLightContrib) {
288 displayNormals(normalsImage, normalDisplayImage);
289 displayNormals(cameraNormalsImage, cameraNormalDisplayImage);
290 displayDepth(depthImage, depthDisplayImage, nearV, farV);
291 if (showLightContrib) {
292 displayLightDifference(colorImage, colorDiffuseOnly, lightDifference);
295 displayCanny(cannyRawData, cannyImage);
310 renderTime.push_back(beforeFetch - beforeRender);
311 fetchTime.push_back(beforeConvert - beforeFetch);
312 displayTime.push_back(endDisplay - beforeConvert);
325 const double delta = (afterAll - beforeRender) / 1000.0;
336 if (renderTime.size() > 0) {
348 std::cerr <<
"Recompile ViSP with Panda3D as a third party to run this tutorial" << std::endl;
Generic class defining intrinsic camera parameters.
Implementation of column vector and the associated operations.
static const vpColor green
Display for windows using Direct3D 3rd party. Thus to enable this class Direct3D should be installed....
Display for windows using GDI (available on any windows 32 platform).
The vpDisplayGTK allows to display image using the GTK 3rd party library. Thus to enable this class G...
The vpDisplayOpenCV allows to display image using the OpenCV library. Thus to enable this class OpenC...
Use the X11 console to display images on unix-like OS. Thus to enable this class X11 should be instal...
static bool getClick(const vpImage< unsigned char > &I, bool blocking=true)
static bool getKeyboardEvent(const vpImage< unsigned char > &I, bool blocking=true)
static void display(const vpImage< unsigned char > &I)
static void flush(const vpImage< unsigned char > &I)
static void displayArrow(const vpImage< unsigned char > &I, const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color=vpColor::white, unsigned int w=4, unsigned int h=2, unsigned int thickness=1)
static void displayText(const vpImage< unsigned char > &I, const vpImagePoint &ip, const std::string &s, const vpColor &color)
static vpHomogeneousMatrix direct(const vpColVector &v)
Implementation of an homogeneous matrix and operations on such kind of matrices.
static void read(vpImage< unsigned char > &I, const std::string &filename, int backend=IO_DEFAULT_BACKEND)
Definition of the vpImage class member functions.
unsigned int getWidth() const
unsigned int getSize() const
Type * bitmap
points toward the bitmap
unsigned int getHeight() const
static double rad(double deg)
static double getStdev(const std::vector< double > &v, bool useBesselCorrection=false)
static double getMean(const std::vector< double > &v)
Class representing an ambient light.
virtual void renderFrame()
void setVerticalSyncEnabled(bool useVsync)
set whether vertical sync is enabled. When vertical sync is enabled, render speed will be limited by ...
void setAbortOnPandaError(bool abort)
Set the behaviour when a Panda3D assertion fails. If abort is true, the program will stop....
NodePath loadObject(const std::string &nodeName, const std::string &modelPath)
Load a 3D object. To load an .obj file, Panda3D must be compiled with assimp support.
Implementation of canny filtering, using Sobel kernels.
Class representing a directional light.
static vpPanda3DFrameworkManager & getInstance()
Renderer that outputs object geometric information.
void getRender(vpImage< vpRGBf > &colorData, vpImage< float > &depth) const
Get render results into ViSP readable structures.
@ CAMERA_NORMALS
Surface normals in the object frame.
Class representing a Point Light.
Implementation of a traditional RGB renderer in Panda3D.
void getRender(vpImage< vpRGBa > &I) const
Store the render resulting from calling renderFrame() into a vpImage.
Rendering parameters for a panda3D simulation.
Class that renders multiple datatypes, in a single pass. A renderer set contains multiple subrenderer...
void addNodeToScene(const NodePath &object) VP_OVERRIDE
void initFramework() VP_OVERRIDE
Initialize the framework and propagate the created panda3D framework to the subrenderers.
virtual void setRenderParameters(const vpPanda3DRenderParameters ¶ms) VP_OVERRIDE
Set new rendering parameters. If the scene has already been initialized, the renderer camera is updat...
void addSubRenderer(std::shared_ptr< vpPanda3DBaseRenderer > renderer)
Add a new subrenderer: This subrenderer should have a unique name, not present in the set.
vpHomogeneousMatrix getNodePose(const std::string &name) VP_OVERRIDE
Retrieve the pose of a scene node. The pose is in the world frame, using a ViSP convention.
std::shared_ptr< RendererType > getRenderer()
Retrieve the first subrenderer with the specified template type.
void setNodePose(const std::string &name, const vpHomogeneousMatrix &wTo) VP_OVERRIDE
Set the pose of an object for all the subrenderers. The pose is specified using the ViSP convention T...
void addLight(const vpPanda3DLight &light) VP_OVERRIDE
Light this lightable object with a new light.
void setCameraPose(const vpHomogeneousMatrix &wTc) VP_OVERRIDE
Set the pose of the camera, using the ViSP convention. This change is propagated to all subrenderers.
static bool parse(int *argcPtr, const char **argv, vpArgvInfo *argTable, int flags)
@ ARGV_NO_DEFAULTS
No default options like -help.
@ ARGV_NO_LEFTOVERS
Print an error message if an option is not in the argument list.
@ ARGV_STRING
Argument is associated to a char * string.
@ ARGV_CONSTANT_BOOL
Stand alone argument associated to a bool var that is set to true.
@ ARGV_END
End of the argument list.
@ ARGV_HELP
Argument is for help displaying.
VISP_EXPORT double measureTimeMs()