VTK  9.1.0
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=========================================================================*/
28#ifndef vtkSOADataArrayTemplate_h
29#define vtkSOADataArrayTemplate_h
30
31#include "vtkBuffer.h"
32#include "vtkCommonCoreModule.h" // For export macro
33#include "vtkCompiler.h" // for VTK_USE_EXTERN_TEMPLATE
34#include "vtkGenericDataArray.h"
35
36// The export macro below makes no sense, but is necessary for older compilers
37// when we export instantiations of this class from vtkCommonCore.
38template <class ValueTypeT>
39class VTKCOMMONCORE_EXPORT vtkSOADataArrayTemplate
40 : public vtkGenericDataArray<vtkSOADataArrayTemplate<ValueTypeT>, ValueTypeT>
41{
43
44public:
47 typedef typename Superclass::ValueType ValueType;
48
50 {
53 VTK_DATA_ARRAY_ALIGNED_FREE = vtkAbstractArray::VTK_DATA_ARRAY_ALIGNED_FREE,
54 VTK_DATA_ARRAY_USER_DEFINED = vtkAbstractArray::VTK_DATA_ARRAY_USER_DEFINED
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
126 void FillTypedComponent(int compIdx, ValueType value) override;
127
141 void SetArray(int comp, VTK_ZEROCOPY ValueType* array, vtkIdType size, bool updateMaxId = false,
142 bool save = false, int deleteMethod = VTK_DATA_ARRAY_FREE);
143
151 void SetArrayFreeFunction(void (*callback)(void*)) override;
152
159 void SetArrayFreeFunction(int comp, void (*callback)(void*));
160
166
171 void* GetVoidPointer(vtkIdType valueIdx) override;
172
177 void ExportToVoidPointer(void* ptr) override;
178
179#ifndef __VTK_WRAP__
181
189#endif
190
193 void SetNumberOfComponents(int numComps) override;
194 void ShallowCopy(vtkDataArray* other) override;
195
196 // Reimplemented for efficiency:
198 vtkIdType dstStart, vtkIdType n, vtkIdType srcStart, vtkAbstractArray* source) override;
199 // MSVC doesn't like 'using' here (error C2487). Just forward instead:
200 // using Superclass::InsertTuples;
201 void InsertTuples(vtkIdList* dstIds, vtkIdList* srcIds, vtkAbstractArray* source) override
202 {
203 this->Superclass::InsertTuples(dstIds, srcIds, source);
204 }
205
206protected:
209
214 bool AllocateTuples(vtkIdType numTuples);
215
221
222 std::vector<vtkBuffer<ValueType>*> Data;
224
225private:
227 void operator=(const vtkSOADataArrayTemplate&) = delete;
228
229 inline void GetTupleIndexFromValueIndex(vtkIdType valueIdx, vtkIdType& tupleIdx, int& comp) const
230 {
231 tupleIdx = valueIdx / this->NumberOfComponents;
232 comp = valueIdx % this->NumberOfComponents;
233 }
234
235 friend class vtkGenericDataArray<vtkSOADataArrayTemplate<ValueTypeT>, ValueTypeT>;
236};
237
238// Declare vtkArrayDownCast implementations for SoA containers:
240
241#endif // header guard
242
243// This portion must be OUTSIDE the include blockers. This is used to tell
244// libraries other than vtkCommonCore that instantiations of
245// vtkSOADataArrayTemplate can be found externally. This prevents each library
246// from instantiating these on their own.
247#ifdef VTK_SOA_DATA_ARRAY_TEMPLATE_INSTANTIATING
248#define VTK_SOA_DATA_ARRAY_TEMPLATE_INSTANTIATE(T) \
249 namespace vtkDataArrayPrivate \
250 { \
251 VTK_INSTANTIATE_VALUERANGE_ARRAYTYPE(vtkSOADataArrayTemplate<T>, double); \
252 } \
253 template class VTKCOMMONCORE_EXPORT vtkSOADataArrayTemplate<T>
254
255#elif defined(VTK_USE_EXTERN_TEMPLATE)
256#ifndef VTK_SOA_DATA_ARRAY_TEMPLATE_EXTERN
257#define VTK_SOA_DATA_ARRAY_TEMPLATE_EXTERN
258#ifdef _MSC_VER
259#pragma warning(push)
260// The following is needed when the vtkSOADataArrayTemplate is declared
261// dllexport and is used from another class in vtkCommonCore
262#pragma warning(disable : 4910) // extern and dllexport incompatible
263#endif
264vtkExternTemplateMacro(extern template class VTKCOMMONCORE_EXPORT vtkSOADataArrayTemplate);
265#ifdef _MSC_VER
266#pragma warning(pop)
267#endif
268#endif // VTK_SOA_DATA_ARRAY_TEMPLATE_EXTERN
269
270// The following clause is only for MSVC 2008 and 2010
271#elif defined(_MSC_VER) && !defined(VTK_BUILD_SHARED_LIBS)
272#pragma warning(push)
273
274// C4091: 'extern ' : ignored on left of 'int' when no variable is declared
275#pragma warning(disable : 4091)
276
277// Compiler-specific extension warning.
278#pragma warning(disable : 4231)
279
280// We need to disable warning 4910 and do an extern dllexport
281// anyway. When deriving new arrays from an
282// instantiation of this template the compiler does an explicit
283// instantiation of the base class. From outside the vtkCommon
284// library we block this using an extern dllimport instantiation.
285// For classes inside vtkCommon we should be able to just do an
286// extern instantiation, but VS 2008 complains about missing
287// definitions. We cannot do an extern dllimport inside vtkCommon
288// since the symbols are local to the dll. An extern dllexport
289// seems to be the only way to convince VS 2008 to do the right
290// thing, so we just disable the warning.
291#pragma warning(disable : 4910) // extern and dllexport incompatible
292
293// Use an "extern explicit instantiation" to give the class a DLL
294// interface. This is a compiler-specific extension.
295vtkInstantiateTemplateMacro(extern template class VTKCOMMONCORE_EXPORT vtkSOADataArrayTemplate);
296
297#pragma warning(pop)
298
299#endif
300
301// VTK-HeaderTest-Exclude: vtkSOADataArrayTemplate.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:159
Base interface for all typed vtkDataArray subclasses.
list of point or cell ids
Definition: vtkIdList.h:140
Struct-Of-Arrays implementation of vtkGenericDataArray.
void ShallowCopy(vtkDataArray *other) override
Create a shallow copy of other into this, if possible.
void ExportToVoidPointer(void *ptr) override
Export a copy of the data in AoS ordering to the preallocated memory buffer.
Superclass::ValueType ValueType
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.
bool ReallocateTuples(vtkIdType numTuples)
Allocate space for numTuples.
void SetValue(vtkIdType valueIdx, ValueType value)
Set the value at valueIdx to value.
vtkTemplateTypeMacro(SelfType, GenericDataArrayType)
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 FillTypedComponent(int compIdx, ValueType value) override
Set component comp of all tuples to value.
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 SetArrayFreeFunction(int comp, void(*callback)(void *))
This method allows the user to specify a custom free function to be called when the array is dealloca...
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...
vtkBuffer< ValueType > * AoSCopy
static vtkSOADataArrayTemplate * New()
bool AllocateTuples(vtkIdType numTuples)
Allocate space for numTuples.
vtkSOADataArrayTemplate< ValueTypeT > SelfType
void GetTypedTuple(vtkIdType tupleIdx, ValueType *tuple) const
Copy the tuple at tupleIdx into tuple.
std::vector< vtkBuffer< ValueType > * > Data
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 SetArrayFreeFunction(void(*callback)(void *)) override
This method allows the user to specify a custom free function to be called when the array is dealloca...
void SetTypedTuple(vtkIdType tupleIdx, const ValueType *tuple)
Set this array's tuple at tupleIdx to the values in tuple.
vtkArrayIterator * NewIterator() override
Subclasses must override this method and provide the right kind of templated vtkArrayIteratorTemplate...
int GetArrayType() const override
Method for type-checking in FastDownCast implementations.
void SetNumberOfComponents(int numComps) override
Set/Get the dimension (n) of the components.
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.
@ value
Definition: vtkX3D.h:226
@ size
Definition: vtkX3D.h:259
vtkInstantiateTemplateMacro(extern template class VTKCOMMONCORE_EXPORT vtkArrayIteratorTemplate)
boost::graph_traits< vtkGraph * >::vertex_descriptor source(boost::graph_traits< vtkGraph * >::edge_descriptor e, vtkGraph *)
vtkExternTemplateMacro(extern template class VTKCOMMONCORE_EXPORT vtkSOADataArrayTemplate)
vtkArrayDownCast_TemplateFastCastMacro(vtkSOADataArrayTemplate)
int vtkIdType
Definition: vtkType.h:332
void save(Archiver &ar, const std::string &str, const unsigned int vtkNotUsed(version))
#define VTK_ZEROCOPY
#define VTK_NEWINSTANCE