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 =========================================================================*/
46 #ifndef vtkFieldData_h
47 #define vtkFieldData_h
48 
49 #include "vtkCommonDataModelModule.h" // For export macro
50 #include "vtkObject.h"
51 
52 #include "vtkAbstractArray.h" // Needed for inline methods.
53 
54 class vtkIdList;
55 
56 class VTKCOMMONDATAMODEL_EXPORT vtkFieldData : public vtkObject
57 {
58 public:
59  static vtkFieldData *New();
60 
61  vtkTypeMacro(vtkFieldData,vtkObject);
62  void PrintSelf(ostream& os, vtkIndent indent) VTK_OVERRIDE;
63 
68  virtual void Initialize();
69 
74  int Allocate(const vtkIdType sz, const vtkIdType ext=1000);
75 
82 
92  void AllocateArrays(int num);
93 
101  {
102  return this->NumberOfActiveArrays;
103  }
104 
111 
113 
116  virtual void RemoveArray(const char *name);
117  virtual void RemoveArray(int index);
119 
126 
132  vtkDataArray *GetArray(const char *arrayName, int &index);
133 
135 
140  vtkDataArray *GetArray(const char *arrayName)
141  {
142  int i;
143  return this->GetArray(arrayName, i);
144  }
146 
153 
159  vtkAbstractArray* GetAbstractArray(const char* arrayName, int &index);
160 
162 
166  vtkAbstractArray* GetAbstractArray(const char* arrayName)
167  {
168  int i;
169  return this->GetAbstractArray(arrayName, i);
170  }
172 
174 
177  int HasArray(const char *name)
178  {
179  int i;
180  vtkAbstractArray *array = this->GetAbstractArray(name, i);
181  // assert( i == -1);
182  return array ? 1 : 0;
183  }
185 
187 
192  const char* GetArrayName(int i)
193  {
194  vtkAbstractArray* da = this->GetAbstractArray(i);
195  return da ? da->GetName() : 0;
196  }
198 
203  virtual void PassData(vtkFieldData* fd);
204 
214  void CopyFieldOn(const char* name) { this->CopyFieldOnOff(name, 1); }
215  void CopyFieldOff(const char* name) { this->CopyFieldOnOff(name, 0); }
216 
226  virtual void CopyAllOn(int unused=0);
227 
237  virtual void CopyAllOff(int unused=0);
238 
242  virtual void DeepCopy(vtkFieldData *da);
243 
247  virtual void ShallowCopy(vtkFieldData *da);
248 
252  void Squeeze();
253 
258  void Reset();
259 
266  virtual unsigned long GetActualMemorySize();
267 
271  vtkMTimeType GetMTime() VTK_OVERRIDE;
272 
282  void GetField(vtkIdList *ptId, vtkFieldData *f);
283 
291  int GetArrayContainingComponent(int i, int& arrayComp);
292 
302  int GetNumberOfComponents();
303 
314  vtkIdType GetNumberOfTuples();
315 
324  void SetNumberOfTuples(const vtkIdType number);
325 
331  void SetTuple(const vtkIdType i, const vtkIdType j, vtkFieldData* source);
332 
337  void InsertTuple(const vtkIdType i, const vtkIdType j, vtkFieldData* source);
338 
344  vtkIdType InsertNextTuple(const vtkIdType j, vtkFieldData* source);
345 
346 protected:
347 
349  ~vtkFieldData() VTK_OVERRIDE;
350 
351  int NumberOfArrays;
352  int NumberOfActiveArrays;
354 
358  void SetArray(int i, vtkAbstractArray *array);
359 
363  virtual void InitializeFields();
364 
366  {
367  char* ArrayName;
368  int IsCopied;
369  };
370 
371  CopyFieldFlag* CopyFieldFlags; //the names of fields not to be copied
372  int NumberOfFieldFlags; //the number of fields not to be copied
373  void CopyFieldOnOff(const char* name, int onOff);
375  int FindFlag(const char* field);
376  int GetFlag(const char* field);
380 
381 
382 private:
383  vtkFieldData(const vtkFieldData&) VTK_DELETE_FUNCTION;
384  void operator=(const vtkFieldData&) VTK_DELETE_FUNCTION;
385 
386 public:
387 
388  class VTKCOMMONDATAMODEL_EXPORT BasicIterator
389  {
390  public:
393  BasicIterator(const int* list, unsigned int listSize);
395  virtual ~BasicIterator();
396  void PrintSelf(ostream &os, vtkIndent indent);
397 
398  int GetListSize() const
399  {
400  return this->ListSize;
401  }
403  {
404  return this->List[this->Position];
405  }
407  {
408  this->Position = -1;
409  return this->NextIndex();
410  }
411  int End() const
412  {
413  return (this->Position >= this->ListSize);
414  }
415  int NextIndex()
416  {
417  this->Position++;
418  return (this->End() ? -1 : this->List[this->Position]);
419  }
420 
421  protected:
422 
423  int* List;
424  int ListSize;
425  int Position;
426  };
427 
428  class VTKCOMMONDATAMODEL_EXPORT Iterator : public BasicIterator
429  {
430  public:
431 
434  ~Iterator() VTK_OVERRIDE;
435  Iterator(vtkFieldData* dsa, const int* list=0,
436  unsigned int listSize=0);
437 
438  vtkDataArray* Begin()
439  {
440  this->Position = -1;
441  return this->Next();
442  }
443 
445  {
446  this->Position++;
447  if (this->End())
448  {
449  return 0;
450  }
451 
452  // vtkFieldData::GetArray() can return null, which implies that
453  // a the array at the given index in not a vtkDataArray subclass.
454  // This iterator skips such arrays.
455  vtkDataArray* cur = Fields->GetArray(this->List[this->Position]);
456  return (cur? cur : this->Next());
457  }
458 
460 
461  protected:
463  int Detached;
464  };
465 
466 };
467 
468 
469 #endif
Abstract superclass for all arrays.
virtual char * GetName()
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:55
BasicIterator(const BasicIterator &source)
BasicIterator(const int *list, unsigned int listSize)
BasicIterator & operator=(const BasicIterator &source)
void PrintSelf(ostream &os, vtkIndent indent)
vtkFieldData * Fields
Definition: vtkFieldData.h:462
Iterator(const Iterator &source)
Iterator & operator=(const Iterator &source)
vtkDataArray * Next()
Definition: vtkFieldData.h:444
represent and manipulate fields of data
Definition: vtkFieldData.h:57
int GetFlag(const char *field)
int GetNumberOfArrays()
Get the number of arrays of data available.
Definition: vtkFieldData.h:100
virtual void DeepCopy(vtkFieldData *da)
Copy a field by creating new data arrays (i.e., duplicate storage).
int AddArray(vtkAbstractArray *array)
Add an array to the array list.
void CopyFlags(const vtkFieldData *source)
static vtkFieldData * New()
void Reset()
Resets each data array in the field (Reset() does not release memory but it makes the arrays look lik...
void AllocateArrays(int num)
AllocateOfArrays actually sets the number of vtkAbstractArray pointers in the vtkFieldData object,...
virtual void RemoveArray(int index)
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
int Allocate(const vtkIdType sz, const vtkIdType ext=1000)
Allocate data for each array.
vtkMTimeType GetMTime() override
Check object's components for modified times.
virtual void RemoveArray(const char *name)
Remove an array (with the given name or index) from the list of arrays.
const char * GetArrayName(int i)
Get the name of ith array.
Definition: vtkFieldData.h:192
virtual void CopyAllOn(int unused=0)
Turn on copying of all data.
CopyFieldFlag * CopyFieldFlags
Definition: vtkFieldData.h:371
vtkDataArray * GetArray(int i)
Return the ith array in the field.
vtkAbstractArray * GetAbstractArray(const char *arrayName)
Return the array with the name given.
Definition: vtkFieldData.h:166
virtual unsigned long GetActualMemorySize()
Return the memory in kibibytes (1024 bytes) consumed by this field data.
void ClearFieldFlags()
int FindFlag(const char *field)
vtkDataArray * GetArray(const char *arrayName)
Return the array with the name given.
Definition: vtkFieldData.h:140
virtual void Initialize()
Release all data but do not delete object.
virtual void CopyAllOff(int unused=0)
Turn off copying of all data.
virtual void ShallowCopy(vtkFieldData *da)
Copy a field by reference counting the data arrays.
void CopyFieldOn(const char *name)
Turn on/off the copying of the field specified by name.
Definition: vtkFieldData.h:214
void CopyFieldOff(const char *name)
Definition: vtkFieldData.h:215
vtkAbstractArray * GetAbstractArray(int i)
Returns the ith array in the field.
void Squeeze()
Squeezes each data array in the field (Squeeze() reclaims unused memory.)
void CopyFieldOnOff(const char *name, int onOff)
virtual void PassData(vtkFieldData *fd)
Pass entire arrays of input data through to output.
void CopyStructure(vtkFieldData *)
Copy data array structure from a given field.
vtkDataArray * GetArray(const char *arrayName, int &index)
Return the array with the name given.
int HasArray(const char *name)
Return 1 if an array with the given name could be found.
Definition: vtkFieldData.h:177
int NumberOfFieldFlags
Definition: vtkFieldData.h:372
vtkAbstractArray * GetAbstractArray(const char *arrayName, int &index)
Return the array with the name given.
list of point or cell ids
Definition: vtkIdList.h:37
a simple class to control print indentation
Definition: vtkIndent.h:40
abstract base class for most VTK objects
Definition: vtkObject.h:60
@ field
Definition: vtkX3D.h:177
@ name
Definition: vtkX3D.h:219
@ index
Definition: vtkX3D.h:246
boost::graph_traits< vtkGraph * >::vertex_descriptor source(boost::graph_traits< vtkGraph * >::edge_descriptor e, vtkGraph *)
int vtkIdType
Definition: vtkType.h:287
vtkTypeUInt64 vtkMTimeType
Definition: vtkType.h:248