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=========================================================================*/
32
33#ifndef vtkScaledSOADataArrayTemplate_h
34#define vtkScaledSOADataArrayTemplate_h
35
36#include "vtkBuffer.h"
37#include "vtkBuild.h" // For VTK_BUILD_SHARED_LIBS
38#include "vtkCommonCoreModule.h" // For export macro
39#include "vtkCompiler.h" // for VTK_USE_EXTERN_TEMPLATE
40#include "vtkGenericDataArray.h"
41
42// The export macro below makes no sense, but is necessary for older compilers
43// when we export instantiations of this class from vtkCommonCore.
44template <class ValueTypeT>
45class VTKCOMMONCORE_EXPORT vtkScaledSOADataArrayTemplate
46 : public vtkGenericDataArray<vtkScaledSOADataArrayTemplate<ValueTypeT>, ValueTypeT>
47{
49 GenericDataArrayType;
50
51public:
53 vtkTemplateTypeMacro(SelfType, GenericDataArrayType);
54 typedef typename Superclass::ValueType ValueType;
55
63
65
67
70 void SetScale(ValueType scale)
71 {
72 if (scale != this->Scale)
73 {
74 if (scale == 0)
75 {
76 vtkErrorMacro("Cannot set Scale to 0");
77 }
78 else
79 {
80 this->Scale = scale;
81 this->Modified();
82 }
83 }
84 }
85 ValueType GetScale() const { return this->Scale; }
87
89
92 inline ValueType GetValue(vtkIdType valueIdx) const
93 {
94 vtkIdType tupleIdx;
95 int comp;
96 this->GetTupleIndexFromValueIndex(valueIdx, tupleIdx, comp);
97 return this->GetTypedComponent(tupleIdx, comp);
98 }
99
100
102
105 inline void SetValue(vtkIdType valueIdx, ValueType value)
106 {
107 vtkIdType tupleIdx;
108 int comp;
109 this->GetTupleIndexFromValueIndex(valueIdx, tupleIdx, comp);
110 this->SetTypedComponent(tupleIdx, comp, value);
111 }
112
113
117 inline void GetTypedTuple(vtkIdType tupleIdx, ValueType* tuple) const
118 {
119 for (size_t cc = 0; cc < this->Data.size(); cc++)
120 {
121 tuple[cc] = this->Data[cc]->GetBuffer()[tupleIdx] * this->Scale;
122 }
123 }
124
128 inline void SetTypedTuple(vtkIdType tupleIdx, const ValueType* tuple)
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 inline ValueType GetTypedComponent(vtkIdType tupleIdx, int comp) const
140 {
141 return this->Data[comp]->GetBuffer()[tupleIdx] * this->Scale;
142 }
143
147 inline void SetTypedComponent(vtkIdType tupleIdx, int comp, ValueType value)
148 {
149 this->Data[comp]->GetBuffer()[tupleIdx] = value / this->Scale;
150 }
151
155 void FillTypedComponent(int compIdx, ValueType value) override;
156
170 void SetArray(int comp, VTK_ZEROCOPY ValueType* array, vtkIdType size, bool updateMaxId = false,
171 bool save = false, int deleteMethod = VTK_DATA_ARRAY_FREE);
172
180 void SetArrayFreeFunction(void (*callback)(void*)) override;
181
188 void SetArrayFreeFunction(int comp, void (*callback)(void*));
189
196
201 void* GetVoidPointer(vtkIdType valueIdx) override;
202
207 void ExportToVoidPointer(void* ptr) override;
208
209#ifndef __VTK_WRAP__
211
218 {
219 if (source)
220 {
221 switch (source->GetArrayType())
222 {
224 if (vtkDataTypesCompare(source->GetDataType(), vtkTypeTraits<ValueType>::VTK_TYPE_ID))
225 {
227 }
228 break;
229 }
230 }
231 return nullptr;
232 }
233
234#endif
235
238 void SetNumberOfComponents(int numComps) override;
239 void ShallowCopy(vtkDataArray* other) override;
240
241 // Reimplemented for efficiency:
243 vtkIdType dstStart, vtkIdType n, vtkIdType srcStart, vtkAbstractArray* source) override;
244 // MSVC doesn't like 'using' here (error C2487). Just forward instead:
245 // using Superclass::InsertTuples;
246 void InsertTuples(vtkIdList* dstIds, vtkIdList* srcIds, vtkAbstractArray* source) override
247 {
248 this->Superclass::InsertTuples(dstIds, srcIds, source);
249 }
251 vtkIdType dstStart, vtkIdList* srcIds, vtkAbstractArray* source) override
252 {
253 this->Superclass::InsertTuplesStartingAt(dstStart, srcIds, source);
254 }
255
256protected:
259
264 bool AllocateTuples(vtkIdType numTuples);
265
271
272 std::vector<vtkBuffer<ValueType>*> Data;
274
275private:
277 void operator=(const vtkScaledSOADataArrayTemplate&) = delete;
278
279 inline 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<vtkScaledSOADataArrayTemplate<ValueTypeT>, ValueTypeT>;
289 ValueType Scale;
290};
291
292// Declare vtkArrayDownCast implementations for scale SoA containers:
294
295#endif // header guard
296
297// This portion must be OUTSIDE the include blockers. This is used to tell
298// libraries other than vtkCommonCore that instantiations of
299// vtkScaledSOADataArrayTemplate can be found externally. This prevents each library
300// from instantiating these on their own.
301#ifdef VTK_SCALED_SOA_DATA_ARRAY_TEMPLATE_INSTANTIATING
302#define VTK_SCALED_SOA_DATA_ARRAY_TEMPLATE_INSTANTIATE(T) \
303 namespace vtkDataArrayPrivate \
304 { \
305 VTK_INSTANTIATE_VALUERANGE_ARRAYTYPE(vtkScaledSOADataArrayTemplate<T>, double); \
306 } \
307 template class VTKCOMMONCORE_EXPORT vtkScaledSOADataArrayTemplate<T>
308
309#elif defined(VTK_USE_EXTERN_TEMPLATE)
310#ifndef VTK_SCALED_SOA_DATA_ARRAY_TEMPLATE_EXTERN
311#define VTK_SCALED_SOA_DATA_ARRAY_TEMPLATE_EXTERN
312#ifdef _MSC_VER
313#pragma warning(push)
314// The following is needed when the vtkScaledSOADataArrayTemplate is declared
315// dllexport and is used from another class in vtkCommonCore
316#pragma warning(disable : 4910) // extern and dllexport incompatible
317#endif
318vtkExternTemplateMacro(extern template class VTKCOMMONCORE_EXPORT vtkScaledSOADataArrayTemplate);
319#ifdef _MSC_VER
320#pragma warning(pop)
321#endif
322#endif // VTK_SCALED_SOA_DATA_ARRAY_TEMPLATE_EXTERN
323
324// The following clause is only for MSVC 2008 and 2010
325#elif defined(_MSC_VER) && !defined(VTK_BUILD_SHARED_LIBS)
326#pragma warning(push)
327
328// C4091: 'extern ' : ignored on left of 'int' when no variable is declared
329#pragma warning(disable : 4091)
330
331// Compiler-specific extension warning.
332#pragma warning(disable : 4231)
333
334// We need to disable warning 4910 and do an extern dllexport
335// anyway. When deriving new arrays from an
336// instantiation of this template the compiler does an explicit
337// instantiation of the base class. From outside the vtkCommon
338// library we block this using an extern dllimport instantiation.
339// For classes inside vtkCommon we should be able to just do an
340// extern instantiation, but VS 2008 complains about missing
341// definitions. We cannot do an extern dllimport inside vtkCommon
342// since the symbols are local to the dll. An extern dllexport
343// seems to be the only way to convince VS 2008 to do the right
344// thing, so we just disable the warning.
345#pragma warning(disable : 4910) // extern and dllexport incompatible
346
347// Use an "extern explicit instantiation" to give the class a DLL
348// interface. This is a compiler-specific extension.
350 extern template class VTKCOMMONCORE_EXPORT vtkScaledSOADataArrayTemplate);
351
352#pragma warning(pop)
353
354#endif
355
356// VTK-HeaderTest-Exclude: vtkScaledSOADataArrayTemplate.h
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
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:31
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.
#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