Helios++
Helios software for LiDAR simulations
visualhelios::VHSceneCanvas Class Reference

Visual Helios Scene Canvas is a class which supports rendering a dynamic scene. More...

#include <VHSceneCanvas.h>

Inheritance diagram for visualhelios::VHSceneCanvas:
Collaboration diagram for visualhelios::VHSceneCanvas:

Public Member Functions

 VHSceneCanvas (DynScene &ds)
 Default constructor for the visual Helios scene canvas. More...
 
 VHSceneCanvas (DynScene &ds, string const title, bool const normalsKeyboardCallbackEnabled=true, bool const normalsUsageTextEnabled=true, bool const renderingNormals=true, float const normalMagnitude=0.2)
 Constructor for the visual Helios scene canvas which allows for title specification, flags configuration and normal magnitude specification. More...
 
void configure () override
 
void start () override
 
void update () override
 
void renderNormals (VHStaticObjectAdapter &staticObj) override
 Render normals for each primitive of given static object. More...
 
void unrenderAllNormals () override
 Remove all rendered normals. More...
 
- Public Member Functions inherited from visualhelios::VHNormalsCanvas
 VHNormalsCanvas ()
 Default constructor for the visual Helios normals canvas. More...
 
 VHNormalsCanvas (string const title, bool const normalsKeyboardCallbackEnabled=true, bool const normalsUsageTextEnabled=true, bool const renderingNormals=true, float const normalMagnitude=1.0)
 Main constructor for the visual helios normals canvas which allows for title specification, flags specification and normal magnitude specification too. More...
 
virtual bool isRenderingNormals () const
 Check whether the normals canvas is rendering normals or not. More...
 
virtual void setRenderingNormals (bool const renderingNormals)
 Enable or disable normals rendering. More...
 
virtual float getNormalMagnitude () const
 Obtain the magnitude for normal vectors visualization. More...
 
virtual void setNormalMagnitude (float const normalMagnitude)
 Set the magnitude for normal vectors visualization. More...
 
virtual bool isNormalsKeyboardCallbackEnabled () const
 Check whether normals keyboard callback is enabled (true) or not (false) More...
 
virtual bool isNormalsUsageTextEnabled () const
 Check whether normals usage text is enabled (true) or not (false) More...
 
virtual float const * getNormalDefColor () const
 Return the default color for normals visualization. More...
 
virtual void setNormalDefColor (float const color[3])
 Set the default color for normals visualization. More...
 
virtual void setNormalDefColor (float const r, float const g, float const b)
 Set the default color for normals visualization. More...
 
- Public Member Functions inherited from visualhelios::VHDynCanvas
 VHDynCanvas ()
 Default constructor for the visual Helios dynamic canvas. More...
 
 VHDynCanvas (string const title)
 Constructor for the visual Helios dynamic canvas which allows for title specification. More...
 
virtual bool isNeedingUpdate () const
 Check whether the dynamic canvas needs an update no matter what (true) or not (false) More...
 
virtual void setNeedsUpdate (bool const needsUpdate)
 Specify if the dynamic canvas needs an update no matter what (true) or not (false) More...
 
- Public Member Functions inherited from visualhelios::VHCanvas
 VHCanvas ()
 Default constructor for the visual helios canvas.
 
 VHCanvas (string const title)
 Constructor for the visual helios canvas which allows for title specification. More...
 
virtual void show ()
 Make the visualization effective.
 
int getTimeBetweenUpdates () const
 Obtain milliseconds between canvas updates. More...
 
void setTimeBetweenUpdates (int const timeBetweenUpdates)
 Set the milliseconds between canvas updates. More...
 
bool isForceRedraw () const
 Check if force redraw is enabled or not. More...
 
void setForceRedraw (bool const forceRedraw)
 Enable or disable force redraw. More...
 
string const & getTitle () const
 Obtain the visual helios canvas title. More...
 

Protected Member Functions

void cameraFromScene ()
 Set the camera position from the scene. More...
 
void unrenderNormals (size_t const m, std::function< ScenePart &(size_t const)> get)
 Unrender normals for objects obtained through given get function ranging in \([0, m)\). More...
 
void addObjectToViewer (VHStaticObjectXYZRGBAdapter &obj)
 Add given object to the viewer and render its normals if scene canvas is requested to render normals. More...
 
- Protected Member Functions inherited from visualhelios::VHNormalsCanvas
virtual void registerNormalsKeyboardCallback ()
 Register the keyboard callback to toggle normals rendering on/off. More...
 
virtual void addKeyboardCallbackUsageText ()
 Render text explaining how to use the normals keyboard callback. More...
 
- Protected Member Functions inherited from visualhelios::VHDynCanvas
void postUpdate () override
 Defines the default post update behavior for dynamic canvas and derived classes. More...
 
- Protected Member Functions inherited from visualhelios::VHCanvas
virtual void onStop ()
 Method to handle the behavior of the canvas after visualization has finished.
 

Protected Attributes

shared_ptr< VHDynSceneAdapter< VHStaticObjectXYZRGBAdapter, VHDynObjectXYZRGBAdapter > > dynScene
 The dynamic scene that must be rendered.
 
- Protected Attributes inherited from visualhelios::VHNormalsCanvas
bool normalsKeyboardCallbackEnabled
 Specify if the keyboard callback to toggle normals visualization is enabled (true) or not (false)
 
bool normalsUsageTextEnabled
 Specify if the normals keyboard callback usage text is enabled (true) or not (false)
 
bool renderingNormals
 Specify if the normals canvas must render normals (true) or not (false)
 
float normalMagnitude
 Specify the magnitude of normal vector for visualization.
 
float normalDefColor [3]
 Default color for normals in RGB format with components in \([0, 1]\).
 
- Protected Attributes inherited from visualhelios::VHDynCanvas
bool needsUpdate = false
 Control whether an update is needed even when dynamic objects themselves have not been updated (true) or not (false)
 
- Protected Attributes inherited from visualhelios::VHCanvas
string const title
 The title of the visual Helios canvas.
 
PCLVisualizer::Ptr viewer
 The PCL visualizer which is used to render graphics.
 
int timeBetweenUpdates
 How many milliseconds must elapsed between canvas updates.
 
bool forceRedraw
 Force redraw even when it is not required if true. Try to avoid unnecessary redraws if false.
 

Static Protected Attributes

static double const cosPIeighth = std::cos(PI_EIGHTH)
 
static double const camCoef
 

Detailed Description

Visual Helios Scene Canvas is a class which supports rendering a dynamic scene.

Author
Alberto M. Esmoris Pena
Version
1.0

Constructor & Destructor Documentation

◆ VHSceneCanvas() [1/2]

visualhelios::VHSceneCanvas::VHSceneCanvas ( DynScene ds)
inline

Default constructor for the visual Helios scene canvas.

See also
visualhelios::VHNormalsCanvas::VHNormalsCanvas

◆ VHSceneCanvas() [2/2]

VHSceneCanvas::VHSceneCanvas ( DynScene ds,
string const  title,
bool const  normalsKeyboardCallbackEnabled = true,
bool const  normalsUsageTextEnabled = true,
bool const  renderingNormals = true,
float const  normalMagnitude = 0.2 
)

Constructor for the visual Helios scene canvas which allows for title specification, flags configuration and normal magnitude specification.

See also
VHNormalsCanvas(string const, bool const, bool const, bool const, float const)

Member Function Documentation

◆ addObjectToViewer()

void VHSceneCanvas::addObjectToViewer ( VHStaticObjectXYZRGBAdapter obj)
protected

Add given object to the viewer and render its normals if scene canvas is requested to render normals.

Parameters
objThe object, whether dynamic or static, to be added to the viewer

◆ cameraFromScene()

void VHSceneCanvas::cameraFromScene ( )
protected

Set the camera position from the scene.

For this purpose let \(O\) be the point where the camera is located, \(P\) be the point with minimum coordinates from the scene and \(C\) be the centroid of the scene. Now lets define the normalized director vector \(\hat{v}\) that will be used to define the \(\overrightarrow{OP}\) direction with a \(\frac{\pi}{8}\) angle which is half of \(\frac{\pi}{4}\) angle that is the approximated angle corresponding to camera field of view:

\[ \hat{v} = \left( \sqrt{1-\cos\left(\frac{\pi}{8}\right)^2}, 0, \cos\left(\frac{\pi}{8}\right) \right) \]

For the point \(O = \left(O_x, O_y, O_z\right)\) its \(O_x\) and \(O_y\) components are known, but its \(O_z\) component must be calculated from expression \(\overrightarrow{OP} = O + t\hat{v}\) as the required \(z\)-distance so the camera is guaranteed to view all the scene from above. Thus, following system must be solved:

\[ \left\{\begin{array}{lll} P_x - O_x &=& O_x + t \hat{v}_x \\ P_z - O_z &=& O_z + t \hat{v}_z \end{array}\right. \]

It is easy to see that:

\[ t = \frac{P_x - 2 O_x}{\hat{v}_x} \]

In consequence:

\[ O_z = \frac{P_z - t \hat{v}_z}{2} = \frac{1}{2}\left[ P_z - \frac{\cos\left(\frac{\pi}{8}\right)} {\sqrt{1-\cos\left(\frac{\pi}{8}\right)^2}} \left(P_x - 2 O_x\right) \right] \]

Finally, one last consideration must be taken into account. If \(z^*\) is the maximum value of the \(z\) coordinate in the scene, then when \(O_z < z^*\) the \(z\) coordinate for the initial camera position will be \(z^*\) instead of \(O_z\). It is, the camera position will be \(O = \left(O_x, O_y, z^*\right)\)

◆ configure()

void VHSceneCanvas::configure ( )
overridevirtual

◆ renderNormals()

void VHSceneCanvas::renderNormals ( VHStaticObjectAdapter staticObj)
overridevirtual

Render normals for each primitive of given static object.

See also
visualhelios::VHNormalsCanvas::renderNormals

Implements visualhelios::VHNormalsCanvas.

◆ start()

void VHSceneCanvas::start ( )
overridevirtual

◆ unrenderAllNormals()

void VHSceneCanvas::unrenderAllNormals ( )
overridevirtual

Remove all rendered normals.

See also
visualhelios::VHNormalsCanvas::unrenderAllNormals

Implements visualhelios::VHNormalsCanvas.

◆ unrenderNormals()

void VHSceneCanvas::unrenderNormals ( size_t const  m,
std::function< ScenePart &(size_t const)>  get 
)
protected

Unrender normals for objects obtained through given get function ranging in \([0, m)\).

Parameters
mHow many objects can be obtained
getGetter to obtain \(i\)-th object

◆ update()

void VHSceneCanvas::update ( )
overridevirtual
See also
VHNormalsCanvas::update

Reimplemented from visualhelios::VHCanvas.

Member Data Documentation

◆ camCoef

double const VHSceneCanvas::camCoef
staticprotected
Initial value:
std::sqrt(1.0-cosPIeighth*cosPIeighth)
static double const cosPIeighth
Definition: VHSceneCanvas.h:30

\[ \frac{\cos\left(\frac{\pi}{8}\right)} {\sqrt{1 - \cos\left(\frac{\pi}{8}\right)^2}} \]

◆ cosPIeighth

double const VHSceneCanvas::cosPIeighth = std::cos(PI_EIGHTH)
staticprotected

\[ \cos\left(\frac{\pi}{8}\right) \]


The documentation for this class was generated from the following files: