Helios++
Helios software for LiDAR simulations
DynObject Class Referenceabstract

Dynamic object base implementation. More...

#include <DynObject.h>

Inheritance diagram for DynObject:
Collaboration diagram for DynObject:

Public Member Functions

 DynObject ()
 Dynamic object default constructor.
 
 DynObject (ScenePart const &sp, bool const shallowPrimitives=false)
 Build the dynamic object from given scene part. More...
 
 DynObject (string const id)
 Dynamic object constructor with id as argument. More...
 
 DynObject (vector< Primitive * > const &primitives)
 Dynamic object constructor with primitives as argument. More...
 
 DynObject (string const id, vector< Primitive * > const &primitives)
 Dynamic object constructor with id and primitives as arguments. More...
 
virtual bool doStep ()
 Handle the computation of current simulation step according to configured step loop. This means that the DynObject::doSimStep method (which implements the logic of the DynObject) will be called by the DynObject::stepLoop when enough simulation steps have elapsed. More...
 
virtual bool doSimStep ()=0
 Any dynamic object concrete implementation must override this method providing dynamic behavior to the object. More...
 
void operator() ()
 Alias for DynObject::doStep method so it can be used as a functor. More...
 
size_t countVertices () const
 Count how many vertices there are defining the dynamic object. More...
 
arma::mat positionMatrixFromPrimitives () const
 Obtain the position matrix for primitives defining the dynamic object. More...
 
arma::mat positionMatrixFromPrimitives (size_t const m) const
 Like DynObject::positionMatrixFromPrimitives but receiving the total number of vertices beforehand. More...
 
arma::mat normalMatrixFromPrimitives () const
 Obtain the normal matrix for primitives defining the dynamic object. More...
 
arma::mat normalMatrixFromPrimitives (size_t const m) const
 Like DynObject::normalMatrixFromPrimitives but receiving the total number of vertices beforehand. More...
 
void updatePrimitivesPositionFromMatrix (arma::mat const &X)
 Update the position of each primitive with given matrix. More...
 
void updatePrimitivesPositionFromMatrix (size_t const m, arma::mat const &X)
 Like updatePrimitivesPositionFromMatrix(arma::mat const &) but receiving the total number of vertices beforehand. More...
 
void updatePrimitivesNormalFromMatrix (arma::mat const &X)
 Update the normal of each primitive with given matrix. More...
 
void updatePrimitivesNormalFromMatrix (size_t const m, arma::mat const &X)
 Like updatePrimitivesNormalFromMatrix(arma::mat const &) but receiving the total number of vertices beforehand. More...
 
ObjectType getType () const override
 
int getStepInterval () const
 Obtain the current step interval for the dynamic object. More...
 
void setStepInterval (int const stepInterval)
 Set the step interval for the dynamic object. More...
 
- Public Member Functions inherited from ScenePart
 ScenePart ()
 Default constructor for a scene part. More...
 
 ScenePart (ScenePart const &sp, bool const shallowPrimitives=false)
 
ScenePartoperator= (const ScenePart &rhs)
 Copy assigment operator.
 
void addObj (WavefrontObj *obj)
 Add the primitives of a WavefrontObj to the ScenePart. More...
 
std::vector< Vertex * > getAllVertices () const
 Obtain all vertices in the scene part. More...
 
void smoothVertexNormals ()
 Smooth normals for each vertex computing the mean for each triangle using it.
 
bool splitSubparts ()
 Split each subpart into a different scene part, with the first one corresponding to this scene part. More...
 
void computeCentroid (bool const computeBound=false)
 Compute the default centroid for the scene part as the midrange point and its boundaries too. More...
 
std::vector< Primitive * > const & getPrimitives () const
 Obtain the primitives of the scene part. More...
 
void setPrimitives (std::vector< Primitive * > const &primitives)
 Set the primitives of the scene part. More...
 
arma::colvec getCentroid () const
 Obtain the centroid of the scene part. More...
 
void setCentroid (arma::colvec centroid)
 Set the centroid of the scene part. More...
 
std::string const & getId () const
 Obtain the ID of the scene part. More...
 
void setId (const std::string &id)
 Set the ID of the scene part. More...
 
virtual PrimitiveType getPrimitiveType () const
 

Protected Member Functions

arma::mat matrixFromPrimitives (std::function< arma::colvec(Vertex const *)> get) const
 Build a matrix from the set of primitives defining the dynamic object. More...
 
arma::mat matrixFromPrimitives (size_t const m, std::function< arma::colvec(Vertex const *)> get) const
 Like DynObject::matrixFromPrimitives but receiving the total number of vertices beforehand. More...
 
void matrixToPrimitives (std::function< void(Vertex *, arma::colvec const &)> set, arma::mat const &X)
 Update primitives defining the dynamic object from given matrix. More...
 
void matrixToPrimitives (size_t const m, std::function< void(Vertex *, arma::colvec const &)> set, arma::mat const &X)
 Like DynObject::matrixToPrimitives but receiving the total number of vertices beforehand. More...
 

Protected Attributes

NonVoidStepLoop< bool > stepLoop
 The object to handle the execution of the dynamic object logic between specified simulation steps. More...
 

Private Member Functions

template<typename Archive >
void serialize (Archive &ar, const unsigned int version)
 Serialize a dynamic object to a stream of bytes. More...
 
template<typename Archive >
void save (Archive &ar, const unsigned int version) const
 Save a serialized dynamic object to a stream of bytes. More...
 
template<typename Archive >
void load (Archive &ar, const unsigned int version)
 Load a serialized dynamic object from a stream of bytes. More...
 

Friends

class boost::serialization::access
 

Additional Inherited Members

- Public Types inherited from ScenePart
enum  ObjectType { STATIC_OBJECT , DYN_OBJECT , DYN_MOVING_OBJECT }
 Specify the type of scene part / object. By default, the ScenePart is a static object.
 
enum  PrimitiveType { NONE , TRIANGLE , VOXEL }
 Specify the type of primitive used to build the scene part By default, the ScenePart is not build from primitives (None) More...
 
- Public Attributes inherited from ScenePart
PrimitiveType primitiveType
 The type of primitive used to build the scene part. More...
 
std::vector< Primitive * > mPrimitives
 Vector of pointers to primitives used by this scene part.
 
arma::colvec centroid
 The centroid of the scene part.
 
std::shared_ptr< AABBbound = nullptr
 The axis aligned bounding box defining scene part boundaries.
 
std::string mId = ""
 Identifier for the scene part.
 
std::vector< size_t > subpartLimit
 Vector specifying the limit of a subpart as the index of first element of next subpart. More...
 
std::string onRayIntersectionMode = ""
 Specify the handling mode for ray intersections.
 
double onRayIntersectionArgument = 0.0
 Specify the extra value to be used for ray intersection handling computation, when needed (depends on mode).
 
bool randomShift = false
 Specify if apply random shift to the scene part (true) or not (false, by default)
 
std::shared_ptr< LadLutladlut = nullptr
 Look-up table for leaf angle distribution.
 
glm::dvec3 mOrigin = glm::dvec3(0, 0, 0)
 Specify the origin for the scene part.
 
Rotation mRotation = Rotation(glm::dvec3(1, 0, 0), 0)
 Specify the rotation for the scene part.
 
double mScale = 1
 Specify the scale for the scene part.
 
int forceOnGround = 0
 Force the scene part to be on ground if \(\neq 0\), do nothing if \(= 0\). More...
 
OGRSpatialReference * mCrs = nullptr
 
OGREnvelope * mEnv = nullptr
 

Detailed Description

Dynamic object base implementation.

Author
Alberto M. Esmoris Pena
Version
1.0

A dynamic object is a set of primitives which together define a single object. This object is expected to have a dynamic behavior which changes over time.

Constructor & Destructor Documentation

◆ DynObject() [1/4]

DynObject::DynObject ( ScenePart const &  sp,
bool const  shallowPrimitives = false 
)
inline

Build the dynamic object from given scene part.

Parameters
spScene part as basis for dynamic object
See also
ScenePart::ScenePart(ScenePart const &, bool const)

◆ DynObject() [2/4]

DynObject::DynObject ( string const  id)
inline

Dynamic object constructor with id as argument.

Parameters
idThe id for the dynamic object
See also
DynObject::id

◆ DynObject() [3/4]

DynObject::DynObject ( vector< Primitive * > const &  primitives)
inline

Dynamic object constructor with primitives as argument.

Parameters
primitivesThe primitives defining the dynamic object
See also
DynObject::primitives

◆ DynObject() [4/4]

DynObject::DynObject ( string const  id,
vector< Primitive * > const &  primitives 
)
inline

Dynamic object constructor with id and primitives as arguments.

Parameters
idThe id for the dynamic object
primitivesThe primitives defining the dynamic object
See also
DynObject::id
DynObject::primitives

Member Function Documentation

◆ countVertices()

size_t DynObject::countVertices ( ) const

Count how many vertices there are defining the dynamic object.

It is the summation of the number of vertices for each primitive

Returns
How many vertices there are defining the dynamic object
See also
primitives

◆ doSimStep()

virtual bool DynObject::doSimStep ( )
pure virtual

Any dynamic object concrete implementation must override this method providing dynamic behavior to the object.

This method must be invoked each time a dynamic object must be updated because the time step has changed. For the sake of understanding, let \(\mathcal{D}\) be the dynamic object so \(\mathcal{D}_0\) represents its status at start time. Now, the doStep method can be understood as a function \(f\) which receives a dynamic object on a given time step \(t\) and update it to correspond with next time step \(t+1\):

\[ \mathcal{D}_{t+1} = f\left(\mathcal{D}_{t}\right) \]

Returns
True if computing the step has modified the dynamic object. False if no changes have been performed.
See also
DynObject::operator()()

Implemented in DynSequentiableMovingObject, and DynMovingObject.

◆ doStep()

bool DynObject::doStep ( )
virtual

Handle the computation of current simulation step according to configured step loop. This means that the DynObject::doSimStep method (which implements the logic of the DynObject) will be called by the DynObject::stepLoop when enough simulation steps have elapsed.

Returns
True if the dynamic object was modified, false otherwise
See also
DynObject::doSimStep
DynObject::stepLoop

◆ getStepInterval()

int DynObject::getStepInterval ( ) const
inline

Obtain the current step interval for the dynamic object.

Returns
Current step interval for the dynamic object
See also
DynObject::stepLoop
DynObject::doStep
DynObject::setStepInterval

◆ getType()

ObjectType DynObject::getType ( ) const
inlineoverridevirtual
See also
ScenePart::getType

Reimplemented from ScenePart.

◆ load()

template<typename Archive >
void DynObject::load ( Archive &  ar,
const unsigned int  version 
)
inlineprivate

Load a serialized dynamic object from a stream of bytes.

See also
DynObject::serialize(Archive &, const unsigned int)
DynObject::save(Archive &, const unsigned int)

◆ matrixFromPrimitives() [1/2]

arma::mat DynObject::matrixFromPrimitives ( size_t const  m,
std::function< arma::colvec(Vertex const *)>  get 
) const
protected

Like DynObject::matrixFromPrimitives but receiving the total number of vertices beforehand.

It can increase efficiency when the number of primitives defining the dynamic object remains the same by caching the countVertices method output and passing it as \(m\). Otherwise, it will be computed for each call of matrixFromPrimitives method which implies iterating through vertices of each primitive.

Parameters
mTotal number of vertices
See also
DynObject::matrixFromPrimitives
DynObject::countVertices

◆ matrixFromPrimitives() [2/2]

arma::mat DynObject::matrixFromPrimitives ( std::function< arma::colvec(Vertex const *)>  get) const
protected

Build a matrix from the set of primitives defining the dynamic object.

Let \(X\) be the built matrix:

\[ X = \left[\begin{array}{lll} x_{11} &\ldots& x_{1n} \\ \vdots &\ddots& \vdots \\ x_{m1} &\ldots& x_{mn} \end{array}\right] \]

Now, let \(\vec{x}_{j}=\left(x_{1j}, \ldots, x_{mj}\right)\) be the \(j\)-th column vector of matrix \(X\), \(p_j\) be the \(j\)-th vertex defining the dynamic object and \(f\) be the get function. Thus, the usage of the get function can be defined as follows:

\[ \vec{x}_{j} = f\left(p_j\right) \]

Parameters
getFunction to extract a column vector for a vertex which will be inserted in the matrix
Returns
Built matrix

◆ matrixToPrimitives() [1/2]

void DynObject::matrixToPrimitives ( size_t const  m,
std::function< void(Vertex *, arma::colvec const &)>  set,
arma::mat const &  X 
)
protected

Like DynObject::matrixToPrimitives but receiving the total number of vertices beforehand.

It can increase efficiency when the number of primitives defining the dynamic object remains the same by caching the countVertices method output and passing it as \(m\). Otherwise, it will be computed for each call of matrixToPrimitives method which implies iterating through vertices of each primitive.

Parameters
mTotal number of vertices
See also
DynObject::matrixToPrimitives
DynObject::countVertices

◆ matrixToPrimitives() [2/2]

void DynObject::matrixToPrimitives ( std::function< void(Vertex *, arma::colvec const &)>  set,
arma::mat const &  X 
)
protected

Update primitives defining the dynamic object from given matrix.

Let \(X\) be the input matrix:

\[ X = \left[\begin{array}{lll} x_{11} &\ldots& x_{1n} \\ \vdots &\ddots& \vdots \\ x_{m1} &\ldots& x_{mn} \end{array}\right] \]

Now, let \(\vec{x}_{j}=\left(x_{1j}, \ldots, x_{mj}\right)\) be the \(j\)-th column vector of matrix \(X\), \(p_j\) be the \(j\)-th vertex defining the dynamic object and \(f\) be the set function. Thus, the usage of the set function can be defined as follows:

\[ p_j = f\left(\vec{x}_{j}\right) \]

Parameters
setFunction to update a vertex from corresponding column vector in given matrix
XMatrix containing necessary data to update vertices. Each column contains the data for its corresponding vertex

◆ normalMatrixFromPrimitives() [1/2]

arma::mat DynObject::normalMatrixFromPrimitives ( ) const

Obtain the normal matrix for primitives defining the dynamic object.

\[ X_{m \times 3} = \left[\begin{array}{lll} \hat{n}_{x1} & \ldots & \hat{n}_{xm} \\ \hat{n}_{y1} & \ldots & \hat{n}_{ym} \\ \hat{n}_{z1} & \ldots & \hat{n}_{zm} \end{array}\right] \]

Returns
Normal matrix

◆ normalMatrixFromPrimitives() [2/2]

arma::mat DynObject::normalMatrixFromPrimitives ( size_t const  m) const

Like DynObject::normalMatrixFromPrimitives but receiving the total number of vertices beforehand.

It can increase efficiency when the number of primitives defining the dynamic object remains the same by caching the countVertices method output and passing it as \(m\). Otherwise, it will be computed for each call of normalMatrixFromPrimitives method which implies iterating through vertices of each primitive.

Parameters
mTotal number of vertices
See also
DynObject::normalMatrixFromPrimitives
DynObject::countVertices

◆ operator()()

void DynObject::operator() ( )
inline

Alias for DynObject::doStep method so it can be used as a functor.

See also
DynObject::doStep

◆ positionMatrixFromPrimitives() [1/2]

arma::mat DynObject::positionMatrixFromPrimitives ( ) const

Obtain the position matrix for primitives defining the dynamic object.

\[ X_{m \times 3} = \left[\begin{array}{lll} x_1 & \ldots & x_m \\ y_1 & \ldots & y_m \\ z_1 & \ldots & z_m \end{array}\right] \]

Returns
Position matrix

◆ positionMatrixFromPrimitives() [2/2]

arma::mat DynObject::positionMatrixFromPrimitives ( size_t const  m) const

Like DynObject::positionMatrixFromPrimitives but receiving the total number of vertices beforehand.

It can increase efficiency when the number of primitives defining the dynamic object remains the same by caching the countVertices method output and passing it as \(m\). Otherwise, it will be computed for each call of positionMatrixFromPrimitives method which implies iterating through vertices of each primitive.

Parameters
mTotal number of vertices
See also
DynObject::positionMatrixFromPrimitives
DynObject::countVertices

◆ save()

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

Save a serialized dynamic object to a stream of bytes.

See also
DynObject::serialize(Archive &, const unsigned int)
DynObject::load(Archive &, const unsigned int)

◆ serialize()

template<typename Archive >
void DynObject::serialize ( Archive &  ar,
const unsigned int  version 
)
inlineprivate

Serialize a dynamic object to a stream of bytes.

Template Parameters
ArchiveType of rendering
Parameters
arSpecific rendering for the stream of bytes
versionVersion number for the dynamic object

◆ setStepInterval()

void DynObject::setStepInterval ( int const  stepInterval)
inline

Set the step interval for the dynamic object.

Parameters
stepIntervalThe new step interval for the dynamic object
See also
DynObject::stepLoop
DynObject::doStep
DynObject::getStepInterval

◆ updatePrimitivesNormalFromMatrix() [1/2]

void DynObject::updatePrimitivesNormalFromMatrix ( arma::mat const &  X)

Update the normal of each primitive with given matrix.

The first column of matrix \(X\) contains the components for the new normal of the first primitive. The last column of matrix \(X\) contains the components for the new normal of the last primitive. The \(j\)-th column of matrix \(X\) contains the components for the new normal of the \(j\)-th primitive.

Parameters
XThe normal matrix containing new components
See also
updatePrimitivesNormalFromMatrix(size_t const, arma::mat const &)

◆ updatePrimitivesNormalFromMatrix() [2/2]

void DynObject::updatePrimitivesNormalFromMatrix ( size_t const  m,
arma::mat const &  X 
)

Like updatePrimitivesNormalFromMatrix(arma::mat const &) but receiving the total number of vertices beforehand.

It can increase efficiency when the number of primitives defining the dynamic object remains the same by caching the countVertices method output and passing as \(m\). Otherwise, it will be computed for each call of updatePrimitivesNormalFromMatrix method which implies iterating through vertices of each primitive.

Parameters
mTotal number of vertices
See also
updatePrimitivesNormalFromMatrix(arma::mat const &)

◆ updatePrimitivesPositionFromMatrix() [1/2]

void DynObject::updatePrimitivesPositionFromMatrix ( arma::mat const &  X)

Update the position of each primitive with given matrix.

The first column of matrix \(X\) contains the coordinates for the new position of the first primitive. The last column of matrix \(X\) contains the coordinates for the new position of the last primitive. The \(j\)-th column of matrix \(X\) contains the coordinates for the new position of the \(j\)-th primitive.

Parameters
XThe position matrix containing new coordinates
See also
updatePrimitivesPositionFromMatrix(size_t const, arma::mat const &)

◆ updatePrimitivesPositionFromMatrix() [2/2]

void DynObject::updatePrimitivesPositionFromMatrix ( size_t const  m,
arma::mat const &  X 
)

Like updatePrimitivesPositionFromMatrix(arma::mat const &) but receiving the total number of vertices beforehand.

It can increase efficiency when the number of primitives defining the dynamic object remains the same by caching the countVertices method output and passing as \(m\). Otherwise, it will be computed for each call of updatePrimitivesPositionFromMatrix method which implies iterating through vertices of each primitive.

Parameters
mTotal number of vertices
See also
updatePrimitivesPositionFromMatrix(arma::mat const &)

Member Data Documentation

◆ stepLoop

NonVoidStepLoop<bool> DynObject::stepLoop
protected

The object to handle the execution of the dynamic object logic between specified simulation steps.

See also
DynObject::doStep

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