VTK  9.2.6
vtkScaledSOADataArrayTemplate.h
Go to the documentation of this file.
1/*=========================================================================
2
3 Program: Visualization Toolkit
4 Module: vtkScaledSOADataArrayTemplate.h
5
6 Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7 All rights reserved.
8 See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9
10 This software is distributed WITHOUT ANY WARRANTY; without even
11 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12 PURPOSE. See the above copyright notice for more information.
13
14=========================================================================*/
36#ifndef vtkScaledSOADataArrayTemplate_h
37#define vtkScaledSOADataArrayTemplate_h
38
39#include "vtkBuffer.h"
40#include "vtkBuild.h" // For VTK_BUILD_SHARED_LIBS
41#include "vtkCommonCoreModule.h" // For export macro
42#include "vtkCompiler.h" // for VTK_USE_EXTERN_TEMPLATE
43#include "vtkGenericDataArray.h"
44
45// The export macro below makes no sense, but is necessary for older compilers
46// when we export instantiations of this class from vtkCommonCore.
47template <class ValueTypeT>
48class VTKCOMMONCORE_EXPORT vtkScaledSOADataArrayTemplate
49 : public vtkGenericDataArray<vtkScaledSOADataArrayTemplate<ValueTypeT>, ValueTypeT>
50{
53
54public:
57 typedef typename Superclass::ValueType ValueType;
58
60 {
63 VTK_DATA_ARRAY_ALIGNED_FREE = vtkAbstractArray::VTK_DATA_ARRAY_ALIGNED_FREE,
64 VTK_DATA_ARRAY_USER_DEFINED = vtkAbstractArray::VTK_DATA_ARRAY_USER_DEFINED
65 };
66
68
70
73 void SetScale(ValueType scale)
74 {
75 if (scale != this->Scale)
76 {
77 if (scale == 0)
78 {
79 vtkErrorMacro("Cannot set Scale to 0");
80 }
81 else
82 {
83 this->Scale = scale;
84 this->Modified();
85 }
86 }
87 }
88 ValueType GetScale() const { return this->Scale; }
90
92
95 inline ValueType GetValue(vtkIdType valueIdx) const
96 {
97 vtkIdType tupleIdx;
98 int comp;
99 this->GetTupleIndexFromValueIndex(valueIdx, tupleIdx, comp);
100 return this->GetTypedComponent(tupleIdx, comp);
101 }
103
105
108 inline void SetValue(vtkIdType valueIdx, ValueType value)
109 {
110 vtkIdType tupleIdx;
111 int comp;
112 this->GetTupleIndexFromValueIndex(valueIdx, tupleIdx, comp);
113 this->SetTypedComponent(tupleIdx, comp, value);
114 }
116
120 inline void GetTypedTuple(vtkIdType tupleIdx, ValueType* tuple) const
121 {
122 for (size_t cc = 0; cc < this->Data.size(); cc++)
123 {
124 tuple[cc] = this->Data[cc]->GetBuffer()[tupleIdx] * this->Scale;
125 }
126 }
127
131 inline void SetTypedTuple(vtkIdType tupleIdx, const ValueType* tuple)
132 {
133 for (size_t cc = 0; cc < this->Data.size(); ++cc)
134 {
135 this->Data[cc]->GetBuffer()[tupleIdx] = tuple[cc] / this->Scale;
136 }
137 }
138
142 inline ValueType GetTypedComponent(vtkIdType tupleIdx, int comp) const
143 {
144 return this->Data[comp]->GetBuffer()[tupleIdx] * this->Scale;
145 }
146
150 inline void SetTypedComponent(vtkIdType tupleIdx, int comp, ValueType value)
151 {
152 this->Data[comp]->GetBuffer()[tupleIdx] = value / this->Scale;
153 }
154
158 void FillTypedComponent(int compIdx, ValueType value) override;
159
173 void SetArray(int comp, VTK_ZEROCOPY ValueType* array, vtkIdType size, bool updateMaxId = false,
174 bool save = false, int deleteMethod = VTK_DATA_ARRAY_FREE);
175
183 void SetArrayFreeFunction(void (*callback)(void*)) override;
184
191 void SetArrayFreeFunction(int comp, void (*callback)(void*));
192
199
204 void* GetVoidPointer(vtkIdType valueIdx) override;
205
210 void ExportToVoidPointer(void* ptr) override;
211
212#ifndef __VTK_WRAP__
214
221 {
222 if (source)
223 {
224 switch (source->GetArrayType())
225 {
227 if (vtkDataTypesCompare(source->GetDataType(), vtkTypeTraits<ValueType>::VTK_TYPE_ID))
228 {
230 }
231 break;
232 }
233 }
234 return nullptr;
235 }
237#endif
238
241 void SetNumberOfComponents(int numComps) override;
242 void ShallowCopy(vtkDataArray* other) override;
243
244 // Reimplemented for efficiency:
246 vtkIdType dstStart, vtkIdType n, vtkIdType srcStart, vtkAbstractArray* source) override;
247 // MSVC doesn't like 'using' here (error C2487). Just forward instead:
248 // using Superclass::InsertTuples;
249 void InsertTuples(vtkIdList* dstIds, vtkIdList* srcIds, vtkAbstractArray* source) override
250 {
251 this->Superclass::InsertTuples(dstIds, srcIds, source);
252 }
254 vtkIdType dstStart, vtkIdList* srcIds, vtkAbstractArray* source) override
255 {
256 this->Superclass::InsertTuplesStartingAt(dstStart, srcIds, source);
257 }
258
259protected:
262
267 bool AllocateTuples(vtkIdType numTuples);
268
274
275 std::vector<vtkBuffer<ValueType>*> Data;
277
278private:
280 void operator=(const vtkScaledSOADataArrayTemplate&) = delete;
281
282 inline void GetTupleIndexFromValueIndex(vtkIdType valueIdx, vtkIdType& tupleIdx, int& comp) const
283 {
284 tupleIdx = valueIdx / this->NumberOfComponents;
285 comp = valueIdx % this->NumberOfComponents;
286 }
287
288 friend class vtkGenericDataArray<vtkScaledSOADataArrayTemplate<ValueTypeT>, ValueTypeT>;
292 ValueType Scale;
293};
294
295// Declare vtkArrayDownCast implementations for scale SoA containers:
297
298#endif // header guard
299
300// This portion must be OUTSIDE the include blockers. This is used to tell
301// libraries other than vtkCommonCore that instantiations of
302// vtkScaledSOADataArrayTemplate can be found externally. This prevents each library
303// from instantiating these on their own.
304#ifdef VTK_SCALED_SOA_DATA_ARRAY_TEMPLATE_INSTANTIATING
305#define VTK_SCALED_SOA_DATA_ARRAY_TEMPLATE_INSTANTIATE(T) \
306 namespace vtkDataArrayPrivate \
307 { \
308 VTK_INSTANTIATE_VALUERANGE_ARRAYTYPE(vtkScaledSOADataArrayTemplate<T>, double); \
309 } \
310 template class VTKCOMMONCORE_EXPORT vtkScaledSOADataArrayTemplate<T>
311
312#elif defined(VTK_USE_EXTERN_TEMPLATE)
313#ifndef VTK_SCALED_SOA_DATA_ARRAY_TEMPLATE_EXTERN
314#define VTK_SCALED_SOA_DATA_ARRAY_TEMPLATE_EXTERN
315#ifdef _MSC_VER
316#pragma warning(push)
317// The following is needed when the vtkScaledSOADataArrayTemplate is declared
318// dllexport and is used from another class in vtkCommonCore
319#pragma warning(disable : 4910) // extern and dllexport incompatible
320#endif
321vtkExternTemplateMacro(extern template class VTKCOMMONCORE_EXPORT vtkScaledSOADataArrayTemplate);
322#ifdef _MSC_VER
323#pragma warning(pop)
324#endif
325#endif // VTK_SCALED_SOA_DATA_ARRAY_TEMPLATE_EXTERN
326
327// The following clause is only for MSVC 2008 and 2010
328#elif defined(_MSC_VER) && !defined(VTK_BUILD_SHARED_LIBS)
329#pragma warning(push)
330
331// C4091: 'extern ' : ignored on left of 'int' when no variable is declared
332#pragma warning(disable : 4091)
333
334// Compiler-specific extension warning.
335#pragma warning(disable : 4231)
336
337// We need to disable warning 4910 and do an extern dllexport
338// anyway. When deriving new arrays from an
339// instantiation of this template the compiler does an explicit
340// instantiation of the base class. From outside the vtkCommon
341// library we block this using an extern dllimport instantiation.
342// For classes inside vtkCommon we should be able to just do an
343// extern instantiation, but VS 2008 complains about missing
344// definitions. We cannot do an extern dllimport inside vtkCommon
345// since the symbols are local to the dll. An extern dllexport
346// seems to be the only way to convince VS 2008 to do the right
347// thing, so we just disable the warning.
348#pragma warning(disable : 4910) // extern and dllexport incompatible
349
350// Use an "extern explicit instantiation" to give the class a DLL
351// interface. This is a compiler-specific extension.
353 extern template class VTKCOMMONCORE_EXPORT vtkScaledSOADataArrayTemplate);
354
355#pragma warning(pop)
356
357#endif
358
359// VTK-HeaderTest-Exclude: vtkScaledSOADataArrayTemplate.h
Abstract superclass for all arrays.
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...
Abstract superclass to iterate over elements in an vtkAbstractArray.
internal storage class used by vtkSOADataArrayTemplate, vtkAOSDataArrayTemplate, and others.
Definition: vtkBuffer.h:35
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:56
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:34
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...
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.
int GetArrayType() const override
Method for type-checking in FastDownCast implementations.
static vtkScaledSOADataArrayTemplate< ValueType > * FastDownCast(vtkAbstractArray *source)
Perform a fast, safe cast from a vtkAbstractArray to a vtkDataArray.
vtkArrayIterator * NewIterator() override
Subclasses must override this method and provide the right kind of templated vtkArrayIteratorTemplate...
vtkScaledSOADataArrayTemplate< ValueTypeT > SelfType
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 InsertTuples(vtkIdList *dstIds, vtkIdList *srcIds, vtkAbstractArray *source) override
See documentation from parent class.
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.
ValueType GetScale() const
Set/Get the Scale value for the object.
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.
void SetTypedComponent(vtkIdType tupleIdx, int compIdx, ValueType value)
Set component compIdx of the tuple at tupleIdx to value.
ValueType GetTypedComponent(vtkIdType tupleIdx, int compIdx) const
Get component compIdx of the tuple at tupleIdx.
Template defining traits of native types used by VTK.
Definition: vtkTypeTraits.h:33
#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 vtkExternTemplateMacro(decl)
A macro to declare extern templates for all numerical types.
Definition: vtkType.h:395
int vtkIdType
Definition: vtkType.h:332
#define vtkInstantiateTemplateMacro(decl)
A macro to instantiate a template over all numerical types.
Definition: vtkType.h:378
void save(Archiver &ar, const std::string &str, const unsigned int vtkNotUsed(version))
#define VTK_ZEROCOPY
#define VTK_NEWINSTANCE