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
76template<class DerivedT, class ValueTypeT>
78{
80public:
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
113 inline void SetValue(vtkIdType valueIdx, ValueType value)
114 {
115 static_cast<DerivedT*>(this)->SetValue(valueIdx, value);
116 }
117
126 inline void GetTypedTuple(vtkIdType tupleIdx, ValueType* tuple) const
127 {
128 static_cast<const DerivedT*>(this)->GetTypedTuple(tupleIdx, tuple);
129 }
130
139 inline void SetTypedTuple(vtkIdType tupleIdx, const ValueType* tuple)
140 {
141 static_cast<DerivedT*>(this)->SetTypedTuple(tupleIdx, tuple);
142 }
143
149 inline ValueType GetTypedComponent(vtkIdType tupleIdx, int compIdx) const
150 {
151 return static_cast<const DerivedT*>(this)->GetTypedComponent(tupleIdx,
152 compIdx);
153 }
154
160 inline void SetTypedComponent(vtkIdType tupleIdx, int compIdx,
162 {
163 static_cast<DerivedT*>(this)->SetTypedComponent(tupleIdx, compIdx, value);
164 }
165
167
171 void *GetVoidPointer(vtkIdType valueIdx) VTK_OVERRIDE;
173 void SetVoidArray(void*, vtkIdType, int) VTK_OVERRIDE;
174 void SetVoidArray(void*, vtkIdType, int, int) VTK_OVERRIDE;
175 void* WriteVoidPointer(vtkIdType valueIdx, vtkIdType numValues) VTK_OVERRIDE;
178
185 void RemoveTuple(vtkIdType tupleIdx) VTK_OVERRIDE;
186
191
196
200 void InsertTypedTuple(vtkIdType tupleIdx, const ValueType *t);
201
206
211 void InsertTypedComponent(vtkIdType tupleIdx, int compIdx, ValueType val);
212
214
218 void GetValueRange(ValueType range[2], int comp);
221
226 ValueType *GetValueRange() { return this->GetValueRange(0); }
227 void GetValueRange(ValueType range[2]) { this->GetValueRange(range, 0); }
228
233 vtkIdType Capacity() { return this->Size; }
234
235 int GetDataType() VTK_OVERRIDE;
236 int GetDataTypeSize() VTK_OVERRIDE;
237 bool HasStandardMemoryLayout() VTK_OVERRIDE;
238 int Allocate(vtkIdType size, vtkIdType ext = 1000) VTK_OVERRIDE;
239 int Resize(vtkIdType numTuples) VTK_OVERRIDE;
240 void SetNumberOfComponents(int num) VTK_OVERRIDE;
241 void SetNumberOfTuples(vtkIdType number) VTK_OVERRIDE;
242 void Initialize() VTK_OVERRIDE;
243 void Squeeze() VTK_OVERRIDE;
244 void SetTuple(vtkIdType dstTupleIdx, vtkIdType srcTupleIdx,
245 vtkAbstractArray* source) VTK_OVERRIDE;
246 // MSVC doesn't like 'using' here (error C2487). Just forward instead:
247 // using Superclass::SetTuple;
248 void SetTuple(vtkIdType tupleIdx, const float *tuple) VTK_OVERRIDE
249 { this->Superclass::SetTuple(tupleIdx, tuple); }
250 void SetTuple(vtkIdType tupleIdx, const double *tuple) VTK_OVERRIDE
251 { this->Superclass::SetTuple(tupleIdx, tuple); }
252
253 void InsertTuples(vtkIdList *dstIds, vtkIdList *srcIds,
254 vtkAbstractArray *source) VTK_OVERRIDE;
255 // MSVC doesn't like 'using' here (error C2487). Just forward instead:
256 // using Superclass::InsertTuples;
257 void InsertTuples(vtkIdType dstStart, vtkIdType n, vtkIdType srcStart,
258 vtkAbstractArray* source) VTK_OVERRIDE
259 { this->Superclass::InsertTuples(dstStart, n, srcStart, source); }
260
261 void InsertTuple(vtkIdType dstTupleIdx, vtkIdType srcTupleIdx,
262 vtkAbstractArray *source) VTK_OVERRIDE;
263 void InsertTuple(vtkIdType tupleIdx, const float *source) VTK_OVERRIDE;
264 void InsertTuple(vtkIdType tupleIdx, const double *source) VTK_OVERRIDE;
265 void InsertComponent(vtkIdType tupleIdx, int compIdx,
266 double value) VTK_OVERRIDE;
268 vtkAbstractArray *source) VTK_OVERRIDE;
269 vtkIdType InsertNextTuple(const float *tuple) VTK_OVERRIDE;
270 vtkIdType InsertNextTuple(const double *tuple) VTK_OVERRIDE;
271 void GetTuples(vtkIdList *tupleIds,
272 vtkAbstractArray *output) VTK_OVERRIDE;
274 vtkAbstractArray *output) VTK_OVERRIDE;
275 double *GetTuple(vtkIdType tupleIdx) VTK_OVERRIDE;
276 void GetTuple(vtkIdType tupleIdx, double * tuple) VTK_OVERRIDE;
277 void InterpolateTuple(vtkIdType dstTupleIdx, vtkIdList *ptIndices,
279 double* weights) VTK_OVERRIDE;
280 void InterpolateTuple(vtkIdType dstTupleIdx,
281 vtkIdType srcTupleIdx1, vtkAbstractArray* source1,
282 vtkIdType srcTupleIdx2, vtkAbstractArray* source2, double t) VTK_OVERRIDE;
283 void SetComponent(vtkIdType tupleIdx, int compIdx, double value) VTK_OVERRIDE;
284 double GetComponent(vtkIdType tupleIdx, int compIdx) VTK_OVERRIDE;
285 void SetVariantValue(vtkIdType valueIdx, vtkVariant value) VTK_OVERRIDE;
286 vtkVariant GetVariantValue(vtkIdType valueIdx) VTK_OVERRIDE;
287 void InsertVariantValue(vtkIdType valueIdx, vtkVariant value) VTK_OVERRIDE;
290 void LookupValue(vtkVariant value, vtkIdList* valueIds) VTK_OVERRIDE;
291 virtual void LookupTypedValue(ValueType value, vtkIdList* valueIds);
292 void ClearLookup() VTK_OVERRIDE;
293 void DataChanged() VTK_OVERRIDE;
295
296protected:
298 ~vtkGenericDataArray() VTK_OVERRIDE;
299
305 inline bool AllocateTuples(vtkIdType numTuples)
306 {
307 return static_cast<DerivedT*>(this)->AllocateTuples(numTuples);
308 }
309
315 inline bool ReallocateTuples(vtkIdType numTuples)
316 {
317 return static_cast<DerivedT*>(this)->ReallocateTuples(numTuples);
318 }
319
320 // This method resizes the array if needed so that the given tuple index is
321 // valid/accessible.
323
325private:
326 vtkGenericDataArray(const vtkGenericDataArray&) VTK_DELETE_FUNCTION;
327 void operator=(const vtkGenericDataArray&) VTK_DELETE_FUNCTION;
328
329 std::vector<double> LegacyTuple;
330 std::vector<ValueType> LegacyValueRange;
331};
332
333#include "vtkGenericDataArray.txx"
334
335// Adds an implementation of NewInstanceInternal() that returns an AoS
336// (unmapped) VTK array, if possible. This allows the pipeline to copy and
337// propagate the array when the array data is not modifiable. Use this in
338// combination with vtkAbstractTypeMacro or vtkAbstractTemplateTypeMacro
339// (instead of vtkTypeMacro) to avoid adding the default NewInstance
340// implementation.
341#define vtkAOSArrayNewInstanceMacro(thisClass) \
342 protected: \
343 vtkObjectBase *NewInstanceInternal() const VTK_OVERRIDE \
344 { \
345 if (vtkDataArray *da = \
346 vtkDataArray::CreateDataArray(thisClass::VTK_DATA_TYPE)) \
347 { \
348 return da; \
349 } \
350 return thisClass::New(); \
351 } \
352 public:
353
354#endif
355// VTK-HeaderTest-Exclude: vtkGenericDataArray.h
Abstract superclass for all arrays.
Abstract superclass to iterate over elements in an vtkAbstractArray.
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:55
internal class used by vtkGenericDataArray to support LookupValue.
Base interface for all typed vtkDataArray subclasses.
void SetNumberOfComponents(int num) override
Set/Get the dimension (n) of the components.
void DataChanged() override
Tell the array explicitly that the data has changed.
void InsertComponent(vtkIdType tupleIdx, int compIdx, double value) override
Insert value at the location specified by tupleIdx and compIdx.
vtkIdType LookupValue(vtkVariant value) override
Return the value indices where a specific value appears.
double GetComponent(vtkIdType tupleIdx, int compIdx) override
Return the data component at the location specified by tupleIdx and compIdx.
void InsertVariantValue(vtkIdType valueIdx, vtkVariant value) override
Insert a value into the array from a variant.
void SetTuple(vtkIdType tupleIdx, const double *tuple) override
void InsertTuple(vtkIdType tupleIdx, const float *source) override
Insert the data tuple at tupleIdx.
ValueType * GetPointer(vtkIdType valueIdx)
int Resize(vtkIdType numTuples) override
Resize the array to the requested number of tuples and preserve data.
void RemoveTuple(vtkIdType tupleIdx) override
Removes a tuple at the given index.
void InsertTypedTuple(vtkIdType tupleIdx, const ValueType *t)
Insert (memory allocation performed) the tuple t at tupleIdx.
void SetNumberOfTuples(vtkIdType number) override
Set the number of tuples (a component group) in the array.
ValueType * WritePointer(vtkIdType valueIdx, vtkIdType numValues)
double * GetTuple(vtkIdType tupleIdx) override
Get the data tuple at tupleIdx.
void InsertTuple(vtkIdType dstTupleIdx, vtkIdType srcTupleIdx, vtkAbstractArray *source) override
Insert the tuple at srcTupleIdx in the source array into this array at dstTupleIdx.
vtkTemplateTypeMacro(SelfType, vtkDataArray) enum
Compile time access to the VTK type identifier.
void * GetVoidPointer(vtkIdType valueIdx) override
Default implementation raises a runtime error.
void GetValueRange(ValueType range[2], int comp)
Get the range of array values for the given component in the native data type.
void GetValueRange(ValueType range[2])
void SetVoidArray(void *, vtkIdType, int, int) override
vtkIdType Capacity()
Return the capacity in typeof T units of the current array.
int GetDataTypeSize() override
Return the size of the underlying data type.
void SetVariantValue(vtkIdType valueIdx, vtkVariant value) override
Set a value in the array from a variant.
vtkVariant GetVariantValue(vtkIdType valueIdx) override
Retrieve value from the array as a variant.
void InsertTypedComponent(vtkIdType tupleIdx, int compIdx, ValueType val)
Insert (memory allocation performed) the value at the specified tuple and component location.
void ClearLookup() override
Delete the associated fast lookup data structure on this array, if it exists.
void GetTuple(vtkIdType tupleIdx, double *tuple) override
Get the data tuple at tupleIdx by filling in a user-provided array, Make sure that your array is larg...
vtkIdType InsertNextTuple(vtkIdType srcTupleIdx, vtkAbstractArray *source) override
Insert the tuple from srcTupleIdx in the source array at the end of this array.
virtual void LookupTypedValue(ValueType value, vtkIdList *valueIds)
vtkIdType InsertNextTuple(const double *tuple) override
void GetTuples(vtkIdType p1, vtkIdType p2, vtkAbstractArray *output) override
Get the tuples for the range of tuple ids specified (i.e., p1->p2 inclusive).
void SetVoidArray(void *, vtkIdType, int) override
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...
vtkIdType InsertNextTuple(const float *tuple) override
Insert the data tuple at the end of the array and return the tuple index at which the data was insert...
VTK_NEWINSTANCE vtkArrayIterator * NewIterator() override
Subclasses must override this method and provide the right kind of templated vtkArrayIteratorTemplate...
virtual vtkIdType LookupTypedValue(ValueType value)
int GetDataType() override
Return the underlying data type.
void LookupValue(vtkVariant value, vtkIdList *valueIds) override
void InsertValue(vtkIdType valueIdx, ValueType value)
Insert data at a specified position in the array.
void InterpolateTuple(vtkIdType dstTupleIdx, vtkIdType srcTupleIdx1, vtkAbstractArray *source1, vtkIdType srcTupleIdx2, vtkAbstractArray *source2, double t) override
Insert the tuple at dstTupleIdx in this array to the tuple interpolated from the two tuple indices,...
void InsertTuple(vtkIdType tupleIdx, const double *source) override
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,...
void Squeeze() override
Free any unnecessary memory.
bool HasStandardMemoryLayout() override
Returns true if this array uses the standard memory layout defined in the VTK user guide,...
bool EnsureAccessToTuple(vtkIdType tupleIdx)
vtkGenericDataArrayLookupHelper< SelfType > Lookup
int Allocate(vtkIdType size, vtkIdType ext=1000) override
Allocate memory for this array.
ValueType * GetValueRange(int comp)
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...
void * WriteVoidPointer(vtkIdType valueIdx, vtkIdType numValues) override
Get the address of a particular data index.
void GetTuples(vtkIdList *tupleIds, vtkAbstractArray *output) override
Given a list of tuple ids, return an array of tuples.
void SetComponent(vtkIdType tupleIdx, int compIdx, double value) override
Set the data component at the location specified by tupleIdx and compIdx to value.
vtkIdType InsertNextValue(ValueType value)
Insert data at the end of the array.
vtkIdType InsertNextTypedTuple(const ValueType *t)
Insert (memory allocation performed) the tuple onto the end of the array.
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.
ValueType * GetValueRange()
Get the range of array values for the 0th component in the native data type.
void Initialize() override
Release storage and reset array to initial state.
list of point or cell ids
Definition: vtkIdList.h:37
A atomic type representing the union of many types.
Definition: vtkVariant.h:76
void SetValue(vtkIdType valueIdx, ValueType value)
Set the value at valueIdx to value.
void SetTypedComponent(vtkIdType tupleIdx, int compIdx, ValueType value)
Set component compIdx of the tuple at tupleIdx to value.
ValueType GetValue(vtkIdType valueIdx) const
Get the value at valueIdx.
void SetTypedTuple(vtkIdType tupleIdx, const ValueType *tuple)
Set this array's tuple at tupleIdx to the values in tuple.
void GetTypedTuple(vtkIdType tupleIdx, ValueType *tuple) const
Copy the tuple at tupleIdx into tuple.
bool ReallocateTuples(vtkIdType numTuples)
Allocate space for numTuples.
ValueType GetTypedComponent(vtkIdType tupleIdx, int compIdx) const
Get component compIdx of the tuple at tupleIdx.
bool AllocateTuples(vtkIdType numTuples)
Allocate space for numTuples.
@ value
Definition: vtkX3D.h:220
@ range
Definition: vtkX3D.h:238
@ size
Definition: vtkX3D.h:253
Template defining traits of native types used by VTK.
Definition: vtkTypeTraits.h:32
boost::graph_traits< vtkGraph * >::vertex_descriptor source(boost::graph_traits< vtkGraph * >::edge_descriptor e, vtkGraph *)
int vtkIdType
Definition: vtkType.h:287
#define VTK_NEWINSTANCE