54 #ifndef vtkCellGridResponders_h
55 #define vtkCellGridResponders_h
58 #include "vtkCommonDataModelModule.h"
64 #include <unordered_map>
65 #include <unordered_set>
67 VTK_ABI_NAMESPACE_BEGIN
79 using TagSet = std::unordered_map<vtkStringToken, std::unordered_set<vtkStringToken>>;
88 bool Matches(
const TagSet& providedTags)
const;
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;
257 std::unordered_map<vtkStringToken,
258 std::unordered_map<vtkStringToken,
259 std::unordered_map<vtkStringToken, vtkSmartPointer<vtkCellAttributeCalculator>>>>
267 VTK_ABI_NAMESPACE_END
bool RegisterCalculator(vtkStringToken tags, vtkCellAttributeCalculator *calculator)
Register a vtkCellAttributeCalculator subclass.
Respond to a query on one particular type of cell.
Perform an operation on cells in a vtkCellMetadata instance.
Perform a per-cell calculation on a vtkCellAttribute.
abstract base class for most VTK objects
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
vtkSmartPointer< CacheType > GetCacheDataAs(std::size_t key, bool createIfAbsent=false)
void RegisterQueryResponder(ResponderType *responder)
Register responder for processing a cell's data.
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 ...
A container that holds objects able to respond to queries specialized for particular vtkCellMetadata ...
static vtkSmartPointer< T > New()
Create an instance of a VTK object.
std::unordered_map< std::size_t, vtkSmartPointer< vtkObject > > Caches
std::unordered_map< vtkStringToken, std::unordered_map< vtkStringToken, vtkSmartPointer< vtkCellGridResponderBase > > > Responders
a simple class to control print indentation
const char * GetClassName() const
Return the class name as a string.
A function defined over the physical domain of a vtkCellGrid.
bool RegisterCalculator(vtkCellAttributeCalculator *calculator, const TagSet &tags)
vtkSmartPointer< CalculatorType > AttributeCalculator(vtkCellMetadata *cellType, vtkCellAttribute *cellAttribute) const
Represent a string by its integer hash.
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::vector< CalculatorForTagSet > > CalculatorRegistry
A map from a calculator base class to a set of registered prototypes.
static vtkObject * New()
Create an object with Debug turned off, modified time initialized to zero, and reference counting on...
const std::string & Data() const
Return the string corresponding to the token.
vtkSmartPointer< CalculatorType > AttributeCalculator(vtkCellMetadata *cellType, vtkCellAttribute *attrib, const TagSet &tags) const