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 
66  static vtkDataArrayTemplate<T>* FastDownCast(vtkAbstractArray *src);
67 
70  int Allocate(vtkIdType sz, vtkIdType ext=1000);
71 
73  void Initialize();
74 
76  int GetDataTypeSize() { return static_cast<int>(sizeof(T)); }
77 
79  void SetNumberOfTuples(vtkIdType number);
80 
86  virtual void SetTuple(vtkIdType i, vtkIdType j, vtkAbstractArray* source);
87 
91  virtual void InsertTuple(vtkIdType i, vtkIdType j, vtkAbstractArray* source);
92 
94 
97  virtual void InsertTuples(vtkIdList *destIds, vtkIdList *srcIds,
100 
102 
105  virtual void InsertTuples(vtkIdType dstStart, vtkIdType n, vtkIdType srcStart,
108 
112  virtual vtkIdType InsertNextTuple(vtkIdType j, vtkAbstractArray* source);
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);
144  vtkIdType InsertNextTupleValue(const T* 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 
203  void SetNumberOfValues(vtkIdType number);
204 
206  void InsertValue(vtkIdType id, T f);
207 
209  void SetVariantValue(vtkIdType id, vtkVariant value);
210 
212  void InsertVariantValue(vtkIdType id, vtkVariant value);
213 
216  vtkIdType InsertNextValue(T f);
217 
219 
222  virtual void RemoveTuple(vtkIdType id);
223  virtual void RemoveFirstTuple();
224  virtual void RemoveLastTuple();
226 
230  double GetComponent(vtkIdType i, int j);
231 
236  void SetComponent(vtkIdType i, int j, double c);
237 
241  virtual void InsertComponent(vtkIdType i, int j, double c);
242 
244 
247  T* WritePointer(vtkIdType id, vtkIdType number);
248  virtual void* WriteVoidPointer(vtkIdType id, vtkIdType number)
249  { return this->WritePointer(id, number); }
251 
253 
257  T* GetPointer(vtkIdType id) { return this->Array + id; }
258  virtual void* GetVoidPointer(vtkIdType id) { return this->GetPointer(id); }
260 
261 //BTX
263  {
265  VTK_DATA_ARRAY_DELETE
266  };
267 //ETX
268 
270 
279  void SetArray(T* array, vtkIdType size, int save, int deleteMethod);
280  void SetArray(T* array, vtkIdType size, int save)
281  { this->SetArray(array, size, save, VTK_DATA_ARRAY_FREE); }
282  virtual void SetVoidArray(void* array, vtkIdType size, int save)
283  { this->SetArray(static_cast<T*>(array), size, save); }
284  virtual void SetVoidArray(void* array,
285  vtkIdType size,
286  int save,
287  int deleteMethod)
288  {
289  this->SetArray(static_cast<T*>(array), size, save, deleteMethod);
290  }
292 
296  virtual void ExportToVoidPointer(void *out_ptr);
297 
299  virtual vtkArrayIterator* NewIterator();
300 
302 
303  virtual vtkIdType LookupValue(vtkVariant value);
304  virtual void LookupValue(vtkVariant value, vtkIdList* ids);
305  vtkIdType LookupValue(T value);
306  void LookupValue(T value, vtkIdList* ids);
308  { return this->LookupValue(value); }
310  { this->LookupValue(value, ids); }
312 
319  virtual void DataChanged();
320 
324  virtual void DataElementChanged(vtkIdType id);
325 
329  virtual void ClearLookup();
330 
333 
334 protected:
337 
338  T* Array; // pointer to data
339  T ValueRange[2]; // range of the data
340  T* ResizeAndExtend(vtkIdType sz); // function to resize data
341  T* Realloc(vtkIdType sz);
342 
343  int TupleSize; //used for data conversion
344  double* Tuple;
345 
348 
349  virtual bool ComputeScalarRange(double* ranges);
350  virtual bool ComputeVectorRange(double range[2]);
351 private:
352  vtkDataArrayTemplate(const vtkDataArrayTemplate&); // Not implemented.
353  void operator=(const vtkDataArrayTemplate&); // Not implemented.
354 
356  bool RebuildLookup;
357  void UpdateLookup();
358 
359  void DeleteArray();
360 };
361 
362 #define VTK_DATA_ARRAY_TEMPLATE_INSTANTIATE(T) \
363  template class VTKCOMMONCORE_EXPORT vtkDataArrayTemplate< T >
364 
365 // This macro is used by the subclasses to create dummy
366 // declarations for these functions such that the wrapper
367 // can see them. The wrappers ignore vtkDataArrayTemplate.
368 #define vtkCreateWrappedArrayInterface(T) \
369  int GetDataType(); \
370  void GetTupleValue(vtkIdType i, T* tuple); \
371  void SetTupleValue(vtkIdType i, const T* tuple); \
372  void InsertTupleValue(vtkIdType i, const T* tuple); \
373  vtkIdType InsertNextTupleValue(const T* tuple); \
374  T GetValue(vtkIdType id); \
375  void SetValue(vtkIdType id, T value); \
376  void SetNumberOfValues(vtkIdType number); \
377  void InsertValue(vtkIdType id, T f); \
378  vtkIdType InsertNextValue(T f); \
379  T *GetValueRange(int comp); \
380  T *GetValueRange(); \
381  T* WritePointer(vtkIdType id, vtkIdType number); \
382  T* GetPointer(vtkIdType id)/*; \
383 
384  * These methods are not wrapped to avoid wrappers exposing these
385  * easy-to-get-wrong methods because passing in the wrong value for 'save' is
386  * guaranteed to cause a memory issue down the line. Either the wrappers
387  * didn't use malloc to allocate the memory or the memory isn't actually
388  * persisted because a temporary array is used that doesn't persist like this
389  * method expects.
390 
391  void SetArray(T* array, vtkIdType size, int save); \
392  void SetArray(T* array, vtkIdType size, int save, int deleteMethod) */
393 
394 #endif // !defined(vtkDataArrayTemplate_h)
395 
396 // This portion must be OUTSIDE the include blockers. Each
397 // vtkDataArray subclass uses this to give its instantiation of this
398 // template a DLL interface.
399 #if defined(VTK_DATA_ARRAY_TEMPLATE_TYPE)
400 # if defined(VTK_BUILD_SHARED_LIBS) && defined(_MSC_VER)
401 # pragma warning (push)
402 # pragma warning (disable: 4091) // warning C4091: 'extern ' :
403  // ignored on left of 'int' when no variable is declared
404 # pragma warning (disable: 4231) // Compiler-specific extension warning.
405 
406  // We need to disable warning 4910 and do an extern dllexport
407  // anyway. When deriving vtkCharArray and other types from an
408  // instantiation of this template the compiler does an explicit
409  // instantiation of the base class. From outside the vtkCommon
410  // library we block this using an extern dllimport instantiation.
411  // For classes inside vtkCommon we should be able to just do an
412  // extern instantiation, but VS 2008 complains about missing
413  // definitions. We cannot do an extern dllimport inside vtkCommon
414  // since the symbols are local to the dll. An extern dllexport
415  // seems to be the only way to convince VS 2008 to do the right
416  // thing, so we just disable the warning.
417 # pragma warning (disable: 4910) // extern and dllexport incompatible
418 
419  // Use an "extern explicit instantiation" to give the class a DLL
420  // interface. This is a compiler-specific extension.
422 # pragma warning (pop)
423 # endif
424 # undef VTK_DATA_ARRAY_TEMPLATE_TYPE
425 #endif
426 // VTK-HeaderTest-Exclude: vtkDataArrayTemplate.h
void LookupTypedValue(T value, vtkIdList *ids)
Provides the equivalent of vtkTypeMacro for use with template classes.
virtual void SetVoidArray(void *array, vtkIdType size, int save, int deleteMethod)
Implementation template for vtkDataArray.
Abstract superclass for all arrays.
#define VTKCOMMONCORE_EXPORT
void SetValue(vtkIdType id, T value)
int vtkIdType
Definition: vtkType.h:247
A atomic type representing the union of many types.
Definition: vtkVariant.h:78
vtkTypedDataArray< T > Superclass
T & GetValueReference(vtkIdType id)
a simple class to control print indentation
Definition: vtkIndent.h:38
virtual void * GetVoidPointer(vtkIdType id)
list of point or cell ids
Definition: vtkIdList.h:35
static void InsertTuples(vtkDataArray *dst, vtkIdType dstStart, vtkIdType n, vtkIdType srcStart, vtkAbstractArray *source)
Abstract superclass to iterate over elements in an vtkAbstractArray.
virtual void SetVoidArray(void *array, vtkIdType size, int save)
void GetValueRange(T range[2])
T * GetPointer(vtkIdType id)
void save(Archiver &ar, const vtkUnicodeString &str, const unsigned int vtkNotUsed(version))
void SetArray(T *array, vtkIdType size, int save)
boost::graph_traits< vtkGraph * >::vertex_descriptor source(boost::graph_traits< vtkGraph * >::edge_descriptor e, vtkGraph *)
void GetValueRange(T range[2], int comp)
vtkIdType LookupTypedValue(T value)
#define VTK_DATA_ARRAY_TEMPLATE_TYPE
Definition: vtkCharArray.h:31
virtual void * WriteVoidPointer(vtkIdType id, vtkIdType number)
#define VTK_DATA_ARRAY_TEMPLATE_INSTANTIATE(T)
Superclass::ValueType ValueType