bullet_collision_shape_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<BulletCollisionShape>> BulletCollisionShapeCache::cache_;
37 // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
39 
40 BulletCollisionShape::BulletCollisionShape(std::shared_ptr<btCollisionShape> top_level_)
41  : top_level(std::move(top_level_))
42 {
43 }
44 
45 void BulletCollisionShapeCache::insert(const std::shared_ptr<const tesseract_geometry::Geometry>& key,
46  const std::shared_ptr<BulletCollisionShape>& value)
47 {
48  assert(!key->getUUID().is_nil());
49  std::scoped_lock lock(mutex_);
50  cache_[key->getUUID()] = value;
51 }
52 
53 std::shared_ptr<BulletCollisionShape>
54 BulletCollisionShapeCache::get(const std::shared_ptr<const tesseract_geometry::Geometry>& key)
55 {
56  assert(!key->getUUID().is_nil());
57  std::scoped_lock lock(mutex_);
58  auto it = cache_.find(key->getUUID());
59  if (it != cache_.end())
60  {
61  std::shared_ptr<BulletCollisionShape> collision_shape = it->second.lock();
62  if (collision_shape != nullptr)
63  return collision_shape;
64 
65  cache_.erase(key->getUUID());
66  }
67  return nullptr;
68 }
69 
71 {
72  std::scoped_lock lock(mutex_);
73  for (auto it = cache_.begin(); it != cache_.end();)
74  {
75  if (it->second.expired())
76  it = cache_.erase(it);
77  else
78  ++it;
79  }
80 }
81 
82 } // namespace tesseract_collision::tesseract_collision_bullet
tesseract_collision::tesseract_collision_bullet
Definition: bullet_cast_bvh_manager.h:48
tesseract_collision::tesseract_collision_bullet::BulletCollisionShape::BulletCollisionShape
BulletCollisionShape()=default
tesseract_collision::tesseract_collision_bullet::BulletCollisionShapeCache::prune
static void prune()
Remove any entries which are no longer valid.
Definition: bullet_collision_shape_cache.cpp:70
bullet_collision_shape_cache.h
This is a static cache mapping tesseract geometry shared pointers to bullet collision shapes to avoid...
tesseract_collision::tesseract_collision_bullet::BulletCollisionShapeCache::insert
static void insert(const std::shared_ptr< const tesseract_geometry::Geometry > &key, const std::shared_ptr< BulletCollisionShape > &value)
Insert a new entry into the cache.
Definition: bullet_collision_shape_cache.cpp:45
geometry.h
tesseract_collision::tesseract_collision_bullet::BulletCollisionShapeCache::mutex_
static std::mutex mutex_
The shared mutex for thread safety.
Definition: bullet_collision_shape_cache.h:79
tesseract_collision::tesseract_collision_bullet::BulletCollisionShapeCache::get
static std::shared_ptr< BulletCollisionShape > get(const std::shared_ptr< const tesseract_geometry::Geometry > &key)
Retrieve the cache entry by key.
Definition: bullet_collision_shape_cache.cpp:54
tesseract_collision::tesseract_collision_bullet::BulletCollisionShapeCache::cache_
static std::map< boost::uuids::uuid, std::weak_ptr< BulletCollisionShape > > cache_
The static cache.
Definition: bullet_collision_shape_cache.h:77


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