54#ifndef vtkCellGridResponders_h
55#define vtkCellGridResponders_h
58#include "vtkCommonDataModelModule.h"
64#include <unordered_map>
65#include <unordered_set>
67VTK_ABI_NAMESPACE_BEGIN
79 using TagSet = std::unordered_map<vtkStringToken, std::unordered_set<vtkStringToken>>;
97 template <
typename CellType,
typename QueryType,
typename ResponderType>
102 this->Responders[queryTypeKey][cellTypeKey] = responder;
120 template <
typename CellType,
typename CalculatorType>
125 vtkErrorMacro(
"Could not register null cell-attribute calculator.");
129 vtkStringToken calculatorBaseKey = vtk::TypeName<CalculatorType>();
131 if (!
dynamic_cast<CalculatorType*
>(calculator))
133 vtkErrorMacro(
"Could not register cell-attribute calculator "
134 << calculator->
GetClassName() <<
" as it does not inherit " << calculatorBaseKey.
Data()
139 this->Calculators[calculatorBaseKey][cellTypeKey][tags] = calculator;
143 template <
typename CellType,
typename CalculatorType>
149 vtkErrorMacro(
"Could not register null cell-attribute calculator.");
153 vtkStringToken calculatorBaseKey = vtk::TypeName<CalculatorType>();
155 if (!
dynamic_cast<CalculatorType*
>(calculator))
157 vtkErrorMacro(
"Could not register cell-attribute calculator "
158 << calculator->
GetClassName() <<
" as it does not inherit " << calculatorBaseKey.
Data()
163 TagSet tagsIncludingType = tags;
164 tagsIncludingType[
"Type"_token] = { cellTypeKey };
165 this->CalculatorRegistry[calculatorBaseKey].push_back(
174 template <
typename CalculatorType>
178 auto calculatorKey = vtk::TypeName<CalculatorType>();
179 auto baseResult = this->AttributeCalculator(calculatorKey, cellType, cellAttribute);
180 auto result = CalculatorType::SafeDownCast(baseResult);
184 template <
typename CalculatorType>
188 auto calculatorKey = vtk::TypeName<CalculatorType>();
189 auto baseResult = this->AttributeCalculator(calculatorKey, cellType, attrib, tags);
190 auto result = CalculatorType::SafeDownCast(baseResult);
203 template <
typename CacheType>
207 auto rawCache = this->GetCacheData(key);
213 this->Caches[key] = castCache;
217 castCache =
dynamic_cast<CacheType*
>(rawCache.GetPointer());
240 std::unordered_map<vtkStringToken, vtkSmartPointer<vtkCellGridResponderBase>>>
243 std::unordered_map<std::size_t, vtkSmartPointer<vtkObject>>
Caches;
259 std::unordered_map<vtkStringToken, vtkSmartPointer<vtkCellAttributeCalculator>>>>
Perform a per-cell calculation on a vtkCellAttribute.
A function defined over the physical domain of a vtkCellGrid.
Perform an operation on cells in a vtkCellMetadata instance.
Respond to a query on one particular type of cell.
A container that holds objects able to respond to queries specialized for particular vtkCellMetadata ...
std::unordered_map< vtkStringToken, std::unordered_map< vtkStringToken, vtkSmartPointer< vtkCellGridResponderBase > > > Responders
bool Query(vtkCellMetadata *cellType, vtkCellGridQuery *query)
Invoke a responder for the given query and cell type.
std::unordered_map< vtkStringToken, std::vector< CalculatorForTagSet > > CalculatorRegistry
A map from a calculator base class to a set of registered prototypes.
std::unordered_map< std::size_t, vtkSmartPointer< vtkObject > > Caches
vtkSmartPointer< vtkCellAttributeCalculator > AttributeCalculator(vtkStringToken calculatorType, vtkCellMetadata *cellType, vtkCellAttribute *attrib, const TagSet &tags) const
Fetch an instance of an attribute calculator for the given tags.
bool RegisterCalculator(vtkCellAttributeCalculator *calculator, const TagSet &tags)
void RegisterQueryResponder(ResponderType *responder)
Register responder for processing a cell's data.
vtkSmartPointer< CacheType > GetCacheDataAs(std::size_t key, bool createIfAbsent=false)
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
std::unordered_map< vtkStringToken, std::unordered_map< vtkStringToken, std::unordered_map< vtkStringToken, vtkSmartPointer< vtkCellAttributeCalculator > > > > Calculators
Nested maps from cell-attribute-query-type to cell-type to cell-attribute-tag-sets to concrete query ...
std::unordered_map< vtkStringToken, std::unordered_set< vtkStringToken > > TagSet
A map of tag names (such as the cell's type-name) to values of the tag accepted or provided for that ...
vtkCellGridResponders()=default
vtkSmartPointer< vtkObject > GetCacheData(std::size_t key)
Return a cache object given a key.
vtkSmartPointer< CalculatorType > AttributeCalculator(vtkCellMetadata *cellType, vtkCellAttribute *cellAttribute) const
~vtkCellGridResponders() override=default
bool RegisterCalculator(vtkStringToken tags, vtkCellAttributeCalculator *calculator)
Register a vtkCellAttributeCalculator subclass.
static vtkCellGridResponders * New()
vtkSmartPointer< CalculatorType > AttributeCalculator(vtkCellMetadata *cellType, vtkCellAttribute *attrib, const TagSet &tags) const
bool SetCacheData(std::size_t key, vtkSmartPointer< vtkObject > value, bool overwrite=false)
Add a cache entry mapping key to value.
a simple class to control print indentation
const char * GetClassName() const
Return the class name as a string.
abstract base class for most VTK objects
Hold a reference to a vtkObjectBase instance.
static vtkSmartPointer< T > New()
Create an instance of a VTK object.
Represent a string by its integer hash.
const std::string & Data() const
Return the string corresponding to the token.