10#ifndef vtkGenericDataArrayLookupHelper_h
11#define vtkGenericDataArrayLookupHelper_h
17#include <unordered_map>
22VTK_ABI_NAMESPACE_BEGIN
23template <
typename T,
bool>
29 static bool isnan(T x) {
return std::isnan(x); }
35 static bool isnan(T) {
return false; }
47VTK_ABI_NAMESPACE_BEGIN
48template <
class ArrayTypeT>
61 if (this->AssociatedArray != array)
64 this->AssociatedArray = array;
71 auto indices = FindIndexVec(elem);
72 if (indices ==
nullptr)
76 return indices->front();
83 auto indices = FindIndexVec(elem);
87 for (
auto index : *indices)
100 this->ValueMap.clear();
101 this->NanIndices.clear();
111 if (!this->AssociatedArray || (this->AssociatedArray->GetNumberOfTuples() < 1) ||
112 (!this->ValueMap.empty() || !this->NanIndices.empty()))
117 vtkIdType num = this->AssociatedArray->GetNumberOfValues();
118 this->ValueMap.reserve(num);
121 auto value = this->AssociatedArray->GetValue(i);
124 NanIndices.push_back(i);
126 this->ValueMap[
value].push_back(i);
132 std::vector<vtkIdType>* FindIndexVec(
ValueType value)
134 std::vector<vtkIdType>* indices{
nullptr };
137 indices = &this->NanIndices;
139 const auto& pos = this->ValueMap.find(value);
140 if (pos != this->ValueMap.end())
142 indices = &pos->second;
147 ArrayTypeT* AssociatedArray{
nullptr };
148 std::unordered_map<ValueType, std::vector<vtkIdType>> ValueMap;
149 std::vector<vtkIdType> NanIndices;
internal class used by vtkGenericDataArray to support LookupValue.
~vtkGenericDataArrayLookupHelper()
void LookupValue(ValueType elem, vtkIdList *ids)
vtkGenericDataArrayLookupHelper()=default
void ClearLookup()
Release any allocated memory for internal data-structures.
void SetArray(ArrayTypeT *array)
vtkIdType LookupValue(ValueType elem)
ArrayType::ValueType ValueType
list of point or cell ids
int Allocate(vtkIdType sz, int strategy=0)
Allocate a capacity for sz ids in the list and set the number of stored ids in the list to 0.
vtkIdType InsertNextId(vtkIdType vtkid)
Add the id specified to the end of the list.
void Reset()
Reset to an empty state but retain previously allocated memory.