Skip to content

Commit

Permalink
Merge pull request #1467 from SamFlt/module_rbt
Browse files Browse the repository at this point in the history
Render-Based Tracking
  • Loading branch information
fspindle authored Dec 19, 2024
2 parents fd5905d + bc9a67e commit 2beba7d
Show file tree
Hide file tree
Showing 102 changed files with 12,477 additions and 262 deletions.
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -205,4 +205,7 @@
{"column": 120, "color": "#ffcc00"}
],
"C_Cpp.default.compilerPath": "/usr/bin/g++",
"[json]": {
"editor.defaultFormatter": "vscode.json-language-features"
},
}
63 changes: 63 additions & 0 deletions doc/mainpage.dox.in
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,69 @@ in different ways. This will motivate us to continue the efforts.
\defgroup group_mbt_xml_parser XML parsers
XML parsers dedicated to model-based trackers.
*/


/*******************************************
* Module rbt
*******************************************/
/*!
\ingroup module_tracker
\defgroup module_rbt RBT: Render-Based Tracker module
Render-Based Tracker module
*/

/*!
\ingroup module_rbt
\defgroup group_rbt_core Core Render-Based Tracking functionalities

This group contains the core classes that make Render-Based tracking work. The main interface for Render-Based tracking is vpRBTracker.
*/

/*!
\ingroup module_rbt
\defgroup group_rbt_trackers Trackable features

These classes represent features that can be tracked by the render-based tracker. All trackable features should inherit from vpRBFeatureTracker

*/

/*!
\ingroup module_rbt
\defgroup group_rbt_mask Object segmentation

These classes allow to perform object segmentaiton from rendering information. This segmentation may be used downstream by feature trackers to filter features.
*/

/*!
\ingroup module_rbt
\defgroup group_rbt_drift Drift and divergence detection

These classes allow to detect tracking drift.
*/

/*!
\ingroup module_rbt
\defgroup group_rbt_rendering Rendering

This group contains additional rendering utilities.
*/

/*!
\ingroup module_mbt
\defgroup group_mbt_features Features
Model-based trackers features.
*/
/*!
\ingroup module_mbt
\defgroup group_mbt_faces Faces management
Faces management including visibility.
*/
/*!
\ingroup module_mbt
\defgroup group_mbt_xml_parser XML parsers
XML parsers dedicated to model-based trackers.
*/

/*******************************************
* Module robot
*******************************************/
Expand Down
33 changes: 32 additions & 1 deletion doc/tutorial/rendering/tutorial-panda3d.dox
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ vpPanda3DBaseRenderer, which implements basic functions for a panda renderer.
\section tutorial-panda3d-install Panda3D installation
\subsection tutorial-panda3d-install-ubuntu Installation on Ubuntu

- It is recommended to install the assimp package before installing Panda3D. This will allow you to load .obj files, which are a common and easily exportable format.
Without it, you will be restricted to .bam files, which is a panda specific format. To convert to a .bam file, see \ref tutorial-panda3d-file-conversion.

To install assimp, run:
\code{.sh}
$ sudo apt install libassimp-dev
\endcode

- Installer are available for Ubuntu browsing the [download](https://www.panda3d.org/download/) page.

- Hereafter you will find the instructions to build and install Panda3D from source on Ubuntu 22.04
Expand Down Expand Up @@ -91,6 +99,14 @@ vpPanda3DBaseRenderer, which implements basic functions for a panda renderer.

- Hereafter you will find the instructions to build Panda3D from source on macOS.

- It is recommended to install the assimp package before installing Panda3D. This will allow you to load .obj files, which are a common and easily exportable format.
Without it, you will be restricted to .bam files, which is a panda specific format. To convert to a .bam file, see \ref tutorial-panda3d-file-conversion.

To install assimp, run:
\code{.sh}
$ brew install assimp
\endcode

- On macOS, you will need to download a set of precompiled third-party packages in order to compile Panda3D.
Navigate to PandaED [download page](https://www.panda3d.org/download/), select the lastest SDK
(in our case SDK 1.10.14), and under `</> Source Code` section, download
Expand All @@ -114,7 +130,7 @@ vpPanda3DBaseRenderer, which implements basic functions for a panda renderer.
\endcode
- Build Panda3D from source
\code{.sh}
$ python3 makepanda/makepanda.py --everything --installer --no-egl --no-gles --no-gles2 --no-opencv --no-python --threads $(sysctl -n hw.logicalcpu)
$ python3 makepanda/makepanda.py --everything --installer --no-opencv --no-python --threads $(sysctl -n hw.logicalcpu)
\endcode

- At this point you can either
Expand Down Expand Up @@ -166,6 +182,21 @@ vpPanda3DBaseRenderer, which implements basic functions for a panda renderer.

- Installer are available for Windows browsing the [download](https://www.panda3d.org/download/) page.

\section tutorial-panda3d-file-conversion Converting a mesh to Panda's file format

If you did not install assimp before installing Panda, you are fairly restricted in what mesh format you can load with Panda.

Panda's recommended format is .bam, a binary format specific to the engine itself.
If you have Python, you can easily convert your model to a .bam file by doing the following:

1. Installing the panda3D-gltf package: `pip install panda3d-gltf`
2. From your favorite 3D modelling software export your model to GLTF (available in blender)
3. Running the converter tool:
\code{.sh}
$ gltf2bam source.gltf output.bam
\endcode
4. If you encounter issues, check the tool's settings with `gltf2bam -h`

\section tutorial-panda3d-usage Using Panda3D for rendering

An example that shows how to exploit Panda3D in ViSP to render a color image with support for textures and lighting, a
Expand Down
4 changes: 3 additions & 1 deletion modules/ar/include/visp3/ar/vpPanda3DPostProcessFilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,10 @@ class VISP_EXPORT vpPanda3DPostProcessFilter : public vpPanda3DBaseRenderer
PointerTo<Texture> m_texture;
PointerTo<GraphicsOutput> m_buffer;

static const char *FILTER_VERTEX_SHADER;
static const std::string FILTER_VERTEX_SHADER;
};

END_VISP_NAMESPACE

#endif
#endif
4 changes: 2 additions & 2 deletions modules/ar/include/visp3/ar/vpPanda3DRGBRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ class VISP_EXPORT vpPanda3DRGBRenderer : public vpPanda3DBaseRenderer, public vp
bool m_showSpeculars;
PointerTo<Texture> m_colorTexture;
PointerTo<GraphicsOutput> m_colorBuffer;
static const char *COOK_TORRANCE_VERT;
static const char *COOK_TORRANCE_FRAG;
static const std::string COOK_TORRANCE_VERT;
static const std::string COOK_TORRANCE_FRAG;

NodePath m_backgroundImage;
PointerTo<DisplayRegion> m_display2d;
Expand Down
16 changes: 12 additions & 4 deletions modules/ar/include/visp3/ar/vpPanda3DRendererSet.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ BEGIN_VISP_NAMESPACE
/**
* \ingroup group_ar_renderer_panda3d
*
* @brief Class that rendering multiple datatypes, in a single pass. A RendererSet contains multiple subrenderers, all inheriting from vpPanda3DBaseRenderer.
* @brief Class that renders multiple datatypes, in a single pass.
* A renderer set contains multiple subrenderers, all inheriting from vpPanda3DBaseRenderer.
* The renderer set synchronizes all scene properties for the different subrenderers. This includes:
* * The camera properties (intrinsics, resolution) and extrinsics
* * The pose and properties of every object in the scene
Expand All @@ -53,13 +54,20 @@ BEGIN_VISP_NAMESPACE
* The overall usage workflow is the following:
* 1. Create vpPanda3DRendererSet instance
* 2. Create the subrenderers (e.g, vpPanda3DGeometryRenderer)
* 3. Add the subrenderers to the set with addSubRenderer
* 4. Call renderFrame() on the rendererSet. Each subrenderer now has its output computed and ready to be retrieved
* 5. Retrieve relevant outputs in ViSP format with something similar to `rendererSet.getRenderer<RendererType>("MyRendererName").getRender(I)` where RendererType is the relevant subclass of vpPanda3DBaseRenderer and "MyRendererName" its name (see vpPanda3DBaseRenderer::getName)
* 3. Add the subrenderers to the set with addSubRenderer()
* 4. Call renderFrame() on the renderer set. Each subrenderer now has its output computed and ready
* to be retrieved
* 5. Retrieve relevant outputs in ViSP format with something similar to
* \code
* rendererSet.getRenderer<RendererType>("MyRendererName").getRender(I)
* \endcode
* where `RendererType` is the relevant subclass of vpPanda3DBaseRenderer and `"MyRendererName"`
* its name (see vpPanda3DBaseRenderer::getName())
*/
class VISP_EXPORT vpPanda3DRendererSet : public vpPanda3DBaseRenderer, public vpPanda3DLightable
{
public:
vpPanda3DRendererSet();
vpPanda3DRendererSet(const vpPanda3DRenderParameters &renderParameters);

virtual ~vpPanda3DRendererSet() = default;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ void vpPanda3DPostProcessFilter::setupScene()
"Cannot add a postprocess filter to a renderer that does not define getMainOutputBuffer()");
}
m_shader = Shader::make(Shader::ShaderLanguage::SL_GLSL,
FILTER_VERTEX_SHADER,
m_fragmentShader);
FILTER_VERTEX_SHADER,
m_fragmentShader);
m_renderRoot.set_shader(m_shader);
m_renderRoot.set_shader_input("dp", LVector2f(1.0 / buffer->get_texture()->get_x_size(), 1.0 / buffer->get_texture()->get_y_size()));
m_renderRoot.set_texture(buffer->get_texture());
Expand Down
15 changes: 5 additions & 10 deletions modules/ar/src/panda3d-simulator/vpPanda3DRGBRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
#include "texturePool.h"

BEGIN_VISP_NAMESPACE
const char *vpPanda3DRGBRenderer::COOK_TORRANCE_VERT =
const std::string vpPanda3DRGBRenderer::COOK_TORRANCE_VERT =
"#version 330\n"
"in vec3 p3d_Normal;\n"
"in vec4 p3d_Vertex;\n"
Expand Down Expand Up @@ -76,7 +76,7 @@ const char *vpPanda3DRGBRenderer::COOK_TORRANCE_VERT =
" F0 = computeF0(p3d_Material.refractiveIndex, p3d_Material.metallic, p3d_Material.baseColor.xyz);\n"
"}\n";

const char *vpPanda3DRGBRenderer::COOK_TORRANCE_FRAG =
const std::string vpPanda3DRGBRenderer::COOK_TORRANCE_FRAG =
"// Version 330, specified when generating shader\n"
"#define M_PI 3.1415926535897932384626433832795\n"
"in vec3 oNormal;\n"
Expand Down Expand Up @@ -200,8 +200,8 @@ void vpPanda3DRGBRenderer::addNodeToScene(const NodePath &object)
}

PT(Shader) shader = Shader::make(Shader::ShaderLanguage::SL_GLSL,
COOK_TORRANCE_VERT,
makeFragmentShader(hasTexture, m_showSpeculars));
COOK_TORRANCE_VERT,
makeFragmentShader(hasTexture, m_showSpeculars));

objectInScene.set_shader(shader);

Expand Down Expand Up @@ -245,12 +245,7 @@ void vpPanda3DRGBRenderer::setBackgroundImage(const vpImage<vpRGBa> &background)
for (unsigned int i = 0; i < background.getHeight(); ++i) {
const vpRGBa *srcRow = background[background.getHeight() - (i + 1)];
unsigned char *destRow = data + i * background.getWidth() * 4;
for (unsigned int j = 0; j < background.getWidth(); ++j) {
destRow[j * 4] = srcRow[j].B;
destRow[j * 4 + 1] = srcRow[j].G;
destRow[j * 4 + 2] = srcRow[j].R;
destRow[j * 4 + 3] = srcRow[j].A;
}
memcpy(destRow, srcRow, background.getWidth() * 4);
}
}

Expand Down
9 changes: 9 additions & 0 deletions modules/ar/src/panda3d-simulator/vpPanda3DRendererSet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@
#include "load_prc_file.h"

BEGIN_VISP_NAMESPACE
vpPanda3DRendererSet::vpPanda3DRendererSet() : vpPanda3DBaseRenderer("set")
{
load_prc_file_data("", "textures-power-2 none");
load_prc_file_data("", "gl-version 3 2");
load_prc_file_data("", "no-singular-invert");
}

vpPanda3DRendererSet::vpPanda3DRendererSet(const vpPanda3DRenderParameters &renderParameters) : vpPanda3DBaseRenderer("set")
{
m_renderParameters = renderParameters;
Expand Down Expand Up @@ -195,6 +202,8 @@ void vpPanda3DRendererSet::enableSharedDepthBuffer(vpPanda3DBaseRenderer &source
}
}

END_VISP_NAMESPACE

#elif !defined(VISP_BUILD_SHARED_LIBS)
// Work around to avoid warning: libvisp_ar.a(vpPanda3DRendererSet.cpp.o) has no symbols
void dummy_vpPanda3DRendererSet() { };
Expand Down
16 changes: 8 additions & 8 deletions modules/core/include/visp3/core/vpPlane.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,9 @@ BEGIN_VISP_NAMESPACE
\brief This class defines the container for a plane geometrical structure.
A plane is given by the equation \f$Ax + By + Cz + D = 0\f$ where
(x,y,z) are the coordinates of a point and where \f$[A,B,C]^T\f$ is a normal
A plane is given by the equation \f$A*X + B*Y + C*Z + D = 0\f$ where
(X,Y,Z) are the coordinates of a point and where \f$[A,B,C]^T\f$ is the normal
vector of the plane.
*/
class VISP_EXPORT vpPlane
{
Expand All @@ -66,14 +65,15 @@ class VISP_EXPORT vpPlane
vpPlane();
vpPlane(const vpPlane &P);
vpPlane(double A, double B, double C, double D);
vpPlane(const vpPoint &P, const vpColVector &n, vpPlaneFrame frame = camera_frame);
vpPlane(const vpPoint &P, const vpColVector &normal, vpPlaneFrame frame = camera_frame);
vpPlane(const vpPoint &P, const vpPoint &Q, const vpPoint &R, vpPlaneFrame frame = camera_frame);

double computeZ(double x, double y) const;

void init(const vpPoint &P, const vpPoint &Q, const vpPoint &R, vpPlaneFrame frame = camera_frame);
void init(const vpColVector &P, const vpColVector &n);
void init(const vpPlane &P);
vpPlane &init(const vpPoint &P, const vpColVector &normal, vpPlaneFrame frame = camera_frame);
vpPlane &init(const vpPoint &P, const vpPoint &Q, const vpPoint &R, vpPlaneFrame frame = camera_frame);
vpPlane &init(const vpColVector &P, const vpColVector &n);
vpPlane &init(const vpPlane &P);

// SET the parameter
/*! Set plane parameter A. */
Expand Down Expand Up @@ -157,7 +157,7 @@ class VISP_EXPORT vpPlane
friend VISP_EXPORT std::ostream &operator<<(std::ostream &os, const vpPlane &p);

// Operation with Plane
void projectionPointOnPlan(const vpPoint &P, vpPoint &Pproj) const;
void projectionPointOnPlan(const vpPoint &P, vpPoint &Pproj, vpPlaneFrame frame = camera_frame) const;

double rayIntersection(const vpPoint &M0, const vpPoint &M1, vpColVector &H) const;

Expand Down
17 changes: 14 additions & 3 deletions modules/core/include/visp3/core/vpRGBa.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@
#include <visp3/core/vpConfig.h>
#include <visp3/core/vpColVector.h>

#if ((__cplusplus >= 201703L) || (defined(_MSVC_LANG) && (_MSVC_LANG >= 201703L)))
#include <type_traits>
#endif


BEGIN_VISP_NAMESPACE
/*!
\class vpRGBa
Expand Down Expand Up @@ -123,7 +128,7 @@ class VISP_EXPORT vpRGBa
/*!
Copy constructor.
*/
inline vpRGBa(const vpRGBa &v) : R(v.R), G(v.G), B(v.B), A(v.A) { }
inline vpRGBa(const vpRGBa &v) = default;

/*!
Create a RGBa value from a 4 dimension column vector.
Expand All @@ -143,9 +148,9 @@ class VISP_EXPORT vpRGBa
vpRGBa &operator=(const unsigned char &v);
vpRGBa &operator=(const unsigned int &v);
vpRGBa &operator=(const int &v);
vpRGBa &operator=(const vpRGBa &v);
vpRGBa &operator=(const vpRGBa &v) = default;
#if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
vpRGBa &operator=(const vpRGBa &&v);
vpRGBa &operator=(vpRGBa &&v) = default;
#endif
vpRGBa &operator=(const vpColVector &v);
bool operator==(const vpRGBa &v) const;
Expand All @@ -171,5 +176,11 @@ class VISP_EXPORT vpRGBa

friend VISP_EXPORT vpRGBa operator*(const double &x, const vpRGBa &rgb);
};

#if ((__cplusplus >= 201703L) || (defined(_MSVC_LANG) && (_MSVC_LANG >= 201703L)))
static_assert(std::is_trivially_assignable_v<vpRGBa, vpRGBa>);
static_assert(std::is_trivially_copyable_v<vpRGBa>);
#endif

END_VISP_NAMESPACE
#endif
Loading

0 comments on commit 2beba7d

Please sign in to comment.