22 #ifndef vtkGenericDataArrayLookupHelper_h
23 #define vtkGenericDataArrayLookupHelper_h
28 #include <unordered_map>
33 template <
typename T,
bool>
45 static bool isnan(T) {
return false; }
56 template <
class ArrayTypeT>
69 if (this->AssociatedArray != array)
72 this->AssociatedArray = array;
79 auto indices = FindIndexVec(elem);
80 if (indices ==
nullptr)
84 return indices->front();
91 auto indices = FindIndexVec(elem);
95 for (
auto index : *indices)
108 this->ValueMap.clear();
109 this->NanIndices.clear();
119 if (!this->AssociatedArray || (this->AssociatedArray->GetNumberOfTuples() < 1) ||
120 (!this->ValueMap.empty() || !this->NanIndices.empty()))
125 vtkIdType num = this->AssociatedArray->GetNumberOfValues();
126 this->ValueMap.reserve(num);
129 auto value = this->AssociatedArray->GetValue(i);
132 NanIndices.push_back(i);
134 this->ValueMap[
value].push_back(i);
142 std::vector<vtkIdType>* indices{
nullptr };
145 indices = &this->NanIndices;
147 const auto& pos = this->ValueMap.find(
value);
148 if (pos != this->ValueMap.end())
150 indices = &pos->second;
155 ArrayTypeT* AssociatedArray{
nullptr };
156 std::unordered_map<ValueType, std::vector<vtkIdType> > ValueMap;
157 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
vtkIdType InsertNextId(const vtkIdType vtkid)
Add the id specified to the end of the list.
int Allocate(const vtkIdType sz, const int strategy=0)
Allocate a capacity for sz ids in the list and set the number of stored ids in the list to 0.
void Reset()
Reset to an empty state but retain previously allocated memory.