Lagrange
Loading...
Searching...
No Matches
Raycasting Module

Raycasting operations. More...

Classes

struct  LocalFeatureSizeOptions
 Options for compute_local_feature_size(). More...
 
struct  ProjectCommonOptions
 Common options for projection functions. More...
 
struct  ProjectDirectionalOptions
 Options for project_directional(). More...
 
struct  ProjectOptions
 Options for project(). More...
 
struct  AdaptiveOptions
 Options for adaptive mode of OccludedFacetSampler. More...
 
struct  OccludedFacetSamplerOptions
 Options for OccludedFacetSampler. More...
 
struct  OccludedFacetEstimateOptions
 Ray-budget options for estimate_occluded_facet_measures() and remove_occluded_facets(). More...
 
struct  RemoveOccludedFacetsOptions
 Options for remove_occluded_facets(). More...
 
struct  OccludedInstanceSamplerOptions
 Options for OccludedInstanceSampler. More...
 
struct  OccludedInstanceEstimateOptions
 Loop options for estimate_occluded_instances() and remove_occluded_instances(). More...
 
struct  RemoveOccludedInstancesOptions
 Options for remove_occluded_instances() and estimate_occluded_instance_measures(). More...
 

Enumerations

enum class  RayDirectionMode { Interior , Exterior , Both }
 Ray direction mode for local feature size computation. More...
 
enum class  InstancingPolicy { FlattenInstances , Max , Average }
 How a facet's measure is reconciled across the instances of its source mesh. More...
 

Functions

template<typename Scalar, typename Index>
AttributeId compute_local_feature_size (SurfaceMesh< Scalar, Index > &mesh, const LocalFeatureSizeOptions &options={}, const RayCaster *ray_caster=nullptr)
 Compute local feature size for each vertex of a mesh using medial axis approximation.
 
template<typename Scalar, typename Index>
void project (const SurfaceMesh< Scalar, Index > &source, SurfaceMesh< Scalar, Index > &target, const ProjectOptions &options={}, const RayCaster *ray_caster=nullptr)
 Project vertex attributes from one mesh to another.
 
template<typename Scalar, typename Index>
void project_closest_point (const SurfaceMesh< Scalar, Index > &source, SurfaceMesh< Scalar, Index > &target, const ProjectCommonOptions &options={}, const RayCaster *ray_caster=nullptr)
 Project vertex attributes from one mesh to another, by copying attributes from the closest point on the input mesh.
 
template<typename Scalar, typename Index>
void project_closest_vertex (const SurfaceMesh< Scalar, Index > &source, SurfaceMesh< Scalar, Index > &target, const ProjectCommonOptions &options={}, const RayCaster *ray_caster=nullptr)
 Project vertex attributes from one mesh to another, by copying attributes from the closest vertex on the source mesh surface.
 
template<typename Scalar, typename Index>
void project_directional (const SurfaceMesh< Scalar, Index > &source, SurfaceMesh< Scalar, Index > &target, const ProjectDirectionalOptions &options={}, const RayCaster *ray_caster=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.
 
template<typename Scalar, typename Index>
scene::SimpleScene< Scalar, Index, 3 > estimate_occluded_facet_measures (const scene::SimpleScene< Scalar, Index, 3 > &scene, std::string_view attribute_name, const RemoveOccludedFacetsOptions &options, ProgressCallback &progress, function_ref< bool(Index mesh_index, Index instance_index)> is_occluder=[](Index, Index) { return true;}, const std::atomic_bool *cancel=nullptr)
 Estimate each facet's visibility measure and write it to a named per-facet Scalar attribute.
 
template<typename Scalar, typename Index>
scene::SimpleScene< Scalar, Index, 3 > remove_occluded_facets (const scene::SimpleScene< Scalar, Index, 3 > &scene, const RemoveOccludedFacetsOptions &options, ProgressCallback &progress, function_ref< bool(Index mesh_index, Index instance_index)> is_occluder=[](Index, Index) { return true;}, const std::atomic_bool *cancel=nullptr)
 Build a new scene with facets not visible from the outside removed.
 
template<typename Scalar, typename Index>
std::vector< std::vector< double > > estimate_occluded_instance_measures (const scene::SimpleScene< Scalar, Index, 3 > &scene, const RemoveOccludedInstancesOptions &options, ProgressCallback &progress, function_ref< bool(Index mesh_index, Index instance_index)> is_occluder=[](Index, Index) { return true;}, const std::atomic_bool *cancel=nullptr)
 Estimate the per-instance visibility measure for a scene.
 
template<typename Scalar, typename Index>
scene::SimpleScene< Scalar, Index, 3 > remove_occluded_instances (const scene::SimpleScene< Scalar, Index, 3 > &scene, const RemoveOccludedInstancesOptions &options, ProgressCallback &progress, function_ref< bool(Index mesh_index, Index instance_index)> is_occluder=[](Index, Index) { return true;}, const std::atomic_bool *cancel=nullptr)
 Remove instances whose visibility measure is below options.sampler_options.threshold.
 
template<typename Scalar, typename Index>
void estimate_occluded_instances (const scene::SimpleScene< Scalar, Index, 3 > &scene, function_ref< void(Index mesh_index, Index instance_index)> callback, const OccludedInstanceEstimateOptions &options, ProgressCallback &progress, function_ref< bool(Index mesh_index, Index instance_index)> is_occluder=[](Index, Index) { return true;}, const std::atomic_bool *cancel=nullptr)
 
template<typename Scalar, typename Index>
scene::SimpleScene< Scalar, Index, 3 > remove_occluded_instances (const scene::SimpleScene< Scalar, Index, 3 > &scene, const OccludedInstanceEstimateOptions &options, ProgressCallback &progress, function_ref< bool(Index mesh_index, Index instance_index)> is_occluder=[](Index, Index) { return true;}, const std::atomic_bool *cancel=nullptr)
 

Detailed Description

Raycasting operations.

Quick links

Enumeration Type Documentation

◆ RayDirectionMode

enum class RayDirectionMode
strong

#include <lagrange/raycasting/compute_local_feature_size.h>

Ray direction mode for local feature size computation.

Enumerator
Interior 

Cast rays into the interior of the shape (hemisphere bounded by 1-ring normals, pointing inward).

Exterior 

Cast rays to the exterior of the shape (hemisphere bounded by 1-ring normals, pointing outward).

Both 

Cast rays in all directions (full sphere).

◆ InstancingPolicy

enum class InstancingPolicy
strong

#include <lagrange/raycasting/remove_occluded_facets.h>

How a facet's measure is reconciled across the instances of its source mesh.

Enumerator
FlattenInstances 

One output mesh per input instance; instancing is lost.

Max 

Preserve instancing; measure is the max (most visible) over its instances.

Average 

Preserve instancing; measure is the mean over its instances.

Function Documentation

◆ compute_local_feature_size()

template<typename Scalar, typename Index>
AttributeId compute_local_feature_size ( SurfaceMesh< Scalar, Index > & mesh,
const LocalFeatureSizeOptions & options = {},
const RayCaster * ray_caster = nullptr )

#include <lagrange/raycasting/compute_local_feature_size.h>

Compute local feature size for each vertex of a mesh using medial axis approximation.

For each vertex, this function:

  1. Casts a single ray along the normal direction (inward for Interior, outward for Exterior, both directions for Both mode) to find the opposite surface.
  2. Performs binary search along the ray to find the medial axis point - approximated as the largest depth from where the closest point on surface is within 1-ring of the vertex.
  3. Returns this distance as the local feature size.
Note
This method works best for meshes with uniformly sized triangles.
For Interior mode, rays are cast inward (negative normal direction). For Exterior mode, rays are cast outward (positive normal direction). For Both mode, rays are cast in both directions and the minimum LFS is taken.
If raycasting fails to find a hit, or if the binary search fails to converge, the default_lfs value is used as a fallback.
Parameters
[in,out]meshMesh to process (must be a triangle mesh). The mesh is modified to add the local feature size attribute.
[in]optionsOptions for local feature size computation.
[in]ray_casterIf provided, use this ray caster to perform the queries. The mesh must have been added to the ray caster in advance, and the scene must have been committed. If nullptr, a temporary ray caster will be created internally.
Template Parameters
ScalarMesh scalar type.
IndexMesh index type.
Returns
The attribute id of the local feature size attribute.

◆ project()

template<typename Scalar, typename Index>
void project ( const SurfaceMesh< Scalar, Index > & source,
SurfaceMesh< Scalar, Index > & target,
const ProjectOptions & options = {},
const RayCaster * ray_caster = nullptr )

#include <lagrange/raycasting/project.h>

Project vertex attributes from one mesh to another.

Different projection modes can be prescribed.

By default, vertex positions are projected. Additional attributes to project can be specified via options.attribute_ids. Set options.project_vertices to false to skip vertex positions.

Parameters
[in]sourceSource mesh (must be a triangle mesh).
[in,out]targetTarget mesh to be modified.
[in]optionsProjection options.
[in]ray_casterIf provided, use this ray caster to perform the queries. The source mesh must have been added to the ray caster in advance, and the scene must have been committed. If nullptr, a temporary ray caster will be created internally.
Template Parameters
ScalarMesh scalar type.
IndexMesh index type.

◆ project_closest_point()

template<typename Scalar, typename Index>
void project_closest_point ( const SurfaceMesh< Scalar, Index > & source,
SurfaceMesh< Scalar, Index > & target,
const ProjectCommonOptions & options = {},
const RayCaster * ray_caster = nullptr )

#include <lagrange/raycasting/project_closest_point.h>

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.

By default, vertex positions are projected. Additional attributes to project can be specified via options.attribute_ids. Set options.project_vertices to false to skip vertex positions.

Parameters
[in]sourceSource mesh (must be a triangle mesh).
[in,out]targetTarget mesh to be modified.
[in]optionsProjection options.
[in]ray_casterIf provided, use this ray caster to perform the queries. The source mesh must have been added to the ray caster in advance, and the scene must have been committed. If nullptr, a temporary ray caster will be created internally.
Template Parameters
ScalarMesh scalar type.
IndexMesh index type.

◆ project_closest_vertex()

template<typename Scalar, typename Index>
void project_closest_vertex ( const SurfaceMesh< Scalar, Index > & source,
SurfaceMesh< Scalar, Index > & target,
const ProjectCommonOptions & options = {},
const RayCaster * ray_caster = nullptr )

#include <lagrange/raycasting/project_closest_vertex.h>

Project vertex attributes from one mesh to another, by copying attributes from the closest vertex on the source mesh surface.

The closest surface point is found via a closest-point query, then snapped to the nearest vertex of the hit triangle (the vertex with the largest barycentric weight).

By default, vertex positions are projected. Additional attributes to project can be specified via options.attribute_ids. Set options.project_vertices to false to skip vertex positions.

Parameters
[in]sourceSource mesh (must be a triangle mesh).
[in,out]targetTarget mesh to be modified.
[in]optionsProjection options.
[in]ray_casterIf provided, use this ray caster to perform the queries. The source mesh must have been added to the ray caster in advance, and the scene must have been committed. If nullptr, a temporary ray caster will be created internally.
Template Parameters
ScalarMesh scalar type.
IndexMesh index type.

◆ project_directional()

template<typename Scalar, typename Index>
void project_directional ( const SurfaceMesh< Scalar, Index > & source,
SurfaceMesh< Scalar, Index > & target,
const ProjectDirectionalOptions & options = {},
const RayCaster * ray_caster = nullptr )

#include <lagrange/raycasting/project_directional.h>

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.

By default, vertex positions are projected. Additional attributes to project can be specified via options.attribute_ids. Set options.project_vertices to false to skip vertex positions.

Parameters
[in]sourceSource mesh (must be a triangle mesh).
[in,out]targetTarget mesh to be modified.
[in]optionsProjection options.
[in]ray_casterIf provided, use this ray caster to perform the queries. The source mesh must have been added to the ray caster in advance, and the scene must have been committed. If nullptr, a temporary ray caster will be created internally.
Template Parameters
ScalarMesh scalar type.
IndexMesh index type.

◆ estimate_occluded_facet_measures()

template<typename Scalar, typename Index>
scene::SimpleScene< Scalar, Index, 3 > estimate_occluded_facet_measures ( const scene::SimpleScene< Scalar, Index, 3 > & scene,
std::string_view attribute_name,
const RemoveOccludedFacetsOptions & options,
ProgressCallback & progress,
function_ref< bool(Index mesh_index, Index instance_index)> is_occluder = [](Index, Index) { return true;},
const std::atomic_bool * cancel = nullptr )

#include <lagrange/raycasting/remove_occluded_facets.h>

Estimate each facet's visibility measure and write it to a named per-facet Scalar attribute.

Instances are reconciled per options.instancing (see InstancingPolicy). The sampler runs at options.sampler_options.threshold, so a caller can re-threshold the measures without re-tracing.

Parameters
[in]sceneInput scene. Every referenced mesh must be a triangle mesh.
[in]attribute_nameName of the per-facet Scalar attribute to create on each output mesh.
[in]optionsOptions.
[in,out]progressProgress callback, updated at batch boundaries.
[in]is_occluderForwarded to the underlying OccludedFacetSampler ctor.
[in]cancelOptional cancellation flag.
Returns
The scene with per-facet visibility measures.
Template Parameters
ScalarMesh scalar type.
IndexMesh index type.

◆ remove_occluded_facets()

template<typename Scalar, typename Index>
scene::SimpleScene< Scalar, Index, 3 > remove_occluded_facets ( const scene::SimpleScene< Scalar, Index, 3 > & scene,
const RemoveOccludedFacetsOptions & options,
ProgressCallback & progress,
function_ref< bool(Index mesh_index, Index instance_index)> is_occluder = [](Index, Index) { return true;},
const std::atomic_bool * cancel = nullptr )

#include <lagrange/raycasting/remove_occluded_facets.h>

Build a new scene with facets not visible from the outside removed.

Instances are reconciled per options.instancing (see InstancingPolicy).

Parameters
[in]sceneInput scene.
[in]optionsOptions.
[in,out]progressProgress callback, updated at batch boundaries.
[in]is_occluderForwarded to the underlying OccludedFacetSampler ctor.
[in]cancelOptional cancellation flag.
Returns
The filtered scene.
Template Parameters
ScalarMesh scalar type.
IndexMesh index type.

◆ estimate_occluded_instance_measures()

template<typename Scalar, typename Index>
std::vector< std::vector< double > > estimate_occluded_instance_measures ( const scene::SimpleScene< Scalar, Index, 3 > & scene,
const RemoveOccludedInstancesOptions & options,
ProgressCallback & progress,
function_ref< bool(Index mesh_index, Index instance_index)> is_occluder = [](Index, Index) { return true; },
const std::atomic_bool * cancel = nullptr )

#include <lagrange/raycasting/remove_occluded_instances.h>

Estimate the per-instance visibility measure for a scene.

The sampler runs at options.sampler_options.threshold. The returned measures let a caller keep instances at any smaller threshold without re-tracing: keep (mesh_index, instance_index) iff measures[mesh_index][instance_index] >= threshold.

Note
Only 3D scenes are supported.
Parameters
[in]sceneScene to process.
[in]optionsOptions.
[in,out]progressProgress callback.
[in]is_occluderForwarded to OccludedInstanceSampler ctor.
[in]cancelOptional cancellation flag.
Returns
Per-instance measures indexed [mesh_index][instance_index].
Template Parameters
ScalarMesh scalar type.
IndexMesh index type.

◆ remove_occluded_instances() [1/2]

template<typename Scalar, typename Index>
scene::SimpleScene< Scalar, Index, 3 > remove_occluded_instances ( const scene::SimpleScene< Scalar, Index, 3 > & scene,
const RemoveOccludedInstancesOptions & options,
ProgressCallback & progress,
function_ref< bool(Index mesh_index, Index instance_index)> is_occluder = [](Index, Index) { return true; },
const std::atomic_bool * cancel = nullptr )

#include <lagrange/raycasting/remove_occluded_instances.h>

Remove instances whose visibility measure is below options.sampler_options.threshold.

Convenience wrapper around OccludedInstanceSampler and lagrange::scene::filter_instances.

Note
Only 3D scenes are supported.
Parameters
[in]sceneScene to process.
[in]optionsOptions.
[in,out]progressProgress callback.
[in]is_occluderForwarded to the underlying sampler.
[in]cancelOptional cancellation flag.
Template Parameters
ScalarMesh scalar type.
IndexMesh index type.

◆ estimate_occluded_instances()

template<typename Scalar, typename Index>
void estimate_occluded_instances ( const scene::SimpleScene< Scalar, Index, 3 > & scene,
function_ref< void(Index mesh_index, Index instance_index)> callback,
const OccludedInstanceEstimateOptions & options,
ProgressCallback & progress,
function_ref< bool(Index mesh_index, Index instance_index)> is_occluder = [](Index, Index) { return true;},
const std::atomic_bool * cancel = nullptr )

#include <lagrange/raycasting/remove_occluded_instances.h>

Deprecated
Use estimate_occluded_instance_measures. This overload reports only the occluded instances via callback. It uses std::numeric_limits<double>::min() as the keep-threshold to preserve the original first-observed-escape behavior.

◆ remove_occluded_instances() [2/2]

template<typename Scalar, typename Index>
scene::SimpleScene< Scalar, Index, 3 > remove_occluded_instances ( const scene::SimpleScene< Scalar, Index, 3 > & scene,
const OccludedInstanceEstimateOptions & options,
ProgressCallback & progress,
function_ref< bool(Index mesh_index, Index instance_index)> is_occluder = [](Index, Index) { return true; },
const std::atomic_bool * cancel = nullptr )

#include <lagrange/raycasting/remove_occluded_instances.h>

Deprecated
Use the RemoveOccludedInstancesOptions overload of remove_occluded_instances, which exposes the keep-threshold. This overload uses std::numeric_limits<double>::min() as the keep-threshold to preserve the original first-observed-escape behavior.