22 #ifndef vtkGenericDataArrayLookupHelper_h 23 #define vtkGenericDataArrayLookupHelper_h 35 template <
typename T,
bool>
struct has_NaN;
63 template <
class ArrayTypeT>
72 : AssociatedArray(nullptr), SortedArray(nullptr),
73 FirstValue(nullptr), SortedArraySize(0)
83 if (this->AssociatedArray != array)
86 this->AssociatedArray = array;
94 if (this->SortedArraySize == 0)
101 if(this->SortedArray && ::
detail::isnan(this->SortedArray->Value))
103 return this->SortedArray->Index;
113 ValueWithIndex* pos =
114 std::lower_bound(this->FirstValue,
115 this->SortedArray + this->SortedArraySize, temp);
116 if (pos == (this->SortedArray + this->SortedArraySize))
120 if (pos->Value != elem)
130 this->UpdateLookup();
132 if (this->SortedArraySize == 0)
139 ValueWithIndex *
range = this->SortedArray;
140 while (range != this->FirstValue)
150 std::pair<ValueWithIndex*, ValueWithIndex*>
range =
151 std::equal_range(this->FirstValue,
152 this->SortedArray + this->SortedArraySize, temp);
153 while (range.first != range.second)
168 free(this->SortedArray);
169 this->SortedArray =
nullptr;
170 this->SortedArraySize = 0;
178 struct ValueWithIndex
182 inline bool operator<(
const ValueWithIndex& other)
const 184 return this->Value < other.Value;
188 static bool isnan(
const ValueWithIndex &tmp)
195 if (!this->AssociatedArray || this->SortedArray)
200 int numComps = this->AssociatedArray->GetNumberOfComponents();
201 this->SortedArraySize =
202 this->AssociatedArray->GetNumberOfTuples() * numComps;
204 if (this->SortedArraySize == 0)
209 this->SortedArray =
reinterpret_cast<ValueWithIndex*
>(
210 malloc(this->SortedArraySize *
sizeof(ValueWithIndex)));
211 for (
vtkIdType cc = 0,
max = this->AssociatedArray->GetNumberOfValues();
214 ValueWithIndex& item = this->SortedArray[cc];
215 item.Value = this->AssociatedArray->GetValue(cc);
218 this->FirstValue = std::partition(this->SortedArray, this->SortedArray + this->SortedArraySize,
isnan);
219 std::sort(this->FirstValue, this->SortedArray + this->SortedArraySize);
222 ArrayTypeT *AssociatedArray;
223 ValueWithIndex* SortedArray;
224 ValueWithIndex* FirstValue;
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.
VTKCOMMONCORE_EXPORT bool operator<(const vtkUnicodeString &lhs, const vtkUnicodeString &rhs)
vtkIdType LookupValue(ValueType elem)
void ClearLookup()
Release any allocated memory for internal data-structures.
vtkGenericDataArrayLookupHelper()
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.