SMTK  @SMTK_VERSION@
Simulation Modeling Tool Kit
Classes | Public Types | Public Member Functions | Static Public Attributes | Protected Attributes | List of all members
smtk::geometry::Cache< BaseClass > Class Template Reference

A geometry provider that uses a cache to answer queries. More...

#include <Cache.h>

Inheritance diagram for smtk::geometry::Cache< BaseClass >:
[legend]
Collaboration diagram for smtk::geometry::Cache< BaseClass >:
[legend]

Classes

struct  CacheEntry
 The values held by the geometry cache. More...
 

Public Types

using GenerationNumber = Geometry::GenerationNumber
 
using DataType = typename BaseClass::DataType
 
using BoundingBox = Geometry::BoundingBox
 
using Visitor = Geometry::Visitor
 

Public Member Functions

 smtkTypeMacro (Cache)
 
 smtkSharedFromThisMacro (Geometry)
 
 smtkSuperclassMacro (BaseClass)
 
virtual void queryGeometry (const smtk::resource::PersistentObject::Ptr &, CacheEntry &cache) const
 Create a geometric representation of an object on demand. More...
 
GenerationNumber generationNumber (const smtk::resource::PersistentObject::Ptr &obj) const override
 Return the generation number of geometry held by the cache for the given object. More...
 
void bounds (const smtk::resource::PersistentObject::Ptr &obj, BoundingBox &bds) const override
 Return the geometric bounds.
 
DataType & data (const smtk::resource::PersistentObject::Ptr &obj) const override
 Provide access to the actual cached geometry reference.
 
void visit (Visitor visitor) const override
 Visit each persistent object that has renderable geometry. More...
 
void markModified (const smtk::resource::PersistentObject::Ptr &obj) override
 Remove a cache entry's geometry (but keep its generation number intact). More...
 
bool erase (const smtk::common::UUID &uid) override
 Remove a cache entry completely. More...
 

Static Public Attributes

static constexpr GenerationNumber Invalid = Geometry::Invalid
 
static constexpr GenerationNumber Initial = Geometry::Initial
 

Protected Attributes

std::map< smtk::common::UUID, CacheEntrym_cache
 

Detailed Description

template<typename BaseClass>
class smtk::geometry::Cache< BaseClass >

A geometry provider that uses a cache to answer queries.

This takes two template parameters:

Member Function Documentation

◆ erase()

template<typename BaseClass >
bool smtk::geometry::Cache< BaseClass >::erase ( const smtk::common::UUID uid)
inlineoverride

Remove a cache entry completely.

This method should be called by resources/operations when an object is about to be or has been deleted. In this case, not only is the geometry freed, but the cache entry is also removed so that visitation will no longer query the resource for geometry with the given UUID.

◆ generationNumber()

template<typename BaseClass >
GenerationNumber smtk::geometry::Cache< BaseClass >::generationNumber ( const smtk::resource::PersistentObject::Ptr &  obj) const
inlineoverride

Return the generation number of geometry held by the cache for the given object.

If no cache entry existed previously, this will construct one.

◆ markModified()

template<typename BaseClass >
void smtk::geometry::Cache< BaseClass >::markModified ( const smtk::resource::PersistentObject::Ptr &  obj)
inlineoverride

Remove a cache entry's geometry (but keep its generation number intact).

This method should be called by resources when an object has had its geometry modified; it results in the cached geometry being freed so that the next request for bounds or geometry will require recomputation.

◆ queryGeometry()

template<typename BaseClass >
virtual void smtk::geometry::Cache< BaseClass >::queryGeometry ( const smtk::resource::PersistentObject::Ptr &  ,
CacheEntry cache 
) const
inlinevirtual

Create a geometric representation of an object on demand.

Subclasses should override this unless the resource keeps the cache up to date via some other method not provided by this class. In that case, the provided implementation should never be invoked; if it is, it will result in cache entries being deleted.

This method should always edit the cache entry, either by marking it invalid (assigning Invalid to m_generation) or updating the geometry in m_geometry. This method should never modify the cache itself.

Anything that calls this method is responsible for checking whether existing cache entries are up to date before calling this method. Only call this when the cache must be updated.

If the cache entry is valid upon entry, this method should either update the geometry and increment the generation number or mark the cache entry as invalid.

Returning the the entry in an invalid state indicates that the object has no geometric representation and any existing cache entry will be removed.

Reimplemented in smtk::session::polygon::vtk::Geometry, smtk::session::mesh::vtk::Geometry, smtk::session::vtk::Geometry, and smtk::extension::vtk::mesh::Geometry.

◆ visit()

template<typename BaseClass >
void smtk::geometry::Cache< BaseClass >::visit ( Visitor  visitor) const
inlineoverride

Visit each persistent object that has renderable geometry.

This implementation calls ThisClass::update() to ensure the cache contains up-to-date geometry for every renderable object. If the cache is always up-to-date, the ThisClass::update() is a no-op. Otherwise, it is the subclass's duty to visit the resource's persistent objects and query each for an updated cache entry as needed.

Visitors may erase the cache entry for the object they are passed, but may not erase others as that may invalidate iteration.


The documentation for this class was generated from the following file: