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#include <cstddef>
23#include <optional>
24#include <string_view>
25
26namespace lagrange::raycasting {
27
32
37{
40
43 double vmf_kappa = 128.0;
44};
45
50{
53 std::optional<AdaptiveOptions> adaptive = AdaptiveOptions{};
54
56 double size_influence = 0.5;
57
61 double threshold = 5e-06;
62
67 double confidence = 0.9;
68};
69
70namespace internal {
71
86template <typename Scalar, typename Index>
87class LA_RAYCASTING_API OccludedFacetSampler
88{
89public:
94 {
95 Index mesh_index;
96 Index instance_index;
98 uint64_t facet_offset;
101 };
102
114 const OccludedFacetSamplerOptions& options = {},
115 function_ref<bool(Index mesh_index, Index instance_index)> is_occluder = [](Index, Index) {
116 return true;
117 });
118
119 ~OccludedFacetSampler();
120 OccludedFacetSampler(OccludedFacetSampler&&) noexcept;
121 OccludedFacetSampler& operator=(OccludedFacetSampler&&) noexcept;
122
124 void run_batch(uint64_t num_rays);
125
127 [[nodiscard]] bool is_visible(uint64_t global_facet_index) const;
128
132 [[nodiscard]] double visibility_measure(uint64_t global_facet_index) const;
133
135 [[nodiscard]] uint64_t num_rays_cast(uint64_t global_facet_index) const;
136
139 [[nodiscard]] uint64_t num_facets() const;
140
143 [[nodiscard]] uint64_t num_retired() const;
144
146 [[nodiscard]] span<const InstanceInfo> instances() const;
147
148private:
149 struct Impl;
150 value_ptr<Impl> m_impl;
151};
152
153} // namespace internal
154
160{
162 uint64_t num_rays = 1600000000ULL;
163
165 uint64_t batch_size = 50000000ULL;
166};
167
179
194
214template <typename Scalar, typename Index>
217 std::string_view attribute_name,
218 const RemoveOccludedFacetsOptions& options,
219 ProgressCallback& progress,
220 function_ref<bool(Index mesh_index, Index instance_index)> is_occluder =
221 [](Index, Index) { return true; },
222 const std::atomic_bool* cancel = nullptr);
223
240template <typename Scalar, typename Index>
243 const RemoveOccludedFacetsOptions& options,
244 ProgressCallback& progress,
245 function_ref<bool(Index mesh_index, Index instance_index)> is_occluder =
246 [](Index, Index) { return true; },
247 const std::atomic_bool* cancel = nullptr);
248
250
251} // 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:45
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:133
::nonstd::span< T, Extent > span
A bounds-safe view for sequences of objects.
Definition span.h:27
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.
InstancingPolicy
How a facet's measure is reconciled across the instances of its source mesh.
Definition remove_occluded_facets.h:171
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.
@ FlattenInstances
One output mesh per input instance; instancing is lost.
Definition remove_occluded_facets.h:173
@ Max
Preserve instancing; measure is the max (most visible) over its instances.
Definition remove_occluded_facets.h:175
@ Average
Preserve instancing; measure is the mean over its instances.
Definition remove_occluded_facets.h:177
Raycasting operations.
Definition compute_local_feature_size.h:20
Options for adaptive mode of OccludedFacetSampler.
Definition remove_occluded_facets.h:37
size_t num_adaptive_per_cosine
Seed-guided rays per cosine ray in the adaptive mixture (1:K ratio, K >= 1).
Definition remove_occluded_facets.h:39
double vmf_kappa
von Mises-Fisher (vMF) lobe concentration on each seed direction (angular width ~ 1/sqrt(kappa)).
Definition remove_occluded_facets.h:43
Ray-budget options for estimate_occluded_facet_measures() and remove_occluded_facets().
Definition remove_occluded_facets.h:160
uint64_t num_rays
Total ray budget. If 0, a non-null cancellation flag is required.
Definition remove_occluded_facets.h:162
uint64_t batch_size
Rays per batch. Cancellation and progress are checked at batch boundaries.
Definition remove_occluded_facets.h:165
Options for OccludedFacetSampler.
Definition remove_occluded_facets.h:50
double size_influence
How much a facet size counts toward keeping it. 0 = size-independent, 1 = area-weighted.
Definition remove_occluded_facets.h:56
double confidence
Per-facet confidence for anytime-valid early-keep retirement.
Definition remove_occluded_facets.h:67
std::optional< AdaptiveOptions > adaptive
Adaptive multiple importance sampling (MIS) with a cosine + seed-guided mixture is enabled by default...
Definition remove_occluded_facets.h:53
double threshold
Keep-threshold for M = mean_visibility * (area_f / mean_face_area)^size_influence.
Definition remove_occluded_facets.h:61
Options for remove_occluded_facets().
Definition remove_occluded_facets.h:184
OccludedFacetEstimateOptions estimate_options
Ray-budget and batch-size options.
Definition remove_occluded_facets.h:189
InstancingPolicy instancing
How to reconcile a facet's measure across the instances of its source mesh.
Definition remove_occluded_facets.h:192
OccludedFacetSamplerOptions sampler_options
Options forwarded to the underlying OccludedFacetSampler.
Definition remove_occluded_facets.h:186
Maps a global facet index back to (mesh, instance, local facet).
Definition remove_occluded_facets.h:94
uint64_t facet_offset
Global index of this instance's first facet in the flat arrays (is_visible, etc.).
Definition remove_occluded_facets.h:98
Index num_facets
Number of facets in this instance's mesh.
Definition remove_occluded_facets.h:100