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) override;
63 
68  virtual void Initialize();
69 
74  vtkTypeBool Allocate(vtkIdType sz, vtkIdType ext=1000);
75 
81  void CopyStructure(vtkFieldData*);
82 
92  void AllocateArrays(int num);
93 
101  {
102  return this->NumberOfActiveArrays;
103  }
104 
110  int AddArray(vtkAbstractArray *array);
111 
113 
116  virtual void RemoveArray(const char *name);
117  virtual void RemoveArray(int index);
119 
128  vtkDataArray *GetArray(int i);
129 
140  vtkDataArray *GetArray(const char *arrayName, int &index);
141 
143 
152  vtkDataArray *GetArray(const char *arrayName)
153  {
154  int i;
155  return this->GetArray(arrayName, i);
156  }
158 
164  vtkAbstractArray* GetAbstractArray(int i);
165 
172  vtkAbstractArray* GetAbstractArray(const char* arrayName, int &index);
173 
175 
180  vtkAbstractArray* GetAbstractArray(const char* arrayName)
181  {
182  int i;
183  return this->GetAbstractArray(arrayName, i);
184  }
186 
188 
191  int HasArray(const char *name)
192  {
193  int i;
194  vtkAbstractArray *array = this->GetAbstractArray(name, i);
195  // assert( i == -1);
196  return array ? 1 : 0;
197  }
199 
201 
206  const char* GetArrayName(int i)
207  {
208  vtkAbstractArray* da = this->GetAbstractArray(i);
209  return da ? da->GetName() : nullptr;
210  }
212 
217  virtual void PassData(vtkFieldData* fd);
218 
228  void CopyFieldOn(const char* name) { this->CopyFieldOnOff(name, 1); }
229  void CopyFieldOff(const char* name) { this->CopyFieldOnOff(name, 0); }
230 
240  virtual void CopyAllOn(int unused=0);
241 
251  virtual void CopyAllOff(int unused=0);
252 
256  virtual void DeepCopy(vtkFieldData *da);
257 
261  virtual void ShallowCopy(vtkFieldData *da);
262 
266  void Squeeze();
267 
272  void Reset();
273 
280  virtual unsigned long GetActualMemorySize();
281 
285  vtkMTimeType GetMTime() override;
286 
296  void GetField(vtkIdList *ptId, vtkFieldData *f);
297 
305  int GetArrayContainingComponent(int i, int& arrayComp);
306 
316  int GetNumberOfComponents();
317 
328  vtkIdType GetNumberOfTuples();
329 
338  void SetNumberOfTuples(const vtkIdType number);
339 
345  void SetTuple(const vtkIdType i, const vtkIdType j, vtkFieldData* source);
346 
351  void InsertTuple(const vtkIdType i, const vtkIdType j, vtkFieldData* source);
352 
358  vtkIdType InsertNextTuple(const vtkIdType j, vtkFieldData* source);
359 
360 protected:
361 
362  vtkFieldData();
363  ~vtkFieldData() override;
364 
368 
372  void SetArray(int i, vtkAbstractArray *array);
373 
377  virtual void InitializeFields();
378 
380  {
381  char* ArrayName;
382  int IsCopied;
383  };
384 
385  CopyFieldFlag* CopyFieldFlags; //the names of fields not to be copied
386  int NumberOfFieldFlags; //the number of fields not to be copied
387  void CopyFieldOnOff(const char* name, int onOff);
388  void ClearFieldFlags();
389  int FindFlag(const char* field);
390  int GetFlag(const char* field);
391  void CopyFlags(const vtkFieldData* source);
394 
395 
396 private:
397  vtkFieldData(const vtkFieldData&) = delete;
398  void operator=(const vtkFieldData&) = delete;
399 
400 public:
401 
402  class VTKCOMMONDATAMODEL_EXPORT BasicIterator
403  {
404  public:
405  BasicIterator();
406  BasicIterator(const BasicIterator& source);
407  BasicIterator(const int* list, unsigned int listSize);
408  BasicIterator& operator=(const BasicIterator& source);
409  virtual ~BasicIterator();
410  void PrintSelf(ostream &os, vtkIndent indent);
411 
412  int GetListSize() const
413  {
414  return this->ListSize;
415  }
417  {
418  return this->List[this->Position];
419  }
421  {
422  this->Position = -1;
423  return this->NextIndex();
424  }
425  int End() const
426  {
427  return (this->Position >= this->ListSize);
428  }
429  int NextIndex()
430  {
431  this->Position++;
432  return (this->End() ? -1 : this->List[this->Position]);
433  }
434 
435  protected:
436 
437  int* List;
438  int ListSize;
439  int Position;
440  };
441 
442  class VTKCOMMONDATAMODEL_EXPORT Iterator : public BasicIterator
443  {
444  public:
445 
446  Iterator(const Iterator& source);
447  Iterator& operator=(const Iterator& source);
448  ~Iterator() override;
449  Iterator(vtkFieldData* dsa, const int* list=nullptr,
450  unsigned int listSize=0);
451 
453  {
454  this->Position = -1;
455  return this->Next();
456  }
457 
459  {
460  this->Position++;
461  if (this->End())
462  {
463  return nullptr;
464  }
465 
466  // vtkFieldData::GetArray() can return null, which implies that
467  // a the array at the given index in not a vtkDataArray subclass.
468  // This iterator skips such arrays.
469  vtkDataArray* cur = Fields->GetArray(this->List[this->Position]);
470  return (cur? cur : this->Next());
471  }
472 
473  void DetachFieldData();
474 
475  protected:
477  int Detached;
478  };
479 
480 };
481 
482 
483 #endif
vtkFieldData * Fields
Definition: vtkFieldData.h:476
vtkDataArray * GetArray(const char *arrayName)
Not recommended for use.
Definition: vtkFieldData.h:152
abstract base class for most VTK objects
Definition: vtkObject.h:59
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
vtkTypeUInt32 vtkMTimeType
Definition: vtkType.h:302
Abstract superclass for all arrays.
CopyFieldFlag * CopyFieldFlags
Definition: vtkFieldData.h:385
int vtkIdType
Definition: vtkType.h:347
void CopyFieldOn(const char *name)
Turn on/off the copying of the field specified by name.
Definition: vtkFieldData.h:228
int vtkTypeBool
Definition: vtkABI.h:69
a simple class to control print indentation
Definition: vtkIndent.h:39
vtkAbstractArray * GetAbstractArray(const char *arrayName)
Return the array with the name given.
Definition: vtkFieldData.h:180
list of point or cell ids
Definition: vtkIdList.h:36
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:54
virtual vtkMTimeType GetMTime()
Return this object's modified time.
virtual char * GetName()
Set/get array's name.
int NumberOfFieldFlags
Definition: vtkFieldData.h:386
const char * GetArrayName(int i)
Get the name of ith array.
Definition: vtkFieldData.h:206
int HasArray(const char *name)
Return 1 if an array with the given name could be found.
Definition: vtkFieldData.h:191
boost::graph_traits< vtkGraph * >::vertex_descriptor source(boost::graph_traits< vtkGraph * >::edge_descriptor e, vtkGraph *)
int NumberOfActiveArrays
Definition: vtkFieldData.h:366
void CopyFieldOff(const char *name)
Definition: vtkFieldData.h:229
vtkAbstractArray ** Data
Definition: vtkFieldData.h:367
vtkDataArray * Begin()
Definition: vtkFieldData.h:452
int GetNumberOfArrays()
Get the number of arrays of data available.
Definition: vtkFieldData.h:100
static vtkObject * New()
Create an object with Debug turned off, modified time initialized to zero, and reference counting on...
vtkDataArray * Next()
Definition: vtkFieldData.h:458
represent and manipulate fields of data
Definition: vtkFieldData.h:56