VTK  9.0.20210418
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();
58 
59  vtkTypeMacro(vtkFieldData, vtkObject);
60  void PrintSelf(ostream& os, vtkIndent indent) override;
61 
66  virtual void Initialize();
67 
73 
80 
90  void AllocateArrays(int num);
91 
98  int GetNumberOfArrays() { return this->NumberOfActiveArrays; }
99 
106 
110  void NullData(vtkIdType id);
111 
113 
116  virtual void RemoveArray(const char* name);
117  virtual void RemoveArray(int index);
119 
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 
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 
317 
329 
338  void SetNumberOfTuples(const vtkIdType number);
339 
345  void SetTuple(const vtkIdType i, const vtkIdType j, vtkFieldData* source);
346 
352 
359 
360 protected:
362  ~vtkFieldData() override;
363 
367 
371  void SetArray(int i, vtkAbstractArray* array);
372 
376  virtual void InitializeFields();
377 
379  {
380  char* ArrayName;
381  int IsCopied;
382  };
383 
384  CopyFieldFlag* CopyFieldFlags; // the names of fields not to be copied
385  int NumberOfFieldFlags; // the number of fields not to be copied
386  void CopyFieldOnOff(const char* name, int onOff);
388  int FindFlag(const char* field);
389  int GetFlag(const char* field);
393 
394 private:
395  vtkFieldData(const vtkFieldData&) = delete;
396  void operator=(const vtkFieldData&) = delete;
397 
398 public:
399  class VTKCOMMONDATAMODEL_EXPORT BasicIterator
400  {
401  public:
404  BasicIterator(const int* list, unsigned int listSize);
406  virtual ~BasicIterator();
407  void PrintSelf(ostream& os, vtkIndent indent);
408 
409  int GetListSize() const { return this->ListSize; }
410  int GetCurrentIndex() { return this->List[this->Position]; }
412  {
413  this->Position = -1;
414  return this->NextIndex();
415  }
416  int End() const { return (this->Position >= this->ListSize); }
417  int NextIndex()
418  {
419  this->Position++;
420  return (this->End() ? -1 : this->List[this->Position]);
421  }
422 
423  protected:
424  int* List;
425  int ListSize;
426  int Position;
427  };
428 
429  class VTKCOMMONDATAMODEL_EXPORT Iterator : public BasicIterator
430  {
431  public:
434  ~Iterator() override;
435  Iterator(vtkFieldData* dsa, const int* list = nullptr, unsigned int listSize = 0);
436 
438  {
439  this->Position = -1;
440  return this->Next();
441  }
442 
444  {
445  this->Position++;
446  if (this->End())
447  {
448  return nullptr;
449  }
450 
451  // vtkFieldData::GetArray() can return null, which implies that
452  // a the array at the given index in not a vtkDataArray subclass.
453  // This iterator skips such arrays.
454  vtkDataArray* cur = Fields->GetArray(this->List[this->Position]);
455  return (cur ? cur : this->Next());
456  }
457 
459 
460  protected:
462  int Detached;
463  };
464 };
465 
466 #endif
vtkFieldData::GetFlag
int GetFlag(const char *field)
vtkAbstractArray::GetName
virtual char * GetName()
Set/get array's name.
vtkFieldData::GetMTime
vtkMTimeType GetMTime() override
Check object's components for modified times.
vtkFieldData::Iterator::DetachFieldData
void DetachFieldData()
vtkFieldData::NullData
void NullData(vtkIdType id)
Sets every vtkDataArray at index id to a null tuple.
vtkFieldData::FindFlag
int FindFlag(const char *field)
vtkFieldData::GetNumberOfTuples
vtkIdType GetNumberOfTuples()
Get the number of tuples in the field.
vtkFieldData::Iterator::Iterator
Iterator(vtkFieldData *dsa, const int *list=nullptr, unsigned int listSize=0)
vtkFieldData::GetAbstractArray
vtkAbstractArray * GetAbstractArray(const char *arrayName)
Return the array with the name given.
Definition: vtkFieldData.h:180
vtkFieldData::GetArray
vtkDataArray * GetArray(const char *arrayName)
Not recommended for use.
Definition: vtkFieldData.h:152
vtkFieldData::BasicIterator::BasicIterator
BasicIterator(const int *list, unsigned int listSize)
vtkFieldData::GetArrayName
const char * GetArrayName(int i)
Get the name of ith array.
Definition: vtkFieldData.h:206
vtkFieldData::GetArray
vtkDataArray * GetArray(const char *arrayName, int &index)
Not recommended for use.
vtkIdType
int vtkIdType
Definition: vtkType.h:338
vtkFieldData::GetAbstractArray
vtkAbstractArray * GetAbstractArray(int i)
Returns the ith array in the field.
vtkFieldData::CopyAllOn
virtual void CopyAllOn(int unused=0)
Turn on copying of all data.
vtkFieldData::SetNumberOfTuples
void SetNumberOfTuples(const vtkIdType number)
Set the number of tuples for each data array in the field.
vtkFieldData::BasicIterator::ListSize
int ListSize
Definition: vtkFieldData.h:425
vtkFieldData::DoCopyAllOff
int DoCopyAllOff
Definition: vtkFieldData.h:392
vtkFieldData::Iterator::Detached
int Detached
Definition: vtkFieldData.h:462
vtkObject
abstract base class for most VTK objects
Definition: vtkObject.h:63
vtkFieldData::InsertTuple
void InsertTuple(const vtkIdType i, const vtkIdType j, vtkFieldData *source)
Insert the jth tuple in source field data at the ith location.
vtkFieldData::BasicIterator
Definition: vtkFieldData.h:400
vtkFieldData::GetActualMemorySize
virtual unsigned long GetActualMemorySize()
Return the memory in kibibytes (1024 bytes) consumed by this field data.
vtkFieldData::DeepCopy
virtual void DeepCopy(vtkFieldData *da)
Copy a field by creating new data arrays (i.e., duplicate storage).
vtkDataArray
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:50
vtkFieldData::PrintSelf
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
vtkFieldData::CopyFieldFlags
CopyFieldFlag * CopyFieldFlags
Definition: vtkFieldData.h:384
vtkFieldData::NumberOfActiveArrays
int NumberOfActiveArrays
Definition: vtkFieldData.h:365
vtkFieldData::Iterator::operator=
Iterator & operator=(const Iterator &source)
vtkFieldData::BasicIterator::BasicIterator
BasicIterator(const BasicIterator &source)
vtkAbstractArray.h
vtkFieldData::Iterator::Begin
vtkDataArray * Begin()
Definition: vtkFieldData.h:437
vtkFieldData::CopyFieldFlag::IsCopied
int IsCopied
Definition: vtkFieldData.h:381
vtkFieldData::GetArray
vtkDataArray * GetArray(int i)
Not recommended for use.
vtkFieldData
represent and manipulate fields of data
Definition: vtkFieldData.h:54
vtkFieldData::Iterator::Next
vtkDataArray * Next()
Definition: vtkFieldData.h:443
vtkFieldData::GetAbstractArray
vtkAbstractArray * GetAbstractArray(const char *arrayName, int &index)
Return the array with the name given.
vtkFieldData::ExtendedNew
static vtkFieldData * ExtendedNew()
vtkFieldData::Iterator
Definition: vtkFieldData.h:430
vtkFieldData::CopyAllOff
virtual void CopyAllOff(int unused=0)
Turn off copying of all data.
vtkFieldData::NumberOfFieldFlags
int NumberOfFieldFlags
Definition: vtkFieldData.h:385
vtkFieldData::SetTuple
void SetTuple(const vtkIdType i, const vtkIdType j, vtkFieldData *source)
Set the jth tuple in source field data at the ith location.
vtkFieldData::CopyStructure
void CopyStructure(vtkFieldData *)
Copy data array structure from a given field.
vtkFieldData::BasicIterator::Position
int Position
Definition: vtkFieldData.h:426
vtkFieldData::Iterator::Fields
vtkFieldData * Fields
Definition: vtkFieldData.h:461
vtkFieldData::Iterator::Iterator
Iterator(const Iterator &source)
vtkFieldData::BasicIterator::BasicIterator
BasicIterator()
vtkIndent
a simple class to control print indentation
Definition: vtkIndent.h:34
vtkFieldData::BasicIterator::operator=
BasicIterator & operator=(const BasicIterator &source)
vtkX3D::field
@ field
Definition: vtkX3D.h:183
vtkFieldData::BasicIterator::List
int * List
Definition: vtkFieldData.h:424
vtkFieldData::AddArray
int AddArray(vtkAbstractArray *array)
Add an array to the array list.
vtkFieldData::HasArray
int HasArray(const char *name)
Return 1 if an array with the given name could be found.
Definition: vtkFieldData.h:191
vtkIdList
list of point or cell ids
Definition: vtkIdList.h:31
vtkFieldData::InitializeFields
virtual void InitializeFields()
Release all data but do not delete object.
vtkFieldData::BasicIterator::GetCurrentIndex
int GetCurrentIndex()
Definition: vtkFieldData.h:410
vtkFieldData::CopyFieldOnOff
void CopyFieldOnOff(const char *name, int onOff)
vtkFieldData::CopyFieldOff
void CopyFieldOff(const char *name)
Definition: vtkFieldData.h:229
vtkFieldData::BasicIterator::NextIndex
int NextIndex()
Definition: vtkFieldData.h:417
vtkFieldData::BasicIterator::PrintSelf
void PrintSelf(ostream &os, vtkIndent indent)
vtkX3D::name
@ name
Definition: vtkX3D.h:225
vtkFieldData::BasicIterator::End
int End() const
Definition: vtkFieldData.h:416
vtkFieldData::Allocate
vtkTypeBool Allocate(vtkIdType sz, vtkIdType ext=1000)
Allocate data for each array.
vtkObject.h
vtkFieldData::CopyFlags
void CopyFlags(const vtkFieldData *source)
vtkAbstractArray
Abstract superclass for all arrays.
Definition: vtkAbstractArray.h:76
vtkFieldData::BasicIterator::BeginIndex
int BeginIndex()
Definition: vtkFieldData.h:411
vtkFieldData::GetNumberOfArrays
int GetNumberOfArrays()
Get the number of arrays of data available.
Definition: vtkFieldData.h:98
vtkFieldData::InsertNextTuple
vtkIdType InsertNextTuple(const vtkIdType j, vtkFieldData *source)
Insert the jth tuple in source field data at the end of the tuple matrix.
vtkFieldData::CopyFieldFlag::ArrayName
char * ArrayName
Definition: vtkFieldData.h:380
vtkParticleTracerBaseNamespace::Position
struct Position_t Position
Definition: vtkParticleTracerBase.h:63
vtkFieldData::GetArrayContainingComponent
int GetArrayContainingComponent(int i, int &arrayComp)
Return the array containing the ith component of the field.
vtkFieldData::ClearFieldFlags
void ClearFieldFlags()
vtkFieldData::Reset
void Reset()
Resets each data array in the field (Reset() does not release memory but it makes the arrays look lik...
vtkFieldData::SetArray
void SetArray(int i, vtkAbstractArray *array)
Set an array to define the field.
vtkFieldData::PassData
virtual void PassData(vtkFieldData *fd)
Pass entire arrays of input data through to output.
vtkFieldData::ShallowCopy
virtual void ShallowCopy(vtkFieldData *da)
Copy a field by reference counting the data arrays.
vtkFieldData::CopyFieldFlag
Definition: vtkFieldData.h:379
vtkFieldData::GetNumberOfComponents
int GetNumberOfComponents()
Get the number of components in the field.
vtkFieldData::AllocateArrays
void AllocateArrays(int num)
AllocateOfArrays actually sets the number of vtkAbstractArray pointers in the vtkFieldData object,...
vtkFieldData::Iterator::~Iterator
~Iterator() override
vtkFieldData::vtkFieldData
vtkFieldData()
vtkFieldData::NumberOfArrays
int NumberOfArrays
Definition: vtkFieldData.h:364
source
boost::graph_traits< vtkGraph * >::vertex_descriptor source(boost::graph_traits< vtkGraph * >::edge_descriptor e, vtkGraph *)
Definition: vtkBoostGraphAdapter.h:959
vtkFieldData::Squeeze
void Squeeze()
Squeezes each data array in the field (Squeeze() reclaims unused memory.)
vtkFieldData::BasicIterator::GetListSize
int GetListSize() const
Definition: vtkFieldData.h:409
vtkFieldData::~vtkFieldData
~vtkFieldData() override
vtkFieldData::Initialize
virtual void Initialize()
Release all data but do not delete object.
vtkFieldData::Data
vtkAbstractArray ** Data
Definition: vtkFieldData.h:366
vtkX3D::index
@ 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:228
vtkTypeBool
int vtkTypeBool
Definition: vtkABI.h:69
vtkFieldData::BasicIterator::~BasicIterator
virtual ~BasicIterator()
vtkFieldData::New
static vtkFieldData * New()
vtkMTimeType
vtkTypeUInt32 vtkMTimeType
Definition: vtkType.h:293
vtkFieldData::DoCopyAllOn
int DoCopyAllOn
Definition: vtkFieldData.h:391
vtkFieldData::GetField
void GetField(vtkIdList *ptId, vtkFieldData *f)
Get a field from a list of ids.