VTK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 "vtkDataArray.h"
28 
29 template <class T>
31 
32 template <class T>
33 class VTKCOMMONCORE_EXPORT vtkDataArrayTemplate: public vtkDataArray
34 {
35 public:
37  void PrintSelf(ostream& os, vtkIndent indent);
38 
41  int Allocate(vtkIdType sz, vtkIdType ext=1000);
42 
44  void Initialize();
45 
47  int GetDataTypeSize() { return static_cast<int>(sizeof(T)); }
48 
50  void SetNumberOfTuples(vtkIdType number);
51 
57  virtual void SetTuple(vtkIdType i, vtkIdType j, vtkAbstractArray* source);
58 
62  virtual void InsertTuple(vtkIdType i, vtkIdType j, vtkAbstractArray* source);
63 
68 
71  double* GetTuple(vtkIdType i);
72 
74 
75  void GetTuple(vtkIdType i, double* tuple);
76  void GetTupleValue(vtkIdType i, T* tuple);
78 
80 
81  void SetTuple(vtkIdType i, const float* tuple);
82  void SetTuple(vtkIdType i, const double* tuple);
83  void SetTupleValue(vtkIdType i, const T* tuple);
85 
87 
89  void InsertTuple(vtkIdType i, const float* tuple);
90  void InsertTuple(vtkIdType i, const double* tuple);
91  void InsertTupleValue(vtkIdType i, const T* tuple);
93 
95 
97  vtkIdType InsertNextTuple(const float* tuple);
98  vtkIdType InsertNextTuple(const double* tuple);
99  vtkIdType InsertNextTupleValue(const T* tuple);
101 
103 
105  void GetValueRange(T range[2], int comp)
106  {
107  double doubleRange[2];
108  this->ComputeRange(doubleRange, comp);
109  range[0] = static_cast<T>(doubleRange[0]);
110  range[1] = static_cast<T>(doubleRange[1]);
111  }
112  T *GetValueRange(int comp)
113  {
114  this->GetValueRange(this->ValueRange, comp);
115  return this->ValueRange;
116  }
118 
120  void Squeeze() { this->ResizeAndExtend (this->MaxId+1); }
121 
123  vtkIdType Capacity() { return this->Size; }
124 
129  virtual int Resize(vtkIdType numTuples);
130 
132  T GetValue(vtkIdType id) { return this->Array[id]; }
133 
135 
137  void SetValue(vtkIdType id, T value)
138  { this->Array[id] = value;};
140 
144  void SetNumberOfValues(vtkIdType number);
145 
147  void InsertValue(vtkIdType id, T f);
148 
150  void SetVariantValue(vtkIdType id, vtkVariant value);
151 
154  vtkIdType InsertNextValue(T f);
155 
157 
160  virtual void RemoveTuple(vtkIdType id);
161  virtual void RemoveFirstTuple();
162  virtual void RemoveLastTuple();
164 
168  double GetComponent(vtkIdType i, int j);
169 
174  void SetComponent(vtkIdType i, int j, double c);
175 
179  virtual void InsertComponent(vtkIdType i, int j, double c);
180 
182 
185  T* WritePointer(vtkIdType id, vtkIdType number);
186  virtual void* WriteVoidPointer(vtkIdType id, vtkIdType number)
187  { return this->WritePointer(id, number); }
189 
191 
193  T* GetPointer(vtkIdType id) { return this->Array + id; }
194  virtual void* GetVoidPointer(vtkIdType id) { return this->GetPointer(id); }
196 
198 
199  void DeepCopy(vtkDataArray* da);
201  { this->Superclass::DeepCopy(aa); }
203 
204 //BTX
206  {
208  VTK_DATA_ARRAY_DELETE
209  };
210 //ETX
211 
213 
222  void SetArray(T* array, vtkIdType size, int save, int deleteMethod);
223  void SetArray(T* array, vtkIdType size, int save)
224  { this->SetArray(array, size, save, VTK_DATA_ARRAY_FREE); }
225  virtual void SetVoidArray(void* array, vtkIdType size, int save)
226  { this->SetArray(static_cast<T*>(array), size, save); }
227  virtual void SetVoidArray(void* array,
228  vtkIdType size,
229  int save,
230  int deleteMethod)
231  {
232  this->SetArray(static_cast<T*>(array), size, save, deleteMethod);
233  }
235 
239  virtual void ExportToVoidPointer(void *out_ptr);
240 
242  virtual vtkArrayIterator* NewIterator();
243 
245 
246  virtual vtkIdType LookupValue(vtkVariant value);
247  virtual void LookupValue(vtkVariant value, vtkIdList* ids);
248  vtkIdType LookupValue(T value);
249  void LookupValue(T value, vtkIdList* ids);
251 
258  virtual void DataChanged();
259 
263  virtual void DataElementChanged(vtkIdType id);
264 
268  virtual void ClearLookup();
269 
270 protected:
273 
274  T* Array; // pointer to data
275  T ValueRange[2]; // range of the data
276  T* ResizeAndExtend(vtkIdType sz); // function to resize data
277  T* Realloc(vtkIdType sz);
278 
279  int TupleSize; //used for data conversion
280  double* Tuple;
281 
284 
285  virtual void ComputeScalarRange(double range[2], int comp);
286  virtual void ComputeVectorRange(double range[2]);
287 private:
288  vtkDataArrayTemplate(const vtkDataArrayTemplate&); // Not implemented.
289  void operator=(const vtkDataArrayTemplate&); // Not implemented.
290 
292  void UpdateLookup();
293 
294  void DeleteArray();
295 };
296 
297 #if !defined(VTK_NO_EXPLICIT_TEMPLATE_INSTANTIATION)
298 # define VTK_DATA_ARRAY_TEMPLATE_INSTANTIATE(T) \
299  template class VTKCOMMONCORE_EXPORT vtkDataArrayTemplate< T >
300 #else
301 # include "vtkDataArrayTemplateImplicit.txx"
302 # define VTK_DATA_ARRAY_TEMPLATE_INSTANTIATE(T)
303 #endif
304 
305 #endif // !defined(__vtkDataArrayTemplate_h)
306 
307 // This portion must be OUTSIDE the include blockers. Each
308 // vtkDataArray subclass uses this to give its instantiation of this
309 // template a DLL interface.
310 #if defined(VTK_DATA_ARRAY_TEMPLATE_TYPE)
311 # if defined(VTK_BUILD_SHARED_LIBS) && defined(_MSC_VER)
312 # pragma warning (push)
313 # pragma warning (disable: 4091) // warning C4091: 'extern ' :
314  // ignored on left of 'int' when no variable is declared
315 # pragma warning (disable: 4231) // Compiler-specific extension warning.
316 
317  // We need to disable warning 4910 and do an extern dllexport
318  // anyway. When deriving vtkCharArray and other types from an
319  // instantiation of this template the compiler does an explicit
320  // instantiation of the base class. From outside the vtkCommon
321  // library we block this using an extern dllimport instantiation.
322  // For classes inside vtkCommon we should be able to just do an
323  // extern instantiation, but VS 2008 complains about missing
324  // definitions. We cannot do an extern dllimport inside vtkCommon
325  // since the symbols are local to the dll. An extern dllexport
326  // seems to be the only way to convince VS 2008 to do the right
327  // thing, so we just disable the warning.
328 # pragma warning (disable: 4910) // extern and dllexport incompatible
329 
330  // Use an "extern explicit instantiation" to give the class a DLL
331  // interface. This is a compiler-specific extension.
333 # pragma warning (pop)
334 # endif
335 # undef VTK_DATA_ARRAY_TEMPLATE_TYPE
336 #endif
337 // VTK-HeaderTest-Exclude: vtkDataArrayTemplate.h
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)
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 InsertComponent(vtkIdType i, int j, double c)
int vtkIdType
Definition: vtkType.h:268
virtual double GetComponent(vtkIdType i, int j)
virtual void ComputeVectorRange(double range[2])
virtual void Initialize()=0
A atomic type representing the union of many types.
Definition: vtkVariant.h:78
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:38
virtual void RemoveLastTuple()=0
#define VTK_DATA_ARRAY_TEMPLATE_TYPE
virtual void * GetVoidPointer(vtkIdType id)
list of point or cell ids
Definition: vtkIdList.h:35
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)
Abstract superclass to iterate over elements in an vtkAbstractArray.
virtual void SetVoidArray(void *array, vtkIdType size, int save)
virtual void ComputeScalarRange(double range[2], int comp)
virtual void SetTuple(vtkIdType i, vtkIdType j, vtkAbstractArray *source)=0
T * GetPointer(vtkIdType id)
void SetArray(T *array, vtkIdType size, int save)
void GetValueRange(T range[2], int comp)
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)
virtual void ComputeRange(double range[2], int comp)