VTK  9.6.20260227
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 : public vtkGenericDataArray<vtkScaledSOADataArrayTemplate<ValueTypeT>, ValueTypeT,
40 /*vtkArrayTypes::VTK_SCALED_SOA_DATA_ARRAY*/ 7>
41{
43 ValueTypeT, /*vtkArrayTypes::VTK_SCALED_SOA_DATA_ARRAY*/ 7>;
44
45public:
47 vtkTemplateTypeMacro(SelfType, GenericDataArrayType);
48 using typename Superclass::ArrayTypeTag;
49 using typename Superclass::DataTypeTag;
50 using typename Superclass::ValueType;
51
59
61
63
66 void SetScale(ValueType scale)
67 {
68 if (scale != this->Scale)
69 {
70 if (scale == 0)
71 {
72 vtkErrorMacro("Cannot set Scale to 0");
73 }
74 else
75 {
76 this->Scale = scale;
77 this->Modified();
78 }
79 }
80 }
81 ValueType GetScale() const { return this->Scale; }
83
85
89 VTK_EXPECTS(0 <= valueIdx && valueIdx < GetNumberOfValues())
90 {
91 vtkIdType tupleIdx;
92 int comp;
93 this->GetTupleIndexFromValueIndex(valueIdx, tupleIdx, comp);
94 return this->GetTypedComponent(tupleIdx, comp);
95 }
96
97
99
102 void SetValue(vtkIdType valueIdx, ValueType value)
103 VTK_EXPECTS(0 <= valueIdx && valueIdx < GetNumberOfValues())
104 {
105 vtkIdType tupleIdx;
106 int comp;
107 this->GetTupleIndexFromValueIndex(valueIdx, tupleIdx, comp);
108 this->SetTypedComponent(tupleIdx, comp, value);
109 }
110
111
115 void GetTypedTuple(vtkIdType tupleIdx, ValueType* tuple) const
116 VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples())
117 {
118 for (size_t cc = 0; cc < this->Data.size(); cc++)
119 {
120 tuple[cc] = this->Data[cc]->GetBuffer()[tupleIdx] * this->Scale;
121 }
122 }
123
127 void SetTypedTuple(vtkIdType tupleIdx, const ValueType* tuple)
128 VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples())
129 {
130 for (size_t cc = 0; cc < this->Data.size(); ++cc)
131 {
132 this->Data[cc]->GetBuffer()[tupleIdx] = tuple[cc] / this->Scale;
133 }
134 }
135
139 ValueType GetTypedComponent(vtkIdType tupleIdx, int comp) const
140 VTK_EXPECTS(0 <= tupleIdx && GetNumberOfComponents() * tupleIdx + comp < GetNumberOfValues())
141 VTK_EXPECTS(0 <= comp && comp < GetNumberOfComponents())
142 {
143 return this->Data[comp]->GetBuffer()[tupleIdx] * this->Scale;
144 }
145
149 void SetTypedComponent(vtkIdType tupleIdx, int comp, ValueType value)
150 VTK_EXPECTS(0 <= tupleIdx && GetNumberOfComponents() * tupleIdx + comp < GetNumberOfValues())
151 VTK_EXPECTS(0 <= comp && comp < GetNumberOfComponents())
152 {
153 this->Data[comp]->GetBuffer()[tupleIdx] = value / this->Scale;
154 }
155
159 void FillTypedComponent(int compIdx, ValueType value) override;
160
174 void SetArray(int comp, VTK_ZEROCOPY ValueType* array, vtkIdType size, bool updateMaxId = false,
175 bool save = false, int deleteMethod = VTK_DATA_ARRAY_FREE);
176
184 void SetArrayFreeFunction(void (*callback)(void*)) override;
185
192 void SetArrayFreeFunction(int comp, void (*callback)(void*));
193
200
207#ifdef __VTK_WRAP__
209#else
211#endif // __VTK_WRAP__
212
217 VTK_DEPRECATED_IN_9_7_0("Use DeepCopy with an vtkAOSDataArrayTemplate array")
218 void ExportToVoidPointer(void* ptr) override;
219
220 VTK_DEPRECATED_IN_9_7_0("Use vtk::DataArrayValueRange, or the array directly")
222 void SetNumberOfComponents(int numComps) override;
223 void ShallowCopy(vtkDataArray* other) override;
225
226 // Reimplemented for efficiency:
228 vtkIdType dstStart, vtkIdType n, vtkIdType srcStart, vtkAbstractArray* source) override;
229 // MSVC doesn't like 'using' here (error C2487). Just forward instead:
230 // using Superclass::InsertTuples;
231 void InsertTuples(vtkIdList* dstIds, vtkIdList* srcIds, vtkAbstractArray* source) override
232 {
233 this->Superclass::InsertTuples(dstIds, srcIds, source);
234 }
236 vtkIdType dstStart, vtkIdList* srcIds, vtkAbstractArray* source) override
237 {
238 this->Superclass::InsertTuplesStartingAt(dstStart, srcIds, source);
239 }
240
241protected:
244
249 bool AllocateTuples(vtkIdType numTuples);
250
256
257 std::vector<vtkBuffer<ValueType>*> Data;
258
259private:
261 void operator=(const vtkScaledSOADataArrayTemplate&) = delete;
262
263 void GetTupleIndexFromValueIndex(vtkIdType valueIdx, vtkIdType& tupleIdx, int& comp) const
264 {
265 tupleIdx = valueIdx / this->NumberOfComponents;
266 comp = valueIdx % this->NumberOfComponents;
267 }
268
269 friend class vtkGenericDataArray<SelfType, ValueType, ArrayTypeTag::value>;
273 ValueType Scale;
274};
275
276// Declare vtkArrayDownCast implementations for scaled SoA containers:
277vtkArrayDownCast_TemplateFastCastMacro(vtkScaledSOADataArrayTemplate);
278
279VTK_ABI_NAMESPACE_END
280
281// This macro is used by the subclasses to create dummy
282// declarations for these functions such that the wrapper
283// can see them. The wrappers ignore vtkScaledSOADataArrayTemplate.
284#define vtkCreateScaledSOAWrappedArrayInterface(T) \
285 int GetDataType() const override; \
286 T GetDataTypeValueMin() const; \
287 T GetDataTypeValueMax() const; \
288 void GetTypedTuple(vtkIdType i, T* tuple) VTK_EXPECTS(0 <= i && i < GetNumberOfTuples()); \
289 T GetValue(vtkIdType id) const VTK_EXPECTS(0 <= id && id < GetNumberOfValues()); \
290 T* GetValueRange(int comp) VTK_SIZEHINT(2); \
291 T* GetValueRange() VTK_SIZEHINT(2); \
292 void SetTypedTuple(vtkIdType i, const T* tuple) VTK_EXPECTS(0 <= i && i < GetNumberOfTuples()); \
293 void InsertTypedTuple(vtkIdType i, const T* tuple) VTK_EXPECTS(0 <= i); \
294 vtkIdType InsertNextTypedTuple(const T* tuple); \
295 void SetValue(vtkIdType id, T value) VTK_EXPECTS(0 <= id && id < GetNumberOfValues()); \
296 bool SetNumberOfValues(vtkIdType number) override; \
297 void InsertValue(vtkIdType id, T f) VTK_EXPECTS(0 <= id); \
298 vtkIdType InsertNextValue(T f); \
299 T* GetComponentArrayPointer(int id); \
300 vtkAbstractBuffer* GetComponentBuffer(int comp); \
301 void SetArray(int comp, VTK_ZEROCOPY T* array, vtkIdType size, bool updateMaxId, bool save, \
302 int deleteMethod);
303#endif // header guard
304
305// This portion must be OUTSIDE the include blockers. This is used to tell
306// libraries other than vtkCommonCore that instantiations of
307// vtkScaledSOADataArrayTemplate can be found externally. This prevents each library
308// from instantiating these on their own.
309#ifdef VTK_SCALED_SOA_DATA_ARRAY_TEMPLATE_INSTANTIATING
310#define VTK_SCALED_SOA_DATA_ARRAY_TEMPLATE_INSTANTIATE(T) \
311 namespace vtkDataArrayPrivate \
312 { \
313 VTK_ABI_NAMESPACE_BEGIN \
314 VTK_INSTANTIATE_VALUERANGE_ARRAYTYPE(vtkScaledSOADataArrayTemplate<T>, double); \
315 VTK_ABI_NAMESPACE_END \
316 } \
317 VTK_ABI_NAMESPACE_BEGIN \
318 template class VTKCOMMONCORE_EXPORT vtkScaledSOADataArrayTemplate<T>; \
319 VTK_ABI_NAMESPACE_END
320
321#elif defined(VTK_USE_EXTERN_TEMPLATE)
322#ifndef VTK_SCALED_SOA_DATA_ARRAY_TEMPLATE_EXTERN
323#define VTK_SCALED_SOA_DATA_ARRAY_TEMPLATE_EXTERN
324#ifdef _MSC_VER
325#pragma warning(push)
326// The following is needed when the vtkScaledSOADataArrayTemplate is declared
327// dllexport and is used from another class in vtkCommonCore
328#pragma warning(disable : 4910) // extern and dllexport incompatible
329#endif
330VTK_ABI_NAMESPACE_BEGIN
331vtkExternTemplateMacro(extern template class VTKCOMMONCORE_EXPORT vtkScaledSOADataArrayTemplate);
332VTK_ABI_NAMESPACE_END
333
334namespace vtkDataArrayPrivate
335{
336VTK_ABI_NAMESPACE_BEGIN
350VTK_ABI_NAMESPACE_END
351}
352
353#ifdef _MSC_VER
354#pragma warning(pop)
355#endif
356#endif // VTK_SCALED_SOA_DATA_ARRAY_TEMPLATE_EXTERN
357
358// The following clause is only for MSVC 2008 and 2010
359#elif defined(_MSC_VER) && !defined(VTK_BUILD_SHARED_LIBS)
360#pragma warning(push)
361
362// C4091: 'extern ' : ignored on left of 'int' when no variable is declared
363#pragma warning(disable : 4091)
364
365// Compiler-specific extension warning.
366#pragma warning(disable : 4231)
367
368// We need to disable warning 4910 and do an extern dllexport
369// anyway. When deriving new arrays from an
370// instantiation of this template the compiler does an explicit
371// instantiation of the base class. From outside the vtkCommon
372// library we block this using an extern dllimport instantiation.
373// For classes inside vtkCommon we should be able to just do an
374// extern instantiation, but VS 2008 complains about missing
375// definitions. We cannot do an extern dllimport inside vtkCommon
376// since the symbols are local to the dll. An extern dllexport
377// seems to be the only way to convince VS 2008 to do the right
378// thing, so we just disable the warning.
379#pragma warning(disable : 4910) // extern and dllexport incompatible
380
381// Use an "extern explicit instantiation" to give the class a DLL
382// interface. This is a compiler-specific extension.
383VTK_ABI_NAMESPACE_BEGIN
385 extern template class VTKCOMMONCORE_EXPORT vtkScaledSOADataArrayTemplate);
386
387#pragma warning(pop)
388
389VTK_ABI_NAMESPACE_END
390#endif
391
392// 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:133
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 VTK_DECLARE_VALUERANGE_ARRAYTYPE(ArrayType, ValueType)
#define vtkExternTemplateMacro(decl)
A macro to declare extern templates for all numerical types.
Definition vtkType.h:490
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