VTK
vtkSOADataArrayTemplate.h
Go to the documentation of this file.
1/*=========================================================================
2
3 Program: Visualization Toolkit
4 Module: vtkSOADataArrayTemplate.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 vtkSOADataArrayTemplate_h
32#define vtkSOADataArrayTemplate_h
33
34#include "vtkCommonCoreModule.h" // For export macro
35#include "vtkGenericDataArray.h"
36#include "vtkBuffer.h"
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.
40template <class ValueTypeT>
41class VTKCOMMONCORE_EXPORT vtkSOADataArrayTemplate :
42 public vtkGenericDataArray<vtkSOADataArrayTemplate<ValueTypeT>, ValueTypeT>
43{
46public:
49 typedef typename Superclass::ValueType ValueType;
50
52 {
55 };
56
58
60
63 inline ValueType GetValue(vtkIdType valueIdx) const
64 {
65 vtkIdType tupleIdx;
66 int comp;
67 this->GetTupleIndexFromValueIndex(valueIdx, tupleIdx, comp);
68 return this->GetTypedComponent(tupleIdx, comp);
69 }
71
73
76 inline void SetValue(vtkIdType valueIdx, ValueType value)
77 {
78 vtkIdType tupleIdx;
79 int comp;
80 this->GetTupleIndexFromValueIndex(valueIdx, tupleIdx, comp);
81 this->SetTypedComponent(tupleIdx, comp, value);
82 }
84
88 inline void GetTypedTuple(vtkIdType tupleIdx, ValueType* tuple) const
89 {
90 for (size_t cc=0; cc < this->Data.size(); cc++)
91 {
92 tuple[cc] = this->Data[cc]->GetBuffer()[tupleIdx];
93 }
94 }
95
99 inline void SetTypedTuple(vtkIdType tupleIdx, const ValueType* tuple)
100 {
101 for (size_t cc=0; cc < this->Data.size(); ++cc)
102 {
103 this->Data[cc]->GetBuffer()[tupleIdx] = tuple[cc];
104 }
105 }
106
110 inline ValueType GetTypedComponent(vtkIdType tupleIdx, int comp) const
111 {
112 return this->Data[comp]->GetBuffer()[tupleIdx];
113 }
114
118 inline void SetTypedComponent(vtkIdType tupleIdx, int comp, ValueType value)
119 {
120 this->Data[comp]->GetBuffer()[tupleIdx] = value;
121 }
122
136 void SetArray(int comp, ValueType* array, vtkIdType size,
137 bool updateMaxId = false, bool save=false,
138 int deleteMethod=VTK_DATA_ARRAY_FREE);
139
145
150 void *GetVoidPointer(vtkIdType valueIdx) VTK_OVERRIDE;
151
156 void ExportToVoidPointer(void *ptr) VTK_OVERRIDE;
157
159
167 {
168 if (source)
169 {
170 switch (source->GetArrayType())
171 {
173 if (vtkDataTypesCompare(source->GetDataType(),
175 {
176 return static_cast<vtkSOADataArrayTemplate<ValueType>*>(source);
177 }
178 break;
179 }
180 }
181 return NULL;
182 }
184
187 void SetNumberOfComponents(int numComps) VTK_OVERRIDE;
188 void ShallowCopy(vtkDataArray *other) VTK_OVERRIDE;
189
190 // Reimplemented for efficiency:
191 void InsertTuples(vtkIdType dstStart, vtkIdType n, vtkIdType srcStart,
192 vtkAbstractArray* source) VTK_OVERRIDE;
193 // MSVC doesn't like 'using' here (error C2487). Just forward instead:
194 // using Superclass::InsertTuples;
195 void InsertTuples(vtkIdList *dstIds, vtkIdList *srcIds,
196 vtkAbstractArray *source) VTK_OVERRIDE
197 { this->Superclass::InsertTuples(dstIds, srcIds, source); }
198
199protected:
202
207 bool AllocateTuples(vtkIdType numTuples);
208
213 bool ReallocateTuples(vtkIdType numTuples);
214
217
218 double NumberOfComponentsReciprocal;
219
220private:
221 vtkSOADataArrayTemplate(const vtkSOADataArrayTemplate&) VTK_DELETE_FUNCTION;
222 void operator=(const vtkSOADataArrayTemplate&) VTK_DELETE_FUNCTION;
223
224 inline void GetTupleIndexFromValueIndex(vtkIdType valueIdx,
225 vtkIdType& tupleIdx, int& comp) const
226 {
227 tupleIdx = static_cast<vtkIdType>(valueIdx *
228 this->NumberOfComponentsReciprocal);
229 comp = valueIdx - (tupleIdx * this->NumberOfComponents);
230 }
231
232 friend class vtkGenericDataArray<vtkSOADataArrayTemplate<ValueTypeT>,
233 ValueTypeT>;
234};
235
236// Declare vtkArrayDownCast implementations for SoA containers:
238
239#endif // header guard
240
241// This portion must be OUTSIDE the include blockers. This is used to tell
242// libraries other than vtkCommonCore that instantiations of
243// vtkSOADataArrayTemplate can be found externally. This prevents each library
244// from instantiating these on their own.
245#ifdef VTK_SOA_DATA_ARRAY_TEMPLATE_INSTANTIATING
246#define VTK_SOA_DATA_ARRAY_TEMPLATE_INSTANTIATE(T) \
247 template class VTKCOMMONCORE_EXPORT vtkSOADataArrayTemplate< T >
248#elif defined(VTK_USE_EXTERN_TEMPLATE)
249#ifndef VTK_SOA_DATA_ARRAY_TEMPLATE_EXTERN
250#define VTK_SOA_DATA_ARRAY_TEMPLATE_EXTERN
251#ifdef _MSC_VER
252#pragma warning (push)
253// The following is needed when the vtkSOADataArrayTemplate is declared
254// dllexport and is used from another class in vtkCommonCore
255#pragma warning (disable: 4910) // extern and dllexport incompatible
256#endif
258 extern template class VTKCOMMONCORE_EXPORT vtkSOADataArrayTemplate)
259#ifdef _MSC_VER
260#pragma warning (pop)
261#endif
262#endif // VTK_SOA_DATA_ARRAY_TEMPLATE_EXTERN
263
264// The following clause is only for MSVC 2008 and 2010
265#elif defined(_MSC_VER) && !defined(VTK_BUILD_SHARED_LIBS)
266#pragma warning (push)
267
268// C4091: 'extern ' : ignored on left of 'int' when no variable is declared
269#pragma warning (disable: 4091)
270
271// Compiler-specific extension warning.
272#pragma warning (disable: 4231)
273
274// We need to disable warning 4910 and do an extern dllexport
275// anyway. When deriving new arrays from an
276// instantiation of this template the compiler does an explicit
277// instantiation of the base class. From outside the vtkCommon
278// library we block this using an extern dllimport instantiation.
279// For classes inside vtkCommon we should be able to just do an
280// extern instantiation, but VS 2008 complains about missing
281// definitions. We cannot do an extern dllimport inside vtkCommon
282// since the symbols are local to the dll. An extern dllexport
283// seems to be the only way to convince VS 2008 to do the right
284// thing, so we just disable the warning.
285#pragma warning (disable: 4910) // extern and dllexport incompatible
286
287// Use an "extern explicit instantiation" to give the class a DLL
288// interface. This is a compiler-specific extension.
290 extern template class VTKCOMMONCORE_EXPORT vtkSOADataArrayTemplate)
291
292#pragma warning (pop)
293
294#endif
295
296// VTK-HeaderTest-Exclude: vtkSOADataArrayTemplate.h
Abstract superclass for all arrays.
Abstract superclass to iterate over elements in an vtkAbstractArray.
internal storage class used by vtkSOADataArrayTemplate, vtkAOSDataArrayTemplate, and others.
Definition: vtkBuffer.h:33
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:55
Base interface for all typed vtkDataArray subclasses.
vtkTemplateTypeMacro(SelfType, vtkDataArray) enum
Compile time access to the VTK type identifier.
list of point or cell ids
Definition: vtkIdList.h:37
Struct-Of-Arrays implementation of vtkGenericDataArray.
void ExportToVoidPointer(void *ptr) override
Export a copy of the data in AoS ordering to the preallocated memory buffer.
static vtkSOADataArrayTemplate< ValueType > * FastDownCast(vtkAbstractArray *source)
Perform a fast, safe cast from a vtkAbstractArray to a vtkDataArray.
ValueType GetTypedComponent(vtkIdType tupleIdx, int comp) const
Get component comp of the tuple at tupleIdx.
void SetValue(vtkIdType valueIdx, ValueType value)
Set the value at valueIdx to value.
VTK_NEWINSTANCE vtkArrayIterator * NewIterator() override
Subclasses must override this method and provide the right kind of templated vtkArrayIteratorTemplate...
void SetTypedComponent(vtkIdType tupleIdx, int comp, ValueType value)
Set component comp of the tuple at tupleIdx to value.
ValueType GetValue(vtkIdType valueIdx) const
Get the value at valueIdx.
~vtkSOADataArrayTemplate() override
ValueType * GetComponentArrayPointer(int comp)
Return a pointer to a contiguous block of memory containing all values for a particular components (i...
void * GetVoidPointer(vtkIdType valueIdx) override
Use of this method is discouraged, it creates a deep copy of the data into a contiguous AoS-ordered b...
int GetArrayType() override
Method for type-checking in FastDownCast implementations.
static vtkSOADataArrayTemplate * New()
vtkSOADataArrayTemplate< ValueTypeT > SelfType
void GetTypedTuple(vtkIdType tupleIdx, ValueType *tuple) const
Copy the tuple at tupleIdx into tuple.
void SetArray(int comp, ValueType *array, vtkIdType size, bool updateMaxId=false, bool save=false, int deleteMethod=VTK_DATA_ARRAY_FREE)
Use this API to pass externally allocated memory to this instance.
void SetTypedTuple(vtkIdType tupleIdx, const ValueType *tuple)
Set this array's tuple at tupleIdx to the values in tuple.
void SetTypedComponent(vtkIdType tupleIdx, int compIdx, ValueType value)
Set component compIdx of the tuple at tupleIdx to value.
ValueType GetTypedComponent(vtkIdType tupleIdx, int compIdx) const
Get component compIdx of the tuple at tupleIdx.
@ vector
Definition: vtkX3D.h:237
@ value
Definition: vtkX3D.h:220
@ 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 *)
#define vtkExternTemplateMacro(decl)
A macro to declare extern templates for all numerical types.
Definition: vtkType.h:345
int vtkIdType
Definition: vtkType.h:287
#define vtkInstantiateTemplateMacro(decl)
A macro to instantiate a template over all numerical types.
Definition: vtkType.h:325
vtkArrayDownCast_TemplateFastCastMacro(vtkTypedDataArray) template< class Scalar > inline typename vtkTypedDataArray< Scalar >
void save(Archiver &ar, const vtkUnicodeString &str, const unsigned int vtkNotUsed(version))
#define VTK_NEWINSTANCE