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 "vtkDataArray.h"
27 
28 template <class T>
30 
31 template <class T>
33 {
34 public:
36  void PrintSelf(ostream& os, vtkIndent indent);
37 
40  int Allocate(vtkIdType sz, vtkIdType ext=1000);
41 
43  void Initialize();
44 
46  int GetDataTypeSize() { return static_cast<int>(sizeof(T)); }
47 
49  void SetNumberOfTuples(vtkIdType number);
50 
56  virtual void SetTuple(vtkIdType i, vtkIdType j, vtkAbstractArray* source);
57 
61  virtual void InsertTuple(vtkIdType i, vtkIdType j, vtkAbstractArray* source);
62 
67 
70  double* GetTuple(vtkIdType i);
71 
73 
74  void GetTuple(vtkIdType i, double* tuple);
75  void GetTupleValue(vtkIdType i, T* tuple);
77 
79 
80  void SetTuple(vtkIdType i, const float* tuple);
81  void SetTuple(vtkIdType i, const double* tuple);
82  void SetTupleValue(vtkIdType i, const T* tuple);
84 
86 
88  void InsertTuple(vtkIdType i, const float* tuple);
89  void InsertTuple(vtkIdType i, const double* tuple);
90  void InsertTupleValue(vtkIdType i, const T* tuple);
92 
94 
96  vtkIdType InsertNextTuple(const float* tuple);
97  vtkIdType InsertNextTuple(const double* tuple);
98  vtkIdType InsertNextTupleValue(const T* tuple);
100 
102 
104  void GetValueRange(T range[2], int comp) {
105  this->ComputeRange(comp);
106  range[0] = this->ValueRange[0];
107  range[1] = this->ValueRange[1]; }
108  T *GetValueRange(int comp) {
109  this->ComputeRange(comp);
110  return this->ValueRange; }
112 
114  void Squeeze() { this->ResizeAndExtend (this->MaxId+1, false); }
115 
117  vtkIdType Capacity() { return this->Size; }
118 
121  virtual int Resize(vtkIdType numTuples);
122 
124  T GetValue(vtkIdType id) { return this->Array[id]; }
125 
127 
129  void SetValue(vtkIdType id, T value)
130  { this->Array[id] = value;};
132 
136  void SetNumberOfValues(vtkIdType number);
137 
139  void InsertValue(vtkIdType id, T f);
140 
142  void SetVariantValue(vtkIdType id, vtkVariant value);
143 
146  vtkIdType InsertNextValue(T f);
147 
149 
152  virtual void RemoveTuple(vtkIdType id);
153  virtual void RemoveFirstTuple();
154  virtual void RemoveLastTuple();
156 
160  double GetComponent(vtkIdType i, int j);
161 
166  void SetComponent(vtkIdType i, int j, double c);
167 
171  virtual void InsertComponent(vtkIdType i, int j, double c);
172 
174 
177  T* WritePointer(vtkIdType id, vtkIdType number);
178  virtual void* WriteVoidPointer(vtkIdType id, vtkIdType number)
179  { return this->WritePointer(id, number); }
181 
183 
185  T* GetPointer(vtkIdType id) { return this->Array + id; }
186  virtual void* GetVoidPointer(vtkIdType id) { return this->GetPointer(id); }
188 
190 
191  void DeepCopy(vtkDataArray* da);
193  { this->Superclass::DeepCopy(aa); }
195 
196 //BTX
198  {
200  VTK_DATA_ARRAY_DELETE
201  };
202 //ETX
203 
205 
214  void SetArray(T* array, vtkIdType size, int save, int deleteMethod);
215  void SetArray(T* array, vtkIdType size, int save)
216  { this->SetArray(array, size, save, VTK_DATA_ARRAY_FREE); }
217  virtual void SetVoidArray(void* array, vtkIdType size, int save)
218  { this->SetArray(static_cast<T*>(array), size, save); }
219  virtual void SetVoidArray(void* array,
220  vtkIdType size,
221  int save,
222  int deleteMethod)
223  {
224  this->SetArray(static_cast<T*>(array), size, save, deleteMethod);
225  }
227 
231  virtual void ExportToVoidPointer(void *out_ptr);
232 
234  virtual vtkArrayIterator* NewIterator();
235 
237 
238  virtual vtkIdType LookupValue(vtkVariant value);
239  virtual void LookupValue(vtkVariant value, vtkIdList* ids);
240  vtkIdType LookupValue(T value);
241  void LookupValue(T value, vtkIdList* ids);
243 
250  virtual void DataChanged();
251 
255  virtual void DataElementChanged(vtkIdType id);
256 
260  virtual void ClearLookup();
261 
262 protected:
265 
266  T* Array; // pointer to data
267  T ValueRange[2]; // range of the data
268  T* ResizeAndExtend(vtkIdType sz, bool useExactSize); // function to resize data
269  T* Realloc(vtkIdType sz);
270 
271  int TupleSize; //used for data conversion
272  double* Tuple;
273 
276 
277  virtual void ComputeScalarRange(int comp);
278  virtual void ComputeVectorRange();
279 private:
280  vtkDataArrayTemplate(const vtkDataArrayTemplate&); // Not implemented.
281  void operator=(const vtkDataArrayTemplate&); // Not implemented.
282 
284  void UpdateLookup();
285 
286  void DeleteArray();
287 };
288 
289 #if !defined(VTK_NO_EXPLICIT_TEMPLATE_INSTANTIATION)
290 # define VTK_DATA_ARRAY_TEMPLATE_INSTANTIATE(T) \
291  template class VTK_COMMON_EXPORT vtkDataArrayTemplate< T >
292 #else
293 # include "vtkDataArrayTemplateImplicit.txx"
294 # define VTK_DATA_ARRAY_TEMPLATE_INSTANTIATE(T)
295 #endif
296 
297 #endif // !defined(__vtkDataArrayTemplate_h)
298 
299 // This portion must be OUTSIDE the include blockers. Each
300 // vtkDataArray subclass uses this to give its instantiation of this
301 // template a DLL interface.
302 #if defined(VTK_DATA_ARRAY_TEMPLATE_TYPE)
303 # if defined(VTK_BUILD_SHARED_LIBS) && defined(_MSC_VER)
304 # pragma warning (push)
305 # pragma warning (disable: 4091) // warning C4091: 'extern ' :
306  // ignored on left of 'int' when no variable is declared
307 # pragma warning (disable: 4231) // Compiler-specific extension warning.
308 
309  // We need to disable warning 4910 and do an extern dllexport
310  // anyway. When deriving vtkCharArray and other types from an
311  // instantiation of this template the compiler does an explicit
312  // instantiation of the base class. From outside the vtkCommon
313  // library we block this using an extern dllimport instantiation.
314  // For classes inside vtkCommon we should be able to just do an
315  // extern instantiation, but VS 2008 complains about missing
316  // definitions. We cannot do an extern dllimport inside vtkCommon
317  // since the symbols are local to the dll. An extern dllexport
318  // seems to be the only way to convince VS 2008 to do the right
319  // thing, so we just disable the warning.
320 # pragma warning (disable: 4910) // extern and dllexport incompatible
321 
322  // Use an "extern explicit instantiation" to give the class a DLL
323  // interface. This is a compiler-specific extension.
325 # pragma warning (pop)
326 # endif
327 # undef VTK_DATA_ARRAY_TEMPLATE_TYPE
328 #endif
virtual double * GetTuple(vtkIdType i)=0
virtual void DeepCopy(vtkAbstractArray *aa)
virtual void SetVoidArray(void *array, vtkIdType size, int save, int deleteMethod)
Implementation template for vtkDataArray.
virtual void DataChanged()=0
virtual void DeepCopy(vtkAbstractArray *da)
virtual void ComputeRange(int comp)
Abstract superclass for all arrays.
virtual vtkIdType LookupValue(vtkVariant value)=0
void SetValue(vtkIdType id, T value)
virtual void RemoveFirstTuple()=0
virtual void SetNumberOfTuples(vtkIdType number)=0
virtual void ComputeVectorRange()
virtual void InsertComponent(vtkIdType i, int j, double c)
int vtkIdType
Definition: vtkType.h:255
virtual double GetComponent(vtkIdType i, int j)
virtual void Initialize()=0
A atomic type representing the union of many types.
Definition: vtkVariant.h:72
virtual void ExportToVoidPointer(void *vtkNotUsed(out_ptr))
virtual int Allocate(vtkIdType sz, vtkIdType ext=1000)=0
virtual void InsertTuple(vtkIdType i, vtkIdType j, vtkAbstractArray *source)=0
virtual void ClearLookup()=0
a simple class to control print indentation
Definition: vtkIndent.h:37
virtual void RemoveLastTuple()=0
#define VTK_DATA_ARRAY_TEMPLATE_TYPE
virtual void * GetVoidPointer(vtkIdType id)
list of point or cell ids
Definition: vtkIdList.h:34
virtual int Resize(vtkIdType numTuples)=0
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:53
virtual vtkArrayIterator * NewIterator()=0
void DeepCopy(vtkAbstractArray *aa)
#define VTK_COMMON_EXPORT
Abstract superclass to iterate over elements in an vtkAbstractArray.
virtual void SetVoidArray(void *array, vtkIdType size, int save)
virtual void SetTuple(vtkIdType i, vtkIdType j, vtkAbstractArray *source)=0
T * GetPointer(vtkIdType id)
virtual void ComputeScalarRange(int comp)
void SetArray(T *array, vtkIdType size, int save)
void GetValueRange(T range[2], int comp)
void save(Archiver &ar, const vtkVariant &variant, const unsigned int vtkNotUsed(version))
virtual void SetComponent(vtkIdType i, int j, double c)
void PrintSelf(ostream &os, vtkIndent indent)
virtual void RemoveTuple(vtkIdType id)=0
virtual void SetVariantValue(vtkIdType idx, vtkVariant value)=0
virtual vtkIdType InsertNextTuple(vtkIdType j, vtkAbstractArray *source)=0
virtual void * WriteVoidPointer(vtkIdType id, vtkIdType number)
#define VTK_DATA_ARRAY_TEMPLATE_INSTANTIATE(T)