10 #ifndef vtkGenericDataArrayLookupHelper_h
11 #define vtkGenericDataArrayLookupHelper_h
17 #include <unordered_map>
22 VTK_ABI_NAMESPACE_BEGIN
23 template <
typename T,
bool>
35 static bool isnan(T) {
return false; }
47 VTK_ABI_NAMESPACE_BEGIN
48 template <
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);
86 ids->
Allocate(static_cast<vtkIdType>(indices->size()));
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;
152 VTK_ABI_NAMESPACE_END
void SetArray(ArrayTypeT *array)
void LookupValue(ValueType elem, vtkIdList *ids)
internal class used by vtkGenericDataArray to support LookupValue.
void Reset()
Reset to an empty state but retain previously allocated memory.
vtkGenericDataArrayLookupHelper()=default
vtkIdType InsertNextId(vtkIdType vtkid)
Add the id specified to the end of the list.
vtkIdType LookupValue(ValueType elem)
void ClearLookup()
Release any allocated memory for internal data-structures.
list of point or cell ids
ArrayType::ValueType ValueType
~vtkGenericDataArrayLookupHelper()
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...