22 #ifndef vtkGenericDataArrayLookupHelper_h 23 #define vtkGenericDataArrayLookupHelper_h 29 #include <unordered_map> 34 template <
typename T,
bool>
46 static bool isnan(T) {
return false; }
57 template <
class ArrayTypeT>
70 if (this->AssociatedArray != array)
73 this->AssociatedArray = array;
80 auto indices = FindIndexVec(elem);
81 if (indices ==
nullptr)
85 return indices->front();
92 auto indices = FindIndexVec(elem);
95 ids->
Allocate(static_cast<vtkIdType>(indices->size()));
96 for (
auto index : *indices)
109 this->ValueMap.clear();
110 this->NanIndices.clear();
120 if (!this->AssociatedArray || (this->AssociatedArray->GetNumberOfTuples() < 1) ||
121 (!this->ValueMap.empty() || !this->NanIndices.empty()))
126 vtkIdType num = this->AssociatedArray->GetNumberOfValues();
127 this->ValueMap.reserve(num);
130 auto value = this->AssociatedArray->GetValue(i);
133 NanIndices.push_back(i);
135 this->ValueMap[
value].push_back(i);
143 std::vector<vtkIdType>* indices{
nullptr };
146 indices = &this->NanIndices;
148 const auto& pos = this->ValueMap.find(
value);
149 if (pos != this->ValueMap.end())
151 indices = &pos->second;
156 ArrayTypeT* AssociatedArray{
nullptr };
157 std::unordered_map<ValueType, std::vector<vtkIdType> > ValueMap;
158 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.