VTK
vtkFieldData.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkFieldData.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 =========================================================================*/
45 #ifndef __vtkFieldData_h
46 #define __vtkFieldData_h
47 
48 #include "vtkObject.h"
49 
50 #include "vtkAbstractArray.h" // Needed for inline methods.
51 
52 #ifndef VTK_LEGACY_REMOVE
53 # include "vtkDataArray.h" // Needed for backwards compatibility.
54 #endif
55 
56 class vtkIdList;
57 
59 {
60 public:
61  static vtkFieldData *New();
62 
63  vtkTypeMacro(vtkFieldData,vtkObject);
64  void PrintSelf(ostream& os, vtkIndent indent);
65 
68  virtual void Initialize();
69 
71  int Allocate(const vtkIdType sz, const vtkIdType ext=1000);
72 
75  void CopyStructure(vtkFieldData*);
76 
83  void AllocateArrays(int num);
84 
86 
90  {
91  return this->NumberOfActiveArrays;
92  }
94 
97  int AddArray(vtkAbstractArray *array);
98 
100 
101  virtual void RemoveArray(const char *name)
102  {
103  int i;
104  this->GetAbstractArray(name, i);
105  this->RemoveArray(i);
106  }
108 
112  vtkDataArray *GetArray(int i);
113 
118  vtkDataArray *GetArray(const char *arrayName, int &index);
119 
121 
124  vtkDataArray *GetArray(const char *arrayName)
125  {
126  int i;
127  return this->GetArray(arrayName, i);
128  }
130 
134  vtkAbstractArray* GetAbstractArray(int i);
135 
139  vtkAbstractArray* GetAbstractArray(const char* arrayName, int &index);
140 
142 
144  vtkAbstractArray* GetAbstractArray(const char* arrayName)
145  {
146  int i;
147  return this->GetAbstractArray(arrayName, i);
148  }
150 
152 
153  int HasArray(const char *name)
154  {
155  int i;
156  vtkAbstractArray *array = this->GetAbstractArray(name, i);
157  // assert( i == -1);
158  return array ? 1 : 0;
159  }
161 
163 
165  const char* GetArrayName(int i)
166  {
167  vtkAbstractArray* da = this->GetAbstractArray(i);
168  return da ? da->GetName() : 0;
169  }
171 
174  virtual void PassData(vtkFieldData* fd);
175 
177 
182  void CopyFieldOn(const char* name) { this->CopyFieldOnOff(name, 1); }
183  void CopyFieldOff(const char* name) { this->CopyFieldOnOff(name, 0); }
185 
191  virtual void CopyAllOn(int unused=0);
192 
198  virtual void CopyAllOff(int unused=0);
199 
201  virtual void DeepCopy(vtkFieldData *da);
202 
204  virtual void ShallowCopy(vtkFieldData *da);
205 
208  void Squeeze();
209 
212  void Reset();
213 
218  virtual unsigned long GetActualMemorySize();
219 
221  unsigned long int GetMTime();
222 
230  void GetField(vtkIdList *ptId, vtkFieldData *f);
231 
237  int GetArrayContainingComponent(int i, int& arrayComp);
238 
245  int GetNumberOfComponents();
246 
254  vtkIdType GetNumberOfTuples();
255 
261  void SetNumberOfTuples(const vtkIdType number);
262 
266  void SetTuple(const vtkIdType i, const vtkIdType j, vtkFieldData* source);
267 
270  void InsertTuple(const vtkIdType i, const vtkIdType j, vtkFieldData* source);
271 
275  vtkIdType InsertNextTuple(const vtkIdType j, vtkFieldData* source);
276 
277  // Following are LEGACY methods. Using these methods for FieldData
278  // having arrays that are not subclasses of vtkDataArray may
279  // yield unexpected results.
280 
286  VTK_LEGACY(double *GetTuple(const vtkIdType i));
287 
292  VTK_LEGACY(void GetTuple(const vtkIdType i, double * tuple));
293 
298  VTK_LEGACY(void SetTuple(const vtkIdType i, const double * tuple));
299 
304  VTK_LEGACY(void InsertTuple(const vtkIdType i, const double * tuple));
305 
310  VTK_LEGACY(vtkIdType InsertNextTuple(const double * tuple));
311 
316  VTK_LEGACY(double GetComponent(const vtkIdType i, const int j));
317 
323  VTK_LEGACY(void SetComponent(const vtkIdType i, const int j, const double c));
324 
326 
331  VTK_LEGACY(void InsertComponent(const vtkIdType i, const int j, const double c));
332 protected:
334 
335  vtkFieldData();
336  ~vtkFieldData();
337 
341 
343  void SetArray(int i, vtkAbstractArray *array);
344 
345  virtual void RemoveArray(int index);
346 
348  virtual void InitializeFields();
349 
350 //BTX
351 
353  {
354  char* ArrayName;
355  int IsCopied;
356  };
357 
358  CopyFieldFlag* CopyFieldFlags; //the names of fields not to be copied
359  int NumberOfFieldFlags; //the number of fields not to be copied
360  void CopyFieldOnOff(const char* name, int onOff);
361  void ClearFieldFlags();
362  int FindFlag(const char* field);
363  int GetFlag(const char* field);
364  void CopyFlags(const vtkFieldData* source);
367 
368 
369 private:
370  vtkFieldData(const vtkFieldData&); // Not implemented.
371  void operator=(const vtkFieldData&); // Not implemented.
372 
373 #ifndef VTK_LEGACY_REMOVE
374  // Must be removed when support for Legacy GetTuple is removed.
375  int TupleSize; // used for type conversion in Legacy support.
376  double* Tuple;
377 #endif
378 public:
379 
381  {
382  public:
383  BasicIterator();
384  BasicIterator(const BasicIterator& source);
385  BasicIterator(const int* list, unsigned int listSize);
386  BasicIterator& operator=(const BasicIterator& source);
387  virtual ~BasicIterator();
388  void PrintSelf(ostream &os, vtkIndent indent);
389 
390  int GetListSize() const
391  {
392  return this->ListSize;
393  }
395  {
396  return this->List[this->Position];
397  }
399  {
400  this->Position = -1;
401  return this->NextIndex();
402  }
403  int End() const
404  {
405  return (this->Position >= this->ListSize);
406  }
407  int NextIndex()
408  {
409  this->Position++;
410  return (this->End() ? -1 : this->List[this->Position]);
411  }
412 
413  protected:
414 
415  int* List;
416  int ListSize;
417  int Position;
418  };
419 
421  {
422  public:
423 
424  Iterator(const Iterator& source);
425  Iterator& operator=(const Iterator& source);
426  virtual ~Iterator();
427  Iterator(vtkFieldData* dsa, const int* list=0,
428  unsigned int listSize=0);
429 
431  {
432  this->Position = -1;
433  return this->Next();
434  }
435 
437  {
438  this->Position++;
439  if (this->End())
440  {
441  return 0;
442  }
443 
444  // vtkFieldData::GetArray() can return null, which implies that
445  // a the array at the given index in not a vtkDataArray subclass.
446  // This iterator skips such arrays.
447  vtkDataArray* cur = Fields->GetArray(this->List[this->Position]);
448  return (cur? cur : this->Next());
449  }
450 
451  void DetachFieldData();
452 
453  protected:
455  int Detached;
456  };
457 
458 
459 //ETX
460 
461 };
462 
463 
464 #endif
vtkFieldData * Fields
Definition: vtkFieldData.h:454
vtkDataArray * GetArray(const char *arrayName)
Definition: vtkFieldData.h:124
abstract base class for most VTK objects
Definition: vtkObject.h:60
#define VTK_FILTERING_EXPORT
Abstract superclass for all arrays.
CopyFieldFlag * CopyFieldFlags
Definition: vtkFieldData.h:358
int vtkIdType
Definition: vtkType.h:255
void CopyFieldOn(const char *name)
Definition: vtkFieldData.h:182
BasicIterator & operator=(const BasicIterator &source)
virtual void PrintSelf(ostream &os, vtkIndent indent)
virtual unsigned long GetMTime()
a simple class to control print indentation
Definition: vtkIndent.h:37
vtkAbstractArray * GetAbstractArray(const char *arrayName)
Definition: vtkFieldData.h:144
list of point or cell ids
Definition: vtkIdList.h:34
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:53
virtual char * GetName()
int NumberOfFieldFlags
Definition: vtkFieldData.h:359
const char * GetArrayName(int i)
Definition: vtkFieldData.h:165
int HasArray(const char *name)
Definition: vtkFieldData.h:153
int NumberOfActiveArrays
Definition: vtkFieldData.h:339
void CopyFieldOff(const char *name)
Definition: vtkFieldData.h:183
vtkAbstractArray ** Data
Definition: vtkFieldData.h:340
vtkDataArray * Begin()
Definition: vtkFieldData.h:430
int GetNumberOfArrays()
Definition: vtkFieldData.h:89
static vtkObject * New()
virtual void RemoveArray(const char *name)
Definition: vtkFieldData.h:101
vtkDataArray * Next()
Definition: vtkFieldData.h:436
represent and manipulate fields of data
Definition: vtkFieldData.h:58