Helios++
Helios software for LiDAR simulations
Scene Class Reference

Class representing a scene asset. More...

#include <Scene.h>

Inheritance diagram for Scene:
Collaboration diagram for Scene:

Public Member Functions

 Scene ()
 Scene default constructor.
 
 Scene (Scene &s)
 
bool finalizeLoading (bool const safe=false)
 Handle scene loading finish process. More...
 
void registerParts ()
 Register all scene parts composing the scene in the parts vector with no repetitions. More...
 
std::shared_ptr< AABBgetAABB ()
 Obtain the axis aligned bounding box defining scene boundaries. More...
 
glm::dvec3 getGroundPointAt (glm::dvec3 point)
 Obtain the ground point at specified XY coordinates. More...
 
std::shared_ptr< RaySceneIntersectiongetIntersection (glm::dvec3 const &rayOrigin, glm::dvec3 const &rayDir, bool const groundOnly) const
 Obtain the intersection between the ray and the scene, if any. More...
 
std::shared_ptr< RaySceneIntersectiongetIntersection (vector< double > const &tMinMax, glm::dvec3 const &rayOrigin, glm::dvec3 const &rayDir, bool const groundOnly) const
 Like Scene::getIntersection(dvec3 const, dvec3 const, bool const) but receiving precomputed minimum and maximum intersection times with respect to the axis aligned bounding box that bounds the scene. More...
 
std::map< double, Primitive * > getIntersections (glm::dvec3 &rayOrigin, glm::dvec3 &rayDir, bool const groundOnly)
 Obtain all intersections between the ray and the scene, if any. More...
 
glm::dvec3 getShift ()
 Obtain the minimum boundaries of the original axis aligned bounding box containing the scene, before it was centered so (0, 0, 0) became its new minimum boundaries. More...
 
glm::dvec3 const & getShiftRef () const
 Like Scene::getShift but returning a const reference instead of a copy. More...
 
std::vector< Vertex * > getAllVertices ()
 Obtain all vertices (without repetitions) composing the scene. More...
 
void doForceOnGround ()
 For each scene part which is flagged as forceOnGround, it will be vertically translated to closest ground scene part. More...
 
glm::dvec3 findForceOnGroundQ (int const searchDepth, glm::dvec3 const minzv, vector< Vertex * > &vertices, vector< double > const &o, vector< double > const &v)
 Assist doForceOnGround function to find an adequate \(q\) for step 4. More...
 
void buildKDGrove (bool const safe=false)
 Build the KDGrove for the scene, overwriting previous one if any. More...
 
void buildKDGroveWithLog (bool const safe=false)
 Call buildKDGrove exporting building information through logging system. More...
 
virtual std::shared_ptr< KDGroveRaycaster > const & getRaycaster () const
 
virtual std::shared_ptr< KDGroveFactorygetKDGroveFactory () const
 Obtain the KDGrove factory used by the scene. More...
 
virtual void setKDGroveFactory (std::shared_ptr< KDGroveFactory > const kdgf)
 Set the KDGrove factory to be used by the scene. More...
 
virtual std::shared_ptr< KDGrovegetKDGrove () const
 Obtain the KDGrove used by the scene. More...
 
virtual void setKDGrove (std::shared_ptr< KDGrove > const kdgrove)
 Set the KDGrove to be used by the scene. More...
 
virtual std::shared_ptr< AABBgetBBox () const
 Obtain the scene's bounding box. More...
 
virtual void setBBox (std::shared_ptr< AABB > const bbox)
 Set the scene's bounding box. More...
 
virtual std::shared_ptr< AABBgetBBoxCRS () const
 Obtain the scene's coordinate reference system bounding box. More...
 
virtual void setBBoxCRS (std::shared_ptr< AABB > const bbox)
 Set the scene's coordinate reference system bounding box. More...
 
virtual bool hasMovingObjects () const
 Checke whether the scene contains at least one moving object (true) or not (false) More...
 
virtual void writeObject (std::string path)
 Serialize the scene and write it to given output file. More...
 
virtual bool doSimStep ()
 Support simulation step handling from scene side. More...
 
- Public Member Functions inherited from Asset
std::string getLocationString ()
 Obtain asset location string. More...
 
virtual bool isEgg () const
 Check whether the asset is an EggAsset or not. More...
 

Static Public Member Functions

static ScenereadObject (std::string path)
 Read serialized scene from given file. More...
 

Public Attributes

std::vector< Primitive * > primitives
 Vector of primitives composing the scene.
 
std::vector< std::shared_ptr< ScenePart > > parts
 Parts composing the scene with no repeats. More...
 
- Public Attributes inherited from Asset
std::string id = ""
 Asset identifier.
 
std::string name = "Unnamed Asset"
 Asset name.
 
std::string sourceFilePath = ""
 Path to asset file.
 

Protected Attributes

std::shared_ptr< KDGroveFactorykdgf
 The KDGrove factory used to build the scene KDGrove. More...
 
std::shared_ptr< KDGrovekdgrove
 KDGrove containing a KDTree for each scene part to speed-up ray-primitive intersection check computations.
 
std::shared_ptr< AABBbbox
 Axis aligned bounding box defining scene boundaries.
 
std::shared_ptr< AABBbbox_crs
 Original axis aligned bounding box defining scene boundaries before centering it.
 
std::shared_ptr< KDGroveRaycasterraycaster
 The raycaster based on KDGrove. More...
 

Private Member Functions

template<class Archive >
void save (Archive &ar, unsigned int const version) const
 Handle scene save operation. More...
 
template<class Archive >
void load (Archive &ar, unsigned int const fileVersion)
 Handle scene load operation. More...
 
 BOOST_SERIALIZATION_SPLIT_MEMBER ()
 

Friends

class boost::serialization::access
 

Detailed Description

Class representing a scene asset.

Member Function Documentation

◆ buildKDGrove()

void Scene::buildKDGrove ( bool const  safe = false)

Build the KDGrove for the scene, overwriting previous one if any.

Parameters
safeThe same safe as the one received by finalizeSceneLoading
See also
Scene::finalizeSceneLoading
Scene::buildKDGroveWithLog

◆ buildKDGroveWithLog()

void Scene::buildKDGroveWithLog ( bool const  safe = false)

Call buildKDGrove exporting building information through logging system.

See also
Scene::buildKDGrove

◆ doForceOnGround()

void Scene::doForceOnGround ( )

For each scene part which is flagged as forceOnGround, it will be vertically translated to closest ground scene part.

This function requires that there is at least one scene part flagged as ground, otherwise it is not possible to apply it. The algorithm can be described in 5 steps:

  1. For any ground scene part, find its min \(a_i = (a_{ix}, a_{iy}, a_{iz})\) and max \(b_i = (b_{ix}, b_{iy}, b_{iz})\) vertices.
  2. Let the scene part to be placed on ground be defined by its \(m\) vertices, such that \(Q = \left\{q_1, \ldots, q_m\right\}\). Also, let it be represented by its minimum \(z\) vertex \(q_* = (q_{*x}, q_{*y}, q_{*z}) \). Thus, the first found ground scene part such that \(q_*\) is inside its \(\mathbb{R}^{2}\) boundaries is considered as the ground reference. More formally, it must be satisfied that:

    \[ q_{*x} \in [a_{ix}, b_{ix}] \land q_{*y} \in [a_{iy}, b_{iy}] \]

  3. Find the best fitting plane \(\pi\) with respect to vertices of ground reference, which orthonormal vector is noted as \(\hat{v}\)

    \[ \pi = \left\{ p=(x, y, z) : \left\langle{\overrightarrow{op}, \hat{v}}\right\rangle = 0 \right\} \]

  4. Compute the vertical projection of \(q\) on best fitting ground plane \(\pi\) as follows:

    \[ \begin{array}{lll} \mathcal{P}^{z}_{\pi}(q) &=& \left( q_{x}, q_{y}, \frac{ \hat{v}_x o_x + \hat{v}_y o_y + \hat{v}_z o_z - \hat{v}_x q_{x} - \hat{v}_y q_{y} } {\hat{v}_z} \right) \\ &=& \left( q_{x}, q_{y}, \frac{ \left\langle{\hat{v}, \vec{o}}\right\rangle - \hat{v}_x q_{x} - \hat{v}_y q_{y} }{\hat{v}_z} \right) \\ &=& (p_x, p_y, p_z) \\ &=& p \end{array} \]

    Where \(q\) varies depending on search depth, as explained in parameter documentation at the Scene::findForceOnGroundQ function.

  5. Let \(\Delta_z = q_{*z} - p_z\) be the magnitude of vertical translation for the entire scene part. Now, each vertex defining the scene part must be translated so:

    \[ \forall q_i \in Q,\, q'_i = (q_{ix}, q_{iy}, q_{iz} - \Delta_z) \]

See also
Scene::findForceOnGroundQ

◆ doSimStep()

virtual bool Scene::doSimStep ( )
inlinevirtual

Support simulation step handling from scene side.

For basic scenes and static scenes, there is nothing to do. However, dynamic scenes are expected to override this method to provide simulation level dynamism.

Returns
True if scene was updated, false otherwise
See also
DynScene::doSimStep

Reimplemented in DynScene.

◆ finalizeLoading()

bool Scene::finalizeLoading ( bool const  safe = false)

Handle scene loading finish process.

Computations such as primitives update and centering the scene (all its vertices) so the axis aligned bounding box defining its boundaries start at (0, 0, 0) and also KDTree building are performed here

Parameters
safeEnable safe mode (true) or disable it (false). Safe mode is mainly useful for debugging purposes because it prevents certain changes such as modification of primitives ordering. Whenever safe mode is not necessary, it is recommended to set it to false as enabling it might lead to a slowdown
Returns
True if scene loading was successfully finished, false otherwise

◆ findForceOnGroundQ()

glm::dvec3 Scene::findForceOnGroundQ ( int const  searchDepth,
glm::dvec3 const  minzv,
vector< Vertex * > &  vertices,
vector< double > const &  o,
vector< double > const &  v 
)

Assist doForceOnGround function to find an adequate \(q\) for step 4.

Parameters
searchDepthThe search strategy specification. This function should never be called with searchDepth 0, that case must be skipped at Scene::doForceOnGround directly. Search depth corresponds with the scene part's forceOnGround attribute

If it is 0 the force on ground process will be skipped. If it is 1, a specific algorithm based on \(q=q_*\) as min \(z\) point will be used. If it is \(>1\), then it specifies the number of search steps to be performed to find \(q\) on a discrete linear search with searchDepth steps. If it is -1, then \( q = \mathrm{argmin}_{q \in Q} \;\;\; q_z - \frac{\left\langle{\hat{v}, \vec{o}}\right\rangle - \left( \hat{v}_x q_x + \hat{v}_y q_y \right)}{\hat{v}_z} \)

Parameters
minzvThe \(q_*\) that is used as \(q\) if searchDepth is 1
verticesAll vertices defining the scene part to be placed on ground
oA point contained in the best fitting ground plane
vThe normal vector of the best fitting ground plane
See also
Scene::doForceOnGround

◆ getAABB()

shared_ptr< AABB > Scene::getAABB ( )

Obtain the axis aligned bounding box defining scene boundaries.

See also
Scene::bbox

◆ getAllVertices()

vector< Vertex * > Scene::getAllVertices ( )

Obtain all vertices (without repetitions) composing the scene.

Returns
All vertices (without repetitions) composing the scene

◆ getBBox()

virtual std::shared_ptr<AABB> Scene::getBBox ( ) const
inlinevirtual

Obtain the scene's bounding box.

Returns
Scene's bounding box
See also
Scene::bbox

◆ getBBoxCRS()

virtual std::shared_ptr<AABB> Scene::getBBoxCRS ( ) const
inlinevirtual

Obtain the scene's coordinate reference system bounding box.

Returns
Scene's coordinate reference system bounding box
See also
Scene::bbox

◆ getGroundPointAt()

glm::dvec3 Scene::getGroundPointAt ( glm::dvec3  point)

Obtain the ground point at specified XY coordinates.

Parameters
pointPoint definint the XY coordinates for which the ground point shall be obtained
Returns
Intersected ground point

◆ getIntersection() [1/2]

shared_ptr< RaySceneIntersection > Scene::getIntersection ( glm::dvec3 const &  rayOrigin,
glm::dvec3 const &  rayDir,
bool const  groundOnly 
) const

Obtain the intersection between the ray and the scene, if any.

Parameters
rayOriginRay origin 3D coordinates
rayDirRay 3D director vector
groundOnlyFlag to specify if only ground points must be considered (true) or not (false)
Returns
Obtained intersection, nullptr if no intersection was detected
See also
RaySceneIntersection
KDTreeRaycaster
KDTreeRaycaster::search

◆ getIntersection() [2/2]

std::shared_ptr< RaySceneIntersection > Scene::getIntersection ( vector< double > const &  tMinMax,
glm::dvec3 const &  rayOrigin,
glm::dvec3 const &  rayDir,
bool const  groundOnly 
) const

Like Scene::getIntersection(dvec3 const, dvec3 const, bool const) but receiving precomputed minimum and maximum intersection times with respect to the axis aligned bounding box that bounds the scene.

Parameters
tMinMaxThe minimum and maximum intersection times
See also
Scene::getIntersection(dvec3 const, dvec3 const, bool const)

◆ getIntersections()

map< double, Primitive * > Scene::getIntersections ( glm::dvec3 &  rayOrigin,
glm::dvec3 &  rayDir,
bool const  groundOnly 
)

Obtain all intersections between the ray and the scene, if any.

Parameters
rayOriginRay origin 3D coordinates
rayDirRay 3D director vector
groundOnlyFlag to specify if only ground points must be considered (true) or not (false)
Returns
Map of all primitives intersected by the ray, which key is the distance with respect to ray origin
See also
RaySceneIntersection
KDTreeRaycaster
KDTreeRaycaster::searchAll

◆ getKDGrove()

virtual std::shared_ptr<KDGrove> Scene::getKDGrove ( ) const
inlinevirtual

Obtain the KDGrove used by the scene.

Returns
KDGrove used by the scene
See also
Scene::kdgrove

◆ getKDGroveFactory()

virtual std::shared_ptr<KDGroveFactory> Scene::getKDGroveFactory ( ) const
inlinevirtual

Obtain the KDGrove factory used by the scene.

Returns
KDGrove factory used by the scene
See also
Scene::kdgf

◆ getShift()

glm::dvec3 Scene::getShift ( )

Obtain the minimum boundaries of the original axis aligned bounding box containing the scene, before it was centered so (0, 0, 0) became its new minimum boundaries.

Returns
Minimum boundaries of the original axis aligned bounding box, before translating to (0, 0, 0)

◆ getShiftRef()

glm::dvec3 const& Scene::getShiftRef ( ) const
inline

Like Scene::getShift but returning a const reference instead of a copy.

See also
Scene::getShift

◆ hasMovingObjects()

virtual bool Scene::hasMovingObjects ( ) const
inlinevirtual

Checke whether the scene contains at least one moving object (true) or not (false)

Returns
True if scene hast at least one moving objects, false otherwise

◆ load()

template<class Archive >
void Scene::load ( Archive &  ar,
unsigned int const  fileVersion 
)
inlineprivate

Handle scene load operation.

Template Parameters
ArchiveType of rendering
Parameters
arSpecific rendering for the stream of bytes
sScene to be loaded
versionVersion number for the Scene

◆ readObject()

Scene * Scene::readObject ( std::string  path)
static

Read serialized scene from given file.

Parameters
pathPath to file where a serialized scene is stored
Returns
Imported scene

◆ registerParts()

void Scene::registerParts ( )

Register all scene parts composing the scene in the parts vector with no repetitions.

See also
Scene::parts

◆ save()

template<class Archive >
void Scene::save ( Archive &  ar,
unsigned int const  version 
) const
inlineprivate

Handle scene save operation.

Template Parameters
ArchiveType of rendering
Parameters
arSpecific rendering for the stream of bytes
sScene to be saved
versionVersion number for the Scene

◆ setBBox()

virtual void Scene::setBBox ( std::shared_ptr< AABB > const  bbox)
inlinevirtual

Set the scene's bounding box.

Parameters
bboxNew bounding box for the scene
See also
Scene::bbox

◆ setBBoxCRS()

virtual void Scene::setBBoxCRS ( std::shared_ptr< AABB > const  bbox)
inlinevirtual

Set the scene's coordinate reference system bounding box.

Parameters
bboxNew coordinate reference system bounding box for the scene
See also
Scene::bbox

◆ setKDGrove()

virtual void Scene::setKDGrove ( std::shared_ptr< KDGrove > const  kdgrove)
inlinevirtual

Set the KDGrove to be used by the scene.

Parameters
kdgroveNew KDGrove to be used by the scene
See also
Scene::kdtree

◆ setKDGroveFactory()

virtual void Scene::setKDGroveFactory ( std::shared_ptr< KDGroveFactory > const  kdgf)
inlinevirtual

Set the KDGrove factory to be used by the scene.

Parameters
kdgfNew KDGrove factory to be used by the scene
See also
Scene::kdgf

◆ writeObject()

void Scene::writeObject ( std::string  path)
virtual

Serialize the scene and write it to given output file.

Parameters
pathPath to output file where serialized scene shall be stored

Reimplemented in StaticScene, and DynScene.

Member Data Documentation

◆ kdgf

std::shared_ptr<KDGroveFactory> Scene::kdgf
protected

The KDGrove factory used to build the scene KDGrove.

See also
KDGroveFactory
Scene::kdgrove

◆ parts

std::vector<std::shared_ptr<ScenePart> > Scene::parts

Parts composing the scene with no repeats.

Please avoid manually computing this vector. If it is necessary to initialize or update it, call registerParts instead.

See also
Scene::registerParts

◆ raycaster

std::shared_ptr<KDGroveRaycaster> Scene::raycaster
protected

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