Lagrange
Loading...
Searching...
No Matches
remove_occluded_facets.h
1/*
2 * Copyright 2026 Adobe. All rights reserved.
3 * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License. You may obtain a copy
5 * of the License at http://www.apache.org/licenses/LICENSE-2.0
6 *
7 * Unless required by applicable law or agreed to in writing, software distributed under
8 * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9 * OF ANY KIND, either express or implied. See the License for the specific language
10 * governing permissions and limitations under the License.
11 */
12#pragma once
13
14#include <lagrange/raycasting/api.h>
15#include <lagrange/scene/SimpleScene.h>
16#include <lagrange/utils/ProgressCallback.h>
17#include <lagrange/utils/function_ref.h>
18#include <lagrange/utils/span.h>
19#include <lagrange/utils/value_ptr.h>
20
21#include <atomic>
22
23namespace lagrange::raycasting {
24
29
34{
36 double jitter_sigma = 0.025;
37
43};
44
61template <typename Scalar, typename Index>
62class LA_RAYCASTING_API OccludedFacetSampler
63{
64public:
69 {
70 Index mesh_index;
71 Index instance_index;
73 uint64_t facet_offset;
76 };
77
89 const OccludedFacetSamplerOptions& options = {},
90 function_ref<bool(Index mesh_index, Index instance_index)> is_occluder = [](Index, Index) {
91 return true;
92 });
93
94 ~OccludedFacetSampler();
95 OccludedFacetSampler(OccludedFacetSampler&&) noexcept;
96 OccludedFacetSampler& operator=(OccludedFacetSampler&&) noexcept;
97
100 void run_normal_batch(uint64_t num_rays);
101
104 void run_adaptive_batch(uint64_t num_rays);
105
108 void run_brute_force_batch(uint64_t num_rays);
109
111 bool is_visible(uint64_t global_facet_index) const;
112
114 uint64_t num_rays_cast(uint64_t global_facet_index) const;
115
118 uint64_t num_facets() const;
119
121 span<const InstanceInfo> instances() const;
122
123private:
124 struct Impl;
125 value_ptr<Impl> m_impl;
126};
127
132{
135 uint64_t num_rays = 1600000000ULL;
136
140 uint64_t batch_size = 20000000ULL;
141
145
147 bool brute_force = false;
148
150 bool until_converged = false;
151};
152
169template <typename Scalar, typename Index>
170LA_RAYCASTING_API void estimate_occluded_facets(
172 const OccludedFacetEstimateOptions& options,
173 ProgressCallback& progress,
174 const std::atomic_bool* cancel = nullptr);
175
187
205template <typename Scalar, typename Index>
208 const RemoveOccludedFacetsOptions& options,
209 ProgressCallback& progress,
210 function_ref<bool(Index mesh_index, Index instance_index)> is_occluder =
211 [](Index, Index) { return true; },
212 const std::atomic_bool* cancel = nullptr);
213
215
216} // namespace lagrange::raycasting
A simple thread-safe progress callback.
Definition ProgressCallback.h:27
A lightweight non-owning reference to a callable.
Definition function_ref.h:47
Stateful algorithm for finding occluded facets across every instance of a scene.
Definition remove_occluded_facets.h:63
OccludedFacetSampler(const scene::SimpleScene< Scalar, Index, 3 > &scene, const OccludedFacetSamplerOptions &options={}, function_ref< bool(Index mesh_index, Index instance_index)> is_occluder=[](Index, Index) { return true;})
Build the ray caster and per-instance world-space facet data.
Simple scene container for instanced meshes.
Definition SimpleScene.h:62
Smart pointer with value semantics.
Definition value_ptr.h:134
LA_RAYCASTING_API 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.
LA_RAYCASTING_API void estimate_occluded_facets(OccludedFacetSampler< Scalar, Index > &sampler, const OccludedFacetEstimateOptions &options, ProgressCallback &progress, const std::atomic_bool *cancel=nullptr)
Drive an OccludedFacetSampler progressively until the budget is exhausted, the search converges,...
Definition remove_occluded_facets.cpp:399
::nonstd::span< T, Extent > span
A bounds-safe view for sequences of objects.
Definition span.h:27
Raycasting operations.
Definition compute_local_feature_size.h:20
Loop options for estimate_occluded_facets() and remove_occluded_facets().
Definition remove_occluded_facets.h:132
uint64_t num_adaptive_per_normal
Adaptive batches per normal batch.
Definition remove_occluded_facets.h:144
uint64_t num_rays
Total ray budget.
Definition remove_occluded_facets.h:135
bool until_converged
Stop early when a cycle finds no new visible facets.
Definition remove_occluded_facets.h:150
uint64_t batch_size
Rays per batch.
Definition remove_occluded_facets.h:140
bool brute_force
Run brute-force batches only — baseline for benchmarking against the adaptive mode.
Definition remove_occluded_facets.h:147
Maps a global facet index back to (mesh, instance, local facet).
Definition remove_occluded_facets.h:69
uint64_t facet_offset
Global index of this instance's first facet in the flat arrays (is_visible, etc.).
Definition remove_occluded_facets.h:73
Index num_facets
Number of facets in this instance's mesh.
Definition remove_occluded_facets.h:75
Options for OccludedFacetSampler.
Definition remove_occluded_facets.h:34
uint8_t visibility_threshold
Number of independent escapes a facet must accumulate before being marked visible.
Definition remove_occluded_facets.h:42
double jitter_sigma
Standard deviation of the Gaussian jitter applied to seed directions in adaptive batches.
Definition remove_occluded_facets.h:36
Options for remove_occluded_facets().
Definition remove_occluded_facets.h:180
OccludedFacetEstimateOptions estimate_options
Estimate-loop options forwarded to estimate_occluded_facets().
Definition remove_occluded_facets.h:182
OccludedFacetSamplerOptions sampler_options
Options forwarded to the underlying OccludedFacetSampler.
Definition remove_occluded_facets.h:185