Lagrange
Loading...
Searching...
No Matches
remove_occluded_instances.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/value_ptr.h>
19
20#include <atomic>
21#include <utility>
22#include <vector>
23
24namespace lagrange::raycasting {
25
30
35{
38 double threshold = 1e-06;
39
42 double size_influence = 0.5;
43
47 double confidence = 0.9;
48};
49
50namespace internal {
51
62template <typename Scalar, typename Index>
63class LA_RAYCASTING_API OccludedInstanceSampler
64{
65public:
77 const OccludedInstanceSamplerOptions& options = {},
78 function_ref<bool(Index mesh_index, Index instance_index)> is_occluder = [](Index, Index) {
79 return true;
80 });
81
82 ~OccludedInstanceSampler();
83 OccludedInstanceSampler(OccludedInstanceSampler&&) noexcept;
84 OccludedInstanceSampler& operator=(OccludedInstanceSampler&&) noexcept;
85
87 void run_batch(uint64_t num_rays);
88
90 [[nodiscard]] bool is_visible(Index mesh_index, Index instance_index) const;
91
95 [[nodiscard]] double visibility_measure(Index mesh_index, Index instance_index) const;
96
98 [[nodiscard]] uint64_t num_rays_cast(Index mesh_index, Index instance_index) const;
99
101 [[nodiscard]] Index num_instances() const;
102
105 [[nodiscard]] Index num_retired() const;
106
109 [[nodiscard]] std::pair<Index, uint64_t> progress() const;
110
111private:
112 struct Impl;
113 value_ptr<Impl> m_impl;
114};
115
116} // namespace internal
117
122{
125 uint64_t num_rays = 1600000000ULL;
126
128 uint64_t batch_size = 50000000ULL;
129
132 bool until_converged = false;
133};
134
146
166template <typename Scalar, typename Index>
167LA_RAYCASTING_API std::vector<std::vector<double>> estimate_occluded_instance_measures(
169 const RemoveOccludedInstancesOptions& options,
170 ProgressCallback& progress,
171 function_ref<bool(Index mesh_index, Index instance_index)> is_occluder =
172 [](Index, Index) { return true; },
173 const std::atomic_bool* cancel = nullptr);
174
191template <typename Scalar, typename Index>
192LA_RAYCASTING_API scene::SimpleScene<Scalar, Index, 3> remove_occluded_instances(
193 const scene::SimpleScene<Scalar, Index, 3>& scene,
194 const RemoveOccludedInstancesOptions& options,
195 ProgressCallback& progress,
196 function_ref<bool(Index mesh_index, Index instance_index)> is_occluder =
197 [](Index, Index) { return true; },
198 const std::atomic_bool* cancel = nullptr);
199
205template <typename Scalar, typename Index>
206[[deprecated("Use estimate_occluded_instance_measures().")]]
207LA_RAYCASTING_API void estimate_occluded_instances(
208 const scene::SimpleScene<Scalar, Index, 3>& scene,
209 function_ref<void(Index mesh_index, Index instance_index)> callback,
210 const OccludedInstanceEstimateOptions& options,
211 ProgressCallback& progress,
212 function_ref<bool(Index mesh_index, Index instance_index)> is_occluder =
213 [](Index, Index) { return true; },
214 const std::atomic_bool* cancel = nullptr);
215
222template <typename Scalar, typename Index>
223[[deprecated("Use the remove_occluded_instances overload taking RemoveOccludedInstancesOptions.")]]
224LA_RAYCASTING_API scene::SimpleScene<Scalar, Index, 3> remove_occluded_instances(
225 const scene::SimpleScene<Scalar, Index, 3>& scene,
226 const OccludedInstanceEstimateOptions& options,
227 ProgressCallback& progress,
228 function_ref<bool(Index mesh_index, Index instance_index)> is_occluder =
229 [](Index, Index) { return true; },
230 const std::atomic_bool* cancel = nullptr);
231
233
234} // 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
OccludedInstanceSampler(const scene::SimpleScene< Scalar, Index, 3 > &scene, const OccludedInstanceSamplerOptions &options={}, function_ref< bool(Index mesh_index, Index instance_index)> is_occluder=[](Index, Index) { return true;})
Build the ray caster and per-instance precomputation.
Simple scene container for instanced meshes.
Definition SimpleScene.h:62
Smart pointer with value semantics.
Definition value_ptr.h:133
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.
Definition remove_occluded_instances.cpp:454
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)
Definition remove_occluded_instances.cpp:483
Raycasting operations.
Definition compute_local_feature_size.h:20
Loop options for estimate_occluded_instances() and remove_occluded_instances().
Definition remove_occluded_instances.h:122
uint64_t num_rays
Total ray budget.
Definition remove_occluded_instances.h:125
bool until_converged
After the initial batch, stop when a batch confidently retires no new instances.
Definition remove_occluded_instances.h:132
uint64_t batch_size
Rays per batch. Cancellation, progress, and convergence are checked at batch boundaries.
Definition remove_occluded_instances.h:128
Options for OccludedInstanceSampler.
Definition remove_occluded_instances.h:35
double size_influence
Exponent on area / R in the measure above.
Definition remove_occluded_instances.h:42
double confidence
Per-instance confidence used by each batch-end early-keep test.
Definition remove_occluded_instances.h:47
double threshold
Keep-threshold for M = mean_visibility * (area / R)^size_influence, where mean_visibility is the cosi...
Definition remove_occluded_instances.h:38
Options for remove_occluded_instances() and estimate_occluded_instance_measures().
Definition remove_occluded_instances.h:139
OccludedInstanceEstimateOptions estimate_options
Estimate-loop options.
Definition remove_occluded_instances.h:144
OccludedInstanceSamplerOptions sampler_options
Sampler options (keep-threshold, size influence, confidence).
Definition remove_occluded_instances.h:141