VTK  9.0.1
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 =========================================================================*/
33 #ifndef vtkScaledSOADataArrayTemplate_h
34 #define vtkScaledSOADataArrayTemplate_h
35 
36 #include "vtkBuffer.h"
37 #include "vtkCommonCoreModule.h" // For export macro
38 #include "vtkGenericDataArray.h"
39 
40 // The export macro below makes no sense, but is necessary for older compilers
41 // when we export instantiations of this class from vtkCommonCore.
42 template <class ValueTypeT>
43 class VTKCOMMONCORE_EXPORT vtkScaledSOADataArrayTemplate
44  : public vtkGenericDataArray<vtkScaledSOADataArrayTemplate<ValueTypeT>, ValueTypeT>
45 {
48 
49 public:
52  typedef typename Superclass::ValueType ValueType;
53 
55  {
57  VTK_DATA_ARRAY_DELETE = vtkAbstractArray::VTK_DATA_ARRAY_DELETE,
58  VTK_DATA_ARRAY_ALIGNED_FREE = vtkAbstractArray::VTK_DATA_ARRAY_ALIGNED_FREE,
59  VTK_DATA_ARRAY_USER_DEFINED = vtkAbstractArray::VTK_DATA_ARRAY_USER_DEFINED
60  };
61 
63 
65 
69  {
70  if (scale != this->Scale)
71  {
72  if (scale == 0)
73  {
74  vtkErrorMacro("Cannot set Scale to 0");
75  }
76  else
77  {
78  this->Scale = scale;
79  this->Modified();
80  }
81  }
82  }
83  ValueType GetScale() const { return this->Scale; }
85 
87 
90  inline ValueType GetValue(vtkIdType valueIdx) const
91  {
92  vtkIdType tupleIdx;
93  int comp;
94  this->GetTupleIndexFromValueIndex(valueIdx, tupleIdx, comp);
95  return this->GetTypedComponent(tupleIdx, comp);
96  }
98 
100 
103  inline void SetValue(vtkIdType valueIdx, ValueType value)
104  {
105  vtkIdType tupleIdx;
106  int comp;
107  this->GetTupleIndexFromValueIndex(valueIdx, tupleIdx, comp);
108  this->SetTypedComponent(tupleIdx, comp, value);
109  }
111 
115  inline void GetTypedTuple(vtkIdType tupleIdx, ValueType* tuple) const
116  {
117  for (size_t cc = 0; cc < this->Data.size(); cc++)
118  {
119  tuple[cc] = this->Data[cc]->GetBuffer()[tupleIdx] * this->Scale;
120  }
121  }
122 
126  inline void SetTypedTuple(vtkIdType tupleIdx, const ValueType* tuple)
127  {
128  for (size_t cc = 0; cc < this->Data.size(); ++cc)
129  {
130  this->Data[cc]->GetBuffer()[tupleIdx] = tuple[cc] / this->Scale;
131  }
132  }
133 
137  inline ValueType GetTypedComponent(vtkIdType tupleIdx, int comp) const
138  {
139  return this->Data[comp]->GetBuffer()[tupleIdx] * this->Scale;
140  }
141 
145  inline void SetTypedComponent(vtkIdType tupleIdx, int comp, ValueType value)
146  {
147  this->Data[comp]->GetBuffer()[tupleIdx] = value / this->Scale;
148  }
149 
153  void FillTypedComponent(int compIdx, ValueType value) override;
154 
168  void SetArray(int comp, VTK_ZEROCOPY ValueType* array, vtkIdType size, bool updateMaxId = false,
169  bool save = false, int deleteMethod = VTK_DATA_ARRAY_FREE);
170 
178  void SetArrayFreeFunction(void (*callback)(void*)) override;
179 
186  void SetArrayFreeFunction(int comp, void (*callback)(void*));
187 
193  ValueType* GetComponentArrayPointer(int comp);
194 
199  void* GetVoidPointer(vtkIdType valueIdx) override;
200 
205  void ExportToVoidPointer(void* ptr) override;
206 
207 #ifndef __VTK_WRAP__
208 
209 
216  {
217  if (source)
218  {
219  switch (source->GetArrayType())
220  {
222  if (vtkDataTypesCompare(source->GetDataType(), vtkTypeTraits<ValueType>::VTK_TYPE_ID))
223  {
224  return static_cast<vtkScaledSOADataArrayTemplate<ValueType>*>(source);
225  }
226  break;
227  }
228  }
229  return nullptr;
230  }
232 #endif
233 
236  void SetNumberOfComponents(int numComps) override;
237  void ShallowCopy(vtkDataArray* other) override;
238 
239  // Reimplemented for efficiency:
240  void InsertTuples(
241  vtkIdType dstStart, vtkIdType n, vtkIdType srcStart, vtkAbstractArray* source) override;
242  // MSVC doesn't like 'using' here (error C2487). Just forward instead:
243  // using Superclass::InsertTuples;
244  void InsertTuples(vtkIdList* dstIds, vtkIdList* srcIds, vtkAbstractArray* source) override
245  {
246  this->Superclass::InsertTuples(dstIds, srcIds, source);
247  }
248 
249 protected:
251  ~vtkScaledSOADataArrayTemplate() override;
252 
257  bool AllocateTuples(vtkIdType numTuples);
258 
263  bool ReallocateTuples(vtkIdType numTuples);
264 
265  std::vector<vtkBuffer<ValueType>*> Data;
267 
268 private:
270  void operator=(const vtkScaledSOADataArrayTemplate&) = delete;
271 
272  inline void GetTupleIndexFromValueIndex(vtkIdType valueIdx, vtkIdType& tupleIdx, int& comp) const
273  {
274  tupleIdx = valueIdx / this->NumberOfComponents;
275  comp = valueIdx % this->NumberOfComponents;
276  }
277 
278  friend class vtkGenericDataArray<vtkScaledSOADataArrayTemplate<ValueTypeT>, ValueTypeT>;
282  ValueType Scale;
283 };
284 
285 // Declare vtkArrayDownCast implementations for scale SoA containers:
287 
288 #endif // header guard
289 
290 // This portion must be OUTSIDE the include blockers. This is used to tell
291 // libraries other than vtkCommonCore that instantiations of
292 // vtkScaledSOADataArrayTemplate can be found externally. This prevents each library
293 // from instantiating these on their own.
294 #ifdef VTK_SCALED_SOA_DATA_ARRAY_TEMPLATE_INSTANTIATING
295 #define VTK_SCALED_SOA_DATA_ARRAY_TEMPLATE_INSTANTIATE(T) \
296  template class VTKCOMMONCORE_EXPORT vtkScaledSOADataArrayTemplate<T>
297 #elif defined(VTK_USE_EXTERN_TEMPLATE)
298 #ifndef VTK_SCALED_SOA_DATA_ARRAY_TEMPLATE_EXTERN
299 #define VTK_SCALED_SOA_DATA_ARRAY_TEMPLATE_EXTERN
300 #ifdef _MSC_VER
301 #pragma warning(push)
302 // The following is needed when the vtkScaledSOADataArrayTemplate is declared
303 // dllexport and is used from another class in vtkCommonCore
304 #pragma warning(disable : 4910) // extern and dllexport incompatible
305 #endif
306 vtkExternTemplateMacro(extern template class VTKCOMMONCORE_EXPORT vtkScaledSOADataArrayTemplate);
307 #ifdef _MSC_VER
308 #pragma warning(pop)
309 #endif
310 #endif // VTK_SCALED_SOA_DATA_ARRAY_TEMPLATE_EXTERN
311 
312 // The following clause is only for MSVC 2008 and 2010
313 #elif defined(_MSC_VER) && !defined(VTK_BUILD_SHARED_LIBS)
314 #pragma warning(push)
315 
316 // C4091: 'extern ' : ignored on left of 'int' when no variable is declared
317 #pragma warning(disable : 4091)
318 
319 // Compiler-specific extension warning.
320 #pragma warning(disable : 4231)
321 
322 // We need to disable warning 4910 and do an extern dllexport
323 // anyway. When deriving new arrays from an
324 // instantiation of this template the compiler does an explicit
325 // instantiation of the base class. From outside the vtkCommon
326 // library we block this using an extern dllimport instantiation.
327 // For classes inside vtkCommon we should be able to just do an
328 // extern instantiation, but VS 2008 complains about missing
329 // definitions. We cannot do an extern dllimport inside vtkCommon
330 // since the symbols are local to the dll. An extern dllexport
331 // seems to be the only way to convince VS 2008 to do the right
332 // thing, so we just disable the warning.
333 #pragma warning(disable : 4910) // extern and dllexport incompatible
334 
335 // Use an "extern explicit instantiation" to give the class a DLL
336 // interface. This is a compiler-specific extension.
338  extern template class VTKCOMMONCORE_EXPORT vtkScaledSOADataArrayTemplate);
339 
340 #pragma warning(pop)
341 
342 #endif
343 
344 // VTK-HeaderTest-Exclude: vtkScaledSOADataArrayTemplate.h
vtkAbstractArray::DeleteMethod
DeleteMethod
Definition: vtkAbstractArray.h:321
VTK_ZEROCOPY
#define VTK_ZEROCOPY
Definition: vtkWrappingHints.h:43
vtkAbstractArray::ScaleSoADataArrayTemplate
@ ScaleSoADataArrayTemplate
Definition: vtkAbstractArray.h:641
vtkAbstractArray::VTK_DATA_ARRAY_ALIGNED_FREE
@ VTK_DATA_ARRAY_ALIGNED_FREE
Definition: vtkAbstractArray.h:325
vtkGenericDataArray::GetTypedComponent
ValueType GetTypedComponent(vtkIdType tupleIdx, int compIdx) const
Get component compIdx of the tuple at tupleIdx.
Definition: vtkGenericDataArray.h:158
vtkTypeTraits
Template defining traits of native types used by VTK.
Definition: vtkTypeTraits.h:30
vtkScaledSOADataArrayTemplate::SetScale
void SetScale(ValueType scale)
Set/Get the Scale value for the object.
Definition: vtkScaledSOADataArrayTemplate.h:68
vtkX3D::scale
@ scale
Definition: vtkX3D.h:235
vtkGenericDataArray::vtkTemplateTypeMacro
vtkTemplateTypeMacro(SelfType, vtkDataArray)
vtkX3D::value
@ value
Definition: vtkX3D.h:226
vtkAbstractArray::VTK_DATA_ARRAY_DELETE
@ VTK_DATA_ARRAY_DELETE
Definition: vtkAbstractArray.h:324
vtkIdType
int vtkIdType
Definition: vtkType.h:338
vtkScaledSOADataArrayTemplate::GetTypedComponent
ValueType GetTypedComponent(vtkIdType tupleIdx, int comp) const
Get component comp of the tuple at tupleIdx.
Definition: vtkScaledSOADataArrayTemplate.h:137
vtkGenericDataArray::GetVoidPointer
void * GetVoidPointer(vtkIdType valueIdx) override
Default implementation raises a runtime error.
vtkObject::New
static vtkObject * New()
Create an object with Debug turned off, modified time initialized to zero, and reference counting on.
save
void save(Archiver &ar, const vtkUnicodeString &str, const unsigned int vtkNotUsed(version))
Definition: vtkVariantBoostSerialization.h:64
vtkScaledSOADataArrayTemplate::AoSCopy
vtkBuffer< ValueType > * AoSCopy
Definition: vtkScaledSOADataArrayTemplate.h:266
vtkGenericDataArray::SetTypedComponent
void SetTypedComponent(vtkIdType tupleIdx, int compIdx, ValueType value)
Set component compIdx of the tuple at tupleIdx to value.
Definition: vtkGenericDataArray.h:169
vtkAbstractArray::VTK_DATA_ARRAY_FREE
@ VTK_DATA_ARRAY_FREE
Definition: vtkAbstractArray.h:323
vtkScaledSOADataArrayTemplate::GetArrayType
int GetArrayType() const override
Method for type-checking in FastDownCast implementations.
Definition: vtkScaledSOADataArrayTemplate.h:234
vtkGenericDataArray
Base interface for all typed vtkDataArray subclasses.
Definition: vtkGenericDataArray.h:79
vtkScaledSOADataArrayTemplate::SelfType
vtkScaledSOADataArrayTemplate< ValueTypeT > SelfType
Definition: vtkScaledSOADataArrayTemplate.h:50
vtkDataArray
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:49
vtkScaledSOADataArrayTemplate::GetTypedTuple
void GetTypedTuple(vtkIdType tupleIdx, ValueType *tuple) const
Copy the tuple at tupleIdx into tuple.
Definition: vtkScaledSOADataArrayTemplate.h:115
vtkScaledSOADataArrayTemplate
Struct-Of-Arrays implementation of vtkGenericDataArray with a scaling factor.
Definition: vtkScaledSOADataArrayTemplate.h:43
vtkGenericDataArray::SetArrayFreeFunction
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...
vtkDataArray::Modified
void Modified() override
Removes out-of-date L2_NORM_RANGE() and L2_NORM_FINITE_RANGE() values.
vtkArrayDownCast_TemplateFastCastMacro
vtkArrayDownCast_TemplateFastCastMacro(vtkScaledSOADataArrayTemplate)
vtkBuffer< ValueType >
vtkGenericDataArray::FillTypedComponent
virtual void FillTypedComponent(int compIdx, ValueType value)
Set component comp of all tuples to value.
vtkGenericDataArray::InsertTuples
void InsertTuples(vtkIdList *dstIds, vtkIdList *srcIds, vtkAbstractArray *source) override
Copy the tuples indexed in srcIds from the source array to the tuple locations indexed by dstIds in t...
vtkScaledSOADataArrayTemplate::GetValue
ValueType GetValue(vtkIdType valueIdx) const
Get the value at valueIdx.
Definition: vtkScaledSOADataArrayTemplate.h:90
vtkScaledSOADataArrayTemplate::SetValue
void SetValue(vtkIdType valueIdx, ValueType value)
Set the value at valueIdx to value.
Definition: vtkScaledSOADataArrayTemplate.h:103
vtkBuffer.h
vtkGenericDataArray::AllocateTuples
bool AllocateTuples(vtkIdType numTuples)
Allocate space for numTuples.
Definition: vtkGenericDataArray.h:335
vtkExternTemplateMacro
#define vtkExternTemplateMacro(decl)
A macro to declare extern templates for all numerical types.
Definition: vtkType.h:403
vtkAbstractArray::VTK_DATA_ARRAY_USER_DEFINED
@ VTK_DATA_ARRAY_USER_DEFINED
Definition: vtkAbstractArray.h:326
vtkGenericDataArray.h
vtkScaledSOADataArrayTemplate::Data
std::vector< vtkBuffer< ValueType > * > Data
Definition: vtkScaledSOADataArrayTemplate.h:265
vtkIdList
list of point or cell ids
Definition: vtkIdList.h:30
vtkX3D::size
@ size
Definition: vtkX3D.h:259
vtkDataArray::ShallowCopy
virtual void ShallowCopy(vtkDataArray *other)
Create a shallow copy of other into this, if possible.
vtkAbstractArray
Abstract superclass for all arrays.
Definition: vtkAbstractArray.h:75
vtkInstantiateTemplateMacro
#define vtkInstantiateTemplateMacro(decl)
A macro to instantiate a template over all numerical types.
Definition: vtkType.h:384
vtkGenericDataArray::NewIterator
vtkArrayIterator * NewIterator() override
Subclasses must override this method and provide the right kind of templated vtkArrayIteratorTemplate...
vtkAbstractArray::ExportToVoidPointer
virtual void ExportToVoidPointer(void *out_ptr)
This method copies the array data to the void pointer specified by the user.
vtkScaledSOADataArrayTemplate::SetTypedTuple
void SetTypedTuple(vtkIdType tupleIdx, const ValueType *tuple)
Set this array's tuple at tupleIdx to the values in tuple.
Definition: vtkScaledSOADataArrayTemplate.h:126
vtkArrayIterator
Abstract superclass to iterate over elements in an vtkAbstractArray.
Definition: vtkArrayIterator.h:49
vtkScaledSOADataArrayTemplate::InsertTuples
void InsertTuples(vtkIdList *dstIds, vtkIdList *srcIds, vtkAbstractArray *source) override
Copy the tuples indexed in srcIds from the source array to the tuple locations indexed by dstIds in t...
Definition: vtkScaledSOADataArrayTemplate.h:244
vtkScaledSOADataArrayTemplate::GetScale
ValueType GetScale() const
Definition: vtkScaledSOADataArrayTemplate.h:83
vtkScaledSOADataArrayTemplate::FastDownCast
static vtkScaledSOADataArrayTemplate< ValueType > * FastDownCast(vtkAbstractArray *source)
Perform a fast, safe cast from a vtkAbstractArray to a vtkDataArray.
Definition: vtkScaledSOADataArrayTemplate.h:215
source
boost::graph_traits< vtkGraph * >::vertex_descriptor source(boost::graph_traits< vtkGraph * >::edge_descriptor e, vtkGraph *)
Definition: vtkBoostGraphAdapter.h:959
VTK_NEWINSTANCE
#define VTK_NEWINSTANCE
Definition: vtkWrappingHints.h:42
vtkScaledSOADataArrayTemplate::ValueType
Superclass::ValueType ValueType
Definition: vtkScaledSOADataArrayTemplate.h:52
vtkGenericDataArray::ReallocateTuples
bool ReallocateTuples(vtkIdType numTuples)
Allocate space for numTuples.
Definition: vtkGenericDataArray.h:345
vtkScaledSOADataArrayTemplate::SetTypedComponent
void SetTypedComponent(vtkIdType tupleIdx, int comp, ValueType value)
Set component comp of the tuple at tupleIdx to value.
Definition: vtkScaledSOADataArrayTemplate.h:145
vtkGenericDataArray::SetNumberOfComponents
void SetNumberOfComponents(int num) override
Set/Get the dimension (n) of the components.
vtkAbstractArray::NumberOfComponents
int NumberOfComponents
Definition: vtkAbstractArray.h:679