VTK
vtkAOSDataArrayTemplate.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkAOSDataArrayTemplate.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 =========================================================================*/
31 #ifndef vtkAOSDataArrayTemplate_h
32 #define vtkAOSDataArrayTemplate_h
33 
34 #include "vtkCommonCoreModule.h" // For export macro
35 #include "vtkGenericDataArray.h"
36 #include "vtkBuffer.h" // For storage buffer.
37 
38 // The export macro below makes no sense, but is necessary for older compilers
39 // when we export instantiations of this class from vtkCommonCore.
40 template <class ValueTypeT>
41 class VTKCOMMONCORE_EXPORT vtkAOSDataArrayTemplate :
42  public vtkGenericDataArray<vtkAOSDataArrayTemplate<ValueTypeT>, ValueTypeT>
43 {
46 public:
48  vtkTemplateTypeMacro(SelfType, GenericDataArrayType)
49  typedef typename Superclass::ValueType ValueType;
50 
52  {
56  };
57 
58  static vtkAOSDataArrayTemplate* New();
59 
63  inline ValueType GetValue(vtkIdType valueIdx) const
64  {
65  return this->Buffer->GetBuffer()[valueIdx];
66  }
67 
71  inline void SetValue(vtkIdType valueIdx, ValueType value)
72  {
73  this->Buffer->GetBuffer()[valueIdx] = value;
74  }
75 
77 
80  inline void GetTypedTuple(vtkIdType tupleIdx, ValueType* tuple) const
81  {
82  const vtkIdType valueIdx = tupleIdx * this->NumberOfComponents;
83  std::copy(this->Buffer->GetBuffer() + valueIdx,
84  this->Buffer->GetBuffer() + valueIdx + this->NumberOfComponents,
85  tuple);
86  }
88 
90 
93  inline void SetTypedTuple(vtkIdType tupleIdx, const ValueType* tuple)
94  {
95  const vtkIdType valueIdx = tupleIdx * this->NumberOfComponents;
96  std::copy(tuple, tuple + this->NumberOfComponents,
97  this->Buffer->GetBuffer() + valueIdx);
98  }
100 
104  inline ValueType GetTypedComponent(vtkIdType tupleIdx, int comp) const
105  {
106  return this->Buffer->GetBuffer()[this->NumberOfComponents*tupleIdx + comp];
107  }
108 
110 
113  inline void SetTypedComponent(vtkIdType tupleIdx, int comp, ValueType value)
114  {
115  const vtkIdType valueIdx = tupleIdx * this->NumberOfComponents + comp;
116  this->SetValue(valueIdx, value);
117  }
119 
121 
124  void FillTypedComponent(int compIdx, ValueType value) VTK_OVERRIDE;
126 
128 
131  void FillValue(ValueType value) VTK_OVERRIDE;
132  void Fill(double value) VTK_OVERRIDE;
134 
136 
141  ValueType* WritePointer(vtkIdType valueIdx, vtkIdType numValues);
142  void* WriteVoidPointer(vtkIdType valueIdx, vtkIdType numValues) VTK_OVERRIDE;
144 
146 
153  ValueType* GetPointer(vtkIdType valueIdx);
154  void* GetVoidPointer(vtkIdType valueIdx) VTK_OVERRIDE;
156 
158 
171  void SetArray(ValueType* array, vtkIdType size, int save, int deleteMethod);
172  void SetArray(ValueType* array, vtkIdType size, int save);
173  void SetVoidArray(void* array, vtkIdType size, int save) VTK_OVERRIDE;
174  void SetVoidArray(void* array, vtkIdType size, int save,
175  int deleteMethod) VTK_OVERRIDE;
177 
178  // Overridden for optimized implementations:
179  void SetTuple(vtkIdType tupleIdx, const float *tuple) VTK_OVERRIDE;
180  void SetTuple(vtkIdType tupleIdx, const double *tuple) VTK_OVERRIDE;
181  // MSVC doesn't like 'using' here (error C2487). Just forward instead:
182  // using Superclass::SetTuple;
183  void SetTuple(vtkIdType dstTupleIdx, vtkIdType srcTupleIdx,
184  vtkAbstractArray *source) VTK_OVERRIDE
185  { this->Superclass::SetTuple(dstTupleIdx, srcTupleIdx, source); }
186  void InsertTuple(vtkIdType tupleIdx, const float *source) VTK_OVERRIDE;
187  void InsertTuple(vtkIdType tupleIdx, const double *source) VTK_OVERRIDE;
188  // MSVC doesn't like 'using' here (error C2487). Just forward instead:
189  // using Superclass::InsertTuple;
190  void InsertTuple(vtkIdType dstTupleIdx, vtkIdType srcTupleIdx,
191  vtkAbstractArray *source) VTK_OVERRIDE
192  { this->Superclass::InsertTuple(dstTupleIdx, srcTupleIdx, source); }
193  void InsertComponent(vtkIdType tupleIdx, int compIdx,
194  double value) VTK_OVERRIDE;
195  vtkIdType InsertNextTuple(const float *tuple) VTK_OVERRIDE;
196  vtkIdType InsertNextTuple(const double *tuple) VTK_OVERRIDE;
197  // MSVC doesn't like 'using' here (error C2487). Just forward instead:
198  // using Superclass::InsertNextTuple;
200  vtkAbstractArray *source) VTK_OVERRIDE
201  { return this->Superclass::InsertNextTuple(srcTupleIdx, source); }
202  void GetTuple(vtkIdType tupleIdx, double * tuple) VTK_OVERRIDE;
203  double *GetTuple(vtkIdType tupleIdx) VTK_OVERRIDE;
204 
216 
221  typedef ValueType* Iterator;
222  Iterator Begin() { return Iterator(this->GetVoidPointer(0)); }
223  Iterator End() { return Iterator(this->GetVoidPointer(this->MaxId + 1)); }
224 
226 
235  {
236  if (source)
237  {
238  switch (source->GetArrayType())
239  {
241  if (vtkDataTypesCompare(source->GetDataType(),
243  {
244  return static_cast<vtkAOSDataArrayTemplate<ValueType>*>(source);
245  }
246  break;
247  }
248  }
249  return NULL;
250  }
252 
255  bool HasStandardMemoryLayout() VTK_OVERRIDE { return true; }
256  void ShallowCopy(vtkDataArray *other) VTK_OVERRIDE;
257 
259 
263  VTK_LEGACY(void GetTupleValue(vtkIdType tupleIdx, ValueType *tuple));
264  VTK_LEGACY(void SetTupleValue(vtkIdType tupleIdx, const ValueType *tuple));
265  VTK_LEGACY(void InsertTupleValue(vtkIdType tupleIdx, const ValueType *tuple));
266  VTK_LEGACY(vtkIdType InsertNextTupleValue(const ValueType *tuple));
268 
269  // Reimplemented for efficiency:
270  void InsertTuples(vtkIdType dstStart, vtkIdType n, vtkIdType srcStart,
271  vtkAbstractArray* source) VTK_OVERRIDE;
272  // MSVC doesn't like 'using' here (error C2487). Just forward instead:
273  // using Superclass::InsertTuples;
274  void InsertTuples(vtkIdList *dstIds, vtkIdList *srcIds,
275  vtkAbstractArray *source) VTK_OVERRIDE
276  { this->Superclass::InsertTuples(dstIds, srcIds, source); }
277 
278 protected:
280  ~vtkAOSDataArrayTemplate() VTK_OVERRIDE;
281 
286  bool AllocateTuples(vtkIdType numTuples);
287 
292  bool ReallocateTuples(vtkIdType numTuples);
293 
295 
296 private:
297  vtkAOSDataArrayTemplate(const vtkAOSDataArrayTemplate&) VTK_DELETE_FUNCTION;
298  void operator=(const vtkAOSDataArrayTemplate&) VTK_DELETE_FUNCTION;
299 
300  friend class vtkGenericDataArray<vtkAOSDataArrayTemplate<ValueTypeT>,
301  ValueTypeT>;
302 
303 };
304 
305 // Declare vtkArrayDownCast implementations for AoS containers:
307 
308 // This macro is used by the subclasses to create dummy
309 // declarations for these functions such that the wrapper
310 // can see them. The wrappers ignore vtkAOSDataArrayTemplate.
311 #define vtkCreateWrappedArrayInterface(T) \
312  int GetDataType(); \
313  void GetTypedTuple(vtkIdType i, T* tuple); \
314  void SetTypedTuple(vtkIdType i, const T* tuple); \
315  void InsertTypedTuple(vtkIdType i, const T* tuple); \
316  vtkIdType InsertNextTypedTuple(const T* tuple); \
317  T GetValue(vtkIdType id); \
318  void SetValue(vtkIdType id, T value); \
319  void SetNumberOfValues(vtkIdType number); \
320  void InsertValue(vtkIdType id, T f); \
321  vtkIdType InsertNextValue(T f); \
322  T *GetValueRange(int comp); \
323  T *GetValueRange(); \
324  T* WritePointer(vtkIdType id, vtkIdType number); \
325  T* GetPointer(vtkIdType id)/*; \
326 
327  * These methods are not wrapped to avoid wrappers exposing these
328  * easy-to-get-wrong methods because passing in the wrong value for 'save' is
329  * guaranteed to cause a memory issue down the line. Either the wrappers
330  * didn't use malloc to allocate the memory or the memory isn't actually
331  * persisted because a temporary array is used that doesn't persist like this
332  * method expects.
333 
334  void SetArray(T* array, vtkIdType size, int save); \
335  void SetArray(T* array, vtkIdType size, int save, int deleteMethod) */
336 
337 #endif // header guard
338 
339 // This portion must be OUTSIDE the include blockers. This is used to tell
340 // libraries other than vtkCommonCore that instantiations of
341 // vtkAOSDataArrayTemplate can be found externally. This prevents each library
342 // from instantiating these on their own.
343 #ifdef VTK_AOS_DATA_ARRAY_TEMPLATE_INSTANTIATING
344 #define VTK_AOS_DATA_ARRAY_TEMPLATE_INSTANTIATE(T) \
345  template class VTKCOMMONCORE_EXPORT vtkAOSDataArrayTemplate< T >
346 #elif defined(VTK_USE_EXTERN_TEMPLATE)
347 #ifndef VTK_AOS_DATA_ARRAY_TEMPLATE_EXTERN
348 #define VTK_AOS_DATA_ARRAY_TEMPLATE_EXTERN
349 #ifdef _MSC_VER
350 #pragma warning (push)
351 // The following is needed when the vtkAOSDataArrayTemplate is declared
352 // dllexport and is used from another class in vtkCommonCore
353 #pragma warning (disable: 4910) // extern and dllexport incompatible
354 #endif
356  extern template class VTKCOMMONCORE_EXPORT vtkAOSDataArrayTemplate)
357 #ifdef _MSC_VER
358 #pragma warning (pop)
359 #endif
360 #endif // VTK_AOS_DATA_ARRAY_TEMPLATE_EXTERN
361 
362 // The following clause is only for MSVC 2008 and 2010
363 #elif defined(_MSC_VER) && !defined(VTK_BUILD_SHARED_LIBS)
364 #pragma warning (push)
365 
366 // C4091: 'extern ' : ignored on left of 'int' when no variable is declared
367 #pragma warning (disable: 4091)
368 
369 // Compiler-specific extension warning.
370 #pragma warning (disable: 4231)
371 
372 // We need to disable warning 4910 and do an extern dllexport
373 // anyway. When deriving vtkCharArray and other types from an
374 // instantiation of this template the compiler does an explicit
375 // instantiation of the base class. From outside the vtkCommon
376 // library we block this using an extern dllimport instantiation.
377 // For classes inside vtkCommon we should be able to just do an
378 // extern instantiation, but VS 2008 complains about missing
379 // definitions. We cannot do an extern dllimport inside vtkCommon
380 // since the symbols are local to the dll. An extern dllexport
381 // seems to be the only way to convince VS 2008 to do the right
382 // thing, so we just disable the warning.
383 #pragma warning (disable: 4910) // extern and dllexport incompatible
384 
385 // Use an "extern explicit instantiation" to give the class a DLL
386 // interface. This is a compiler-specific extension.
388  extern template class VTKCOMMONCORE_EXPORT vtkAOSDataArrayTemplate)
389 
390 #pragma warning (pop)
391 
392 #endif
393 
394 // VTK-HeaderTest-Exclude: vtkAOSDataArrayTemplate.h
void SetValue(vtkIdType valueIdx, ValueType value)
Set the value at valueIdx to value.
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...
virtual void ShallowCopy(vtkDataArray *other)
Create a shallow copy of other into this, if possible.
vtkIdType InsertNextTuple(vtkIdType srcTupleIdx, vtkAbstractArray *source) override
Insert the tuple from srcTupleIdx in the source array at the end of this array.
Abstract superclass for all arrays.
ValueType * GetPointer(vtkIdType valueIdx)
Default implementation raises a runtime error.
void SetTypedComponent(vtkIdType tupleIdx, int comp, ValueType value)
Set component comp of the tuple at tupleIdx to value.
vtkTemplateTypeMacro(SelfType, vtkDataArray) enum
Compile time access to the VTK type identifier.
VTK_NEWINSTANCE vtkArrayIterator * NewIterator() override
Subclasses must override this method and provide the right kind of templated vtkArrayIteratorTemplate...
virtual int GetDataType()=0
Return the underlying data type.
virtual int GetArrayType()
Method for type-checking in FastDownCast implementations.
int vtkIdType
Definition: vtkType.h:345
Base interface for all typed vtkDataArray subclasses.
void SetVoidArray(void *, vtkIdType, int) override
Default implementation raises a runtime error.
vtkAOSDataArrayTemplate< ValueTypeT > SelfType
virtual void Fill(double value)
Fill all values of a data array with a specified value.
void GetTypedTuple(vtkIdType tupleIdx, ValueType *tuple) const
Copy the tuple at tupleIdx into tuple.
void InsertTuple(vtkIdType dstTupleIdx, vtkIdType srcTupleIdx, vtkAbstractArray *source) override
Insert the tuple at srcTupleIdx in the source array into this array at dstTupleIdx.
double * GetTuple(vtkIdType tupleIdx) override
Get the data tuple at tupleIdx.
#define vtkExternTemplateMacro(decl)
A macro to declare extern templates for all numerical types.
Definition: vtkType.h:411
Array-Of-Structs implementation of vtkGenericDataArray.
list of point or cell ids
Definition: vtkIdList.h:30
bool AllocateTuples(vtkIdType numTuples)
Allocate space for numTuples.
ValueType GetValue(vtkIdType valueIdx) const
Get the value at valueIdx.
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:48
void SetValue(vtkIdType valueIdx, ValueType value)
Set the value at valueIdx to value.
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...
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.
bool HasStandardMemoryLayout() override
Returns true if this array uses the standard memory layout defined in the VTK user guide...
void DataChanged() override
Tell the array explicitly that the data has changed.
#define VTK_NEWINSTANCE
#define vtkInstantiateTemplateMacro(decl)
A macro to instantiate a template over all numerical types.
Definition: vtkType.h:391
void * GetVoidPointer(vtkIdType valueIdx) override
Default implementation raises a runtime error.
int GetArrayType() override
Method for type-checking in FastDownCast implementations.
void save(Archiver &ar, const vtkUnicodeString &str, const unsigned int vtkNotUsed(version))
vtkArrayDownCast_TemplateFastCastMacro(vtkTypedDataArray) template< class Scalar > inline typename vtkTypedDataArray< Scalar >
boost::graph_traits< vtkGraph *>::vertex_descriptor source(boost::graph_traits< vtkGraph * >::edge_descriptor e, vtkGraph *)
void DataElementChanged(vtkIdType)
Tell the array explicitly that a single data element has changed.
virtual void FillTypedComponent(int compIdx, ValueType value)
Set component comp of all tuples to value.
static vtkAOSDataArrayTemplate< ValueType > * FastDownCast(vtkAbstractArray *source)
Perform a fast, safe cast from a vtkAbstractArray to a vtkAOSDataArrayTemplate.
ValueType GetTypedComponent(vtkIdType tupleIdx, int comp) const
Get component comp of the tuple at tupleIdx.
void SetTypedTuple(vtkIdType tupleIdx, const ValueType *tuple)
Set this array&#39;s tuple at tupleIdx to the values in tuple.
void InsertComponent(vtkIdType tupleIdx, int compIdx, double value) override
Insert value at the location specified by tupleIdx and compIdx.
ValueType * Iterator
Legacy support for array-of-structs value iteration.
static vtkObject * New()
Create an object with Debug turned off, modified time initialized to zero, and reference counting on...
bool ReallocateTuples(vtkIdType numTuples)
Allocate space for numTuples.
vtkIdType InsertNextTuple(vtkIdType srcTupleIdx, vtkAbstractArray *source) override
Insert the tuple from srcTupleIdx in the source array at the end of this 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...
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 InsertTuple(vtkIdType dstTupleIdx, vtkIdType srcTupleIdx, vtkAbstractArray *source) override
Insert the tuple at srcTupleIdx in the source array into this array at dstTupleIdx.
Template defining traits of native types used by VTK.
Definition: vtkTypeTraits.h:29
vtkBuffer< ValueType > * Buffer