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 =========================================================================*/
31 #ifndef vtkSOADataArrayTemplate_h
32 #define vtkSOADataArrayTemplate_h
33 
34 #include "vtkCommonCoreModule.h" // For export macro
35 #include "vtkGenericDataArray.h"
36 #include "vtkBuffer.h"
37 
38 // The export macro below makes no sense, but is necessary for older compilers
39 // when we export instantiations of this class from vtkCommonCore.
40 template <class ValueTypeT>
41 class VTKCOMMONCORE_EXPORT vtkSOADataArrayTemplate :
42  public vtkGenericDataArray<vtkSOADataArrayTemplate<ValueTypeT>, ValueTypeT>
43 {
46 public:
49  typedef typename Superclass::ValueType ValueType;
50 
52  {
55  };
56 
58 
60 
63  inline ValueType GetValue(vtkIdType valueIdx) const
64  {
65  vtkIdType tupleIdx;
66  int comp;
67  this->GetTupleIndexFromValueIndex(valueIdx, tupleIdx, comp);
68  return this->GetTypedComponent(tupleIdx, comp);
69  }
71 
73 
76  inline void SetValue(vtkIdType valueIdx, ValueType value)
77  {
78  vtkIdType tupleIdx;
79  int comp;
80  this->GetTupleIndexFromValueIndex(valueIdx, tupleIdx, comp);
81  this->SetTypedComponent(tupleIdx, comp, value);
82  }
84 
88  inline void GetTypedTuple(vtkIdType tupleIdx, ValueType* tuple) const
89  {
90  for (size_t cc=0; cc < this->Data.size(); cc++)
91  {
92  tuple[cc] = this->Data[cc]->GetBuffer()[tupleIdx];
93  }
94  }
95 
99  inline void SetTypedTuple(vtkIdType tupleIdx, const ValueType* tuple)
100  {
101  for (size_t cc=0; cc < this->Data.size(); ++cc)
102  {
103  this->Data[cc]->GetBuffer()[tupleIdx] = tuple[cc];
104  }
105  }
106 
110  inline ValueType GetTypedComponent(vtkIdType tupleIdx, int comp) const
111  {
112  return this->Data[comp]->GetBuffer()[tupleIdx];
113  }
114 
118  inline void SetTypedComponent(vtkIdType tupleIdx, int comp, ValueType value)
119  {
120  this->Data[comp]->GetBuffer()[tupleIdx] = value;
121  }
122 
136  void SetArray(int comp, ValueType* array, vtkIdType size,
137  bool updateMaxId = false, bool save=false,
138  int deleteMethod=VTK_DATA_ARRAY_FREE);
139 
145 
150  void *GetVoidPointer(vtkIdType valueIdx) VTK_OVERRIDE;
151 
156  void ExportToVoidPointer(void *ptr) VTK_OVERRIDE;
157 
159 
167  {
168  if (source)
169  {
170  switch (source->GetArrayType())
171  {
173  if (vtkDataTypesCompare(source->GetDataType(),
175  {
176  return static_cast<vtkSOADataArrayTemplate<ValueType>*>(source);
177  }
178  break;
179  }
180  }
181  return NULL;
182  }
184 
187  void SetNumberOfComponents(int numComps) VTK_OVERRIDE;
188  void ShallowCopy(vtkDataArray *other) VTK_OVERRIDE;
189 
190  // Reimplemented for efficiency:
191  void InsertTuples(vtkIdType dstStart, vtkIdType n, vtkIdType srcStart,
192  vtkAbstractArray* source) VTK_OVERRIDE;
193  // MSVC doesn't like 'using' here (error C2487). Just forward instead:
194  // using Superclass::InsertTuples;
195  void InsertTuples(vtkIdList *dstIds, vtkIdList *srcIds,
196  vtkAbstractArray *source) VTK_OVERRIDE
197  { this->Superclass::InsertTuples(dstIds, srcIds, source); }
198 
199 protected:
201  ~vtkSOADataArrayTemplate() VTK_OVERRIDE;
202 
207  bool AllocateTuples(vtkIdType numTuples);
208 
213  bool ReallocateTuples(vtkIdType numTuples);
214 
215  std::vector<vtkBuffer<ValueType>*> Data;
216  vtkBuffer<ValueType> *AoSCopy;
217 
218  double NumberOfComponentsReciprocal;
219 
220 private:
221  vtkSOADataArrayTemplate(const vtkSOADataArrayTemplate&) VTK_DELETE_FUNCTION;
222  void operator=(const vtkSOADataArrayTemplate&) VTK_DELETE_FUNCTION;
223 
224  inline void GetTupleIndexFromValueIndex(vtkIdType valueIdx,
225  vtkIdType& tupleIdx, int& comp) const
226  {
227  tupleIdx = static_cast<vtkIdType>(valueIdx *
228  this->NumberOfComponentsReciprocal);
229  comp = valueIdx - (tupleIdx * this->NumberOfComponents);
230  }
231 
232  friend class vtkGenericDataArray<vtkSOADataArrayTemplate<ValueTypeT>,
233  ValueTypeT>;
234 };
235 
236 // Declare vtkArrayDownCast implementations for SoA containers:
238 
239 #endif // header guard
240 
241 // This portion must be OUTSIDE the include blockers. This is used to tell
242 // libraries other than vtkCommonCore that instantiations of
243 // vtkSOADataArrayTemplate can be found externally. This prevents each library
244 // from instantiating these on their own.
245 #ifdef VTK_SOA_DATA_ARRAY_TEMPLATE_INSTANTIATING
246 #define VTK_SOA_DATA_ARRAY_TEMPLATE_INSTANTIATE(T) \
247  template class VTKCOMMONCORE_EXPORT vtkSOADataArrayTemplate< T >
248 #elif defined(VTK_USE_EXTERN_TEMPLATE)
249 #ifndef VTK_SOA_DATA_ARRAY_TEMPLATE_EXTERN
250 #define VTK_SOA_DATA_ARRAY_TEMPLATE_EXTERN
251 #ifdef _MSC_VER
252 #pragma warning (push)
253 // The following is needed when the vtkSOADataArrayTemplate is declared
254 // dllexport and is used from another class in vtkCommonCore
255 #pragma warning (disable: 4910) // extern and dllexport incompatible
256 #endif
258  extern template class VTKCOMMONCORE_EXPORT vtkSOADataArrayTemplate)
259 #ifdef _MSC_VER
260 #pragma warning (pop)
261 #endif
262 #endif // VTK_SOA_DATA_ARRAY_TEMPLATE_EXTERN
263 
264 // The following clause is only for MSVC 2008 and 2010
265 #elif defined(_MSC_VER) && !defined(VTK_BUILD_SHARED_LIBS)
266 #pragma warning (push)
267 
268 // C4091: 'extern ' : ignored on left of 'int' when no variable is declared
269 #pragma warning (disable: 4091)
270 
271 // Compiler-specific extension warning.
272 #pragma warning (disable: 4231)
273 
274 // We need to disable warning 4910 and do an extern dllexport
275 // anyway. When deriving new arrays from an
276 // instantiation of this template the compiler does an explicit
277 // instantiation of the base class. From outside the vtkCommon
278 // library we block this using an extern dllimport instantiation.
279 // For classes inside vtkCommon we should be able to just do an
280 // extern instantiation, but VS 2008 complains about missing
281 // definitions. We cannot do an extern dllimport inside vtkCommon
282 // since the symbols are local to the dll. An extern dllexport
283 // seems to be the only way to convince VS 2008 to do the right
284 // thing, so we just disable the warning.
285 #pragma warning (disable: 4910) // extern and dllexport incompatible
286 
287 // Use an "extern explicit instantiation" to give the class a DLL
288 // interface. This is a compiler-specific extension.
290  extern template class VTKCOMMONCORE_EXPORT vtkSOADataArrayTemplate)
291 
292 #pragma warning (pop)
293 
294 #endif
295 
296 // VTK-HeaderTest-Exclude: vtkSOADataArrayTemplate.h
vtkAbstractArray::DeleteMethod
DeleteMethod
Definition: vtkAbstractArray.h:334
vtkX3D::vector
@ vector
Definition: vtkX3D.h:237
vtkGenericDataArray::ValueType
ValueTypeT ValueType
Definition: vtkGenericDataArray.h:81
vtkGenericDataArray::GetTypedComponent
ValueType GetTypedComponent(vtkIdType tupleIdx, int compIdx) const
Get component compIdx of the tuple at tupleIdx.
Definition: vtkGenericDataArray.h:149
vtkTypeTraits
Template defining traits of native types used by VTK.
Definition: vtkTypeTraits.h:32
vtkSOADataArrayTemplate::SetArray
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.
vtkSOADataArrayTemplate::~vtkSOADataArrayTemplate
~vtkSOADataArrayTemplate() override
vtkSOADataArrayTemplate::ExportToVoidPointer
void ExportToVoidPointer(void *ptr) override
Export a copy of the data in AoS ordering to the preallocated memory buffer.
vtkX3D::value
@ value
Definition: vtkX3D.h:220
vtkSOADataArrayTemplate
Struct-Of-Arrays implementation of vtkGenericDataArray.
Definition: vtkSOADataArrayTemplate.h:43
vtkIdType
int vtkIdType
Definition: vtkType.h:287
vtkSOADataArrayTemplate::SetTypedTuple
void SetTypedTuple(vtkIdType tupleIdx, const ValueType *tuple)
Set this array's tuple at tupleIdx to the values in tuple.
Definition: vtkSOADataArrayTemplate.h:99
vtkSOADataArrayTemplate::GetTypedComponent
ValueType GetTypedComponent(vtkIdType tupleIdx, int comp) const
Get component comp of the tuple at tupleIdx.
Definition: vtkSOADataArrayTemplate.h:110
save
void save(Archiver &ar, const vtkUnicodeString &str, const unsigned int vtkNotUsed(version))
Definition: vtkVariantBoostSerialization.h:65
vtkGenericDataArray::SetTypedComponent
void SetTypedComponent(vtkIdType tupleIdx, int compIdx, ValueType value)
Set component compIdx of the tuple at tupleIdx to value.
Definition: vtkGenericDataArray.h:160
vtkGenericDataArray
Base interface for all typed vtkDataArray subclasses.
Definition: vtkGenericDataArray.h:78
vtkDataArray
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:55
vtkSOADataArrayTemplate::FastDownCast
static vtkSOADataArrayTemplate< ValueType > * FastDownCast(vtkAbstractArray *source)
Perform a fast, safe cast from a vtkAbstractArray to a vtkDataArray.
Definition: vtkSOADataArrayTemplate.h:166
vtkSOADataArrayTemplate::SelfType
vtkSOADataArrayTemplate< ValueTypeT > SelfType
Definition: vtkSOADataArrayTemplate.h:47
source
boost::graph_traits< vtkGraph * >::vertex_descriptor source(boost::graph_traits< vtkGraph * >::edge_descriptor e, vtkGraph *)
Definition: vtkBoostGraphAdapter.h:822
vtkBuffer
internal storage class used by vtkSOADataArrayTemplate, vtkAOSDataArrayTemplate, and others.
Definition: vtkBuffer.h:33
vtkSOADataArrayTemplate::vtkSOADataArrayTemplate
vtkSOADataArrayTemplate()
vtkSOADataArrayTemplate::GetComponentArrayPointer
ValueType * GetComponentArrayPointer(int comp)
Return a pointer to a contiguous block of memory containing all values for a particular components (i...
vtkBuffer.h
vtkAbstractArray::SoADataArrayTemplate
@ SoADataArrayTemplate
Definition: vtkAbstractArray.h:610
vtkExternTemplateMacro
#define vtkExternTemplateMacro(decl)
A macro to declare extern templates for all numerical types.
Definition: vtkType.h:345
vtkSOADataArrayTemplate::SetValue
void SetValue(vtkIdType valueIdx, ValueType value)
Set the value at valueIdx to value.
Definition: vtkSOADataArrayTemplate.h:76
vtkGenericDataArray::vtkTemplateTypeMacro
vtkTemplateTypeMacro(SelfType, vtkDataArray) enum
Compile time access to the VTK type identifier.
Definition: vtkGenericDataArray.h:82
vtkGenericDataArray.h
vtkSOADataArrayTemplate::NewIterator
VTK_NEWINSTANCE vtkArrayIterator * NewIterator() override
Subclasses must override this method and provide the right kind of templated vtkArrayIteratorTemplate...
vtkIdList
list of point or cell ids
Definition: vtkIdList.h:37
vtkX3D::size
@ size
Definition: vtkX3D.h:253
vtkAbstractArray
Abstract superclass for all arrays.
Definition: vtkAbstractArray.h:79
vtkInstantiateTemplateMacro
#define vtkInstantiateTemplateMacro(decl)
A macro to instantiate a template over all numerical types.
Definition: vtkType.h:325
vtkSOADataArrayTemplate::GetTypedTuple
void GetTypedTuple(vtkIdType tupleIdx, ValueType *tuple) const
Copy the tuple at tupleIdx into tuple.
Definition: vtkSOADataArrayTemplate.h:88
vtkSOADataArrayTemplate::GetVoidPointer
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...
vtkArrayIterator
Abstract superclass to iterate over elements in an vtkAbstractArray.
Definition: vtkArrayIterator.h:50
vtkArrayDownCast_TemplateFastCastMacro
vtkArrayDownCast_TemplateFastCastMacro(vtkTypedDataArray) template< class Scalar > inline typename vtkTypedDataArray< Scalar >
Definition: vtkTypedDataArray.h:191
vtkSOADataArrayTemplate::GetArrayType
int GetArrayType() override
Method for type-checking in FastDownCast implementations.
Definition: vtkSOADataArrayTemplate.h:185
VTK_NEWINSTANCE
#define VTK_NEWINSTANCE
Definition: vtkWrappingHints.h:30
vtkSOADataArrayTemplate::New
static vtkSOADataArrayTemplate * New()
vtkSOADataArrayTemplate::GetValue
ValueType GetValue(vtkIdType valueIdx) const
Get the value at valueIdx.
Definition: vtkSOADataArrayTemplate.h:63
vtkAbstractArray::NumberOfComponents
int NumberOfComponents
Definition: vtkAbstractArray.h:653
vtkSOADataArrayTemplate::SetTypedComponent
void SetTypedComponent(vtkIdType tupleIdx, int comp, ValueType value)
Set component comp of the tuple at tupleIdx to value.
Definition: vtkSOADataArrayTemplate.h:118