fcl_collision_geometry_cache.cpp
Go to the documentation of this file.
1 
30 #include <mutex>
31 
33 {
34 // Static member definitions
35 // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
36 std::map<boost::uuids::uuid, std::weak_ptr<fcl::CollisionGeometryd>> FCLCollisionGeometryCache::cache_;
37 // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
39 
40 void FCLCollisionGeometryCache::insert(const std::shared_ptr<const tesseract_geometry::Geometry>& key,
41  const std::shared_ptr<fcl::CollisionGeometryd>& value)
42 {
43  assert(!key->getUUID().is_nil());
44  std::scoped_lock lock(mutex_);
45  cache_[key->getUUID()] = value;
46 }
47 
48 std::shared_ptr<fcl::CollisionGeometryd>
49 FCLCollisionGeometryCache::get(const std::shared_ptr<const tesseract_geometry::Geometry>& key)
50 {
51  assert(!key->getUUID().is_nil());
52  std::scoped_lock lock(mutex_);
53  auto it = cache_.find(key->getUUID());
54  if (it != cache_.end())
55  {
56  std::shared_ptr<fcl::CollisionGeometryd> collision_shape = it->second.lock();
57  if (collision_shape != nullptr)
58  return collision_shape;
59 
60  cache_.erase(key->getUUID());
61  }
62  return nullptr;
63 }
64 
66 {
67  std::scoped_lock lock(mutex_);
68  for (auto it = cache_.begin(); it != cache_.end();)
69  {
70  if (it->second.expired())
71  it = cache_.erase(it);
72  else
73  ++it;
74  }
75 }
76 
77 } // namespace tesseract_collision::tesseract_collision_fcl
tesseract_collision::tesseract_collision_fcl::FCLCollisionGeometryCache::get
static std::shared_ptr< fcl::CollisionGeometryd > get(const std::shared_ptr< const tesseract_geometry::Geometry > &key)
Retrieve the cache entry by key.
Definition: fcl_collision_geometry_cache.cpp:49
fcl_collision_geometry_cache.h
This is a static cache mapping tesseract geometry shared pointers to fcl collision geometry to avoid ...
tesseract_collision::tesseract_collision_fcl::FCLCollisionGeometryCache::cache_
static std::map< boost::uuids::uuid, std::weak_ptr< fcl::CollisionGeometryd > > cache_
The static cache.
Definition: fcl_collision_geometry_cache.h:67
tesseract_collision::tesseract_collision_fcl
Definition: fcl_collision_geometry_cache.h:42
tesseract_collision::tesseract_collision_fcl::FCLCollisionGeometryCache::mutex_
static std::mutex mutex_
The shared mutex for thread safety.
Definition: fcl_collision_geometry_cache.h:69
tesseract_collision::tesseract_collision_fcl::FCLCollisionGeometryCache::prune
static void prune()
Remove any entries which are no longer valid.
Definition: fcl_collision_geometry_cache.cpp:65
geometry.h
tesseract_collision::tesseract_collision_fcl::FCLCollisionGeometryCache::insert
static void insert(const std::shared_ptr< const tesseract_geometry::Geometry > &key, const std::shared_ptr< fcl::CollisionGeometryd > &value)
Insert a new entry into the cache.
Definition: fcl_collision_geometry_cache.cpp:40


tesseract_collision
Author(s): Levi Armstrong
autogenerated on Sun May 18 2025 03:01:52