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 =========================================================================*/
66 #ifndef vtkGenericDataArray_h
67 #define vtkGenericDataArray_h
68 
69 #include "vtkDataArray.h"
70 #include "vtkSmartPointer.h"
71 #include "vtkTypeTraits.h"
73 
74 #include <cassert>
75 
76 template<class DerivedT, class ValueTypeT>
78 {
80 public:
81  typedef ValueTypeT ValueType;
83 
84 
87  enum { VTK_DATA_TYPE = vtkTypeTraits<ValueType>::VTK_TYPE_ID };
88 
93 
101  inline ValueType GetValue(vtkIdType valueIdx) const
102  {
103  return static_cast<const DerivedT*>(this)->GetValue(valueIdx);
104  }
105 
114  VTK_EXPECTS(0 <= valueIdx && valueIdx < GetNumberOfValues())
115  {
116  static_cast<DerivedT*>(this)->SetValue(valueIdx, value);
117  }
118 
127  void GetTypedTuple(vtkIdType tupleIdx, ValueType* tuple) const
128  VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples())
129  {
130  static_cast<const DerivedT*>(this)->GetTypedTuple(tupleIdx, tuple);
131  }
132 
141  void SetTypedTuple(vtkIdType tupleIdx, const ValueType* tuple)
142  VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples())
143  {
144  static_cast<DerivedT*>(this)->SetTypedTuple(tupleIdx, tuple);
145  }
146 
152  ValueType GetTypedComponent(vtkIdType tupleIdx, int compIdx) const
153  VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples())
154  VTK_EXPECTS(0 <= compIdx && compIdx < GetNumberOfComponents())
155  {
156  return static_cast<const DerivedT*>(this)->GetTypedComponent(tupleIdx,
157  compIdx);
158  }
159 
165  void SetTypedComponent(vtkIdType tupleIdx, int compIdx, ValueType value)
166  VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples())
167  VTK_EXPECTS(0 <= compIdx && compIdx < GetNumberOfComponents())
168  {
169  static_cast<DerivedT*>(this)->SetTypedComponent(tupleIdx, compIdx, value);
170  }
171 
173 
177  void *GetVoidPointer(vtkIdType valueIdx) override;
178  ValueType* GetPointer(vtkIdType valueIdx);
179  void SetVoidArray(void*, vtkIdType, int) override;
180  void SetVoidArray(void*, vtkIdType, int, int) override;
181  void SetArrayFreeFunction(void (*callback)(void *)) override;
182  void* WriteVoidPointer(vtkIdType valueIdx, vtkIdType numValues) override;
183  ValueType* WritePointer(vtkIdType valueIdx, vtkIdType numValues);
185 
192  void RemoveTuple(vtkIdType tupleIdx) override;
193 
198 
202  void InsertValue(vtkIdType valueIdx, ValueType value);
203 
207  void InsertTypedTuple(vtkIdType tupleIdx, const ValueType *t);
208 
213 
218  void InsertTypedComponent(vtkIdType tupleIdx, int compIdx, ValueType val);
219 
221 
225  void GetValueRange(ValueType range[2], int comp);
226  ValueType *GetValueRange(int comp) VTK_SIZEHINT(2);
228 
234  void GetValueRange(ValueType range[2]) { this->GetValueRange(range, 0); }
235 
240  vtkIdType Capacity() { return this->Size; }
241 
245  virtual void FillTypedComponent(int compIdx, ValueType value);
246 
250  virtual void FillValue(ValueType value);
251 
252  int GetDataType() override;
253  int GetDataTypeSize() override;
254  bool HasStandardMemoryLayout() override;
255  vtkTypeBool Allocate(vtkIdType size, vtkIdType ext = 1000) override;
256  vtkTypeBool Resize(vtkIdType numTuples) override;
257  void SetNumberOfComponents(int num) override;
258  void SetNumberOfTuples(vtkIdType number) override;
259  void Initialize() override;
260  void Squeeze() override;
261  void SetTuple(vtkIdType dstTupleIdx, vtkIdType srcTupleIdx,
262  vtkAbstractArray* source) override;
263  // MSVC doesn't like 'using' here (error C2487). Just forward instead:
264  // using Superclass::SetTuple;
265  void SetTuple(vtkIdType tupleIdx, const float *tuple) override
266  { this->Superclass::SetTuple(tupleIdx, tuple); }
267  void SetTuple(vtkIdType tupleIdx, const double *tuple) override
268  { this->Superclass::SetTuple(tupleIdx, tuple); }
269 
270  void InsertTuples(vtkIdList *dstIds, vtkIdList *srcIds,
271  vtkAbstractArray *source) override;
272  // MSVC doesn't like 'using' here (error C2487). Just forward instead:
273  // using Superclass::InsertTuples;
274  void InsertTuples(vtkIdType dstStart, vtkIdType n, vtkIdType srcStart,
275  vtkAbstractArray* source) override
276  { this->Superclass::InsertTuples(dstStart, n, srcStart, source); }
277 
278  void InsertTuple(vtkIdType dstTupleIdx, vtkIdType srcTupleIdx,
279  vtkAbstractArray *source) override;
280  void InsertTuple(vtkIdType tupleIdx, const float *source) override;
281  void InsertTuple(vtkIdType tupleIdx, const double *source) override;
282  void InsertComponent(vtkIdType tupleIdx, int compIdx,
283  double value) override;
284  vtkIdType InsertNextTuple(vtkIdType srcTupleIdx,
285  vtkAbstractArray *source) override;
286  vtkIdType InsertNextTuple(const float *tuple) override;
287  vtkIdType InsertNextTuple(const double *tuple) override;
288  void GetTuples(vtkIdList *tupleIds,
289  vtkAbstractArray *output) override;
290  void GetTuples(vtkIdType p1, vtkIdType p2,
291  vtkAbstractArray *output) override;
292  double *GetTuple(vtkIdType tupleIdx) override;
293  void GetTuple(vtkIdType tupleIdx, double * tuple) override;
294  void InterpolateTuple(vtkIdType dstTupleIdx, vtkIdList *ptIndices,
296  double* weights) override;
297  void InterpolateTuple(vtkIdType dstTupleIdx,
298  vtkIdType srcTupleIdx1, vtkAbstractArray* source1,
299  vtkIdType srcTupleIdx2, vtkAbstractArray* source2, double t) override;
300  void SetComponent(vtkIdType tupleIdx, int compIdx, double value) override;
301  double GetComponent(vtkIdType tupleIdx, int compIdx) override;
302  void SetVariantValue(vtkIdType valueIdx, vtkVariant value) override;
303  vtkVariant GetVariantValue(vtkIdType valueIdx) override;
304  void InsertVariantValue(vtkIdType valueIdx, vtkVariant value) override;
307  void LookupValue(vtkVariant value, vtkIdList* valueIds) override;
308  virtual void LookupTypedValue(ValueType value, vtkIdList* valueIds);
309  void ClearLookup() override;
310  void DataChanged() override;
311  void FillComponent(int compIdx, double value) override;
313 
314 protected:
316  ~vtkGenericDataArray() override;
317 
323  inline bool AllocateTuples(vtkIdType numTuples)
324  {
325  return static_cast<DerivedT*>(this)->AllocateTuples(numTuples);
326  }
327 
333  inline bool ReallocateTuples(vtkIdType numTuples)
334  {
335  return static_cast<DerivedT*>(this)->ReallocateTuples(numTuples);
336  }
337 
338  // This method resizes the array if needed so that the given tuple index is
339  // valid/accessible.
340  bool EnsureAccessToTuple(vtkIdType tupleIdx);
341 
342  std::vector<double> LegacyTuple;
343  std::vector<ValueType> LegacyValueRange;
344 
346 
347 private:
348  vtkGenericDataArray(const vtkGenericDataArray&) = delete;
349  void operator=(const vtkGenericDataArray&) = delete;
350 
351 };
352 
353 #include "vtkGenericDataArray.txx"
354 
355 // Adds an implementation of NewInstanceInternal() that returns an AoS
356 // (unmapped) VTK array, if possible. This allows the pipeline to copy and
357 // propagate the array when the array data is not modifiable. Use this in
358 // combination with vtkAbstractTypeMacro or vtkAbstractTemplateTypeMacro
359 // (instead of vtkTypeMacro) to avoid adding the default NewInstance
360 // implementation.
361 #define vtkAOSArrayNewInstanceMacro(thisClass) \
362  protected: \
363  vtkObjectBase *NewInstanceInternal() const override \
364  { \
365  if (vtkDataArray *da = \
366  vtkDataArray::CreateDataArray(thisClass::VTK_DATA_TYPE)) \
367  { \
368  return da; \
369  } \
370  return thisClass::New(); \
371  } \
372  public:
373 
374 #endif
375 // 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.
vtkIdType GetNumberOfValues() const
Get the total number of values in the array.
ValueType GetTypedComponent(vtkIdType tupleIdx, int compIdx) const
Get component compIdx of the tuple at tupleIdx.
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.
ValueType GetValue(vtkIdType valueIdx) const
Get the value at valueIdx.
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 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
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.
void GetTypedTuple(vtkIdType tupleIdx, ValueType *tuple) const
Copy the tuple at tupleIdx into tuple.
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...