VTK
vtkDataArrayTemplate.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkDataArrayTemplate.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 =========================================================================*/
23 #ifndef vtkDataArrayTemplate_h
24 #define vtkDataArrayTemplate_h
25 
26 #include "vtkCommonCoreModule.h" // For export macro
27 #include "vtkTypedDataArray.h"
28 #include "vtkTypeTemplate.h" // For templated vtkObject API
29 #include <cassert> // for assert()
30 
31 template <class T>
33 
34 template <class T>
36  public vtkTypeTemplate<vtkDataArrayTemplate<T>, vtkTypedDataArray<T> >
37 {
38 public:
40  typedef typename Superclass::ValueType ValueType;
42 
43  void PrintSelf(ostream& os, vtkIndent indent);
44 
48  typedef ValueType* Iterator;
49 
53  Iterator Begin() { return Iterator(this->GetVoidPointer(0)); }
54 
58  Iterator End() { return Iterator(this->GetVoidPointer(this->MaxId + 1)); }
59 
67 
70  int Allocate(vtkIdType sz, vtkIdType ext=1000);
71 
73  void Initialize();
74 
76  int GetDataTypeSize() { return static_cast<int>(sizeof(T)); }
77 
80 
87 
92 
94 
97  virtual void InsertTuples(vtkIdList *destIds, vtkIdList *srcIds,
100 
102 
105  virtual void InsertTuples(vtkIdType dstStart, vtkIdType n, vtkIdType srcStart,
108 
113 
116  double* GetTuple(vtkIdType i);
117 
119 
120  void GetTuple(vtkIdType i, double* tuple);
121  void GetTupleValue(vtkIdType i, T* tuple);
123 
125 
126  void SetTuple(vtkIdType i, const float* tuple);
127  void SetTuple(vtkIdType i, const double* tuple);
128  void SetTupleValue(vtkIdType i, const T* tuple);
130 
132 
134  void InsertTuple(vtkIdType i, const float* tuple);
135  void InsertTuple(vtkIdType i, const double* tuple);
136  void InsertTupleValue(vtkIdType i, const T* tuple);
138 
140 
142  vtkIdType InsertNextTuple(const float* tuple);
143  vtkIdType InsertNextTuple(const double* tuple);
146 
148 
150  void GetValueRange(T range[2], int comp)
151  {
152  double doubleRange[2];
153  this->ComputeRange(doubleRange, comp);
154  range[0] = static_cast<T>(doubleRange[0]);
155  range[1] = static_cast<T>(doubleRange[1]);
156  }
157  T *GetValueRange(int comp)
158  {
159  this->GetValueRange(this->ValueRange, comp);
160  return this->ValueRange;
161  }
163 
165 
168  { return this->GetValueRange(0); }
169  void GetValueRange(T range[2])
170  { this->GetValueRange(range, 0); }
172 
174  void Squeeze() { this->ResizeAndExtend (this->MaxId+1); }
175 
177  vtkIdType Capacity() { return this->Size; }
178 
183  virtual int Resize(vtkIdType numTuples);
184 
186 
188  { assert(id >= 0 && id < this->Size); return this->Array[id]; }
190  { assert(id >= 0 && id < this->Size); return this->Array[id]; }
192 
194 
197  { assert(id >= 0 && id < this->Size); this->Array[id] = value;};
199 
204 
206  void InsertValue(vtkIdType id, T f);
207 
210 
214 
216 
219  virtual void RemoveTuple(vtkIdType id);
220  virtual void RemoveFirstTuple();
221  virtual void RemoveLastTuple();
223 
227  double GetComponent(vtkIdType i, int j);
228 
233  void SetComponent(vtkIdType i, int j, double c);
234 
238  virtual void InsertComponent(vtkIdType i, int j, double c);
239 
241 
245  virtual void* WriteVoidPointer(vtkIdType id, vtkIdType number)
246  { return this->WritePointer(id, number); }
248 
250 
254  T* GetPointer(vtkIdType id) { return this->Array + id; }
255  virtual void* GetVoidPointer(vtkIdType id) { return this->GetPointer(id); }
257 
258 //BTX
260  {
262  VTK_DATA_ARRAY_DELETE
263  };
264 //ETX
265 
267 
276  void SetArray(T* array, vtkIdType size, int save, int deleteMethod);
277  void SetArray(T* array, vtkIdType size, int save)
278  { this->SetArray(array, size, save, VTK_DATA_ARRAY_FREE); }
279  virtual void SetVoidArray(void* array, vtkIdType size, int save)
280  { this->SetArray(static_cast<T*>(array), size, save); }
281  virtual void SetVoidArray(void* array,
282  vtkIdType size,
283  int save,
284  int deleteMethod)
285  {
286  this->SetArray(static_cast<T*>(array), size, save, deleteMethod);
287  }
289 
293  virtual void ExportToVoidPointer(void *out_ptr);
294 
297 
299 
305  { return this->LookupValue(value); }
307  { this->LookupValue(value, ids); }
309 
316  virtual void DataChanged();
317 
321  virtual void DataElementChanged(vtkIdType id);
322 
326  virtual void ClearLookup();
327 
330 
331 protected:
334 
335  T* Array; // pointer to data
336  T ValueRange[2]; // range of the data
337  T* ResizeAndExtend(vtkIdType sz); // function to resize data
339 
340  int TupleSize; //used for data conversion
341  double* Tuple;
342 
345 
346  virtual bool ComputeScalarRange(double* ranges);
347  virtual bool ComputeVectorRange(double range[2]);
348 private:
349  vtkDataArrayTemplate(const vtkDataArrayTemplate&); // Not implemented.
350  void operator=(const vtkDataArrayTemplate&); // Not implemented.
351 
353  bool RebuildLookup;
354  void UpdateLookup();
355 
356  void DeleteArray();
357 };
358 
359 #if !defined(VTK_NO_EXPLICIT_TEMPLATE_INSTANTIATION)
360 # define VTK_DATA_ARRAY_TEMPLATE_INSTANTIATE(T) \
361  template class VTKCOMMONCORE_EXPORT vtkDataArrayTemplate< T >
362 #else
363 # include "vtkDataArrayTemplateImplicit.txx"
364 # define VTK_DATA_ARRAY_TEMPLATE_INSTANTIATE(T)
365 #endif
366 
367 // This macro is used by the subclasses to create dummy
368 // declarations for these functions such that the wrapper
369 // can see them. The wrappers ignore vtkDataArrayTemplate.
370 #define vtkCreateWrappedArrayInterface(T) \
371  int GetDataType(); \
372  void GetTupleValue(vtkIdType i, T* tuple); \
373  void SetTupleValue(vtkIdType i, const T* tuple); \
374  void InsertTupleValue(vtkIdType i, const T* tuple); \
375  vtkIdType InsertNextTupleValue(const T* tuple); \
376  T GetValue(vtkIdType id); \
377  void SetValue(vtkIdType id, T value); \
378  void SetNumberOfValues(vtkIdType number); \
379  void InsertValue(vtkIdType id, T f); \
380  vtkIdType InsertNextValue(T f); \
381  T *GetValueRange(int comp); \
382  T *GetValueRange(); \
383  T* WritePointer(vtkIdType id, vtkIdType number); \
384  T* GetPointer(vtkIdType id)/*; \
385 
386  * These methods are not wrapped to avoid wrappers exposing these
387  * easy-to-get-wrong methods because passing in the wrong value for 'save' is
388  * guaranteed to cause a memory issue down the line. Either the wrappers
389  * didn't use malloc to allocate the memory or the memory isn't actually
390  * persisted because a temporary array is used that doesn't persist like this
391  * method expects.
392 
393  void SetArray(T* array, vtkIdType size, int save); \
394  void SetArray(T* array, vtkIdType size, int save, int deleteMethod) */
395 
396 #endif // !defined(vtkDataArrayTemplate_h)
397 
398 // This portion must be OUTSIDE the include blockers. Each
399 // vtkDataArray subclass uses this to give its instantiation of this
400 // template a DLL interface.
401 #if defined(VTK_DATA_ARRAY_TEMPLATE_TYPE) && !defined(VTK_NO_EXPLICIT_TEMPLATE_INSTANTIATION)
402 # if defined(VTK_BUILD_SHARED_LIBS) && defined(_MSC_VER)
403 # pragma warning (push)
404 # pragma warning (disable: 4091) // warning C4091: 'extern ' :
405  // ignored on left of 'int' when no variable is declared
406 # pragma warning (disable: 4231) // Compiler-specific extension warning.
407 
408  // We need to disable warning 4910 and do an extern dllexport
409  // anyway. When deriving vtkCharArray and other types from an
410  // instantiation of this template the compiler does an explicit
411  // instantiation of the base class. From outside the vtkCommon
412  // library we block this using an extern dllimport instantiation.
413  // For classes inside vtkCommon we should be able to just do an
414  // extern instantiation, but VS 2008 complains about missing
415  // definitions. We cannot do an extern dllimport inside vtkCommon
416  // since the symbols are local to the dll. An extern dllexport
417  // seems to be the only way to convince VS 2008 to do the right
418  // thing, so we just disable the warning.
419 # pragma warning (disable: 4910) // extern and dllexport incompatible
420 
421  // Use an "extern explicit instantiation" to give the class a DLL
422  // interface. This is a compiler-specific extension.
424 # pragma warning (pop)
425 # endif
426 # undef VTK_DATA_ARRAY_TEMPLATE_TYPE
427 #endif
428 // VTK-HeaderTest-Exclude: vtkDataArrayTemplate.h
vtkDataArrayTemplate::SetComponent
void SetComponent(vtkIdType i, int j, double c)
VTK_DATA_ARRAY_TEMPLATE_INSTANTIATE
#define VTK_DATA_ARRAY_TEMPLATE_INSTANTIATE(T)
Definition: vtkDataArrayTemplate.h:360
vtkDataArrayTemplate::DeleteMethod
int DeleteMethod
Definition: vtkDataArrayTemplate.h:344
VTK_DATA_ARRAY_TEMPLATE_TYPE
#define VTK_DATA_ARRAY_TEMPLATE_TYPE
Definition: vtk__Int64Array.h:33
vtkDataArrayTemplate::InsertValue
void InsertValue(vtkIdType id, T f)
vtkDataArrayTemplate::NewIterator
virtual vtkArrayIterator * NewIterator()
vtkDataArrayTemplate::LookupTypedValue
void LookupTypedValue(T value, vtkIdList *ids)
Definition: vtkDataArrayTemplate.h:306
vtkgl::id
GLuint id
Definition: vtkgl.h:11834
VTKCOMMONCORE_EXPORT
#define VTKCOMMONCORE_EXPORT
Definition: vtkCommonCoreModule.h:15
vtkDataArrayTemplate::WriteVoidPointer
virtual void * WriteVoidPointer(vtkIdType id, vtkIdType number)
Definition: vtkDataArrayTemplate.h:245
vtkDataArrayTemplate::RemoveFirstTuple
virtual void RemoveFirstTuple()
vtkDataArrayTemplate::LookupValue
virtual vtkIdType LookupValue(vtkVariant value)
vtkDataArrayTemplate::Capacity
vtkIdType Capacity()
Definition: vtkDataArrayTemplate.h:177
vtkDataArrayTemplate::SaveUserArray
int SaveUserArray
Definition: vtkDataArrayTemplate.h:343
vtkDataArrayTemplate::Allocate
int Allocate(vtkIdType sz, vtkIdType ext=1000)
vtkDataArrayTemplate::GetValueRange
void GetValueRange(T range[2])
Definition: vtkDataArrayTemplate.h:169
vtkIdType
int vtkIdType
Definition: vtkType.h:275
vtkDataArrayTemplate::RemoveLastTuple
virtual void RemoveLastTuple()
vtkDataArrayTemplate::SetTupleValue
void SetTupleValue(vtkIdType i, const T *tuple)
vtkDataArrayTemplate::TupleSize
int TupleSize
Definition: vtkDataArrayTemplate.h:340
vtkDataArrayTemplate::RemoveTuple
virtual void RemoveTuple(vtkIdType id)
vtkDataArrayTemplate::LookupValue
vtkIdType LookupValue(T value)
vtkTypedDataArray< T >
vtkDataArrayTemplate::Realloc
T * Realloc(vtkIdType sz)
save
void save(Archiver &ar, const vtkUnicodeString &str, const unsigned int vtkNotUsed(version))
Definition: vtkVariantBoostSerialization.h:64
vtkDataArrayTemplate::DataChanged
virtual void DataChanged()
vtkDataArrayTemplate::FastDownCast
static vtkDataArrayTemplate< T > * FastDownCast(vtkAbstractArray *src)
vtkgl::n
GLclampd n
Definition: vtkgl.h:14370
vtkDataArrayTemplate::LookupValue
void LookupValue(T value, vtkIdList *ids)
vtkDataArrayTemplate< Scalar >::DeleteMethod
DeleteMethod
Definition: vtkDataArrayTemplate.h:260
vtkDataArrayTemplate::Tuple
double * Tuple
Definition: vtkDataArrayTemplate.h:341
vtkDataArrayTemplate::Resize
virtual int Resize(vtkIdType numTuples)
vtkDataArrayTemplate::GetValue
T GetValue(vtkIdType id)
Definition: vtkDataArrayTemplate.h:187
vtkDataArrayTemplate::InsertTuples
virtual void InsertTuples(vtkIdType dstStart, vtkIdType n, vtkIdType srcStart, vtkAbstractArray *source)
vtkDataArrayTemplate::DataElementChanged
virtual void DataElementChanged(vtkIdType id)
vtkDataArrayTemplate::SetTuple
void SetTuple(vtkIdType i, const float *tuple)
vtkTypeTemplate.h
vtkgl::range
GLenum GLint * range
Definition: vtkgl.h:14180
vtkDataArrayTemplate::GetTupleValue
void GetTupleValue(vtkIdType i, T *tuple)
vtkDataArrayTemplate::GetTuple
void GetTuple(vtkIdType i, double *tuple)
vtkDataArrayTemplate::SetTuple
void SetTuple(vtkIdType i, const double *tuple)
vtkDataArrayTemplate::GetValueRange
void GetValueRange(T range[2], int comp)
Definition: vtkDataArrayTemplate.h:150
vtkDataArrayTemplate::SetArray
void SetArray(T *array, vtkIdType size, int save, int deleteMethod)
vtkDataArrayTemplate::InsertNextTupleValue
vtkIdType InsertNextTupleValue(const T *tuple)
source
boost::graph_traits< vtkGraph * >::vertex_descriptor source(boost::graph_traits< vtkGraph * >::edge_descriptor e, vtkGraph *)
Definition: vtkBoostGraphAdapter.h:821
vtkDataArrayTemplate::GetPointer
T * GetPointer(vtkIdType id)
Definition: vtkDataArrayTemplate.h:254
vtkDataArrayTemplate::ClearLookup
virtual void ClearLookup()
vtkTypedDataArray::ValueType
Scalar ValueType
Definition: vtkTypedDataArray.h:50
vtkgl::value
GLsizei const GLfloat * value
Definition: vtkgl.h:12021
vtkDataArrayTemplate::InsertTuple
void InsertTuple(vtkIdType i, const double *tuple)
vtkDataArrayTemplate::SetVoidArray
virtual void SetVoidArray(void *array, vtkIdType size, int save, int deleteMethod)
Definition: vtkDataArrayTemplate.h:281
vtkgl::c
const GLubyte * c
Definition: vtkgl.h:15720
vtkDataArrayTemplate::PrintSelf
void PrintSelf(ostream &os, vtkIndent indent)
vtkCommonCoreModule.h
vtkgl::ids
GLuint * ids
Definition: vtkgl.h:11831
vtkDataArrayTemplate::GetValueRange
T * GetValueRange()
Definition: vtkDataArrayTemplate.h:167
vtkDataArrayTemplate::InsertComponent
virtual void InsertComponent(vtkIdType i, int j, double c)
vtkDataArrayTemplate::GetArrayType
virtual int GetArrayType()
Definition: vtkDataArrayTemplate.h:329
vtkgl::src
GLenum src
Definition: vtkgl.h:12525
vtkDataArrayTemplate::InsertTuple
virtual void InsertTuple(vtkIdType i, vtkIdType j, vtkAbstractArray *source)
vtkDataArrayTemplate::InsertNextValue
vtkIdType InsertNextValue(T f)
vtkDataArrayTemplate::InsertNextTuple
vtkIdType InsertNextTuple(const double *tuple)
vtkDataArrayTemplate::GetValueRange
T * GetValueRange(int comp)
Definition: vtkDataArrayTemplate.h:157
vtkIndent
a simple class to control print indentation
Definition: vtkIndent.h:39
vtkDataArrayTemplate::ComputeVectorRange
virtual bool ComputeVectorRange(double range[2])
vtkDataArrayTemplate::LookupTypedValue
vtkIdType LookupTypedValue(T value)
Definition: vtkDataArrayTemplate.h:304
vtkVariant
A atomic type representing the union of many types.
Definition: vtkVariant.h:79
vtkIdList
list of point or cell ids
Definition: vtkIdList.h:36
vtkTypedDataArray.h
vtkDataArrayTemplate::VTK_DATA_ARRAY_FREE
@ VTK_DATA_ARRAY_FREE
Definition: vtkDataArrayTemplate.h:261
vtkDataArrayTemplate
Implementation template for vtkDataArray.
Definition: vtkDataArrayTemplate.h:37
vtkDataArrayTemplateHelper
Definition: vtkDataArrayTemplateHelper.h:35
vtkDataArrayTemplate::End
Iterator End()
Definition: vtkDataArrayTemplate.h:58
vtkgl::f
GLclampf f
Definition: vtkgl.h:14181
vtkDataArrayTemplate::InsertTuple
void InsertTuple(vtkIdType i, const float *tuple)
vtkDataArrayTemplate::GetVoidPointer
virtual void * GetVoidPointer(vtkIdType id)
Definition: vtkDataArrayTemplate.h:255
vtkAbstractArray
Abstract superclass for all arrays.
Definition: vtkAbstractArray.h:65
vtkDataArrayTemplate::GetTuple
double * GetTuple(vtkIdType i)
vtkDataArrayTemplate::Initialize
void Initialize()
vtkDataArrayTemplate::~vtkDataArrayTemplate
~vtkDataArrayTemplate()
vtkDataArrayTemplate::InsertTupleValue
void InsertTupleValue(vtkIdType i, const T *tuple)
vtkAbstractArray::DataArrayTemplate
@ DataArrayTemplate
Definition: vtkAbstractArray.h:463
vtkDataArrayTemplate::Squeeze
void Squeeze()
Definition: vtkDataArrayTemplate.h:174
vtkArrayIterator
Abstract superclass to iterate over elements in an vtkAbstractArray.
Definition: vtkArrayIterator.h:49
vtkDataArrayTemplate::ExportToVoidPointer
virtual void ExportToVoidPointer(void *out_ptr)
vtkDataArrayTemplate::ValueType
Superclass::ValueType ValueType
Definition: vtkDataArrayTemplate.h:40
vtkDataArrayTemplate::Iterator
ValueType * Iterator
Definition: vtkDataArrayTemplate.h:48
vtkDataArrayTemplate::SetVoidArray
virtual void SetVoidArray(void *array, vtkIdType size, int save)
Definition: vtkDataArrayTemplate.h:279
vtkDataArrayTemplate::Superclass
vtkTypedDataArray< T > Superclass
Definition: vtkDataArrayTemplate.h:39
vtkDataArrayTemplate::Array
T * Array
Definition: vtkDataArrayTemplate.h:335
vtkDataArrayTemplate::InsertNextTuple
virtual vtkIdType InsertNextTuple(vtkIdType j, vtkAbstractArray *source)
vtkDataArrayTemplate::SetValue
void SetValue(vtkIdType id, T value)
Definition: vtkDataArrayTemplate.h:196
vtkDataArrayTemplate::Begin
Iterator Begin()
Definition: vtkDataArrayTemplate.h:53
vtkDataArrayTemplate::GetDataTypeSize
int GetDataTypeSize()
Definition: vtkDataArrayTemplate.h:76
vtkTypedDataArrayIterator
STL-style random access iterator for vtkTypedDataArrays.
Definition: vtkTypedDataArrayIterator.h:41
vtkDataArrayTemplate::SetVariantValue
void SetVariantValue(vtkIdType id, vtkVariant value)
vtkDataArrayTemplate::InsertTuples
virtual void InsertTuples(vtkIdList *destIds, vtkIdList *srcIds, vtkAbstractArray *source)
vtkDataArrayTemplate::GetValueReference
T & GetValueReference(vtkIdType id)
Definition: vtkDataArrayTemplate.h:189
vtkDataArrayTemplate::SetArray
void SetArray(T *array, vtkIdType size, int save)
Definition: vtkDataArrayTemplate.h:277
vtkDataArrayTemplate::InsertNextTuple
vtkIdType InsertNextTuple(const float *tuple)
vtkDataArrayTemplate::SetNumberOfValues
void SetNumberOfValues(vtkIdType number)
vtkDataArrayTemplate::ResizeAndExtend
T * ResizeAndExtend(vtkIdType sz)
vtkDataArrayTemplate::vtkDataArrayTemplate
vtkDataArrayTemplate()
vtkDataArrayTemplate::WritePointer
T * WritePointer(vtkIdType id, vtkIdType number)
vtkDataArrayTemplate::SetTuple
virtual void SetTuple(vtkIdType i, vtkIdType j, vtkAbstractArray *source)
vtkDataArrayTemplateLookup
Definition: vtkDataArrayTemplate.h:32
vtkDataArrayTemplate::SetNumberOfTuples
void SetNumberOfTuples(vtkIdType number)
vtkDataArrayTemplate::GetComponent
double GetComponent(vtkIdType i, int j)
vtkDataArrayTemplate::LookupValue
virtual void LookupValue(vtkVariant value, vtkIdList *ids)
vtkDataArrayTemplate::ComputeScalarRange
virtual bool ComputeScalarRange(double *ranges)
vtkgl::size
GLsizeiptr size
Definition: vtkgl.h:11843
vtkTypeTemplate
Provides the equivalent of vtkTypeMacro for use with template classes.
Definition: vtkTypeTemplate.h:40