VTK
vtkSOADataArrayTemplate.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkSOADataArrayTemplate.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 =========================================================================*/
28 #ifndef vtkSOADataArrayTemplate_h
29 #define vtkSOADataArrayTemplate_h
30 
31 #include "vtkCommonCoreModule.h" // For export macro
32 #include "vtkGenericDataArray.h"
33 #include "vtkBuffer.h"
34 
35 // The export macro below makes no sense, but is necessary for older compilers
36 // when we export instantiations of this class from vtkCommonCore.
37 template <class ValueTypeT>
38 class VTKCOMMONCORE_EXPORT vtkSOADataArrayTemplate :
39  public vtkGenericDataArray<vtkSOADataArrayTemplate<ValueTypeT>, ValueTypeT>
40 {
43 public:
46  typedef typename Superclass::ValueType ValueType;
47 
49  {
53  };
54 
55  static vtkSOADataArrayTemplate* New();
56 
58 
61  inline ValueType GetValue(vtkIdType valueIdx) const
62  {
63  vtkIdType tupleIdx;
64  int comp;
65  this->GetTupleIndexFromValueIndex(valueIdx, tupleIdx, comp);
66  return this->GetTypedComponent(tupleIdx, comp);
67  }
69 
71 
74  inline void SetValue(vtkIdType valueIdx, ValueType value)
75  {
76  vtkIdType tupleIdx;
77  int comp;
78  this->GetTupleIndexFromValueIndex(valueIdx, tupleIdx, comp);
79  this->SetTypedComponent(tupleIdx, comp, value);
80  }
82 
86  inline void GetTypedTuple(vtkIdType tupleIdx, ValueType* tuple) const
87  {
88  for (size_t cc=0; cc < this->Data.size(); cc++)
89  {
90  tuple[cc] = this->Data[cc]->GetBuffer()[tupleIdx];
91  }
92  }
93 
97  inline void SetTypedTuple(vtkIdType tupleIdx, const ValueType* tuple)
98  {
99  for (size_t cc=0; cc < this->Data.size(); ++cc)
100  {
101  this->Data[cc]->GetBuffer()[tupleIdx] = tuple[cc];
102  }
103  }
104 
108  inline ValueType GetTypedComponent(vtkIdType tupleIdx, int comp) const
109  {
110  return this->Data[comp]->GetBuffer()[tupleIdx];
111  }
112 
116  inline void SetTypedComponent(vtkIdType tupleIdx, int comp, ValueType value)
117  {
118  this->Data[comp]->GetBuffer()[tupleIdx] = value;
119  }
120 
124  void FillTypedComponent(int compIdx, ValueType value) override;
125 
139  void SetArray(int comp, VTK_ZEROCOPY ValueType* array, vtkIdType size,
140  bool updateMaxId = false, bool save=false,
141  int deleteMethod=VTK_DATA_ARRAY_FREE);
142 
147  ValueType* GetComponentArrayPointer(int comp);
148 
153  void *GetVoidPointer(vtkIdType valueIdx) override;
154 
159  void ExportToVoidPointer(void *ptr) override;
160 
161 #ifndef __VTK_WRAP__
162 
163 
171  {
172  if (source)
173  {
174  switch (source->GetArrayType())
175  {
177  if (vtkDataTypesCompare(source->GetDataType(),
179  {
180  return static_cast<vtkSOADataArrayTemplate<ValueType>*>(source);
181  }
182  break;
183  }
184  }
185  return nullptr;
186  }
188 #endif
189 
192  void SetNumberOfComponents(int numComps) override;
193  void ShallowCopy(vtkDataArray *other) override;
194 
195  // Reimplemented for efficiency:
196  void InsertTuples(vtkIdType dstStart, vtkIdType n, vtkIdType srcStart,
197  vtkAbstractArray* source) override;
198  // MSVC doesn't like 'using' here (error C2487). Just forward instead:
199  // using Superclass::InsertTuples;
200  void InsertTuples(vtkIdList *dstIds, vtkIdList *srcIds,
201  vtkAbstractArray *source) override
202  { this->Superclass::InsertTuples(dstIds, srcIds, source); }
203 
204 protected:
206  ~vtkSOADataArrayTemplate() override;
207 
212  bool AllocateTuples(vtkIdType numTuples);
213 
218  bool ReallocateTuples(vtkIdType numTuples);
219 
220  std::vector<vtkBuffer<ValueType>*> Data;
222 
224 
225 private:
227  void operator=(const vtkSOADataArrayTemplate&) = delete;
228 
229  inline void GetTupleIndexFromValueIndex(vtkIdType valueIdx,
230  vtkIdType& tupleIdx, int& comp) const
231  {
232  tupleIdx = static_cast<vtkIdType>(valueIdx *
233  this->NumberOfComponentsReciprocal);
234  comp = valueIdx - (tupleIdx * this->NumberOfComponents);
235  }
236 
237  friend class vtkGenericDataArray<vtkSOADataArrayTemplate<ValueTypeT>,
238  ValueTypeT>;
239 };
240 
241 // Declare vtkArrayDownCast implementations for SoA containers:
243 
244 #endif // header guard
245 
246 // This portion must be OUTSIDE the include blockers. This is used to tell
247 // libraries other than vtkCommonCore that instantiations of
248 // vtkSOADataArrayTemplate can be found externally. This prevents each library
249 // from instantiating these on their own.
250 #ifdef VTK_SOA_DATA_ARRAY_TEMPLATE_INSTANTIATING
251 #define VTK_SOA_DATA_ARRAY_TEMPLATE_INSTANTIATE(T) \
252  template class VTKCOMMONCORE_EXPORT vtkSOADataArrayTemplate< T >
253 #elif defined(VTK_USE_EXTERN_TEMPLATE)
254 #ifndef VTK_SOA_DATA_ARRAY_TEMPLATE_EXTERN
255 #define VTK_SOA_DATA_ARRAY_TEMPLATE_EXTERN
256 #ifdef _MSC_VER
257 #pragma warning (push)
258 // The following is needed when the vtkSOADataArrayTemplate is declared
259 // dllexport and is used from another class in vtkCommonCore
260 #pragma warning (disable: 4910) // extern and dllexport incompatible
261 #endif
263  extern template class VTKCOMMONCORE_EXPORT vtkSOADataArrayTemplate)
264 #ifdef _MSC_VER
265 #pragma warning (pop)
266 #endif
267 #endif // VTK_SOA_DATA_ARRAY_TEMPLATE_EXTERN
268 
269 // The following clause is only for MSVC 2008 and 2010
270 #elif defined(_MSC_VER) && !defined(VTK_BUILD_SHARED_LIBS)
271 #pragma warning (push)
272 
273 // C4091: 'extern ' : ignored on left of 'int' when no variable is declared
274 #pragma warning (disable: 4091)
275 
276 // Compiler-specific extension warning.
277 #pragma warning (disable: 4231)
278 
279 // We need to disable warning 4910 and do an extern dllexport
280 // anyway. When deriving new arrays from an
281 // instantiation of this template the compiler does an explicit
282 // instantiation of the base class. From outside the vtkCommon
283 // library we block this using an extern dllimport instantiation.
284 // For classes inside vtkCommon we should be able to just do an
285 // extern instantiation, but VS 2008 complains about missing
286 // definitions. We cannot do an extern dllimport inside vtkCommon
287 // since the symbols are local to the dll. An extern dllexport
288 // seems to be the only way to convince VS 2008 to do the right
289 // thing, so we just disable the warning.
290 #pragma warning (disable: 4910) // extern and dllexport incompatible
291 
292 // Use an "extern explicit instantiation" to give the class a DLL
293 // interface. This is a compiler-specific extension.
295  extern template class VTKCOMMONCORE_EXPORT vtkSOADataArrayTemplate)
296 
297 #pragma warning (pop)
298 
299 #endif
300 
301 // VTK-HeaderTest-Exclude: vtkSOADataArrayTemplate.h
Struct-Of-Arrays implementation of vtkGenericDataArray.
vtkBuffer< ValueType > * AoSCopy
ValueType GetTypedComponent(vtkIdType tupleIdx, int comp) const
Get component comp of the tuple at tupleIdx.
virtual void ShallowCopy(vtkDataArray *other)
Create a shallow copy of other into this, if possible.
ValueType GetTypedComponent(vtkIdType tupleIdx, int compIdx) const
Get component compIdx of the tuple at tupleIdx.
ValueType GetValue(vtkIdType valueIdx) const
Get the value at valueIdx.
Abstract superclass for all arrays.
vtkTemplateTypeMacro(SelfType, vtkDataArray) enum
Compile time access to the VTK type identifier.
static vtkSOADataArrayTemplate< ValueType > * FastDownCast(vtkAbstractArray *source)
Perform a fast, safe cast from a vtkAbstractArray to a vtkDataArray.
void SetTypedComponent(vtkIdType tupleIdx, int compIdx, ValueType value)
Set component compIdx of the tuple at tupleIdx to value.
int vtkIdType
Definition: vtkType.h:345
Base interface for all typed vtkDataArray subclasses.
void SetTypedTuple(vtkIdType tupleIdx, const ValueType *tuple)
Set this array&#39;s tuple at tupleIdx to the values in tuple.
#define vtkExternTemplateMacro(decl)
A macro to declare extern templates for all numerical types.
Definition: vtkType.h:413
list of point or cell ids
Definition: vtkIdList.h:30
bool AllocateTuples(vtkIdType numTuples)
Allocate space for numTuples.
vtkSOADataArrayTemplate< ValueTypeT > SelfType
void SetValue(vtkIdType valueIdx, ValueType value)
Set the value at valueIdx to value.
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:48
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...
Abstract superclass to iterate over elements in an vtkAbstractArray.
vtkArrayIterator * NewIterator() override
Subclasses must override this method and provide the right kind of templated vtkArrayIteratorTemplate...
#define VTK_NEWINSTANCE
#define vtkInstantiateTemplateMacro(decl)
A macro to instantiate a template over all numerical types.
Definition: vtkType.h:393
void * GetVoidPointer(vtkIdType valueIdx) override
Default implementation raises a runtime error.
void save(Archiver &ar, const vtkUnicodeString &str, const unsigned int vtkNotUsed(version))
vtkArrayDownCast_TemplateFastCastMacro(vtkTypedDataArray) template< class Scalar > inline typename vtkTypedDataArray< Scalar >
void GetTypedTuple(vtkIdType tupleIdx, ValueType *tuple) const
Copy the tuple at tupleIdx into tuple.
boost::graph_traits< vtkGraph *>::vertex_descriptor source(boost::graph_traits< vtkGraph * >::edge_descriptor e, vtkGraph *)
#define VTK_ZEROCOPY
std::vector< vtkBuffer< ValueType > * > Data
virtual void FillTypedComponent(int compIdx, ValueType value)
Set component comp of all tuples to value.
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...
static vtkObject * New()
Create an object with Debug turned off, modified time initialized to zero, and reference counting on...
bool ReallocateTuples(vtkIdType numTuples)
Allocate space for numTuples.
void SetNumberOfComponents(int num) override
Set/Get the dimension (n) of the components.
int GetArrayType() override
Method for type-checking in FastDownCast implementations.
Template defining traits of native types used by VTK.
Definition: vtkTypeTraits.h:29
void SetTypedComponent(vtkIdType tupleIdx, int comp, ValueType value)
Set component comp of the tuple at tupleIdx to value.
virtual void ExportToVoidPointer(void *out_ptr)
This method copies the array data to the void pointer specified by the user.