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);
94 ids->
Allocate(static_cast<vtkIdType>(indices->size()));
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;
void SetArray(ArrayTypeT *array)
void LookupValue(ValueType elem, vtkIdList *ids)
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.
internal class used by vtkGenericDataArray to support LookupValue.
void Reset()
Reset to an empty state but retain previously allocated memory.
vtkGenericDataArrayLookupHelper()=default
vtkIdType LookupValue(ValueType elem)
void ClearLookup()
Release any allocated memory for internal data-structures.
list of point or cell ids
ArrayType::ValueType ValueType
~vtkGenericDataArrayLookupHelper()
vtkIdType InsertNextId(const vtkIdType vtkid)
Add the id specified to the end of the list.