VTK  9.6.20260411
vtkScaledSOADataArrayTemplate.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
23
24#ifndef vtkScaledSOADataArrayTemplate_h
25#define vtkScaledSOADataArrayTemplate_h
26
27#include "vtkBuffer.h"
28#include "vtkBuild.h" // For VTK_BUILD_SHARED_LIBS
29#include "vtkCommonCoreModule.h" // For export macro
30#include "vtkCompiler.h" // for VTK_USE_EXTERN_TEMPLATE
31#include "vtkGenericDataArray.h"
32
33// The export macro below makes no sense, but is necessary for older compilers
34// when we export instantiations of this class from vtkCommonCore.
35VTK_ABI_NAMESPACE_BEGIN
36template <class ValueTypeT>
37class VTK_DEPRECATED_IN_9_7_0("Use vtkSOADataArrayTemplate and scale values yourself")
38 VTKCOMMONCORE_EXPORT vtkScaledSOADataArrayTemplate
39#ifndef __VTK_WRAP__
40 : public vtkGenericDataArray<vtkScaledSOADataArrayTemplate<ValueTypeT>, ValueTypeT,
41 /*vtkArrayTypes::VTK_SCALED_SOA_DATA_ARRAY*/ 7>
42{
44 ValueTypeT, /*vtkArrayTypes::VTK_SCALED_SOA_DATA_ARRAY*/ 7>;
45#else
46 : public vtkDataArray
47{
48 using GenericDataArrayType = vtkDataArray;
49#endif
50
51public:
53 vtkTemplateTypeMacro(SelfType, GenericDataArrayType);
54#ifndef __VTK_WRAP__
55 using typename Superclass::ArrayTypeTag;
56 using typename Superclass::DataTypeTag;
57 using typename Superclass::ValueType;
58#else
59 using ValueType = ValueTypeT;
60#endif
61
69
71
73
76 void SetScale(ValueType scale)
77 {
78 if (scale != this->Scale)
79 {
80 if (scale == 0)
81 {
82 vtkErrorMacro("Cannot set Scale to 0");
83 }
84 else
85 {
86 this->Scale = scale;
87 this->Modified();
88 }
89 }
90 }
91 ValueType GetScale() const { return this->Scale; }
93
95
99 VTK_EXPECTS(0 <= valueIdx && valueIdx < GetNumberOfValues())
100 {
101 vtkIdType tupleIdx;
102 int comp;
103 this->GetTupleIndexFromValueIndex(valueIdx, tupleIdx, comp);
104 return this->GetTypedComponent(tupleIdx, comp);
105 }
106
107
109
112 void SetValue(vtkIdType valueIdx, ValueType value)
113 VTK_EXPECTS(0 <= valueIdx && valueIdx < GetNumberOfValues())
114 {
115 vtkIdType tupleIdx;
116 int comp;
117 this->GetTupleIndexFromValueIndex(valueIdx, tupleIdx, comp);
118 this->SetTypedComponent(tupleIdx, comp, value);
119 }
120
121
125 void GetTypedTuple(vtkIdType tupleIdx, ValueType* tuple) const
126 VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples())
127 {
128 for (size_t cc = 0; cc < this->Data.size(); cc++)
129 {
130 tuple[cc] = this->Data[cc]->GetBuffer()[tupleIdx] * this->Scale;
131 }
132 }
133
137 void SetTypedTuple(vtkIdType tupleIdx, const ValueType* tuple)
138 VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples())
139 {
140 for (size_t cc = 0; cc < this->Data.size(); ++cc)
141 {
142 this->Data[cc]->GetBuffer()[tupleIdx] = tuple[cc] / this->Scale;
143 }
144 }
145
149 ValueType GetTypedComponent(vtkIdType tupleIdx, int comp) const
150 VTK_EXPECTS(0 <= tupleIdx && GetNumberOfComponents() * tupleIdx + comp < GetNumberOfValues())
151 VTK_EXPECTS(0 <= comp && comp < GetNumberOfComponents())
152 {
153 return this->Data[comp]->GetBuffer()[tupleIdx] * this->Scale;
154 }
155
159 void SetTypedComponent(vtkIdType tupleIdx, int comp, ValueType value)
160 VTK_EXPECTS(0 <= tupleIdx && GetNumberOfComponents() * tupleIdx + comp < GetNumberOfValues())
161 VTK_EXPECTS(0 <= comp && comp < GetNumberOfComponents())
162 {
163 this->Data[comp]->GetBuffer()[tupleIdx] = value / this->Scale;
164 }
165
169 void FillTypedComponent(int compIdx, ValueType value) override;
170
184 void SetArray(int comp, VTK_ZEROCOPY ValueType* array, vtkIdType size, bool updateMaxId = false,
185 bool save = false, int deleteMethod = VTK_DATA_ARRAY_FREE);
186
194 void SetArrayFreeFunction(void (*callback)(void*)) override;
195
202 void SetArrayFreeFunction(int comp, void (*callback)(void*));
203
210
217#ifdef __VTK_WRAP__
219#else
221#endif // __VTK_WRAP__
222
227 VTK_DEPRECATED_IN_9_7_0("Use DeepCopy with an vtkAOSDataArrayTemplate array")
228 void ExportToVoidPointer(void* ptr) override;
229
230 VTK_DEPRECATED_IN_9_7_0("Use vtk::DataArrayValueRange, or the array directly")
232 void SetNumberOfComponents(int numComps) override;
233 void ShallowCopy(vtkDataArray* other) override;
235
236 // Reimplemented for efficiency:
238 vtkIdType dstStart, vtkIdType n, vtkIdType srcStart, vtkAbstractArray* source) override;
239 // MSVC doesn't like 'using' here (error C2487). Just forward instead:
240 // using Superclass::InsertTuples;
241 void InsertTuples(vtkIdList* dstIds, vtkIdList* srcIds, vtkAbstractArray* source) override
242 {
243 this->Superclass::InsertTuples(dstIds, srcIds, source);
244 }
246 vtkIdType dstStart, vtkIdList* srcIds, vtkAbstractArray* source) override
247 {
248 this->Superclass::InsertTuplesStartingAt(dstStart, srcIds, source);
249 }
250
251#ifdef __VTK_WRAP__
252 // Add APIs inherited from vtkGenericDataArray, which is excluded from wrapping
254#endif
255
256protected:
259
264 VTK_DEPRECATED_IN_9_7_0("No longer needed")
265 bool AllocateTuples(vtkIdType numTuples);
266
272
274
275private:
277 void operator=(const vtkScaledSOADataArrayTemplate&) = delete;
278
279 void GetTupleIndexFromValueIndex(vtkIdType valueIdx, vtkIdType& tupleIdx, int& comp) const
280 {
281 tupleIdx = valueIdx / this->NumberOfComponents;
282 comp = valueIdx % this->NumberOfComponents;
283 }
284
285 friend class vtkGenericDataArray<SelfType, ValueType, ArrayTypeTag::value>;
289 ValueType Scale;
290};
291
292// Declare vtkArrayDownCast implementations for scaled SoA containers:
293vtkArrayDownCast_TemplateFastCastMacro(vtkScaledSOADataArrayTemplate);
294
295VTK_ABI_NAMESPACE_END
296
297// This macro is used by the subclasses to create dummy
298// declarations for these functions such that the wrapper
299// can see them. The wrappers ignore vtkScaledSOADataArrayTemplate.
300#define vtkCreateScaledSOAWrappedArrayInterface(T) \
301 vtkCreateWrappedArrayReadInterface(T); \
302 vtkCreateWrappedArrayWriteInterface(T); \
303 T* GetComponentArrayPointer(int id); \
304 vtkAbstractBuffer* GetComponentBuffer(int comp); \
305 void SetArray(int comp, VTK_ZEROCOPY T* array, vtkIdType size, bool updateMaxId, bool save, \
306 int deleteMethod);
307#endif // header guard
308
309// This portion must be OUTSIDE the include blockers. This is used to tell
310// libraries other than vtkCommonCore that instantiations of
311// vtkScaledSOADataArrayTemplate can be found externally. This prevents each library
312// from instantiating these on their own.
313#ifdef VTK_SCALED_SOA_DATA_ARRAY_TEMPLATE_INSTANTIATING
314#define VTK_SCALED_SOA_DATA_ARRAY_TEMPLATE_INSTANTIATE(T) \
315 namespace vtkDataArrayPrivate \
316 { \
317 VTK_ABI_NAMESPACE_BEGIN \
318 VTK_INSTANTIATE_VALUERANGE_ARRAYTYPE(vtkScaledSOADataArrayTemplate<T>, double); \
319 VTK_ABI_NAMESPACE_END \
320 } \
321 VTK_ABI_NAMESPACE_BEGIN \
322 template class VTKCOMMONCORE_EXPORT vtkScaledSOADataArrayTemplate<T>; \
323 VTK_ABI_NAMESPACE_END
324// We only provide these specializations for the 64-bit integer types, since
325// other types can reuse the double-precision mechanism in
326// vtkDataArray::GetRange without losing precision.
327#define VTK_SCALED_SOA_DATA_ARRAY_TEMPLATE_INSTANTIATE_VALUERANGE(T) \
328 namespace vtkDataArrayPrivate \
329 { \
330 VTK_ABI_NAMESPACE_BEGIN \
331 VTK_INSTANTIATE_VALUERANGE_ARRAYTYPE(vtkScaledSOADataArrayTemplate<T>, T); \
332 VTK_ABI_NAMESPACE_END \
333 }
334#elif defined(VTK_USE_EXTERN_TEMPLATE)
335#ifndef VTK_SCALED_SOA_DATA_ARRAY_TEMPLATE_EXTERN
336#define VTK_SCALED_SOA_DATA_ARRAY_TEMPLATE_EXTERN
337#ifdef _MSC_VER
338#pragma warning(push)
339// The following is needed when the vtkScaledSOADataArrayTemplate is declared
340// dllexport and is used from another class in vtkCommonCore
341#pragma warning(disable : 4910) // extern and dllexport incompatible
342#endif
343VTK_ABI_NAMESPACE_BEGIN
344vtkExternTemplateMacro(extern template class VTKCOMMONCORE_EXPORT vtkScaledSOADataArrayTemplate);
345VTK_ABI_NAMESPACE_END
346
347namespace vtkDataArrayPrivate
348{
349VTK_ABI_NAMESPACE_BEGIN
350// These are instantiated in vtkGenericDataArrayValueRange${i}.cxx
356// These are instantiated in vtkScaledSOADataArrayTemplateInstantiate${i}.cxx
370VTK_ABI_NAMESPACE_END
371}
372
373#ifdef _MSC_VER
374#pragma warning(pop)
375#endif
376#endif // VTK_SCALED_SOA_DATA_ARRAY_TEMPLATE_EXTERN
377
378// The following clause is only for MSVC 2008 and 2010
379#elif defined(_MSC_VER) && !defined(VTK_BUILD_SHARED_LIBS)
380#pragma warning(push)
381
382// C4091: 'extern ' : ignored on left of 'int' when no variable is declared
383#pragma warning(disable : 4091)
384
385// Compiler-specific extension warning.
386#pragma warning(disable : 4231)
387
388// We need to disable warning 4910 and do an extern dllexport
389// anyway. When deriving new arrays from an
390// instantiation of this template the compiler does an explicit
391// instantiation of the base class. From outside the vtkCommon
392// library we block this using an extern dllimport instantiation.
393// For classes inside vtkCommon we should be able to just do an
394// extern instantiation, but VS 2008 complains about missing
395// definitions. We cannot do an extern dllimport inside vtkCommon
396// since the symbols are local to the dll. An extern dllexport
397// seems to be the only way to convince VS 2008 to do the right
398// thing, so we just disable the warning.
399#pragma warning(disable : 4910) // extern and dllexport incompatible
400
401// Use an "extern explicit instantiation" to give the class a DLL
402// interface. This is a compiler-specific extension.
403VTK_ABI_NAMESPACE_BEGIN
405 extern template class VTKCOMMONCORE_EXPORT vtkScaledSOADataArrayTemplate);
406
407#pragma warning(pop)
408
409VTK_ABI_NAMESPACE_END
410#endif
411
412// VTK-HeaderTest-Exclude: vtkScaledSOADataArrayTemplate.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
void Modified() override
Removes out-of-date L2_NORM_RANGE() and L2_NORM_FINITE_RANGE() values.
Base interface for all typed vtkDataArray subclasses.
list of point or cell ids
Definition vtkIdList.h:135
Struct-Of-Arrays implementation of vtkGenericDataArray with a scaling factor.
void ShallowCopy(vtkDataArray *other) override
Create a shallow copy of other into this, if possible.
void SetNumberOfComponents(int numComps) override
Set/Get the dimension (n) of the components.
void SetTypedComponent(vtkIdType tupleIdx, int comp, ValueType value)
Set component comp of the tuple at tupleIdx to value.
static vtkScaledSOADataArrayTemplate * New()
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(int comp, void(*callback)(void *))
This method allows the user to specify a custom free function to be called when the array is dealloca...
std::vector< vtkBuffer< ValueType > * > Data
vtkTemplateTypeMacro(SelfType, GenericDataArrayType)
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...
ValueType * GetComponentArrayPointer(int comp)
Return a pointer to a contiguous block of memory containing all values for a particular components (i...
vtkScaledSOADataArrayTemplate< ValueTypeT > SelfType
bool ReallocateTuples(vtkIdType numTuples)
Allocate space for numTuples.
void GetTypedTuple(vtkIdType tupleIdx, ValueType *tuple) const
Copy the tuple at tupleIdx into tuple.
void InsertTuples(vtkIdType dstStart, vtkIdType n, vtkIdType srcStart, vtkAbstractArray *source) override
See documentation from parent class.
vtkArrayIterator * NewIterator() override
Subclasses must override this method and provide the right kind of templated vtkArrayIteratorTemplate...
void SetScale(ValueType scale)
Set/Get the Scale value for the object.
void SetValue(vtkIdType valueIdx, ValueType value)
Set the value at valueIdx to value.
~vtkScaledSOADataArrayTemplate() override
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 SetTypedTuple(vtkIdType tupleIdx, const ValueType *tuple)
Set this array's tuple at tupleIdx to the values in tuple.
ValueType GetValue(vtkIdType valueIdx) const
Get the value at valueIdx.
void FillTypedComponent(int compIdx, ValueType value) override
Set component comp of all tuples to value.
bool AllocateTuples(vtkIdType numTuples)
Allocate space for numTuples.
vtkBuffer< ValueTypeT > * GetComponentBuffer(int comp)
Return the underlying buffer object for a particular component.
ValueType GetScale() const
Set/Get the Scale value for the object.
void InsertTuplesStartingAt(vtkIdType dstStart, vtkIdList *srcIds, vtkAbstractArray *source) override
See documentation from parent class.
#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
void save(Archiver &ar, const std::string &str, const unsigned int version)
#define VTK_EXPECTS(x)
#define VTK_ZEROCOPY
#define VTK_NEWINSTANCE