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
22namespace lagrange::raycasting {
23
28
38template <typename Scalar, typename Index>
39class LA_RAYCASTING_API OccludedInstanceSampler
40{
41public:
52 function_ref<bool(Index mesh_index, Index instance_index)> is_occluder = [](Index, Index) {
53 return true;
54 });
55
59
61 void run_batch(uint64_t num_rays);
62
64 bool is_visible(Index global_index) const;
65
67 uint64_t num_rays_cast(Index global_index) const;
68
70 Index num_instances() const;
71
72private:
73 struct Impl;
74 value_ptr<Impl> m_impl;
75};
76
81{
84 uint64_t num_rays = 1600000000ULL;
85
87 uint64_t batch_size = 20000000ULL;
88
90 bool until_converged = false;
91};
92
105template <typename Scalar, typename Index>
106LA_RAYCASTING_API void estimate_occluded_instances(
108 const OccludedInstanceEstimateOptions& options,
109 ProgressCallback& progress,
110 const std::atomic_bool* cancel = nullptr);
111
133template <typename Scalar, typename Index>
134LA_RAYCASTING_API void estimate_occluded_instances(
136 function_ref<void(Index mesh_index, Index instance_index)> callback,
137 const OccludedInstanceEstimateOptions& options,
138 ProgressCallback& progress,
139 function_ref<bool(Index mesh_index, Index instance_index)> is_occluder =
140 [](Index, Index) { return true; },
141 const std::atomic_bool* cancel = nullptr);
142
160template <typename Scalar, typename Index>
161LA_RAYCASTING_API scene::SimpleScene<Scalar, Index, 3> remove_occluded_instances(
163 const OccludedInstanceEstimateOptions& options,
164 ProgressCallback& progress,
165 function_ref<bool(Index mesh_index, Index instance_index)> is_occluder =
166 [](Index, Index) { return true; },
167 const std::atomic_bool* cancel = nullptr);
168
170
171} // 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 instances in a scene.
Definition remove_occluded_instances.h:40
OccludedInstanceSampler(const scene::SimpleScene< Scalar, Index, 3 > &scene, 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:134
LA_RAYCASTING_API void estimate_occluded_instances(OccludedInstanceSampler< Scalar, Index > &sampler, const OccludedInstanceEstimateOptions &options, ProgressCallback &progress, const std::atomic_bool *cancel=nullptr)
Drive an OccludedInstanceSampler progressively.
Definition remove_occluded_instances.cpp:224
Raycasting operations.
Definition compute_local_feature_size.h:20
Loop options for estimate_occluded_instances() and remove_occluded_instances().
Definition remove_occluded_instances.h:81
uint64_t num_rays
Total ray budget.
Definition remove_occluded_instances.h:84
bool until_converged
Stop early when a batch finds no new visible instances.
Definition remove_occluded_instances.h:90
uint64_t batch_size
Rays per batch. Cancellation, progress, and convergence are checked at batch boundaries.
Definition remove_occluded_instances.h:87