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:
52  typedef typename Superclass::ValueType ValueType;
53 
55  {
58  };
59 
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 
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
vtkAbstractArray::DeleteMethod
DeleteMethod
Definition: vtkAbstractArray.h:334
vtkGenericDataArray::ValueType
ValueTypeT ValueType
Definition: vtkGenericDataArray.h:81
vtkGenericDataArray::SetValue
void SetValue(vtkIdType valueIdx, ValueType value)
Set the value at valueIdx to value.
Definition: vtkGenericDataArray.h:113
vtkTypeTraits
Template defining traits of native types used by VTK.
Definition: vtkTypeTraits.h:32
vtkAOSDataArrayTemplate::WritePointer
ValueType * WritePointer(vtkIdType valueIdx, vtkIdType numValues)
Get the address of a particular data index.
vtkAOSDataArrayTemplate::InsertTuples
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,...
vtkAOSDataArrayTemplate::Begin
Iterator Begin()
Definition: vtkAOSDataArrayTemplate.h:180
vtkX3D::value
@ value
Definition: vtkX3D.h:220
vtkIdType
int vtkIdType
Definition: vtkType.h:287
vtkGenericDataArray::GetVoidPointer
void * GetVoidPointer(vtkIdType valueIdx) override
Default implementation raises a runtime error.
vtkAOSDataArrayTemplate::SetArray
void SetArray(ValueType *array, vtkIdType size, int save)
vtkAOSDataArrayTemplate::SelfType
vtkAOSDataArrayTemplate< ValueTypeT > SelfType
Definition: vtkAOSDataArrayTemplate.h:50
save
void save(Archiver &ar, const vtkUnicodeString &str, const unsigned int vtkNotUsed(version))
Definition: vtkVariantBoostSerialization.h:65
vtkAOSDataArrayTemplate::SetVoidArray
void SetVoidArray(void *array, vtkIdType size, int save) override
vtkAOSDataArrayTemplate::New
static vtkAOSDataArrayTemplate * New()
vtkGenericDataArray
Base interface for all typed vtkDataArray subclasses.
Definition: vtkGenericDataArray.h:78
vtkAbstractArray::AoSDataArrayTemplate
@ AoSDataArrayTemplate
Definition: vtkAbstractArray.h:609
vtkAOSDataArrayTemplate::GetTupleValue
void GetTupleValue(vtkIdType tupleIdx, ValueType *tuple)
vtkAOSDataArrayTemplate::GetPointer
ValueType * GetPointer(vtkIdType valueIdx)
Get the address of a particular data index.
vtkDataArray
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:55
vtkAOSDataArrayTemplate::ShallowCopy
void ShallowCopy(vtkDataArray *other) override
Create a shallow copy of other into this, if possible.
vtkAOSDataArrayTemplate::SetArray
void SetArray(ValueType *array, vtkIdType size, int save, int deleteMethod)
This method lets the user specify data to be held by the array.
vtkAOSDataArrayTemplate::SetTypedComponent
void SetTypedComponent(vtkIdType tupleIdx, int comp, ValueType value)
Set component comp of the tuple at tupleIdx to value.
Definition: vtkAOSDataArrayTemplate.h:115
vtkGenericDataArray::DataChanged
void DataChanged() override
Tell the array explicitly that the data has changed.
vtkAOSDataArrayTemplate::GetTypedTuple
void GetTypedTuple(vtkIdType tupleIdx, ValueType *tuple) const
Copy the tuple at tupleIdx into tuple.
Definition: vtkAOSDataArrayTemplate.h:82
vtkAOSDataArrayTemplate::SetTupleValue
void SetTupleValue(vtkIdType tupleIdx, const ValueType *tuple)
source
boost::graph_traits< vtkGraph * >::vertex_descriptor source(boost::graph_traits< vtkGraph * >::edge_descriptor e, vtkGraph *)
Definition: vtkBoostGraphAdapter.h:822
vtkBuffer
internal storage class used by vtkSOADataArrayTemplate, vtkAOSDataArrayTemplate, and others.
Definition: vtkBuffer.h:33
vtkBuffer.h
vtkAOSDataArrayTemplate::GetValue
ValueType GetValue(vtkIdType valueIdx) const
Get the value at valueIdx.
Definition: vtkAOSDataArrayTemplate.h:65
vtkExternTemplateMacro
#define vtkExternTemplateMacro(decl)
A macro to declare extern templates for all numerical types.
Definition: vtkType.h:345
vtkAOSDataArrayTemplate::NewIterator
VTK_NEWINSTANCE vtkArrayIterator * NewIterator() override
Subclasses must override this method and provide the right kind of templated vtkArrayIteratorTemplate...
vtkGenericDataArray::vtkTemplateTypeMacro
vtkTemplateTypeMacro(SelfType, vtkDataArray) enum
Compile time access to the VTK type identifier.
Definition: vtkGenericDataArray.h:82
vtkGenericDataArray.h
vtkIdList
list of point or cell ids
Definition: vtkIdList.h:37
vtkX3D::size
@ size
Definition: vtkX3D.h:253
vtkAOSDataArrayTemplate::End
Iterator End()
Definition: vtkAOSDataArrayTemplate.h:181
vtkAOSDataArrayTemplate::~vtkAOSDataArrayTemplate
~vtkAOSDataArrayTemplate() override
vtkAOSDataArrayTemplate::DataElementChanged
void DataElementChanged(vtkIdType)
Tell the array explicitly that a single data element has changed.
Definition: vtkAOSDataArrayTemplate.h:173
vtkAOSDataArrayTemplate::SetValue
void SetValue(vtkIdType valueIdx, ValueType value)
Set the value at valueIdx to value.
Definition: vtkAOSDataArrayTemplate.h:73
vtkAOSDataArrayTemplate::GetArrayType
int GetArrayType() override
Method for type-checking in FastDownCast implementations.
Definition: vtkAOSDataArrayTemplate.h:211
vtkAOSDataArrayTemplate::SetVoidArray
void SetVoidArray(void *array, vtkIdType size, int save, int deleteMethod) override
vtkAbstractArray
Abstract superclass for all arrays.
Definition: vtkAbstractArray.h:79
vtkAOSDataArrayTemplate::InsertNextTupleValue
vtkIdType InsertNextTupleValue(const ValueType *tuple)
vtkInstantiateTemplateMacro
#define vtkInstantiateTemplateMacro(decl)
A macro to instantiate a template over all numerical types.
Definition: vtkType.h:325
vtkAOSDataArrayTemplate::GetTypedComponent
ValueType GetTypedComponent(vtkIdType tupleIdx, int comp) const
Get component comp of the tuple at tupleIdx.
Definition: vtkAOSDataArrayTemplate.h:106
vtkArrayIterator
Abstract superclass to iterate over elements in an vtkAbstractArray.
Definition: vtkArrayIterator.h:50
vtkArrayDownCast_TemplateFastCastMacro
vtkArrayDownCast_TemplateFastCastMacro(vtkTypedDataArray) template< class Scalar > inline typename vtkTypedDataArray< Scalar >
Definition: vtkTypedDataArray.h:191
vtkAOSDataArrayTemplate::InsertTupleValue
void InsertTupleValue(vtkIdType tupleIdx, const ValueType *tuple)
vtkAOSDataArrayTemplate::WriteVoidPointer
void * WriteVoidPointer(vtkIdType valueIdx, vtkIdType numValues) override
Get the address of a particular data index.
vtkAOSDataArrayTemplate::InsertTuples
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...
Definition: vtkAOSDataArrayTemplate.h:232
vtkAOSDataArrayTemplate::FastDownCast
static vtkAOSDataArrayTemplate< ValueType > * FastDownCast(vtkAbstractArray *source)
Perform a fast, safe cast from a vtkAbstractArray to a vtkAOSDataArrayTemplate.
Definition: vtkAOSDataArrayTemplate.h:192
vtkAOSDataArrayTemplate
Array-Of-Structs implementation of vtkGenericDataArray.
Definition: vtkAOSDataArrayTemplate.h:46
vtkAOSDataArrayTemplate::vtkAOSDataArrayTemplate
vtkAOSDataArrayTemplate()
VTK_NEWINSTANCE
#define VTK_NEWINSTANCE
Definition: vtkWrappingHints.h:30
vtkAOSDataArrayTemplate::GetVoidPointer
void * GetVoidPointer(vtkIdType valueIdx) override
Return a void pointer.
vtkAOSDataArrayTemplate::SetTypedTuple
void SetTypedTuple(vtkIdType tupleIdx, const ValueType *tuple)
Set this array's tuple at tupleIdx to the values in tuple.
Definition: vtkAOSDataArrayTemplate.h:95
vtkAOSDataArrayTemplate::Iterator
ValueType * Iterator
Legacy support for array-of-structs value iteration.
Definition: vtkAOSDataArrayTemplate.h:179
vtkAbstractArray::NumberOfComponents
int NumberOfComponents
Definition: vtkAbstractArray.h:653