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 =========================================================================*/
43 #ifndef vtkFieldData_h
44 #define vtkFieldData_h
45 
46 #include "vtkCommonDataModelModule.h" // For export macro
47 #include "vtkObject.h"
48 
49 #include "vtkAbstractArray.h" // Needed for inline methods.
50 
51 class vtkIdList;
52 
53 class VTKCOMMONDATAMODEL_EXPORT vtkFieldData : public vtkObject
54 {
55 public:
56  static vtkFieldData* New();
57 
58  vtkTypeMacro(vtkFieldData, vtkObject);
59  void PrintSelf(ostream& os, vtkIndent indent) override;
60 
65  virtual void Initialize();
66 
71  vtkTypeBool Allocate(vtkIdType sz, vtkIdType ext = 1000);
72 
78  void CopyStructure(vtkFieldData*);
79 
89  void AllocateArrays(int num);
90 
97  int GetNumberOfArrays() { return this->NumberOfActiveArrays; }
98 
104  int AddArray(vtkAbstractArray* array);
105 
107 
110  virtual void RemoveArray(const char* name);
111  virtual void RemoveArray(int index);
113 
122  vtkDataArray* GetArray(int i);
123 
134  vtkDataArray* GetArray(const char* arrayName, int& index);
135 
137 
146  vtkDataArray* GetArray(const char* arrayName)
147  {
148  int i;
149  return this->GetArray(arrayName, i);
150  }
152 
158  vtkAbstractArray* GetAbstractArray(int i);
159 
166  vtkAbstractArray* GetAbstractArray(const char* arrayName, int& index);
167 
169 
174  vtkAbstractArray* GetAbstractArray(const char* arrayName)
175  {
176  int i;
177  return this->GetAbstractArray(arrayName, i);
178  }
180 
182 
185  int HasArray(const char* name)
186  {
187  int i;
188  vtkAbstractArray* array = this->GetAbstractArray(name, i);
189  // assert( i == -1);
190  return array ? 1 : 0;
191  }
193 
195 
200  const char* GetArrayName(int i)
201  {
202  vtkAbstractArray* da = this->GetAbstractArray(i);
203  return da ? da->GetName() : nullptr;
204  }
206 
211  virtual void PassData(vtkFieldData* fd);
212 
222  void CopyFieldOn(const char* name) { this->CopyFieldOnOff(name, 1); }
223  void CopyFieldOff(const char* name) { this->CopyFieldOnOff(name, 0); }
224 
234  virtual void CopyAllOn(int unused = 0);
235 
245  virtual void CopyAllOff(int unused = 0);
246 
250  virtual void DeepCopy(vtkFieldData* da);
251 
255  virtual void ShallowCopy(vtkFieldData* da);
256 
260  void Squeeze();
261 
266  void Reset();
267 
274  virtual unsigned long GetActualMemorySize();
275 
279  vtkMTimeType GetMTime() override;
280 
290  void GetField(vtkIdList* ptId, vtkFieldData* f);
291 
299  int GetArrayContainingComponent(int i, int& arrayComp);
300 
310  int GetNumberOfComponents();
311 
322  vtkIdType GetNumberOfTuples();
323 
332  void SetNumberOfTuples(const vtkIdType number);
333 
339  void SetTuple(const vtkIdType i, const vtkIdType j, vtkFieldData* source);
340 
345  void InsertTuple(const vtkIdType i, const vtkIdType j, vtkFieldData* source);
346 
352  vtkIdType InsertNextTuple(const vtkIdType j, vtkFieldData* source);
353 
354 protected:
355  vtkFieldData();
356  ~vtkFieldData() override;
357 
361 
365  void SetArray(int i, vtkAbstractArray* array);
366 
370  virtual void InitializeFields();
371 
373  {
374  char* ArrayName;
375  int IsCopied;
376  };
377 
378  CopyFieldFlag* CopyFieldFlags; // the names of fields not to be copied
379  int NumberOfFieldFlags; // the number of fields not to be copied
380  void CopyFieldOnOff(const char* name, int onOff);
381  void ClearFieldFlags();
382  int FindFlag(const char* field);
383  int GetFlag(const char* field);
384  void CopyFlags(const vtkFieldData* source);
387 
388 private:
389  vtkFieldData(const vtkFieldData&) = delete;
390  void operator=(const vtkFieldData&) = delete;
391 
392 public:
393  class VTKCOMMONDATAMODEL_EXPORT BasicIterator
394  {
395  public:
396  BasicIterator();
398  BasicIterator(const int* list, unsigned int listSize);
399  BasicIterator& operator=(const BasicIterator& source);
400  virtual ~BasicIterator();
401  void PrintSelf(ostream& os, vtkIndent indent);
402 
403  int GetListSize() const { return this->ListSize; }
404  int GetCurrentIndex() { return this->List[this->Position]; }
406  {
407  this->Position = -1;
408  return this->NextIndex();
409  }
410  int End() const { return (this->Position >= this->ListSize); }
411  int NextIndex()
412  {
413  this->Position++;
414  return (this->End() ? -1 : this->List[this->Position]);
415  }
416 
417  protected:
418  int* List;
419  int ListSize;
420  int Position;
421  };
422 
423  class VTKCOMMONDATAMODEL_EXPORT Iterator : public BasicIterator
424  {
425  public:
426  Iterator(const Iterator& source);
428  ~Iterator() override;
429  Iterator(vtkFieldData* dsa, const int* list = nullptr, unsigned int listSize = 0);
430 
432  {
433  this->Position = -1;
434  return this->Next();
435  }
436 
438  {
439  this->Position++;
440  if (this->End())
441  {
442  return nullptr;
443  }
444 
445  // vtkFieldData::GetArray() can return null, which implies that
446  // a the array at the given index in not a vtkDataArray subclass.
447  // This iterator skips such arrays.
448  vtkDataArray* cur = Fields->GetArray(this->List[this->Position]);
449  return (cur ? cur : this->Next());
450  }
451 
452  void DetachFieldData();
453 
454  protected:
456  int Detached;
457  };
458 };
459 
460 #endif
vtkAbstractArray::GetName
virtual char * GetName()
vtkFieldData::GetAbstractArray
vtkAbstractArray * GetAbstractArray(const char *arrayName)
Return the array with the name given.
Definition: vtkFieldData.h:174
vtkFieldData::GetArray
vtkDataArray * GetArray(const char *arrayName)
Not recommended for use.
Definition: vtkFieldData.h:146
vtkFieldData::GetArrayName
const char * GetArrayName(int i)
Get the name of ith array.
Definition: vtkFieldData.h:200
vtkIdType
int vtkIdType
Definition: vtkType.h:349
vtkObject::New
static vtkObject * New()
Create an object with Debug turned off, modified time initialized to zero, and reference counting on.
vtkFieldData::BasicIterator::ListSize
int ListSize
Definition: vtkFieldData.h:419
vtkFieldData::DoCopyAllOff
int DoCopyAllOff
Definition: vtkFieldData.h:386
vtkFieldData::Iterator::Detached
int Detached
Definition: vtkFieldData.h:456
vtkObject
abstract base class for most VTK objects
Definition: vtkObject.h:53
vtkFieldData::BasicIterator
Definition: vtkFieldData.h:393
vtkDataArray
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:49
vtkFieldData::CopyFieldFlags
CopyFieldFlag * CopyFieldFlags
Definition: vtkFieldData.h:378
vtkFieldData::NumberOfActiveArrays
int NumberOfActiveArrays
Definition: vtkFieldData.h:359
vtkAbstractArray.h
vtkFieldData::Iterator::Begin
vtkDataArray * Begin()
Definition: vtkFieldData.h:431
vtkFieldData::CopyFieldFlag::IsCopied
int IsCopied
Definition: vtkFieldData.h:375
vtkFieldData
represent and manipulate fields of data
Definition: vtkFieldData.h:53
vtkFieldData::Iterator::Next
vtkDataArray * Next()
Definition: vtkFieldData.h:437
vtkFieldData::Iterator
Definition: vtkFieldData.h:423
vtkFieldData::NumberOfFieldFlags
int NumberOfFieldFlags
Definition: vtkFieldData.h:379
vtkFieldData::BasicIterator::Position
int Position
Definition: vtkFieldData.h:420
vtkObject::GetMTime
virtual vtkMTimeType GetMTime()
Return this object's modified time.
vtkFieldData::Iterator::Fields
vtkFieldData * Fields
Definition: vtkFieldData.h:455
vtkIndent
a simple class to control print indentation
Definition: vtkIndent.h:33
vtkFieldData::BasicIterator::operator=
BasicIterator & operator=(const BasicIterator &source)
vtkX3D::field
Definition: vtkX3D.h:183
vtkFieldData::BasicIterator::List
int * List
Definition: vtkFieldData.h:418
vtkFieldData::HasArray
int HasArray(const char *name)
Return 1 if an array with the given name could be found.
Definition: vtkFieldData.h:185
vtkIdList
list of point or cell ids
Definition: vtkIdList.h:30
vtkFieldData::BasicIterator::GetCurrentIndex
int GetCurrentIndex()
Definition: vtkFieldData.h:404
vtkObject::PrintSelf
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
vtkFieldData::CopyFieldOff
void CopyFieldOff(const char *name)
Definition: vtkFieldData.h:223
vtkFieldData::BasicIterator::NextIndex
int NextIndex()
Definition: vtkFieldData.h:411
vtkX3D::name
Definition: vtkX3D.h:225
vtkFieldData::BasicIterator::End
int End() const
Definition: vtkFieldData.h:410
vtkObject.h
vtkAbstractArray
Abstract superclass for all arrays.
Definition: vtkAbstractArray.h:75
vtkFieldData::BasicIterator::BeginIndex
int BeginIndex()
Definition: vtkFieldData.h:405
vtkFieldData::GetNumberOfArrays
int GetNumberOfArrays()
Get the number of arrays of data available.
Definition: vtkFieldData.h:97
vtkFieldData::CopyFieldFlag::ArrayName
char * ArrayName
Definition: vtkFieldData.h:374
vtkFieldData::CopyFieldFlag
Definition: vtkFieldData.h:372
vtkFieldData::NumberOfArrays
int NumberOfArrays
Definition: vtkFieldData.h:358
source
boost::graph_traits< vtkGraph * >::vertex_descriptor source(boost::graph_traits< vtkGraph * >::edge_descriptor e, vtkGraph *)
Definition: vtkBoostGraphAdapter.h:959
vtkFieldData::BasicIterator::GetListSize
int GetListSize() const
Definition: vtkFieldData.h:403
vtkFieldData::Data
vtkAbstractArray ** Data
Definition: vtkFieldData.h:360
vtkX3D::index
Definition: vtkX3D.h:252
vtkFieldData::CopyFieldOn
void CopyFieldOn(const char *name)
Turn on/off the copying of the field specified by name.
Definition: vtkFieldData.h:222
vtkTypeBool
int vtkTypeBool
Definition: vtkABI.h:69
vtkMTimeType
vtkTypeUInt32 vtkMTimeType
Definition: vtkType.h:304
vtkFieldData::DoCopyAllOn
int DoCopyAllOn
Definition: vtkFieldData.h:385