SMTK
@SMTK_VERSION@
Simulation Modeling Tool Kit
|
10 #ifndef smtk_geometry_Cache_h
11 #define smtk_geometry_Cache_h
13 #include "smtk/geometry/GeometryForBackend.h"
14 #include "smtk/geometry/Resource.h"
16 #include "smtk/resource/CopyOptions.h"
39 template<
typename BaseClass>
45 smtkSuperclassMacro(BaseClass);
49 using DataType =
typename BaseClass::DataType;
73 CacheEntry& operator=(
const CacheEntry&) =
default;
102 virtual void queryGeometry(
const smtk::resource::PersistentObject::Ptr&, CacheEntry& cache)
const
104 cache.m_generation = Invalid;
110 GenerationNumber
generationNumber(
const smtk::resource::PersistentObject::Ptr& obj)
const override
114 auto it = m_cache.find(obj->id());
115 bool found = it != m_cache.end();
116 if (found && it->second.m_geometry)
118 return it->second.m_generation;
123 if (!it->second.isValid())
129 return it->second.m_generation;
138 m_cache[obj->id()] = entry;
139 return entry.m_generation;
151 auto it = m_cache.find(obj->id());
152 bool found = it != m_cache.end();
153 if (found && it->second.m_geometry)
155 this->geometricBounds(it->second.m_geometry, bds);
161 if (it->second.isValid())
163 this->geometricBounds(it->second.m_geometry, bds);
177 m_cache[obj->id()] = entry;
178 this->geometricBounds(entry.m_geometry, bds);
184 bds[0] = bds[2] = bds[4] = 0.0;
185 bds[1] = bds[3] = bds[5] = -1.0;
189 DataType&
data(
const smtk::resource::PersistentObject::Ptr& obj)
const override
193 auto it = m_cache.find(obj->id());
194 bool found = it != m_cache.end();
195 if (found && it->second.m_geometry)
197 return it->second.m_geometry;
202 if (it->second.isValid())
204 return it->second.m_geometry;
217 m_cache[obj->id()] = entry;
218 return m_cache[obj->id()].m_geometry;
222 static DataType invalid;
241 auto rsrc = this->resource();
244 auto it = m_cache.begin();
245 for (
auto entry = it; entry != m_cache.end(); entry = it)
248 auto comp = rsrc->find(entry->first);
251 visitor(comp, entry->second.m_generation);
253 else if (entry->first == rsrc->id())
255 visitor(rsrc, entry->second.m_generation);
269 if (!options.copyGeometry())
275 const auto* sourceCache =
dynamic_cast<Cache*
>(source.get());
281 for (
const auto& entry : sourceCache->m_cache)
291 m_cache[targetObj->id()] = entry.second;
295 m_cache[entry.first] = entry.second;
306 void markModified(
const smtk::resource::PersistentObject::Ptr& obj)
override
310 ++this->BaseClass::m_lastModified;
311 auto it = m_cache.find(obj->id());
312 if (it != m_cache.end())
315 it->second.m_geometry = blank;
320 m_cache[obj->id()] = invalid;
335 mutable std::map<smtk::common::UUID, CacheEntry> m_cache;
341 #endif // smtk_geometry_Cache_h
The main namespace for the Simulation Modeling Tool Kit (SMTK).
Definition: doc.h:33
GenerationNumber m_generation
A generation number or Invalid.
Definition: Cache.h:58
void bounds(const smtk::resource::PersistentObject::Ptr &obj, BoundingBox &bds) const override
Return the geometric bounds.
Definition: Cache.h:147
std::unique_ptr< smtk::geometry::Geometry > UniquePtr
The return type of the geometry-provider generator class.
Definition: Geometry.h:97
static constexpr GenerationNumber Invalid
A special generation number that marks an object as having no geometric representation.
Definition: Geometry.h:75
GenerationNumber generationNumber(const smtk::resource::PersistentObject::Ptr &obj) const override
Return the generation number of geometry held by the cache for the given object.
Definition: Cache.h:110
void markModified(const smtk::resource::PersistentObject::Ptr &obj) override
Remove a cache entry's geometry (but keep its generation number intact).
Definition: Cache.h:306
std::function< bool(const resource::PersistentObject::Ptr &, GenerationNumber)> Visitor
The signature of functions used to visit all objects with tessellation data.
Definition: Geometry.h:85
bool erase(const smtk::common::UUID &uid) override
Remove a cache entry completely.
Definition: Cache.h:332
bool copyGeometry(const UniquePtr &source, smtk::resource::CopyOptions &options) override
Copy data from another backend as directed by options.
Definition: Cache.h:266
static constexpr GenerationNumber Initial
The lowest valid generation number (which may be used as the initial value).
Definition: Geometry.h:78
ObjectType * targetObjectFromSourceId(const smtk::common::UUID &sourceId) const
A convenience to fetch an entry from objectMapping(), casting it to the given type.
Definition: CopyOptions.h:144
std::array< double, 6 > BoundingBox
A bounding box is represented as an array of 6 numbers, ordered xmin, xmax, ymin, ymax,...
Definition: Geometry.h:82
DataType m_geometry
Geometry held by the cache.
Definition: Cache.h:59
Definition: CopyOptions.h:31
A geometry provider that uses a cache to answer queries.
Definition: Cache.h:40
A base class for objects which can provide renderable geometry.
Definition: Geometry.h:64
bool shouldOmitId(const smtk::common::UUID &sourceId) const
Return whether a sourceId should be omitted from the copy.
Definition: CopyOptions.cxx:93
virtual void queryGeometry(const smtk::resource::PersistentObject::Ptr &, CacheEntry &cache) const
Create a geometric representation of an object on demand.
Definition: Cache.h:102
The values held by the geometry cache.
Definition: Cache.h:56
size_t GenerationNumber
An integral type to hold monotonically increasing generation numbers (a.k.a.
Definition: Geometry.h:72
An abstract base class for SMTK resources and their components.
Definition: PersistentObject.h:39
DataType & data(const smtk::resource::PersistentObject::Ptr &obj) const override
Provide access to the actual cached geometry reference.
Definition: Cache.h:189
void visit(Visitor visitor) const override
Visit each persistent object that has renderable geometry.
Definition: Cache.h:238