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 
213  vtkIdType InsertNextValue(T f);
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 
244  T* WritePointer(vtkIdType id, vtkIdType number);
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 
296  virtual vtkArrayIterator* NewIterator();
297 
299 
300  virtual vtkIdType LookupValue(vtkVariant value);
301  virtual void LookupValue(vtkVariant value, vtkIdList* ids);
302  vtkIdType LookupValue(T value);
303  void LookupValue(T value, vtkIdList* ids);
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
338  T* Realloc(vtkIdType sz);
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
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:275
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
#define VTK_DATA_ARRAY_TEMPLATE_TYPE
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)
virtual void * WriteVoidPointer(vtkIdType id, vtkIdType number)
#define VTK_DATA_ARRAY_TEMPLATE_INSTANTIATE(T)
Superclass::ValueType ValueType