VTK
vtkGenericDataArray.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkGenericDataArray.h
5 
6  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7  All rights reserved.
8  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10  This software is distributed WITHOUT ANY WARRANTY; without even
11  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12  PURPOSE. See the above copyright notice for more information.
13 
14 =========================================================================*/
69 #ifndef vtkGenericDataArray_h
70 #define vtkGenericDataArray_h
71 
72 #include "vtkDataArray.h"
73 #include "vtkSmartPointer.h"
74 #include "vtkTypeTraits.h"
76 
77 #include <cassert>
78 
79 template<class DerivedT, class ValueTypeT>
81 {
83 public:
84  typedef ValueTypeT ValueType;
86 
87 
90  enum { VTK_DATA_TYPE = vtkTypeTraits<ValueType>::VTK_TYPE_ID };
91 
96 
104  inline ValueType GetValue(vtkIdType valueIdx) const
105  {
106  return static_cast<const DerivedT*>(this)->GetValue(valueIdx);
107  }
108 
116  void SetValue(vtkIdType valueIdx, ValueType value)
117  VTK_EXPECTS(0 <= valueIdx && valueIdx < GetNumberOfValues())
118  {
119  static_cast<DerivedT*>(this)->SetValue(valueIdx, value);
120  }
121 
130  void GetTypedTuple(vtkIdType tupleIdx, ValueType* tuple) const
131  VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples())
132  {
133  static_cast<const DerivedT*>(this)->GetTypedTuple(tupleIdx, tuple);
134  }
135 
144  void SetTypedTuple(vtkIdType tupleIdx, const ValueType* tuple)
145  VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples())
146  {
147  static_cast<DerivedT*>(this)->SetTypedTuple(tupleIdx, tuple);
148  }
149 
155  ValueType GetTypedComponent(vtkIdType tupleIdx, int compIdx) const
156  VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples())
157  VTK_EXPECTS(0 <= compIdx && compIdx < GetNumberOfComponents())
158  {
159  return static_cast<const DerivedT*>(this)->GetTypedComponent(tupleIdx,
160  compIdx);
161  }
162 
168  void SetTypedComponent(vtkIdType tupleIdx, int compIdx, ValueType value)
169  VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples())
170  VTK_EXPECTS(0 <= compIdx && compIdx < GetNumberOfComponents())
171  {
172  static_cast<DerivedT*>(this)->SetTypedComponent(tupleIdx, compIdx, value);
173  }
174 
176 
180  void *GetVoidPointer(vtkIdType valueIdx) override;
181  ValueType* GetPointer(vtkIdType valueIdx);
182  void SetVoidArray(void*, vtkIdType, int) override;
183  void SetVoidArray(void*, vtkIdType, int, int) override;
184  void SetArrayFreeFunction(void (*callback)(void *)) override;
185  void* WriteVoidPointer(vtkIdType valueIdx, vtkIdType numValues) override;
186  ValueType* WritePointer(vtkIdType valueIdx, vtkIdType numValues);
188 
195  void RemoveTuple(vtkIdType tupleIdx) override;
196 
200  vtkIdType InsertNextValue(ValueType value);
201 
205  void InsertValue(vtkIdType valueIdx, ValueType value);
206 
210  void InsertTypedTuple(vtkIdType tupleIdx, const ValueType *t);
211 
215  vtkIdType InsertNextTypedTuple(const ValueType *t);
216 
221  void InsertTypedComponent(vtkIdType tupleIdx, int compIdx, ValueType val);
222 
224 
228  void GetValueRange(ValueType range[2], int comp);
229  ValueType *GetValueRange(int comp) VTK_SIZEHINT(2);
231 
236  ValueType *GetValueRange() VTK_SIZEHINT(2) { return this->GetValueRange(0); }
237  void GetValueRange(ValueType range[2]) { this->GetValueRange(range, 0); }
238 
243  vtkIdType Capacity() { return this->Size; }
244 
248  virtual void FillTypedComponent(int compIdx, ValueType value);
249 
253  virtual void FillValue(ValueType value);
254 
255  int GetDataType() override;
256  int GetDataTypeSize() override;
257  bool HasStandardMemoryLayout() override;
258  vtkTypeBool Allocate(vtkIdType size, vtkIdType ext = 1000) override;
259  vtkTypeBool Resize(vtkIdType numTuples) override;
260  void SetNumberOfComponents(int num) override;
261  void SetNumberOfTuples(vtkIdType number) override;
262  void Initialize() override;
263  void Squeeze() override;
264  void SetTuple(vtkIdType dstTupleIdx, vtkIdType srcTupleIdx,
265  vtkAbstractArray* source) override;
266  // MSVC doesn't like 'using' here (error C2487). Just forward instead:
267  // using Superclass::SetTuple;
268  void SetTuple(vtkIdType tupleIdx, const float *tuple) override
269  { this->Superclass::SetTuple(tupleIdx, tuple); }
270  void SetTuple(vtkIdType tupleIdx, const double *tuple) override
271  { this->Superclass::SetTuple(tupleIdx, tuple); }
272 
273  void InsertTuples(vtkIdList *dstIds, vtkIdList *srcIds,
274  vtkAbstractArray *source) override;
275  // MSVC doesn't like 'using' here (error C2487). Just forward instead:
276  // using Superclass::InsertTuples;
277  void InsertTuples(vtkIdType dstStart, vtkIdType n, vtkIdType srcStart,
278  vtkAbstractArray* source) override
279  { this->Superclass::InsertTuples(dstStart, n, srcStart, source); }
280 
281  void InsertTuple(vtkIdType dstTupleIdx, vtkIdType srcTupleIdx,
282  vtkAbstractArray *source) override;
283  void InsertTuple(vtkIdType tupleIdx, const float *source) override;
284  void InsertTuple(vtkIdType tupleIdx, const double *source) override;
285  void InsertComponent(vtkIdType tupleIdx, int compIdx,
286  double value) override;
287  vtkIdType InsertNextTuple(vtkIdType srcTupleIdx,
288  vtkAbstractArray *source) override;
289  vtkIdType InsertNextTuple(const float *tuple) override;
290  vtkIdType InsertNextTuple(const double *tuple) override;
291  void GetTuples(vtkIdList *tupleIds,
292  vtkAbstractArray *output) override;
293  void GetTuples(vtkIdType p1, vtkIdType p2,
294  vtkAbstractArray *output) override;
295  double *GetTuple(vtkIdType tupleIdx) override;
296  void GetTuple(vtkIdType tupleIdx, double * tuple) override;
297  void InterpolateTuple(vtkIdType dstTupleIdx, vtkIdList *ptIndices,
298  vtkAbstractArray* source,
299  double* weights) override;
300  void InterpolateTuple(vtkIdType dstTupleIdx,
301  vtkIdType srcTupleIdx1, vtkAbstractArray* source1,
302  vtkIdType srcTupleIdx2, vtkAbstractArray* source2, double t) override;
303  void SetComponent(vtkIdType tupleIdx, int compIdx, double value) override;
304  double GetComponent(vtkIdType tupleIdx, int compIdx) override;
305  void SetVariantValue(vtkIdType valueIdx, vtkVariant value) override;
306  vtkVariant GetVariantValue(vtkIdType valueIdx) override;
307  void InsertVariantValue(vtkIdType valueIdx, vtkVariant value) override;
308  vtkIdType LookupValue(vtkVariant value) override;
309  virtual vtkIdType LookupTypedValue(ValueType value);
310  void LookupValue(vtkVariant value, vtkIdList* valueIds) override;
311  virtual void LookupTypedValue(ValueType value, vtkIdList* valueIds);
312  void ClearLookup() override;
313  void DataChanged() override;
314  void FillComponent(int compIdx, double value) override;
316 
317 protected:
319  ~vtkGenericDataArray() override;
320 
326  inline bool AllocateTuples(vtkIdType numTuples)
327  {
328  return static_cast<DerivedT*>(this)->AllocateTuples(numTuples);
329  }
330 
336  inline bool ReallocateTuples(vtkIdType numTuples)
337  {
338  return static_cast<DerivedT*>(this)->ReallocateTuples(numTuples);
339  }
340 
341  // This method resizes the array if needed so that the given tuple index is
342  // valid/accessible.
343  bool EnsureAccessToTuple(vtkIdType tupleIdx);
344 
345  std::vector<double> LegacyTuple;
346  std::vector<ValueType> LegacyValueRange;
347 
349 
350 private:
351  vtkGenericDataArray(const vtkGenericDataArray&) = delete;
352  void operator=(const vtkGenericDataArray&) = delete;
353 
354 };
355 
356 #include "vtkGenericDataArray.txx"
357 
358 // Adds an implementation of NewInstanceInternal() that returns an AoS
359 // (unmapped) VTK array, if possible. This allows the pipeline to copy and
360 // propagate the array when the array data is not modifiable. Use this in
361 // combination with vtkAbstractTypeMacro or vtkAbstractTemplateTypeMacro
362 // (instead of vtkTypeMacro) to avoid adding the default NewInstance
363 // implementation.
364 #define vtkAOSArrayNewInstanceMacro(thisClass) \
365  protected: \
366  vtkObjectBase *NewInstanceInternal() const override \
367  { \
368  if (vtkDataArray *da = \
369  vtkDataArray::CreateDataArray(thisClass::VTK_DATA_TYPE)) \
370  { \
371  return da; \
372  } \
373  return thisClass::New(); \
374  } \
375  public:
376 
377 #endif
378 // VTK-HeaderTest-Exclude: vtkGenericDataArray.h
void SetValue(vtkIdType valueIdx, ValueType value)
Set the value at valueIdx to value.
bool HasStandardMemoryLayout() override
Returns true if this array uses the standard memory layout defined in the VTK user guide...
void SetTuple(vtkIdType dstTupleIdx, vtkIdType srcTupleIdx, vtkAbstractArray *source) override
Set the tuple at dstTupleIdx in this array to the tuple at srcTupleIdx in the source array...
void FillComponent(int compIdx, double value) override
Fill a component of a data array with a specified value.
vtkIdType InsertNextTypedTuple(const ValueType *t)
Insert (memory allocation performed) the tuple onto the end of the array.
void Squeeze() override
Free any unnecessary memory.
void InsertValue(vtkIdType valueIdx, ValueType value)
Insert data at a specified position in the array.
vtkIdType GetNumberOfTuples()
Get the number of complete tuples (a component group) in the array.
vtkIdType InsertNextTuple(vtkIdType srcTupleIdx, vtkAbstractArray *source) override
Insert the tuple from srcTupleIdx in the source array at the end of this array.
internal class used by vtkGenericDataArray to support LookupValue.
Abstract superclass for all arrays.
ValueType * GetPointer(vtkIdType valueIdx)
Default implementation raises a runtime error.
vtkGenericDataArrayLookupHelper< SelfType > Lookup
void SetVariantValue(vtkIdType valueIdx, vtkVariant value) override
Set a value in the array from a variant.
vtkTemplateTypeMacro(SelfType, vtkDataArray) enum
Compile time access to the VTK type identifier.
void SetArrayFreeFunction(void(*callback)(void *)) override
Default implementation raises a runtime error.
vtkTypeBool Allocate(vtkIdType size, vtkIdType ext=1000) override
Allocate memory for this array.
void SetComponent(vtkIdType tupleIdx, int compIdx, double value) override
Set the data component at the location specified by tupleIdx and compIdx to value.
void GetTypedTuple(vtkIdType tupleIdx, ValueType *tuple) const
Copy the tuple at tupleIdx into tuple.
void Initialize() override
Release storage and reset array to initial state.
void SetTypedComponent(vtkIdType tupleIdx, int compIdx, ValueType value)
Set component compIdx of the tuple at tupleIdx to value.
int vtkIdType
Definition: vtkType.h:347
Base interface for all typed vtkDataArray subclasses.
int GetNumberOfComponents()
Set/Get the dimension (n) of the components.
void SetVoidArray(void *, vtkIdType, int) override
Default implementation raises a runtime error.
void SetNumberOfTuples(vtkIdType number) override
Set the number of tuples (a component group) in the array.
void SetTuple(vtkIdType tupleIdx, const float *tuple) override
Set the data tuple at tupleIdx.
A atomic type representing the union of many types.
Definition: vtkVariant.h:71
void SetTuple(vtkIdType tupleIdx, const double *tuple) override
Set the data tuple at tupleIdx.
int vtkTypeBool
Definition: vtkABI.h:69
vtkIdType GetNumberOfValues() const
Get the total number of values in the array.
ValueType GetValue(vtkIdType valueIdx) const
Get the value at valueIdx.
void InsertTuple(vtkIdType dstTupleIdx, vtkIdType srcTupleIdx, vtkAbstractArray *source) override
Insert the tuple at srcTupleIdx in the source array into this array at dstTupleIdx.
void InsertVariantValue(vtkIdType valueIdx, vtkVariant value) override
Insert a value into the array from a variant.
double * GetTuple(vtkIdType tupleIdx) override
Get the data tuple at tupleIdx.
vtkIdType Capacity()
Return the capacity in typeof T units of the current array.
ValueType * GetValueRange()
Get the range of array values for the 0th component in the native data type.
vtkIdType InsertNextValue(ValueType value)
Insert data at the end of the array.
list of point or cell ids
Definition: vtkIdList.h:36
vtkVariant GetVariantValue(vtkIdType valueIdx) override
Retrieve value from the array as a variant.
bool AllocateTuples(vtkIdType numTuples)
Allocate space for numTuples.
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:54
void InsertTuples(vtkIdList *dstIds, vtkIdList *srcIds, vtkAbstractArray *source) override
Copy the tuples indexed in srcIds from the source array to the tuple locations indexed by dstIds in t...
int GetDataTypeSize() override
Return the size of the underlying data type.
virtual void FillValue(ValueType value)
Set all the values in array to value.
void * WriteVoidPointer(vtkIdType valueIdx, vtkIdType numValues) override
Default implementation raises a runtime error.
ValueType * WritePointer(vtkIdType valueIdx, vtkIdType numValues)
Default implementation raises a runtime error.
Abstract superclass to iterate over elements in an vtkAbstractArray.
void ClearLookup() override
Delete the associated fast lookup data structure on this array, if it exists.
#define VTK_SIZEHINT(...)
void GetTuples(vtkIdList *tupleIds, vtkAbstractArray *output) override
Given a list of tuple ids, return an array of tuples.
vtkArrayIterator * NewIterator() override
Subclasses must override this method and provide the right kind of templated vtkArrayIteratorTemplate...
void RemoveTuple(vtkIdType tupleIdx) override
Removes a tuple at the given index.
void GetValueRange(ValueType range[2])
~vtkGenericDataArray() override
void DataChanged() override
Tell the array explicitly that the data has changed.
#define VTK_NEWINSTANCE
void * GetVoidPointer(vtkIdType valueIdx) override
Default implementation raises a runtime error.
boost::graph_traits< vtkGraph * >::vertex_descriptor source(boost::graph_traits< vtkGraph * >::edge_descriptor e, vtkGraph *)
void SetTypedTuple(vtkIdType tupleIdx, const ValueType *tuple)
Set this array&#39;s tuple at tupleIdx to the values in tuple.
std::vector< ValueType > LegacyValueRange
double GetComponent(vtkIdType tupleIdx, int compIdx) override
Return the data component at the location specified by tupleIdx and compIdx.
vtkIdType LookupValue(vtkVariant value) override
Return the value indices where a specific value appears.
std::vector< double > LegacyTuple
virtual void FillTypedComponent(int compIdx, ValueType value)
Set component comp of all tuples to value.
void InsertTypedTuple(vtkIdType tupleIdx, const ValueType *t)
Insert (memory allocation performed) the tuple t at tupleIdx.
void InsertComponent(vtkIdType tupleIdx, int compIdx, double value) override
Insert value at the location specified by tupleIdx and compIdx.
bool ReallocateTuples(vtkIdType numTuples)
Allocate space for numTuples.
void InterpolateTuple(vtkIdType dstTupleIdx, vtkIdList *ptIndices, vtkAbstractArray *source, double *weights) override
Set the tuple at dstTupleIdx in this array to the interpolated tuple value, given the ptIndices in th...
virtual vtkIdType LookupTypedValue(ValueType value)
#define VTK_EXPECTS(x)
void SetNumberOfComponents(int num) override
Set/Get the dimension (n) of the components.
vtkTypeBool Resize(vtkIdType numTuples) override
Resize the array to the requested number of tuples and preserve data.
int GetDataType() override
Return the underlying data type.
void InsertTuples(vtkIdType dstStart, vtkIdType n, vtkIdType srcStart, vtkAbstractArray *source) override
Copy n consecutive tuples starting at srcStart from the source array to this array, starting at the dstStart location.
Template defining traits of native types used by VTK.
Definition: vtkTypeTraits.h:32
bool EnsureAccessToTuple(vtkIdType tupleIdx)
void InsertTypedComponent(vtkIdType tupleIdx, int compIdx, ValueType val)
Insert (memory allocation performed) the value at the specified tuple and component location...
ValueType GetTypedComponent(vtkIdType tupleIdx, int compIdx) const
Get component compIdx of the tuple at tupleIdx.