|
24 | 24 | #include <geode/model/helpers/ray_tracing.hpp> |
25 | 25 |
|
26 | 26 | #include <absl/base/call_once.h> |
27 | | -#include <absl/synchronization/mutex.h> |
28 | 27 |
|
29 | 28 | #include <geode/basic/pimpl_impl.hpp> |
30 | 29 |
|
@@ -238,7 +237,15 @@ namespace geode |
238 | 237 | class BRepRayTracing::Impl |
239 | 238 | { |
240 | 239 | public: |
241 | | - explicit Impl( const BRep& brep ) : brep_( brep ) {} |
| 240 | + explicit Impl( const BRep& brep ) : brep_( brep ) |
| 241 | + { |
| 242 | + aabb_trees_.reserve( brep.nb_surfaces() ); |
| 243 | + for( const auto& surface : brep.surfaces() ) |
| 244 | + { |
| 245 | + aabb_trees_.emplace( |
| 246 | + surface.id(), std::make_unique< CachedTree >() ); |
| 247 | + } |
| 248 | + } |
242 | 249 |
|
243 | 250 | BoundarySurfaceIntersections find_intersections_with_boundaries( |
244 | 251 | const InfiniteLine3D& infinite_line, const Block3D& block ) |
@@ -307,26 +314,16 @@ namespace geode |
307 | 314 |
|
308 | 315 | const AABBTree3D& surface_aabb( const Surface3D& surface ) |
309 | 316 | { |
310 | | - auto& entry = cached_tree( surface.id() ); |
| 317 | + auto& entry = *aabb_trees_.at( surface.id() ); |
311 | 318 | absl::call_once( entry.built, [&surface, &entry] { |
312 | 319 | entry.tree = create_aabb_tree( surface.mesh() ); |
313 | 320 | } ); |
314 | 321 | return entry.tree; |
315 | 322 | } |
316 | 323 |
|
317 | | - CachedTree& cached_tree( const uuid& surface_id ) |
318 | | - { |
319 | | - absl::MutexLock lock{ mutex_ }; |
320 | | - return *aabb_trees_ |
321 | | - .try_emplace( |
322 | | - surface_id, std::make_unique< CachedTree >() ) |
323 | | - .first->second; |
324 | | - } |
325 | | - |
326 | 324 | private: |
327 | 325 | const BRep& brep_; |
328 | 326 | absl::flat_hash_map< uuid, std::unique_ptr< CachedTree > > aabb_trees_; |
329 | | - absl::Mutex mutex_; |
330 | 327 | }; |
331 | 328 |
|
332 | 329 | BRepRayTracing::BRepRayTracing( const BRep& brep ) : impl_{ brep } {} |
|
0 commit comments