VTK  9.6.20260320
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 VTK_DEPRECATED_IN_9_7_0("No longer needed")
250 bool AllocateTuples(vtkIdType numTuples);
251
257
259
260private:
262 void operator=(const vtkScaledSOADataArrayTemplate&) = delete;
263
264 void GetTupleIndexFromValueIndex(vtkIdType valueIdx, vtkIdType& tupleIdx, int& comp) const
265 {
266 tupleIdx = valueIdx / this->NumberOfComponents;
267 comp = valueIdx % this->NumberOfComponents;
268 }
269
270 friend class vtkGenericDataArray<SelfType, ValueType, ArrayTypeTag::value>;
274 ValueType Scale;
275};
276
277// Declare vtkArrayDownCast implementations for scaled SoA containers:
278vtkArrayDownCast_TemplateFastCastMacro(vtkScaledSOADataArrayTemplate);
279
280VTK_ABI_NAMESPACE_END
281
282// This macro is used by the subclasses to create dummy
283// declarations for these functions such that the wrapper
284// can see them. The wrappers ignore vtkScaledSOADataArrayTemplate.
285#define vtkCreateScaledSOAWrappedArrayInterface(T) \
286 vtkCreateWrappedArrayReadInterface(T); \
287 vtkCreateWrappedArrayWriteInterface(T); \
288 T* GetComponentArrayPointer(int id); \
289 vtkAbstractBuffer* GetComponentBuffer(int comp); \
290 void SetArray(int comp, VTK_ZEROCOPY T* array, vtkIdType size, bool updateMaxId, bool save, \
291 int deleteMethod);
292#endif // header guard
293
294// This portion must be OUTSIDE the include blockers. This is used to tell
295// libraries other than vtkCommonCore that instantiations of
296// vtkScaledSOADataArrayTemplate can be found externally. This prevents each library
297// from instantiating these on their own.
298#ifdef VTK_SCALED_SOA_DATA_ARRAY_TEMPLATE_INSTANTIATING
299#define VTK_SCALED_SOA_DATA_ARRAY_TEMPLATE_INSTANTIATE(T) \
300 namespace vtkDataArrayPrivate \
301 { \
302 VTK_ABI_NAMESPACE_BEGIN \
303 VTK_INSTANTIATE_VALUERANGE_ARRAYTYPE(vtkScaledSOADataArrayTemplate<T>, double); \
304 VTK_ABI_NAMESPACE_END \
305 } \
306 VTK_ABI_NAMESPACE_BEGIN \
307 template class VTKCOMMONCORE_EXPORT vtkScaledSOADataArrayTemplate<T>; \
308 VTK_ABI_NAMESPACE_END
309// We only provide these specializations for the 64-bit integer types, since
310// other types can reuse the double-precision mechanism in
311// vtkDataArray::GetRange without losing precision.
312#define VTK_SCALED_SOA_DATA_ARRAY_TEMPLATE_INSTANTIATE_VALUERANGE(T) \
313 namespace vtkDataArrayPrivate \
314 { \
315 VTK_ABI_NAMESPACE_BEGIN \
316 VTK_INSTANTIATE_VALUERANGE_ARRAYTYPE(vtkScaledSOADataArrayTemplate<T>, T); \
317 VTK_ABI_NAMESPACE_END \
318 }
319#elif defined(VTK_USE_EXTERN_TEMPLATE)
320#ifndef VTK_SCALED_SOA_DATA_ARRAY_TEMPLATE_EXTERN
321#define VTK_SCALED_SOA_DATA_ARRAY_TEMPLATE_EXTERN
322#ifdef _MSC_VER
323#pragma warning(push)
324// The following is needed when the vtkScaledSOADataArrayTemplate is declared
325// dllexport and is used from another class in vtkCommonCore
326#pragma warning(disable : 4910) // extern and dllexport incompatible
327#endif
328VTK_ABI_NAMESPACE_BEGIN
329vtkExternTemplateMacro(extern template class VTKCOMMONCORE_EXPORT vtkScaledSOADataArrayTemplate);
330VTK_ABI_NAMESPACE_END
331
332namespace vtkDataArrayPrivate
333{
334VTK_ABI_NAMESPACE_BEGIN
335// These are instantiated in vtkGenericDataArrayValueRange${i}.cxx
341// These are instantiated in vtkScaledSOADataArrayTemplateInstantiate${i}.cxx
355VTK_ABI_NAMESPACE_END
356}
357
358#ifdef _MSC_VER
359#pragma warning(pop)
360#endif
361#endif // VTK_SCALED_SOA_DATA_ARRAY_TEMPLATE_EXTERN
362
363// The following clause is only for MSVC 2008 and 2010
364#elif defined(_MSC_VER) && !defined(VTK_BUILD_SHARED_LIBS)
365#pragma warning(push)
366
367// C4091: 'extern ' : ignored on left of 'int' when no variable is declared
368#pragma warning(disable : 4091)
369
370// Compiler-specific extension warning.
371#pragma warning(disable : 4231)
372
373// We need to disable warning 4910 and do an extern dllexport
374// anyway. When deriving new arrays from an
375// instantiation of this template the compiler does an explicit
376// instantiation of the base class. From outside the vtkCommon
377// library we block this using an extern dllimport instantiation.
378// For classes inside vtkCommon we should be able to just do an
379// extern instantiation, but VS 2008 complains about missing
380// definitions. We cannot do an extern dllimport inside vtkCommon
381// since the symbols are local to the dll. An extern dllexport
382// seems to be the only way to convince VS 2008 to do the right
383// thing, so we just disable the warning.
384#pragma warning(disable : 4910) // extern and dllexport incompatible
385
386// Use an "extern explicit instantiation" to give the class a DLL
387// interface. This is a compiler-specific extension.
388VTK_ABI_NAMESPACE_BEGIN
390 extern template class VTKCOMMONCORE_EXPORT vtkScaledSOADataArrayTemplate);
391
392#pragma warning(pop)
393
394VTK_ABI_NAMESPACE_END
395#endif
396
397// 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 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