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 =========================================================================*/
34 #ifndef vtkAOSDataArrayTemplate_h
35 #define vtkAOSDataArrayTemplate_h
36 
37 #include "vtkCommonCoreModule.h" // For export macro
38 #include "vtkGenericDataArray.h"
39 #include "vtkBuffer.h" // For storage buffer.
40 
41 // The export macro below makes no sense, but is necessary for older compilers
42 // when we export instantiations of this class from vtkCommonCore.
43 template <class ValueTypeT>
44 class VTKCOMMONCORE_EXPORT vtkAOSDataArrayTemplate :
45  public vtkGenericDataArray<vtkAOSDataArrayTemplate<ValueTypeT>, ValueTypeT>
46 {
49 public:
51  vtkTemplateTypeMacro(SelfType, GenericDataArrayType)
52  typedef typename Superclass::ValueType ValueType;
53 
55  {
58  };
59 
60  static vtkAOSDataArrayTemplate* New();
61 
65  inline ValueType GetValue(vtkIdType valueIdx) const
66  {
67  return this->Buffer->GetBuffer()[valueIdx];
68  }
69 
73  inline void SetValue(vtkIdType valueIdx, ValueType value)
74  {
75  this->Buffer->GetBuffer()[valueIdx] = value;
76  }
77 
79 
82  inline void GetTypedTuple(vtkIdType tupleIdx, ValueType* tuple) const
83  {
84  const vtkIdType valueIdx = tupleIdx * this->NumberOfComponents;
85  std::copy(this->Buffer->GetBuffer() + valueIdx,
86  this->Buffer->GetBuffer() + valueIdx + this->NumberOfComponents,
87  tuple);
88  }
90 
92 
95  inline void SetTypedTuple(vtkIdType tupleIdx, const ValueType* tuple)
96  {
97  const vtkIdType valueIdx = tupleIdx * this->NumberOfComponents;
98  std::copy(tuple, tuple + this->NumberOfComponents,
99  this->Buffer->GetBuffer() + valueIdx);
100  }
102 
106  inline ValueType GetTypedComponent(vtkIdType tupleIdx, int comp) const
107  {
108  return this->Buffer->GetBuffer()[this->NumberOfComponents*tupleIdx + comp];
109  }
110 
112 
115  inline void SetTypedComponent(vtkIdType tupleIdx, int comp, ValueType value)
116  {
117  const vtkIdType valueIdx = tupleIdx * this->NumberOfComponents + comp;
118  this->SetValue(valueIdx, value);
119  }
121 
123 
128  ValueType* WritePointer(vtkIdType valueIdx, vtkIdType numValues);
129  void* WriteVoidPointer(vtkIdType valueIdx, vtkIdType numValues) VTK_OVERRIDE;
131 
133 
140  ValueType* GetPointer(vtkIdType valueIdx);
141  void* GetVoidPointer(vtkIdType valueIdx) VTK_OVERRIDE;
143 
145 
156  void SetArray(ValueType* array, vtkIdType size, int save, int deleteMethod);
157  void SetArray(ValueType* array, vtkIdType size, int save);
158  void SetVoidArray(void* array, vtkIdType size, int save) VTK_OVERRIDE;
159  void SetVoidArray(void* array, vtkIdType size, int save,
160  int deleteMethod) VTK_OVERRIDE;
162 
174 
179  typedef ValueType* Iterator;
180  Iterator Begin() { return Iterator(this->GetVoidPointer(0)); }
181  Iterator End() { return Iterator(this->GetVoidPointer(this->MaxId + 1)); }
182 
184 
193  {
194  if (source)
195  {
196  switch (source->GetArrayType())
197  {
199  if (vtkDataTypesCompare(source->GetDataType(),
201  {
202  return static_cast<vtkAOSDataArrayTemplate<ValueType>*>(source);
203  }
204  break;
205  }
206  }
207  return NULL;
208  }
210 
213  bool HasStandardMemoryLayout() VTK_OVERRIDE { return true; }
214  void ShallowCopy(vtkDataArray *other) VTK_OVERRIDE;
215 
217 
221  VTK_LEGACY(void GetTupleValue(vtkIdType tupleIdx, ValueType *tuple));
222  VTK_LEGACY(void SetTupleValue(vtkIdType tupleIdx, const ValueType *tuple));
223  VTK_LEGACY(void InsertTupleValue(vtkIdType tupleIdx, const ValueType *tuple));
224  VTK_LEGACY(vtkIdType InsertNextTupleValue(const ValueType *tuple));
226 
227  // Reimplemented for efficiency:
228  void InsertTuples(vtkIdType dstStart, vtkIdType n, vtkIdType srcStart,
229  vtkAbstractArray* source) VTK_OVERRIDE;
230  // MSVC doesn't like 'using' here (error C2487). Just forward instead:
231  // using Superclass::InsertTuples;
232  void InsertTuples(vtkIdList *dstIds, vtkIdList *srcIds,
233  vtkAbstractArray *source) VTK_OVERRIDE
234  { this->Superclass::InsertTuples(dstIds, srcIds, source); }
235 
236 protected:
238  ~vtkAOSDataArrayTemplate() VTK_OVERRIDE;
239 
244  bool AllocateTuples(vtkIdType numTuples);
245 
250  bool ReallocateTuples(vtkIdType numTuples);
251 
253 
254 private:
255  vtkAOSDataArrayTemplate(const vtkAOSDataArrayTemplate&) VTK_DELETE_FUNCTION;
256  void operator=(const vtkAOSDataArrayTemplate&) VTK_DELETE_FUNCTION;
257 
258  friend class vtkGenericDataArray<vtkAOSDataArrayTemplate<ValueTypeT>,
259  ValueTypeT>;
260 
261 };
262 
263 // Declare vtkArrayDownCast implementations for AoS containers:
265 
266 // This macro is used by the subclasses to create dummy
267 // declarations for these functions such that the wrapper
268 // can see them. The wrappers ignore vtkAOSDataArrayTemplate.
269 #define vtkCreateWrappedArrayInterface(T) \
270  int GetDataType(); \
271  void GetTypedTuple(vtkIdType i, T* tuple); \
272  void SetTypedTuple(vtkIdType i, const T* tuple); \
273  void InsertTypedTuple(vtkIdType i, const T* tuple); \
274  vtkIdType InsertNextTypedTuple(const T* tuple); \
275  T GetValue(vtkIdType id); \
276  void SetValue(vtkIdType id, T value); \
277  void SetNumberOfValues(vtkIdType number); \
278  void InsertValue(vtkIdType id, T f); \
279  vtkIdType InsertNextValue(T f); \
280  T *GetValueRange(int comp); \
281  T *GetValueRange(); \
282  T* WritePointer(vtkIdType id, vtkIdType number); \
283  T* GetPointer(vtkIdType id)/*; \
284 
285  * These methods are not wrapped to avoid wrappers exposing these
286  * easy-to-get-wrong methods because passing in the wrong value for 'save' is
287  * guaranteed to cause a memory issue down the line. Either the wrappers
288  * didn't use malloc to allocate the memory or the memory isn't actually
289  * persisted because a temporary array is used that doesn't persist like this
290  * method expects.
291 
292  void SetArray(T* array, vtkIdType size, int save); \
293  void SetArray(T* array, vtkIdType size, int save, int deleteMethod) */
294 
295 #endif // header guard
296 
297 // This portion must be OUTSIDE the include blockers. This is used to tell
298 // libraries other than vtkCommonCore that instantiations of
299 // vtkAOSDataArrayTemplate can be found externally. This prevents each library
300 // from instantiating these on their own.
301 #ifdef VTK_AOS_DATA_ARRAY_TEMPLATE_INSTANTIATING
302 #define VTK_AOS_DATA_ARRAY_TEMPLATE_INSTANTIATE(T) \
303  template class VTKCOMMONCORE_EXPORT vtkAOSDataArrayTemplate< T >
304 #elif defined(VTK_USE_EXTERN_TEMPLATE)
305 #ifndef VTK_AOS_DATA_ARRAY_TEMPLATE_EXTERN
306 #define VTK_AOS_DATA_ARRAY_TEMPLATE_EXTERN
307 #ifdef _MSC_VER
308 #pragma warning (push)
309 // The following is needed when the vtkAOSDataArrayTemplate is declared
310 // dllexport and is used from another class in vtkCommonCore
311 #pragma warning (disable: 4910) // extern and dllexport incompatible
312 #endif
314  extern template class VTKCOMMONCORE_EXPORT vtkAOSDataArrayTemplate)
315 #ifdef _MSC_VER
316 #pragma warning (pop)
317 #endif
318 #endif // VTK_AOS_DATA_ARRAY_TEMPLATE_EXTERN
319 
320 // The following clause is only for MSVC 2008 and 2010
321 #elif defined(_MSC_VER) && !defined(VTK_BUILD_SHARED_LIBS)
322 #pragma warning (push)
323 
324 // C4091: 'extern ' : ignored on left of 'int' when no variable is declared
325 #pragma warning (disable: 4091)
326 
327 // Compiler-specific extension warning.
328 #pragma warning (disable: 4231)
329 
330 // We need to disable warning 4910 and do an extern dllexport
331 // anyway. When deriving vtkCharArray and other types from an
332 // instantiation of this template the compiler does an explicit
333 // instantiation of the base class. From outside the vtkCommon
334 // library we block this using an extern dllimport instantiation.
335 // For classes inside vtkCommon we should be able to just do an
336 // extern instantiation, but VS 2008 complains about missing
337 // definitions. We cannot do an extern dllimport inside vtkCommon
338 // since the symbols are local to the dll. An extern dllexport
339 // seems to be the only way to convince VS 2008 to do the right
340 // thing, so we just disable the warning.
341 #pragma warning (disable: 4910) // extern and dllexport incompatible
342 
343 // Use an "extern explicit instantiation" to give the class a DLL
344 // interface. This is a compiler-specific extension.
346  extern template class VTKCOMMONCORE_EXPORT vtkAOSDataArrayTemplate)
347 
348 #pragma warning (pop)
349 
350 #endif
351 
352 // VTK-HeaderTest-Exclude: vtkAOSDataArrayTemplate.h
void SetValue(vtkIdType valueIdx, ValueType value)
Set the value at valueIdx to value.
abstract base class for most VTK objects
Definition: vtkObject.h:59
virtual void ShallowCopy(vtkDataArray *other)
Create a shallow copy of other into this, if possible.
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...
ValueType GetValue(vtkIdType valueIdx) const
Get the value at valueIdx.
virtual int GetDataType()=0
Return the underlying data type.
virtual int GetArrayType()
Method for type-checking in FastDownCast implementations.
int vtkIdType
Definition: vtkType.h:287
Base interface for all typed vtkDataArray subclasses.
void SetVoidArray(void *, vtkIdType, int) override
Default implementation raises a runtime error.
vtkAOSDataArrayTemplate< ValueTypeT > SelfType
internal storage class used by vtkSOADataArrayTemplate, vtkAOSDataArrayTemplate, and others...
Definition: vtkBuffer.h:32
#define vtkExternTemplateMacro(decl)
A macro to declare extern templates for all numerical types.
Definition: vtkType.h:345
Array-Of-Structs implementation of vtkGenericDataArray.
list of point or cell ids
Definition: vtkIdList.h:36
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:54
void SetValue(vtkIdType valueIdx, ValueType value)
Set the value at valueIdx to value.
void GetTypedTuple(vtkIdType tupleIdx, ValueType *tuple) const
Copy the tuple at tupleIdx into tuple.
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
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 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:325
void * GetVoidPointer(vtkIdType valueIdx) override
Default implementation raises a runtime error.
int GetArrayType() override
Method for type-checking in FastDownCast implementations.
ValueType GetTypedComponent(vtkIdType tupleIdx, int comp) const
Get component comp of the tuple at tupleIdx.
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.
static vtkAOSDataArrayTemplate< ValueType > * FastDownCast(vtkAbstractArray *source)
Perform a fast, safe cast from a vtkAbstractArray to a vtkAOSDataArrayTemplate.
void SetTypedTuple(vtkIdType tupleIdx, const ValueType *tuple)
Set this array's tuple at tupleIdx to the values in tuple.
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...
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...
Template defining traits of native types used by VTK.
Definition: vtkTypeTraits.h:32