Thanks to visit codestin.com
Credit goes to vtk.org

VTK  9.5.20251004
vtkSOADataArrayTemplate.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2// SPDX-License-Identifier: BSD-3-Clause
22#ifndef vtkSOADataArrayTemplate_h
23#define vtkSOADataArrayTemplate_h
24
25#include "vtkBuffer.h"
26#include "vtkCommonCoreModule.h" // For export macro
27#include "vtkCompiler.h" // for VTK_USE_EXTERN_TEMPLATE
28#include "vtkGenericDataArray.h"
29
30// The export macro below makes no sense, but is necessary for older compilers
31// when we export instantiations of this class from vtkCommonCore.
32VTK_ABI_NAMESPACE_BEGIN
33template <class ValueTypeT>
34class VTKCOMMONCORE_EXPORT vtkSOADataArrayTemplate
35 : public vtkGenericDataArray<vtkSOADataArrayTemplate<ValueTypeT>, ValueTypeT,
36 vtkArrayTypes::SoADataArrayTemplate>
37{
40
41public:
44 using typename Superclass::ArrayTypeTag;
45 using typename Superclass::DataTypeTag;
46 using typename Superclass::ValueType;
47
49 {
52 VTK_DATA_ARRAY_ALIGNED_FREE = vtkAbstractArray::VTK_DATA_ARRAY_ALIGNED_FREE,
53 VTK_DATA_ARRAY_USER_DEFINED = vtkAbstractArray::VTK_DATA_ARRAY_USER_DEFINED
54 };
55
57
59
63 {
64 vtkIdType tupleIdx;
65 int comp;
66 this->GetTupleIndexFromValueIndex(valueIdx, tupleIdx, comp);
67 return this->GetTypedComponent(tupleIdx, comp);
68 }
70
72
75 void SetValue(vtkIdType valueIdx, ValueType value)
76 {
77 vtkIdType tupleIdx;
78 int comp;
79 this->GetTupleIndexFromValueIndex(valueIdx, tupleIdx, comp);
80 this->SetTypedComponent(tupleIdx, comp, value);
81 }
83
87 void GetTypedTuple(vtkIdType tupleIdx, ValueType* tuple) const
88 {
89 if (this->StorageType == StorageTypeEnum::SOA)
90 {
91 for (size_t cc = 0; cc < this->Data.size(); cc++)
92 {
93 tuple[cc] = this->Data[cc]->GetBuffer()[tupleIdx];
94 }
95 }
96 else
97 {
98 ValueType* buffer = this->AoSData->GetBuffer();
99 std::copy(buffer + tupleIdx * this->GetNumberOfComponents(),
100 buffer + (tupleIdx + 1) * this->GetNumberOfComponents(), tuple);
101 }
102 }
103
107 void SetTypedTuple(vtkIdType tupleIdx, const ValueType* tuple)
108 {
109 if (this->StorageType == StorageTypeEnum::SOA)
110 {
111 for (size_t cc = 0; cc < this->Data.size(); ++cc)
112 {
113 this->Data[cc]->GetBuffer()[tupleIdx] = tuple[cc];
114 }
115 }
116 else
117 {
118 ValueType* buffer = this->AoSData->GetBuffer();
119 std::copy(tuple, tuple + this->GetNumberOfComponents(),
120 buffer + tupleIdx * this->GetNumberOfComponents());
121 }
122 }
123
127 ValueType GetTypedComponent(vtkIdType tupleIdx, int comp) const
128 {
129 if (this->StorageType == StorageTypeEnum::SOA)
130 {
131 return this->Data[comp]->GetBuffer()[tupleIdx];
132 }
133 return this->AoSData->GetBuffer()[tupleIdx * this->GetNumberOfComponents() + comp];
134 }
135
139 void SetTypedComponent(vtkIdType tupleIdx, int comp, ValueType value)
140 {
141 if (this->StorageType == StorageTypeEnum::SOA)
142 {
143 this->Data[comp]->GetBuffer()[tupleIdx] = value;
144 }
145 else
146 {
147 this->AoSData->GetBuffer()[tupleIdx * this->GetNumberOfComponents() + comp] = value;
148 }
149 }
150
154 void FillTypedComponent(int compIdx, ValueType value) override;
155
169 void SetArray(int comp, VTK_ZEROCOPY ValueType* array, vtkIdType size, bool updateMaxId = false,
170 bool save = false, int deleteMethod = VTK_DATA_ARRAY_FREE);
171
179 void SetArrayFreeFunction(void (*callback)(void*)) override;
180
187 void SetArrayFreeFunction(int comp, void (*callback)(void*));
188
194
199 void* GetVoidPointer(vtkIdType valueIdx) override;
200
205 void ExportToVoidPointer(void* ptr) override;
206
208 void SetNumberOfComponents(int numComps) override;
209 void ShallowCopy(vtkDataArray* other) override;
210
211 // Reimplemented for efficiency:
213 vtkIdType dstStart, vtkIdType n, vtkIdType srcStart, vtkAbstractArray* source) override;
214 // MSVC doesn't like 'using' here (error C2487). Just forward instead:
215 // using Superclass::InsertTuples;
216 void InsertTuples(vtkIdList* dstIds, vtkIdList* srcIds, vtkAbstractArray* source) override
217 {
218 this->Superclass::InsertTuples(dstIds, srcIds, source);
219 }
221 vtkIdType dstStart, vtkIdList* srcIds, vtkAbstractArray* source) override
222 {
223 this->Superclass::InsertTuplesStartingAt(dstStart, srcIds, source);
224 }
225
226#ifndef __VTK_WRAP__
227 // helper method for vtkDataArray.cxx DeepCopyWorker () operator
229#endif
230
231protected:
234
239 bool AllocateTuples(vtkIdType numTuples);
240
246
247 std::vector<vtkBuffer<ValueType>*> Data;
249
256 {
258 SOA
259 };
261
263
264private:
266 void operator=(const vtkSOADataArrayTemplate&) = delete;
267
268 void GetTupleIndexFromValueIndex(vtkIdType valueIdx, vtkIdType& tupleIdx, int& comp) const
269 {
270 tupleIdx = valueIdx / this->NumberOfComponents;
271 comp = valueIdx % this->NumberOfComponents;
272 }
273
274 friend class vtkGenericDataArray<SelfType, ValueType, ArrayTypeTag::value>;
275};
276
277// Declare vtkArrayDownCast implementations for SoA containers:
279
280VTK_ABI_NAMESPACE_END
281#endif // header guard
282
283// This portion must be OUTSIDE the include blockers. This is used to tell
284// libraries other than vtkCommonCore that instantiations of
285// vtkSOADataArrayTemplate can be found externally. This prevents each library
286// from instantiating these on their own.
287#ifdef VTK_SOA_DATA_ARRAY_TEMPLATE_INSTANTIATING
288#define VTK_SOA_DATA_ARRAY_TEMPLATE_INSTANTIATE(T) \
289 namespace vtkDataArrayPrivate \
290 { \
291 VTK_ABI_NAMESPACE_BEGIN \
292 VTK_INSTANTIATE_VALUERANGE_ARRAYTYPE(vtkSOADataArrayTemplate<T>, double); \
293 VTK_ABI_NAMESPACE_END \
294 } \
295 VTK_ABI_NAMESPACE_BEGIN \
296 template class VTKCOMMONCORE_EXPORT vtkSOADataArrayTemplate<T>; \
297 VTK_ABI_NAMESPACE_END
298
299#elif defined(VTK_USE_EXTERN_TEMPLATE)
300#ifndef VTK_SOA_DATA_ARRAY_TEMPLATE_EXTERN
301#define VTK_SOA_DATA_ARRAY_TEMPLATE_EXTERN
302#ifdef _MSC_VER
303#pragma warning(push)
304// The following is needed when the vtkSOADataArrayTemplate is declared
305// dllexport and is used from another class in vtkCommonCore
306#pragma warning(disable : 4910) // extern and dllexport incompatible
307#endif
308VTK_ABI_NAMESPACE_BEGIN
309vtkExternTemplateMacro(extern template class VTKCOMMONCORE_EXPORT vtkSOADataArrayTemplate);
310VTK_ABI_NAMESPACE_END
311
312namespace vtkDataArrayPrivate
313{
314VTK_ABI_NAMESPACE_BEGIN
315
316// These are instantiated in vtkSOADataArrayTemplateInstantiate${i}.cxx
330
331VTK_ABI_NAMESPACE_END
332} // namespace vtkDataArrayPrivate
333
334#ifdef _MSC_VER
335#pragma warning(pop)
336#endif
337#endif // VTK_SOA_DATA_ARRAY_TEMPLATE_EXTERN
338
339// The following clause is only for MSVC 2008 and 2010
340#elif defined(_MSC_VER) && !defined(VTK_BUILD_SHARED_LIBS)
341#pragma warning(push)
342
343// C4091: 'extern ' : ignored on left of 'int' when no variable is declared
344#pragma warning(disable : 4091)
345
346// Compiler-specific extension warning.
347#pragma warning(disable : 4231)
348
349// We need to disable warning 4910 and do an extern dllexport
350// anyway. When deriving new arrays from an
351// instantiation of this template the compiler does an explicit
352// instantiation of the base class. From outside the vtkCommon
353// library we block this using an extern dllimport instantiation.
354// For classes inside vtkCommon we should be able to just do an
355// extern instantiation, but VS 2008 complains about missing
356// definitions. We cannot do an extern dllimport inside vtkCommon
357// since the symbols are local to the dll. An extern dllexport
358// seems to be the only way to convince VS 2008 to do the right
359// thing, so we just disable the warning.
360#pragma warning(disable : 4910) // extern and dllexport incompatible
361
362// Use an "extern explicit instantiation" to give the class a DLL
363// interface. This is a compiler-specific extension.
364VTK_ABI_NAMESPACE_BEGIN
365vtkInstantiateTemplateMacro(extern template class VTKCOMMONCORE_EXPORT vtkSOADataArrayTemplate);
366VTK_ABI_NAMESPACE_END
367
368#pragma warning(pop)
369
370#endif
371
372// VTK-HeaderTest-Exclude: vtkSOADataArrayTemplate.h
Abstract superclass for all arrays.
std::integral_constant< int, vtkArrayTypes::AbstractArray > ArrayTypeTag
std::integral_constant< int, VTK_OPAQUE > DataTypeTag
Abstract superclass to iterate over elements in an vtkAbstractArray.
internal storage class used by vtkSOADataArrayTemplate, vtkAOSDataArrayTemplate, and others.
Definition vtkBuffer.h:30
abstract superclass for arrays of numeric data
Base interface for all typed vtkDataArray subclasses.
list of point or cell ids
Definition vtkIdList.h:133
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.
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...
void InsertTuplesStartingAt(vtkIdType dstStart, vtkIdList *srcIds, vtkAbstractArray *source) override
See documentation from parent class.
vtkBuffer< ValueType > * AoSData
static vtkSOADataArrayTemplate * New()
bool AllocateTuples(vtkIdType numTuples)
Allocate space for numTuples.
StorageTypeEnum
Because we still need to support GetVoidPointer() for both reading from and writing to memory we may ...
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...
void CopyData(vtkSOADataArrayTemplate< ValueType > *src)
void SetNumberOfComponents(int numComps) override
Set/Get the dimension (n) of the components.
#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 VTK_DECLARE_VALUERANGE_ARRAYTYPE(ArrayType, ValueType)
#define vtkExternTemplateMacro(decl)
A macro to declare extern templates for all numerical types.
Definition vtkType.h:492
int vtkIdType
Definition vtkType.h:367
#define vtkInstantiateTemplateMacro(decl)
A macro to instantiate a template over all numerical types.
Definition vtkType.h:415
@ SoADataArrayTemplate
Definition vtkType.h:84
void save(Archiver &ar, const std::string &str, const unsigned int version)
#define VTK_ZEROCOPY
#define VTK_NEWINSTANCE