VTK  9.2.6
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 }
206 vtkIdType dstStart, vtkIdList* srcIds, vtkAbstractArray* source) override
207 {
208 this->Superclass::InsertTuplesStartingAt(dstStart, srcIds, source);
209 }
210
211protected:
214
219 bool AllocateTuples(vtkIdType numTuples);
220
226
227 std::vector<vtkBuffer<ValueType>*> Data;
229
230private:
232 void operator=(const vtkSOADataArrayTemplate&) = delete;
233
234 inline void GetTupleIndexFromValueIndex(vtkIdType valueIdx, vtkIdType& tupleIdx, int& comp) const
235 {
236 tupleIdx = valueIdx / this->NumberOfComponents;
237 comp = valueIdx % this->NumberOfComponents;
238 }
239
240 friend class vtkGenericDataArray<vtkSOADataArrayTemplate<ValueTypeT>, ValueTypeT>;
241};
242
243// Declare vtkArrayDownCast implementations for SoA containers:
245
246#endif // header guard
247
248// This portion must be OUTSIDE the include blockers. This is used to tell
249// libraries other than vtkCommonCore that instantiations of
250// vtkSOADataArrayTemplate can be found externally. This prevents each library
251// from instantiating these on their own.
252#ifdef VTK_SOA_DATA_ARRAY_TEMPLATE_INSTANTIATING
253#define VTK_SOA_DATA_ARRAY_TEMPLATE_INSTANTIATE(T) \
254 namespace vtkDataArrayPrivate \
255 { \
256 VTK_INSTANTIATE_VALUERANGE_ARRAYTYPE(vtkSOADataArrayTemplate<T>, double); \
257 } \
258 template class VTKCOMMONCORE_EXPORT vtkSOADataArrayTemplate<T>
259
260#elif defined(VTK_USE_EXTERN_TEMPLATE)
261#ifndef VTK_SOA_DATA_ARRAY_TEMPLATE_EXTERN
262#define VTK_SOA_DATA_ARRAY_TEMPLATE_EXTERN
263#ifdef _MSC_VER
264#pragma warning(push)
265// The following is needed when the vtkSOADataArrayTemplate is declared
266// dllexport and is used from another class in vtkCommonCore
267#pragma warning(disable : 4910) // extern and dllexport incompatible
268#endif
269vtkExternTemplateMacro(extern template class VTKCOMMONCORE_EXPORT vtkSOADataArrayTemplate);
270#ifdef _MSC_VER
271#pragma warning(pop)
272#endif
273#endif // VTK_SOA_DATA_ARRAY_TEMPLATE_EXTERN
274
275// The following clause is only for MSVC 2008 and 2010
276#elif defined(_MSC_VER) && !defined(VTK_BUILD_SHARED_LIBS)
277#pragma warning(push)
278
279// C4091: 'extern ' : ignored on left of 'int' when no variable is declared
280#pragma warning(disable : 4091)
281
282// Compiler-specific extension warning.
283#pragma warning(disable : 4231)
284
285// We need to disable warning 4910 and do an extern dllexport
286// anyway. When deriving new arrays from an
287// instantiation of this template the compiler does an explicit
288// instantiation of the base class. From outside the vtkCommon
289// library we block this using an extern dllimport instantiation.
290// For classes inside vtkCommon we should be able to just do an
291// extern instantiation, but VS 2008 complains about missing
292// definitions. We cannot do an extern dllimport inside vtkCommon
293// since the symbols are local to the dll. An extern dllexport
294// seems to be the only way to convince VS 2008 to do the right
295// thing, so we just disable the warning.
296#pragma warning(disable : 4910) // extern and dllexport incompatible
297
298// Use an "extern explicit instantiation" to give the class a DLL
299// interface. This is a compiler-specific extension.
300vtkInstantiateTemplateMacro(extern template class VTKCOMMONCORE_EXPORT vtkSOADataArrayTemplate);
301
302#pragma warning(pop)
303
304#endif
305
306// VTK-HeaderTest-Exclude: vtkSOADataArrayTemplate.h
Abstract superclass for all arrays.
virtual void InsertTuples(vtkIdList *dstIds, vtkIdList *srcIds, vtkAbstractArray *source)=0
Copy the tuples indexed in srcIds from the source array to the tuple locations indexed by dstIds in t...
virtual void InsertTuplesStartingAt(vtkIdType dstStart, vtkIdList *srcIds, vtkAbstractArray *source)=0
Copy the tuples indexed in srcIds from the source array to the tuple locations starting at index dstS...
Abstract superclass to iterate over elements in an vtkAbstractArray.
internal storage class used by vtkSOADataArrayTemplate, vtkAOSDataArrayTemplate, and others.
Definition vtkBuffer.h:35
abstract superclass for arrays of numeric data
Base interface for all typed vtkDataArray subclasses.
list of point or cell ids
Definition vtkIdList.h:31
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
See documentation from parent class.
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
See documentation from parent class.
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
void InsertTuplesStartingAt(vtkIdType dstStart, vtkIdList *srcIds, vtkAbstractArray *source) override
See documentation from parent class.
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.
#define vtkArrayDownCast_TemplateFastCastMacro(ArrayT)
Same as vtkArrayDownCast_FastCastMacro, but treats ArrayT as a single-parameter template (the paramet...
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:395
int vtkIdType
Definition vtkType.h:332
#define vtkInstantiateTemplateMacro(decl)
A macro to instantiate a template over all numerical types.
Definition vtkType.h:378
void save(Archiver &ar, const std::string &str, const unsigned int vtkNotUsed(version))
#define VTK_ZEROCOPY
#define VTK_NEWINSTANCE