Lagrange
lagrange::raycasting Namespace Reference

Raycasting operations. More...

Classes

struct  ClosestPointResult
 
class  EmbreeRayCaster
 A wrapper for Embree's raycasting API to compute ray intersections with (instances of) meshes. More...
 
class  RaycasterMesh
 
class  RaycasterMeshDerived
 

Enumerations

enum  RayCasterType { EMBREE_DEFAULT = 1 , EMBREE_DYNAMIC = 2 , EMBREE_ROBUST = 4 , EMBREE_COMPACT = 8 }
 
enum  RayCasterQuality { BUILD_QUALITY_LOW , BUILD_QUALITY_MEDIUM , BUILD_QUALITY_HIGH }
 
enum class  ProjectMode { CLOSEST_VERTEX , CLOSEST_POINT , RAY_CASTING }
 Main projection mode. More...
 
enum class  CastMode { ONE_WAY , BOTH_WAYS }
 Ray-casting mode. More...
 
enum class  WrapMode { CONSTANT , CLOSEST_VERTEX , CLOSEST_POINT }
 Wraping mode for vertices without a hit. More...
 

Functions

template<typename Scalar >
std::unique_ptr< EmbreeRayCaster< Scalar > > create_ray_caster (RayCasterType engine, RayCasterQuality quality=BUILD_QUALITY_LOW)
 
template<typename Scalar >
bool embree_closest_point (RTCPointQueryFunctionArguments *args)
 
template<typename SourceMeshType , typename TargetMeshType , typename DerivedVector = Eigen::Matrix<ScalarOf<SourceMeshType>, 3, 1>, typename DefaultScalar = typename SourceMeshType::Scalar>
void project_attributes (const SourceMeshType &source, TargetMeshType &target, const std::vector< std::string > &names, ProjectMode project_mode, const Eigen::MatrixBase< DerivedVector > &direction=DerivedVector(0, 0, 1), CastMode cast_mode=CastMode::BOTH_WAYS, WrapMode wrap_mode=WrapMode::CONSTANT, DefaultScalar default_value=DefaultScalar(0), std::function< void(typename TargetMeshType::Index, bool)> user_callback=nullptr, EmbreeRayCaster< ScalarOf< SourceMeshType > > *ray_caster=nullptr, std::function< bool(IndexOf< TargetMeshType >)> skip_vertex=nullptr)
 Project vertex attributes from one mesh to another. More...
 
template<typename SourceMeshType , typename TargetMeshType >
void project_attributes_closest_point (const SourceMeshType &source, TargetMeshType &target, const std::vector< std::string > &names, EmbreeRayCaster< ScalarOf< SourceMeshType > > *ray_caster=nullptr, std::function< bool(IndexOf< TargetMeshType >)> skip_vertex=nullptr)
 Project vertex attributes from one mesh to another, by copying attributes from the closest point on the input mesh. More...
 
template<typename SourceMeshType , typename TargetMeshType , typename DerivedVector , typename DefaultScalar = typename SourceMeshType::Scalar>
void project_attributes_directional (const SourceMeshType &source, TargetMeshType &target, const std::vector< std::string > &names, const Eigen::MatrixBase< DerivedVector > &direction, CastMode cast_mode=CastMode::BOTH_WAYS, WrapMode wrap_mode=WrapMode::CONSTANT, DefaultScalar default_value=DefaultScalar(0), std::function< void(typename TargetMeshType::Index, bool)> user_callback=nullptr, EmbreeRayCaster< ScalarOf< SourceMeshType > > *ray_caster=nullptr, std::function< bool(IndexOf< TargetMeshType >)> skip_vertex=nullptr)
 Project vertex attributes from one mesh to another, by projecting target vertices along a prescribed direction, and interpolating surface values from facet corners of the source mesh. More...
 
const std::map< std::string, ProjectMode > & project_modes ()
 
const std::map< std::string, CastMode > & cast_modes ()
 
const std::map< std::string, WrapMode > & wrap_modes ()
 
template<typename ParticleDataType , typename MeshType , typename DefaultScalar = typename ParticleDataType::value_type::Scalar, typename MatrixType = typename Eigen::Matrix<DefaultScalar, 4, 4>, typename VectorType = typename Eigen::Matrix<DefaultScalar, 3, 1>>
void project_particles_directional (const ParticleDataType &origins, const MeshType &mesh_proj_on, const VectorType &direction, ParticleDataType &out_origins, ParticleDataType &out_normals, const MatrixType &parent_transforms=MatrixType::Identity(), EmbreeRayCaster< ScalarOf< MeshType > > *ray_caster=nullptr, bool has_normals=true)
 Project particles (a particle contains origin and tangent info) to another mesh, by projecting their positions along a prescribed direction. More...
 

Detailed Description

Raycasting operations.

Enumeration Type Documentation

◆ RayCasterType

Enumerator
EMBREE_DEFAULT 

Corresponds to RTC_SCENE_FLAG_NONE.

EMBREE_DYNAMIC 

Corresponds to RTC_SCENE_FLAG_DYNAMIC.

EMBREE_ROBUST 

Corresponds to RTC_SCENE_FLAG_ROBUST.

EMBREE_COMPACT 

Corresponds to RTC_SCENE_FLAG_COMPACT.

◆ RayCasterQuality

Enumerator
BUILD_QUALITY_LOW 

Corresponds to RTC_BUILD_QUALITY_LOW.

BUILD_QUALITY_MEDIUM 

Corresponds to RTC_BUILD_QUALITY_MEDIUM.

BUILD_QUALITY_HIGH 

Corresponds to RTC_BUILD_QUALITY_HIGH.

◆ ProjectMode

enum class ProjectMode
strong

Main projection mode.

Enumerator
CLOSEST_VERTEX 

Copy attribute from the closest vertex on the source mesh.

CLOSEST_POINT 

Interpolate attribute from the closest point on the source mesh.

RAY_CASTING 

Copy attribute by projecting along a prescribed direction on the source mesh.

◆ CastMode

enum class CastMode
strong

Ray-casting mode.

Enumerator
ONE_WAY 

Cast a ray forward in the prescribed direction.

BOTH_WAYS 

Cast a ray both forward and backward in the prescribed direction.

◆ WrapMode

enum class WrapMode
strong

Wraping mode for vertices without a hit.

Enumerator
CONSTANT 

Fill with a constant value (defaults to 0).

CLOSEST_VERTEX 

Copy attribute from the closest vertex on the source mesh.

CLOSEST_POINT 

Interpolate attribute from the closest point on the source mesh.

Function Documentation

◆ project_attributes()

void project_attributes ( const SourceMeshType &  source,
TargetMeshType &  target,
const std::vector< std::string > &  names,
ProjectMode  project_mode,
const Eigen::MatrixBase< DerivedVector > &  direction = DerivedVector(0, 0, 1),
CastMode  cast_mode = CastMode::BOTH_WAYS,
WrapMode  wrap_mode = WrapMode::CONSTANT,
DefaultScalar  default_value = DefaultScalar(0),
std::function< void(typename TargetMeshType::Index, bool)>  user_callback = nullptr,
EmbreeRayCaster< ScalarOf< SourceMeshType > > *  ray_caster = nullptr,
std::function< bool(IndexOf< TargetMeshType >)>  skip_vertex = nullptr 
)

Project vertex attributes from one mesh to another.

Different projection modes can be prescribed.

Parameters
[in]sourceSource mesh.
[in,out]targetTarget mesh to be modified.
[in]namesName of the vertex attributes to transfer.
[in]project_modeProjection mode to choose from.
[in]directionRaycasting direction to project attributes.
[in]cast_modeWhether to project forward along the ray, or to project along the whole ray (both forward and backward).
[in]wrap_modeWrapping mode for values where there is no hit.
[in]default_valueScalar used to fill attributes in CONSTANT wrapping mode.
[in]user_callbackOptional user callback that can be used to set attribute values depending on whether there is a hit or not.
[in,out]ray_casterIf provided, the use ray_caster to perform the queries instead. The source mesh will assume to have been added to ray_caster in advance, and this function will not try to add it. This allows to use a different ray caster than the one computed by this function, and allows to nest function calls.
[in]skip_vertexIf provided, whether to skip assignment for a target vertex or not. This can be used for partial assignment (e.g. to only set boundary vertices of a mesh).
Template Parameters
SourceMeshTypeSource mesh type.
TargetMeshTypeTarget mesh type.
DerivedVectorVector type for the direction.
DefaultScalarScalar type used to fill attributes.

◆ project_attributes_closest_point()

void project_attributes_closest_point ( const SourceMeshType &  source,
TargetMeshType &  target,
const std::vector< std::string > &  names,
EmbreeRayCaster< ScalarOf< SourceMeshType > > *  ray_caster = nullptr,
std::function< bool(IndexOf< TargetMeshType >)>  skip_vertex = nullptr 
)

Project vertex attributes from one mesh to another, by copying attributes from the closest point on the input mesh.

Values are linearly interpolated from the face corners.

Parameters
[in]sourceSource mesh.
[in,out]targetTarget mesh to be modified.
[in]namesName of the vertex attributes to transfer.
[in,out]ray_casterIf provided, the use ray_caster to perform the queries instead. The source mesh will assume to have been added to ray_caster in advance, and this function will not try to add it. This allows to use a different ray caster than the one computed by this function, and allows to nest function calls.
[in]skip_vertexIf provided, whether to skip assignment for a target vertex or not. This can be used for partial assignment (e.g. to only set boundary vertices of a mesh).
Template Parameters
SourceMeshTypeSource mesh type.
TargetMeshTypeTarget mesh type.

◆ project_attributes_directional()

void project_attributes_directional ( const SourceMeshType &  source,
TargetMeshType &  target,
const std::vector< std::string > &  names,
const Eigen::MatrixBase< DerivedVector > &  direction,
CastMode  cast_mode = CastMode::BOTH_WAYS,
WrapMode  wrap_mode = WrapMode::CONSTANT,
DefaultScalar  default_value = DefaultScalar(0),
std::function< void(typename TargetMeshType::Index, bool)>  user_callback = nullptr,
EmbreeRayCaster< ScalarOf< SourceMeshType > > *  ray_caster = nullptr,
std::function< bool(IndexOf< TargetMeshType >)>  skip_vertex = nullptr 
)

Project vertex attributes from one mesh to another, by projecting target vertices along a prescribed direction, and interpolating surface values from facet corners of the source mesh.

Note
In the future may want to support using a vector field instead of a constant direction for projection.
Parameters
[in]sourceSource mesh.
[in,out]targetTarget mesh to be modified.
[in]namesName of the vertex attributes to transfer.
[in]directionRaycasting direction to project attributes.
[in]cast_modeWhether to project forward along the ray, or to project along the whole ray (both forward and backward).
[in]wrap_modeWrapping mode for values where there is no hit.
[in]default_valueScalar used to fill attributes in CONSTANT wrapping mode.
[in]user_callbackOptional user callback that can be used to set attribute values depending on whether there is a hit or not.
[in,out]ray_casterIf provided, the use ray_caster to perform the queries instead. The source mesh will assume to have been added to ray_caster in advance, and this function will not try to add it. This allows to use a different ray caster than the one computed by this function, and allows to nest function calls.
[in]skip_vertexIf provided, whether to skip assignment for a target vertex or not. This can be used for partial assignment (e.g. to only set boundary vertices of a mesh).
Template Parameters
SourceMeshTypeSource mesh type.
TargetMeshTypeTarget mesh type.
DerivedVectorVector type for the direction.
DefaultScalarScalar type used to fill attributes.

◆ project_particles_directional()

void project_particles_directional ( const ParticleDataType &  origins,
const MeshType mesh_proj_on,
const VectorType &  direction,
ParticleDataType &  out_origins,
ParticleDataType &  out_normals,
const MatrixType &  parent_transforms = MatrixType::Identity(),
EmbreeRayCaster< ScalarOf< MeshType > > *  ray_caster = nullptr,
bool  has_normals = true 
)

Project particles (a particle contains origin and tangent info) to another mesh, by projecting their positions along a prescribed direction.

The returned results are particles whose transform is recorded in the local coordinate.

Note
How to compute the particle transformation after the projection:
           Assuming the projection transformation is P and the cumulated parents transformation
           is C, The matrix M that transforms local to world coordinates is given by:

           M = P * C
             = C * (C^-1 * P * C)

           Where the matrix in parenthesis is the new axis system matrix after projection:
           P' = C^-1 * P * C

           We compute P * C, and then deduce P'
Parameters
[in]originsOrigin of the particles.
[in]mesh_proj_onMesh to be projected on.
[in]directionRaycasting direction to project attributes.
[out]out_originsOutput origin of the particles.
[out]out_normalsOutput normal of the polygon at intersections.
[in]parent_transformsCumulated parent transforms applied on the particles
[in,out]ray_casterIf provided, the use ray_caster to perform the queries instead. The target mesh will assume to have been added to ray_caster in advance, and this function will not try to add it. This allows to use a different ray caster than the one computed by this function, and allows to nest function calls.
[in]has_normalsWhether to compute and output normals
Template Parameters
ParticleDataTypeParticle data vector type.
MeshTypeMesh type.
DefaultScalarScalar type used in computation.
MatrixTypeMatrix type for the transform.
VectorTypeVector type for the direction.