VTK  9.7.20261004
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
21
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 "vtkDeprecation.h" // For VTK_DEPRECATED_IN_9_7_0
29#include "vtkGenericDataArray.h"
30#include "vtkWrappingHints.h" // For VTK_NEWINSTANCE
31
32// The export macro below makes no sense, but is necessary for older compilers
33// when we export instantiations of this class from vtkCommonCore.
34VTK_ABI_NAMESPACE_BEGIN
35template <class ValueTypeT>
36class VTKCOMMONCORE_EXPORT vtkSOADataArrayTemplate
37#ifndef __VTK_WRAP__
38 : public vtkGenericDataArray<vtkSOADataArrayTemplate<ValueTypeT>, ValueTypeT,
39 vtkArrayTypes::VTK_SOA_DATA_ARRAY>
40{
41 using GenericDataArrayType = vtkGenericDataArray<vtkSOADataArrayTemplate<ValueTypeT>, ValueTypeT,
43#else // Fake the superclass for the wrappers.
44 : public vtkDataArray
45{
46 using GenericDataArrayType = vtkDataArray;
47#endif
48
49public:
51 vtkTemplateTypeMacro(SelfType, GenericDataArrayType);
52#ifndef __VTK_WRAP__
53 using typename Superclass::ArrayTypeTag;
54 using typename Superclass::DataTypeTag;
55 using typename Superclass::ValueType;
56#else
57 using ValueType = ValueTypeT;
58#endif
59
67
69
71
75 VTK_EXPECTS(0 <= valueIdx && valueIdx < GetNumberOfValues())
76 {
77 auto div = std::div(valueIdx, static_cast<vtkIdType>(this->NumberOfComponents));
78 return this->GetTypedComponent(div.quot, div.rem);
79 }
80
81
83
86 void SetValue(vtkIdType valueIdx, ValueType value)
87 VTK_EXPECTS(0 <= valueIdx && valueIdx < GetNumberOfValues())
88 {
89 auto div = std::div(valueIdx, static_cast<vtkIdType>(this->NumberOfComponents));
90 this->SetTypedComponent(div.quot, div.rem, value);
91 }
92
93
97 void GetTypedTuple(vtkIdType tupleIdx, ValueType* tuple) const
98 VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
99
103 void SetTypedTuple(vtkIdType tupleIdx, const ValueType* tuple)
104 VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples())
105 {
106 for (size_t cc = 0; cc < this->Data.size(); ++cc)
107 {
108 this->Data[cc]->GetBuffer()[tupleIdx] = tuple[cc];
109 }
110 }
111
115 ValueType GetTypedComponent(vtkIdType tupleIdx, int comp) const
116 VTK_EXPECTS(0 <= tupleIdx && GetNumberOfComponents() * tupleIdx + comp < GetNumberOfValues())
117 VTK_EXPECTS(0 <= comp && comp < GetNumberOfComponents());
118
122 void SetTypedComponent(vtkIdType tupleIdx, int comp, ValueType value)
123 VTK_EXPECTS(0 <= tupleIdx && GetNumberOfComponents() * tupleIdx + comp < GetNumberOfValues())
124 VTK_EXPECTS(0 <= comp && comp < GetNumberOfComponents());
125
129 void FillTypedComponent(int compIdx, ValueType value) override;
130
144 void SetArray(int comp, VTK_ZEROCOPY ValueType* array, vtkIdType size, bool updateMaxId = false,
145 bool save = false, int deleteMethod = VTK_DATA_ARRAY_FREE);
146
147#ifndef __VTK_WRAP__
156 void SetBuffer(int comp, vtkBuffer<ValueType>* buffer, bool updateMaxId = false);
157#endif
158
168 void SetBuffer(int comp, vtkAbstractBuffer* buffer, bool updateMaxId = false);
169
177 void SetArrayFreeFunction(void (*callback)(void*)) override;
178
185 void SetArrayFreeFunction(int comp, void (*callback)(void*));
186
192
207
213#ifdef __VTK_WRAP__
215#else
217#endif // __VTK_WRAP__
218
223 void* GetVoidPointer(vtkIdType valueIdx) override;
224
229 VTK_DEPRECATED_IN_9_7_0("Use DeepCopy with an vtkAOSDataArrayTemplate array")
230 void ExportToVoidPointer(void* ptr) override;
231
238 {
239 AOS VTK_DEPRECATED_IN_9_7_0("The storage will always be SOA going forward.") = 0,
240 SOA VTK_DEPRECATED_IN_9_7_0("The storage will always be SOA going forward.") = 1
241 };
242 VTK_DEPRECATED_IN_9_7_0("The storage will always be SOA going forward.")
243 StorageTypeEnum GetStorageType() { return static_cast<StorageTypeEnum>(1); }
244
245 VTK_DEPRECATED_IN_9_7_0("Use vtk::DataArrayValueRange, or the array directly")
247 void SetNumberOfComponents(int numComps) override;
248 void ShallowCopy(vtkDataArray* other) override;
250
251 // Reimplemented for efficiency:
253 vtkIdType dstStart, vtkIdType n, vtkIdType srcStart, vtkAbstractArray* source) override;
254 // MSVC doesn't like 'using' here (error C2487). Just forward instead:
255 // using Superclass::InsertTuples;
256 void InsertTuples(vtkIdList* dstIds, vtkIdList* srcIds, vtkAbstractArray* source) override
257 {
258 this->Superclass::InsertTuples(dstIds, srcIds, source);
259 }
261 vtkIdType dstStart, vtkIdList* srcIds, vtkAbstractArray* source) override
262 {
263 this->Superclass::InsertTuplesStartingAt(dstStart, srcIds, source);
264 }
265
266#ifndef __VTK_WRAP__
267 // helper method for vtkDataArray.cxx DeepCopyWorker () operator
269#endif
270
271#ifdef __VTK_WRAP__
272 // Add APIs inherited from vtkGenericDataArray, which is excluded from wrapping
274#endif
275
276protected:
279
284 VTK_DEPRECATED_IN_9_7_0("No longer needed")
285 bool AllocateTuples(vtkIdType numTuples);
286
292
294
295private:
297 void operator=(const vtkSOADataArrayTemplate&) = delete;
298
299 friend class vtkGenericDataArray<SelfType, ValueType, ArrayTypeTag::value>;
300};
301
302// Declare vtkArrayDownCast implementations for SoA containers:
304
305VTK_ABI_NAMESPACE_END
306
307// This macro is used by the subclasses to create dummy
308// declarations for these functions such that the wrapper
309// can see them. The wrappers ignore vtkSOADataArrayTemplate.
310#define vtkCreateSOAWrappedArrayInterface(T) \
311 vtkCreateWrappedArrayReadInterface(T); \
312 vtkCreateWrappedArrayWriteInterface(T); \
313 T* GetComponentArrayPointer(int id); \
314 vtkAbstractBuffer* GetComponentBuffer(int comp); \
315 void SetArray(int comp, VTK_ZEROCOPY T* array, vtkIdType size, bool updateMaxId, bool save, \
316 int deleteMethod); \
317 void SetBuffer(int comp, vtkAbstractBuffer* buffer, bool updateMaxId);
318
319#endif // header guard
320
321// This portion must be OUTSIDE the include blockers. This is used to tell
322// libraries other than vtkCommonCore that instantiations of
323// vtkSOADataArrayTemplate can be found externally. This prevents each library
324// from instantiating these on their own.
325#ifdef VTK_SOA_DATA_ARRAY_TEMPLATE_INSTANTIATING
326#define VTK_SOA_DATA_ARRAY_TEMPLATE_INSTANTIATE(T) \
327 namespace vtkDataArrayPrivate \
328 { \
329 VTK_ABI_NAMESPACE_BEGIN \
330 VTK_INSTANTIATE_VALUERANGE_ARRAYTYPE(vtkSOADataArrayTemplate<T>, double); \
331 VTK_ABI_NAMESPACE_END \
332 } \
333 VTK_ABI_NAMESPACE_BEGIN \
334 template class VTKCOMMONCORE_EXPORT vtkSOADataArrayTemplate<T>; \
335 VTK_ABI_NAMESPACE_END
336// This portion must be OUTSIDE the include blockers. This is used to tell
337// libraries other than vtkCommonCore that instantiations of
338// vtkSOADataArrayTemplate can be found externally. This prevents each library
339// from instantiating these on their own.
340#define VTK_SOA_DATA_ARRAY_TEMPLATE_INSTANTIATE_VALUERANGE(T) \
341 namespace vtkDataArrayPrivate \
342 { \
343 VTK_ABI_NAMESPACE_BEGIN \
344 VTK_INSTANTIATE_VALUERANGE_ARRAYTYPE(vtkSOADataArrayTemplate<T>, T); \
345 VTK_ABI_NAMESPACE_END \
346 }
347// MinGW GCC does not reliably export inline member functions (such as IsTypeOf
348// defined by vtkTemplateTypeMacro above) when using template class __declspec(dllexport)
349// with extern template. This guard is applied here rather than in other VTK places
350// with #elif defined(VTK_USE_EXTERN_TEMPLATE) because only these three DataArrayTemplate
351// classes combine extern template with vtkTemplateTypeMacro inline functions in the class
352// body; other VTK template classes using this pattern (e.g. vtkConstantArray,
353// vtkAffineArray) use vtkImplicitArrayTypeMacro instead and were not observed with this
354// MinGW issue.
355#elif defined(VTK_USE_EXTERN_TEMPLATE) && !defined(__MINGW32__)
356#ifndef VTK_SOA_DATA_ARRAY_TEMPLATE_EXTERN
357#define VTK_SOA_DATA_ARRAY_TEMPLATE_EXTERN
358#ifdef _MSC_VER
359#pragma warning(push)
360// The following is needed when the vtkSOADataArrayTemplate is declared
361// dllexport and is used from another class in vtkCommonCore
362#pragma warning(disable : 4910) // extern and dllexport incompatible
363#endif
364VTK_ABI_NAMESPACE_BEGIN
365vtkExternTemplateMacro(extern template class VTKCOMMONCORE_EXPORT vtkSOADataArrayTemplate);
366VTK_ABI_NAMESPACE_END
367
368namespace vtkDataArrayPrivate
369{
370VTK_ABI_NAMESPACE_BEGIN
371
372// These are instantiated in vtkGenericDataArrayValueRange${i}.cxx
377// These are instantiated in vtkSOADataArrayTemplateInstantiate${i}.cxx
391
392VTK_ABI_NAMESPACE_END
393} // namespace vtkDataArrayPrivate
394
395#ifdef _MSC_VER
396#pragma warning(pop)
397#endif
398#endif // VTK_SOA_DATA_ARRAY_TEMPLATE_EXTERN
399
400// The following clause is only for MSVC 2008 and 2010
401#elif defined(_MSC_VER) && !defined(VTK_BUILD_SHARED_LIBS)
402#pragma warning(push)
403
404// C4091: 'extern ' : ignored on left of 'int' when no variable is declared
405#pragma warning(disable : 4091)
406
407// Compiler-specific extension warning.
408#pragma warning(disable : 4231)
409
410// We need to disable warning 4910 and do an extern dllexport
411// anyway. When deriving new arrays from an
412// instantiation of this template the compiler does an explicit
413// instantiation of the base class. From outside the vtkCommon
414// library we block this using an extern dllimport instantiation.
415// For classes inside vtkCommon we should be able to just do an
416// extern instantiation, but VS 2008 complains about missing
417// definitions. We cannot do an extern dllimport inside vtkCommon
418// since the symbols are local to the dll. An extern dllexport
419// seems to be the only way to convince VS 2008 to do the right
420// thing, so we just disable the warning.
421#pragma warning(disable : 4910) // extern and dllexport incompatible
422
423// Use an "extern explicit instantiation" to give the class a DLL
424// interface. This is a compiler-specific extension.
425VTK_ABI_NAMESPACE_BEGIN
426vtkInstantiateTemplateMacro(extern template class VTKCOMMONCORE_EXPORT vtkSOADataArrayTemplate);
427VTK_ABI_NAMESPACE_END
428
429#pragma warning(pop)
430
431#endif
432
433// VTK-HeaderTest-Exclude: vtkSOADataArrayTemplate.h
int GetNumberOfComponents() const
Set/Get the dimension (n) of the components.
vtkIdType GetNumberOfTuples() const
Get the number of complete tuples (a component group) in the array.
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...
std::integral_constant< int, VTK_OPAQUE > DataTypeTag
std::integral_constant< int, vtkArrayTypes::VTK_ABSTRACT_ARRAY > ArrayTypeTag
vtkIdType GetNumberOfValues() const
Get the total number of values in the array.
Abstract base class for vtkBuffer providing buffer protocol support.
Abstract superclass to iterate over elements in an vtkAbstractArray.
internal storage class used by vtkSOADataArrayTemplate, vtkAOSDataArrayTemplate, and others.
Definition vtkBuffer.h:32
create and manipulate ordered lists of objects
list of point or cell ids
Definition vtkIdList.h:135
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.
void SetBuffer(int comp, vtkAbstractBuffer *buffer, bool updateMaxId=false)
Use this API to pass an existing vtkAbstractBuffer to this instance.
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 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 SetBuffer(int comp, vtkBuffer< ValueType > *buffer, bool updateMaxId=false)
Use this API to pass an existing vtkBuffer to this instance.
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< ValueTypeT > * GetComponentBuffer(int comp)
Return the underlying buffer object for a particular component.
static vtkSOADataArrayTemplate * New()
bool AllocateTuples(vtkIdType numTuples)
Allocate space for numTuples.
std::integral_constant< int, vtkArrayTypes::VTK_ABSTRACT_ARRAY > ArrayTypeTag
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
vtkCollection * NewMemoryDescriptors() override
One descriptor per component, roled "component_0", "component_1", ...
vtkSOADataArrayTemplate< ValueTypeT > SelfType
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_DEPRECATED_IN_9_7_0(reason)
#define vtkCreateGenericWrappedArrayInterface(T)
#define VTK_DECLARE_VALUERANGE_ARRAYTYPE(ArrayType, ValueType)
#define vtkExternTemplateMacro(decl)
A macro to declare extern templates for all numerical types.
Definition vtkType.h:458
int vtkIdType
Definition vtkType.h:363
#define vtkInstantiateTemplateMacro(decl)
A macro to instantiate a template over all numerical types.
Definition vtkType.h:411
@ VTK_SOA_DATA_ARRAY
Definition vtkType.h:84
void save(Archiver &ar, const std::string &str, const unsigned int version)
#define VTK_EXPECTS(x)
#define VTK_ZEROCOPY
#define VTK_NEWINSTANCE