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;
41  void PrintSelf(ostream& os, vtkIndent indent);
42 
46  typedef ValueType* Iterator;
47 
51  Iterator Begin() { return Iterator(this->GetVoidPointer(0)); }
52 
56  Iterator End() { return Iterator(this->GetVoidPointer(this->MaxId + 1)); }
57 
64  static vtkDataArrayTemplate<T>* FastDownCast(vtkAbstractArray *src);
65 
68  int Allocate(vtkIdType sz, vtkIdType ext=1000);
69 
71  void Initialize();
72 
74  int GetDataTypeSize() { return static_cast<int>(sizeof(T)); }
75 
77  void SetNumberOfTuples(vtkIdType number);
78 
84  virtual void SetTuple(vtkIdType i, vtkIdType j, vtkAbstractArray* source);
85 
89  virtual void InsertTuple(vtkIdType i, vtkIdType j, vtkAbstractArray* source);
90 
92 
95  virtual void InsertTuples(vtkIdList *destIds, vtkIdList *srcIds,
98 
102  virtual vtkIdType InsertNextTuple(vtkIdType j, vtkAbstractArray* source);
103 
106  double* GetTuple(vtkIdType i);
107 
109 
110  void GetTuple(vtkIdType i, double* tuple);
111  void GetTupleValue(vtkIdType i, T* tuple);
113 
115 
116  void SetTuple(vtkIdType i, const float* tuple);
117  void SetTuple(vtkIdType i, const double* tuple);
118  void SetTupleValue(vtkIdType i, const T* tuple);
120 
122 
124  void InsertTuple(vtkIdType i, const float* tuple);
125  void InsertTuple(vtkIdType i, const double* tuple);
126  void InsertTupleValue(vtkIdType i, const T* tuple);
128 
130 
132  vtkIdType InsertNextTuple(const float* tuple);
133  vtkIdType InsertNextTuple(const double* tuple);
134  vtkIdType InsertNextTupleValue(const T* tuple);
136 
138 
140  void GetValueRange(T range[2], int comp)
141  {
142  double doubleRange[2];
143  this->ComputeRange(doubleRange, comp);
144  range[0] = static_cast<T>(doubleRange[0]);
145  range[1] = static_cast<T>(doubleRange[1]);
146  }
147  T *GetValueRange(int comp)
148  {
149  this->GetValueRange(this->ValueRange, comp);
150  return this->ValueRange;
151  }
153 
155 
158  { return this->GetValueRange(0); }
159  void GetValueRange(T range[2])
160  { this->GetValueRange(range, 0); }
162 
164  void Squeeze() { this->ResizeAndExtend (this->MaxId+1); }
165 
167  vtkIdType Capacity() { return this->Size; }
168 
173  virtual int Resize(vtkIdType numTuples);
174 
176 
178  { assert(id >= 0 && id < this->Size); return this->Array[id]; }
180  { assert(id >= 0 && id < this->Size); return this->Array[id]; }
182 
184 
187  { assert(id >= 0 && id < this->Size); this->Array[id] = value;};
189 
193  void SetNumberOfValues(vtkIdType number);
194 
196  void InsertValue(vtkIdType id, T f);
197 
199  void SetVariantValue(vtkIdType id, vtkVariant value);
200 
203  vtkIdType InsertNextValue(T f);
204 
206 
209  virtual void RemoveTuple(vtkIdType id);
210  virtual void RemoveFirstTuple();
211  virtual void RemoveLastTuple();
213 
217  double GetComponent(vtkIdType i, int j);
218 
223  void SetComponent(vtkIdType i, int j, double c);
224 
228  virtual void InsertComponent(vtkIdType i, int j, double c);
229 
231 
234  T* WritePointer(vtkIdType id, vtkIdType number);
235  virtual void* WriteVoidPointer(vtkIdType id, vtkIdType number)
236  { return this->WritePointer(id, number); }
238 
240 
244  T* GetPointer(vtkIdType id) { return this->Array + id; }
245  virtual void* GetVoidPointer(vtkIdType id) { return this->GetPointer(id); }
247 
248 //BTX
250  {
252  VTK_DATA_ARRAY_DELETE
253  };
254 //ETX
255 
257 
266  void SetArray(T* array, vtkIdType size, int save, int deleteMethod);
267  void SetArray(T* array, vtkIdType size, int save)
268  { this->SetArray(array, size, save, VTK_DATA_ARRAY_FREE); }
269  virtual void SetVoidArray(void* array, vtkIdType size, int save)
270  { this->SetArray(static_cast<T*>(array), size, save); }
271  virtual void SetVoidArray(void* array,
272  vtkIdType size,
273  int save,
274  int deleteMethod)
275  {
276  this->SetArray(static_cast<T*>(array), size, save, deleteMethod);
277  }
279 
283  virtual void ExportToVoidPointer(void *out_ptr);
284 
286  virtual vtkArrayIterator* NewIterator();
287 
289 
290  virtual vtkIdType LookupValue(vtkVariant value);
291  virtual void LookupValue(vtkVariant value, vtkIdList* ids);
292  vtkIdType LookupValue(T value);
293  void LookupValue(T value, vtkIdList* ids);
295  { return this->LookupValue(value); }
297  { this->LookupValue(value, ids); }
299 
306  virtual void DataChanged();
307 
311  virtual void DataElementChanged(vtkIdType id);
312 
316  virtual void ClearLookup();
317 
320 
321 protected:
324 
325  T* Array; // pointer to data
326  T ValueRange[2]; // range of the data
327  T* ResizeAndExtend(vtkIdType sz); // function to resize data
328  T* Realloc(vtkIdType sz);
329 
330  int TupleSize; //used for data conversion
331  double* Tuple;
332 
335 
336  virtual void ComputeScalarRange(double range[2], int comp);
337  virtual void ComputeVectorRange(double range[2]);
338 private:
339  vtkDataArrayTemplate(const vtkDataArrayTemplate&); // Not implemented.
340  void operator=(const vtkDataArrayTemplate&); // Not implemented.
341 
343  bool RebuildLookup;
344  void UpdateLookup();
345 
346  void DeleteArray();
347 };
348 
349 #if !defined(VTK_NO_EXPLICIT_TEMPLATE_INSTANTIATION)
350 # define VTK_DATA_ARRAY_TEMPLATE_INSTANTIATE(T) \
351  template class VTKCOMMONCORE_EXPORT vtkDataArrayTemplate< T >
352 #else
353 # include "vtkDataArrayTemplateImplicit.txx"
354 # define VTK_DATA_ARRAY_TEMPLATE_INSTANTIATE(T)
355 #endif
356 
357 // This macro is used by the subclasses to create dummy
358 // declarations for these functions such that the wrapper
359 // can see them. The wrappers ignore vtkDataArrayTemplate.
360 #define vtkCreateWrappedArrayInterface(T) \
361  int GetDataType(); \
362  void GetTupleValue(vtkIdType i, T* tuple); \
363  void SetTupleValue(vtkIdType i, const T* tuple); \
364  void InsertTupleValue(vtkIdType i, const T* tuple); \
365  vtkIdType InsertNextTupleValue(const T* tuple); \
366  T GetValue(vtkIdType id); \
367  void SetValue(vtkIdType id, T value); \
368  void SetNumberOfValues(vtkIdType number); \
369  void InsertValue(vtkIdType id, T f); \
370  vtkIdType InsertNextValue(T f); \
371  T *GetValueRange(int comp); \
372  T *GetValueRange(); \
373  T* WritePointer(vtkIdType id, vtkIdType number); \
374  T* GetPointer(vtkIdType id)/*; \
375 
376  * These methods are not wrapped to avoid wrappers exposing these
377  * easy-to-get-wrong methods because passing in the wrong value for 'save' is
378  * guaranteed to cause a memory issue down the line. Either the wrappers
379  * didn't use malloc to allocate the memory or the memory isn't actually
380  * persisted because a temporary array is used that doesn't persist like this
381  * method expects.
382 
383  void SetArray(T* array, vtkIdType size, int save); \
384  void SetArray(T* array, vtkIdType size, int save, int deleteMethod) */
385 
386 #endif // !defined(__vtkDataArrayTemplate_h)
387 
388 // This portion must be OUTSIDE the include blockers. Each
389 // vtkDataArray subclass uses this to give its instantiation of this
390 // template a DLL interface.
391 #if defined(VTK_DATA_ARRAY_TEMPLATE_TYPE)
392 # if defined(VTK_BUILD_SHARED_LIBS) && defined(_MSC_VER)
393 # pragma warning (push)
394 # pragma warning (disable: 4091) // warning C4091: 'extern ' :
395  // ignored on left of 'int' when no variable is declared
396 # pragma warning (disable: 4231) // Compiler-specific extension warning.
397 
398  // We need to disable warning 4910 and do an extern dllexport
399  // anyway. When deriving vtkCharArray and other types from an
400  // instantiation of this template the compiler does an explicit
401  // instantiation of the base class. From outside the vtkCommon
402  // library we block this using an extern dllimport instantiation.
403  // For classes inside vtkCommon we should be able to just do an
404  // extern instantiation, but VS 2008 complains about missing
405  // definitions. We cannot do an extern dllimport inside vtkCommon
406  // since the symbols are local to the dll. An extern dllexport
407  // seems to be the only way to convince VS 2008 to do the right
408  // thing, so we just disable the warning.
409 # pragma warning (disable: 4910) // extern and dllexport incompatible
410 
411  // Use an "extern explicit instantiation" to give the class a DLL
412  // interface. This is a compiler-specific extension.
414 # pragma warning (pop)
415 # endif
416 # undef VTK_DATA_ARRAY_TEMPLATE_TYPE
417 #endif
418 // VTK-HeaderTest-Exclude: vtkDataArrayTemplate.h
GLsizeiptr size
Definition: vtkgl.h:11843
void LookupTypedValue(T value, vtkIdList *ids)
Provides the equivalent of vtkTypeMacro for use with template classes.
GLclampf f
Definition: vtkgl.h:14181
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)
GLsizei const GLfloat * value
Definition: vtkgl.h:12021
int vtkIdType
Definition: vtkType.h:268
GLuint * ids
Definition: vtkgl.h:11831
A atomic type representing the union of many types.
Definition: vtkVariant.h:78
vtkTypedDataArray< T > Superclass
GLenum src
Definition: vtkgl.h:12525
T & GetValueReference(vtkIdType id)
a simple class to control print indentation
Definition: vtkIndent.h:38
#define VTK_DATA_ARRAY_TEMPLATE_TYPE
const GLubyte * c
Definition: vtkgl.h:15720
virtual void * GetVoidPointer(vtkIdType id)
list of point or cell ids
Definition: vtkIdList.h:35
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)
GLuint id
Definition: vtkgl.h:11834
GLenum GLint * range
Definition: vtkgl.h:14180
virtual void * WriteVoidPointer(vtkIdType id, vtkIdType number)
#define VTK_DATA_ARRAY_TEMPLATE_INSTANTIATE(T)
Superclass::ValueType ValueType