Tesseract
Motion Planning Environment
Loading...
Searching...
No Matches
environment_cache.h
Go to the documentation of this file.
1
26#ifndef TESSERACT_ENVIRONMENT_ENVIRONMENT_CACHE_H
27#define TESSERACT_ENVIRONMENT_ENVIRONMENT_CACHE_H
28
31#include <memory>
32#include <thread>
33#include <mutex>
34#include <shared_mutex>
36
39{
41{
42public:
43 using Ptr = std::shared_ptr<EnvironmentCache>;
44 using ConstPtr = std::shared_ptr<const EnvironmentCache>;
45 using UPtr = std::unique_ptr<EnvironmentCache>;
46 using ConstUPtr = std::unique_ptr<const EnvironmentCache>;
47
48 EnvironmentCache() = default;
49 virtual ~EnvironmentCache() = default;
54
59 virtual void setCacheSize(long size) = 0;
60
65 virtual long getCacheSize() const = 0;
66
68 virtual void refreshCache() const = 0;
69
75};
76
78{
79public:
80 using Ptr = std::shared_ptr<DefaultEnvironmentCache>;
81 using ConstPtr = std::shared_ptr<const DefaultEnvironmentCache>;
82
83 DefaultEnvironmentCache(Environment::ConstPtr env, std::size_t cache_size = 5);
84
89 void setCacheSize(long size) override final;
90
95 long getCacheSize() const override final;
96
98 void refreshCache() const override final;
99
104 Environment::UPtr getCachedEnvironment() const override final;
105
106protected:
109
111 std::size_t cache_size_{ 5 };
112
114 mutable int cache_env_revision_{ 0 };
115
117 mutable std::deque<Environment::UPtr> cache_;
118
120 mutable std::shared_mutex cache_mutex_;
121
123 void refreshCacheHelper() const;
124};
125} // namespace tesseract_environment
126
127#endif // TESSERACT_ENVIRONMENT_ENVIRONMENT_CACHE_H
Definition: environment_cache.h:78
void refreshCache() const override final
If the environment has changed it will rebuild the cache of tesseract objects.
Definition: environment_cache.cpp:45
Environment::UPtr getCachedEnvironment() const override final
This will pop an Environment object from the queue.
Definition: environment_cache.cpp:51
std::shared_mutex cache_mutex_
The mutex used when reading and writing to cache_.
Definition: environment_cache.h:120
long getCacheSize() const override final
Get the cache size used to hold tesseract objects for motion planning.
Definition: environment_cache.cpp:43
std::shared_ptr< const DefaultEnvironmentCache > ConstPtr
Definition: environment_cache.h:81
std::size_t cache_size_
The assigned cache size.
Definition: environment_cache.h:111
std::shared_ptr< DefaultEnvironmentCache > Ptr
Definition: environment_cache.h:80
int cache_env_revision_
The environment revision number at the time the cache was populated.
Definition: environment_cache.h:114
void setCacheSize(long size) override final
Set the cache size used to hold tesseract objects for motion planning.
Definition: environment_cache.cpp:37
std::deque< Environment::UPtr > cache_
A vector of cached Tesseract objects.
Definition: environment_cache.h:117
void refreshCacheHelper() const
This does not take a lock.
Definition: environment_cache.cpp:67
Environment::ConstPtr env_
The tesseract_object used to create the cache.
Definition: environment_cache.h:108
Definition: environment_cache.h:41
virtual void refreshCache() const =0
If the environment has changed it will rebuild the cache of tesseract objects.
EnvironmentCache(EnvironmentCache &&)=delete
EnvironmentCache & operator=(EnvironmentCache &&)=delete
std::shared_ptr< const EnvironmentCache > ConstPtr
Definition: environment_cache.h:44
std::unique_ptr< const EnvironmentCache > ConstUPtr
Definition: environment_cache.h:46
EnvironmentCache(const EnvironmentCache &)=delete
std::unique_ptr< EnvironmentCache > UPtr
Definition: environment_cache.h:45
std::shared_ptr< EnvironmentCache > Ptr
Definition: environment_cache.h:43
virtual long getCacheSize() const =0
Get the cache size used to hold tesseract objects for motion planning.
virtual void setCacheSize(long size)=0
Set the cache size used to hold tesseract objects for motion planning.
virtual Environment::UPtr getCachedEnvironment() const =0
This will pop an Environment object from the queue.
EnvironmentCache & operator=(const EnvironmentCache &)=delete
Definition: environment.h:65
std::unique_ptr< Environment > UPtr
Definition: environment.h:73
std::shared_ptr< const Environment > ConstPtr
Definition: environment.h:72
Common Tesseract Macros.
#define TESSERACT_COMMON_IGNORE_WARNINGS_PUSH
Definition: macros.h:71
Definition: create_convex_hull.cpp:36
Definition: command.h:39
auto env
Definition: tesseract_environment_cache_unit.cpp:67