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>
29 class vtkDataArrayTemplateLookup;
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 
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); }
115 
117  vtkIdType Capacity() { return this->Size; }
118 
123  virtual int Resize(vtkIdType numTuples);
124 
126  T GetValue(vtkIdType id) { return this->Array[id]; }
127 
129 
131  void SetValue(vtkIdType id, T value)
132  { this->Array[id] = value;};
134 
138  void SetNumberOfValues(vtkIdType number);
139 
141  void InsertValue(vtkIdType id, T f);
142 
145 
148  vtkIdType InsertNextValue(T f);
149 
151 
154  virtual void RemoveTuple(vtkIdType id);
155  virtual void RemoveFirstTuple();
156  virtual void RemoveLastTuple();
158 
162  double GetComponent(vtkIdType i, int j);
163 
168  void SetComponent(vtkIdType i, int j, double c);
169 
173  virtual void InsertComponent(vtkIdType i, int j, double c);
174 
176 
179  T* WritePointer(vtkIdType id, vtkIdType number);
180  virtual void* WriteVoidPointer(vtkIdType id, vtkIdType number)
181  { return this->WritePointer(id, number); }
183 
185 
187  T* GetPointer(vtkIdType id) { return this->Array + id; }
188  virtual void* GetVoidPointer(vtkIdType id) { return this->GetPointer(id); }
190 
192 
193  void DeepCopy(vtkDataArray* da);
195  { this->Superclass::DeepCopy(aa); }
197 
198 //BTX
200  {
202  VTK_DATA_ARRAY_DELETE
203  };
204 //ETX
205 
207 
216  void SetArray(T* array, vtkIdType size, int save, int deleteMethod);
217  void SetArray(T* array, vtkIdType size, int save)
218  { this->SetArray(array, size, save, VTK_DATA_ARRAY_FREE); }
219  virtual void SetVoidArray(void* array, vtkIdType size, int save)
220  { this->SetArray(static_cast<T*>(array), size, save); }
221  virtual void SetVoidArray(void* array,
222  vtkIdType size,
223  int save,
224  int deleteMethod)
225  {
226  this->SetArray(static_cast<T*>(array), size, save, deleteMethod);
227  }
229 
233  virtual void ExportToVoidPointer(void *out_ptr);
234 
236  virtual vtkArrayIterator* NewIterator();
237 
239 
241  virtual void LookupValue(vtkVariant value, vtkIdList* ids);
243  void LookupValue(T value, vtkIdList* ids);
245 
252  virtual void DataChanged();
253 
257  virtual void DataElementChanged(vtkIdType id);
258 
262  virtual void ClearLookup();
263 
264 protected:
267 
268  T* Array; // pointer to data
269  T ValueRange[2]; // range of the data
270  T* ResizeAndExtend(vtkIdType sz); // function to resize data
271  T* Realloc(vtkIdType sz);
272 
273  int TupleSize; //used for data conversion
274  double* Tuple;
275 
278 
279  virtual void ComputeScalarRange(int comp);
280  virtual void ComputeVectorRange();
281 private:
282  vtkDataArrayTemplate(const vtkDataArrayTemplate&); // Not implemented.
283  void operator=(const vtkDataArrayTemplate&); // Not implemented.
284 
285  vtkDataArrayTemplateLookup<T>* Lookup;
286  void UpdateLookup();
287 
288  void DeleteArray();
289 };
290 
291 #if !defined(VTK_NO_EXPLICIT_TEMPLATE_INSTANTIATION)
292 # define VTK_DATA_ARRAY_TEMPLATE_INSTANTIATE(T) \
293  template class VTK_COMMON_EXPORT vtkDataArrayTemplate< T >
294 #else
295 # include "vtkDataArrayTemplateImplicit.txx"
296 # define VTK_DATA_ARRAY_TEMPLATE_INSTANTIATE(T)
297 #endif
298 
299 #endif // !defined(__vtkDataArrayTemplate_h)
300 
301 // This portion must be OUTSIDE the include blockers. Each
302 // vtkDataArray subclass uses this to give its instantiation of this
303 // template a DLL interface.
304 #if defined(VTK_DATA_ARRAY_TEMPLATE_TYPE)
305 # if defined(VTK_BUILD_SHARED_LIBS) && defined(_MSC_VER)
306 # pragma warning (push)
307 # pragma warning (disable: 4091) // warning C4091: 'extern ' :
308  // ignored on left of 'int' when no variable is declared
309 # pragma warning (disable: 4231) // Compiler-specific extension warning.
310 
311  // We need to disable warning 4910 and do an extern dllexport
312  // anyway. When deriving vtkCharArray and other types from an
313  // instantiation of this template the compiler does an explicit
314  // instantiation of the base class. From outside the vtkCommon
315  // library we block this using an extern dllimport instantiation.
316  // For classes inside vtkCommon we should be able to just do an
317  // extern instantiation, but VS 2008 complains about missing
318  // definitions. We cannot do an extern dllimport inside vtkCommon
319  // since the symbols are local to the dll. An extern dllexport
320  // seems to be the only way to convince VS 2008 to do the right
321  // thing, so we just disable the warning.
322 # pragma warning (disable: 4910) // extern and dllexport incompatible
323 
324  // Use an "extern explicit instantiation" to give the class a DLL
325  // interface. This is a compiler-specific extension.
327 # pragma warning (pop)
328 # endif
329 # undef VTK_DATA_ARRAY_TEMPLATE_TYPE
330 #endif