VTK  9.3.0
vtkFieldData.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2 // SPDX-License-Identifier: BSD-3-Clause
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 #include <array> // For CachedGhostRangeType
52 #include <tuple> // For CachedGhostRangeType
53 #include <vector> // For list indices
54 
55 VTK_ABI_NAMESPACE_BEGIN
56 class vtkIdList;
57 class vtkDoubleArray;
59 
60 class VTKCOMMONDATAMODEL_EXPORT vtkFieldData : public vtkObject
61 {
62 public:
63  static vtkFieldData* New();
65 
66  vtkTypeMacro(vtkFieldData, vtkObject);
67  void PrintSelf(ostream& os, vtkIndent indent) override;
68 
73  virtual void Initialize();
74 
80 
87 
97  void AllocateArrays(int num);
98 
105  int GetNumberOfArrays() { return this->NumberOfActiveArrays; }
106 
114 
118  void NullData(vtkIdType id);
119 
121 
124  virtual void RemoveArray(const char* name);
125 
129  virtual void RemoveArray(int index);
131 
141 
152  vtkDataArray* GetArray(const char* arrayName, int& index);
153 
155 
164  vtkDataArray* GetArray(const char* arrayName)
165  {
166  int i;
167  return this->GetArray(arrayName, i);
168  }
170 
177 
184  vtkAbstractArray* GetAbstractArray(const char* arrayName, int& index);
185 
187 
192  vtkAbstractArray* GetAbstractArray(const char* arrayName)
193  {
194  int i;
195  return this->GetAbstractArray(arrayName, i);
196  }
198 
200 
203  vtkTypeBool HasArray(const char* name)
204  {
205  int i;
206  vtkAbstractArray* array = this->GetAbstractArray(name, i);
207  return array ? 1 : 0;
208  }
210 
212 
217  const char* GetArrayName(int i)
218  {
219  vtkAbstractArray* da = this->GetAbstractArray(i);
220  return da ? da->GetName() : nullptr;
221  }
223 
228  virtual void PassData(vtkFieldData* fd);
229 
239  void CopyFieldOn(const char* name) { this->CopyFieldOnOff(name, 1); }
240  void CopyFieldOff(const char* name) { this->CopyFieldOnOff(name, 0); }
241 
251  virtual void CopyAllOn(int unused = 0);
252 
262  virtual void CopyAllOff(int unused = 0);
263 
267  virtual void DeepCopy(vtkFieldData* da);
268 
272  virtual void ShallowCopy(vtkFieldData* da);
273 
277  void Squeeze();
278 
283  void Reset();
284 
291  virtual unsigned long GetActualMemorySize();
292 
296  vtkMTimeType GetMTime() override;
297 
307  void GetField(vtkIdList* ptId, vtkFieldData* f);
308 
316  int GetArrayContainingComponent(int i, int& arrayComp);
317 
328 
340 
350 
357 
363 
370 
372 
391  bool GetRange(const char* name, double range[2], int comp = 0);
392  bool GetRange(int index, double range[2], int comp = 0);
393  bool GetFiniteRange(const char* name, double range[2], int comp = 0);
394  bool GetFiniteRange(int index, double range[2], int comp = 0);
396 
398 
409  vtkGetMacro(GhostsToSkip, unsigned char);
410  virtual void SetGhostsToSkip(unsigned char);
412 
417  bool HasAnyGhostBitSet(int bitFlag);
418 
427  vtkGetObjectMacro(GhostArray, vtkUnsignedCharArray);
428 
429 protected:
431  ~vtkFieldData() override;
432 
436 
440  void SetArray(int i, vtkAbstractArray* array);
441 
445  virtual void InitializeFields();
446 
448  {
449  char* ArrayName;
450  int IsCopied;
451  };
452 
453  CopyFieldFlag* CopyFieldFlags; // the names of fields not to be copied
454  int NumberOfFieldFlags; // the number of fields not to be copied
455  void CopyFieldOnOff(const char* name, int onOff);
457  int FindFlag(const char* field);
458  int GetFlag(const char* field);
462 
463  /*
464  * This tuple holds: [array time stamp, ghost array time stamp, cached ranges].
465  * Those time stamps are used to decide whether the cached range should be recomputed or not.
466  * when requesting the range of an array.
467  *
468  * When there is no ghost array, the ghost array time stamp is defined as equal to 0.
469  */
470  using CachedGhostRangeType = std::tuple<vtkMTimeType, vtkMTimeType, std::vector<double>>;
471  unsigned char GhostsToSkip;
473 
475 
482  std::vector<std::array<CachedGhostRangeType, 2>> Ranges;
483  std::vector<std::array<CachedGhostRangeType, 2>> FiniteRanges;
485 
486 private:
487  vtkFieldData(const vtkFieldData&) = delete;
488  void operator=(const vtkFieldData&) = delete;
489 
490 public:
491  class VTKCOMMONDATAMODEL_EXPORT BasicIterator
492  {
493  public:
494  BasicIterator() = default;
496  BasicIterator(const int* list, unsigned int listSize);
498  virtual ~BasicIterator() = default;
499  void PrintSelf(ostream& os, vtkIndent indent);
500 
501  int GetListSize() const { return static_cast<int>(this->List.size()); }
502  int GetCurrentIndex() { return this->List[this->Position]; }
504  {
505  this->Position = -1;
506  return this->NextIndex();
507  }
508  int End() const { return (this->Position >= static_cast<int>(this->List.size())); }
509  int NextIndex()
510  {
511  this->Position++;
512  return (this->End() ? -1 : this->List[this->Position]);
513  }
514 
515  // Support C++ range-for loops; e.g, code like
516  // "for (const auto& i : basicIterator)".
517  std::vector<int>::const_iterator begin() { return this->List.begin(); }
518  std::vector<int>::const_iterator end() { return this->List.end(); }
519 
520  protected:
521  std::vector<int> List;
522  int Position;
523  };
524 
525  class VTKCOMMONDATAMODEL_EXPORT Iterator : public BasicIterator
526  {
527  public:
530  ~Iterator() override;
531  Iterator(vtkFieldData* dsa, const int* list = nullptr, unsigned int listSize = 0);
532 
534  {
535  this->Position = -1;
536  return this->Next();
537  }
538 
540  {
541  this->Position++;
542  if (this->End())
543  {
544  return nullptr;
545  }
546 
547  // vtkFieldData::GetArray() can return null, which implies that
548  // a the array at the given index in not a vtkDataArray subclass.
549  // This iterator skips such arrays.
550  vtkDataArray* cur = Fields->GetArray(this->List[this->Position]);
551  return (cur ? cur : this->Next());
552  }
553 
555 
556  protected:
558  int Detached;
559  };
560 };
561 
562 VTK_ABI_NAMESPACE_END
563 #endif
Abstract superclass for all arrays.
virtual char * GetName()
Set/get array's name.
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:54
dynamic, self-adjusting array of double
BasicIterator(const BasicIterator &source)
std::vector< int >::const_iterator begin()
Definition: vtkFieldData.h:517
BasicIterator(const int *list, unsigned int listSize)
BasicIterator & operator=(const BasicIterator &source)
virtual ~BasicIterator()=default
void PrintSelf(ostream &os, vtkIndent indent)
std::vector< int > List
Definition: vtkFieldData.h:521
std::vector< int >::const_iterator end()
Definition: vtkFieldData.h:518
vtkDataArray * Begin()
Definition: vtkFieldData.h:533
Iterator(vtkFieldData *dsa, const int *list=nullptr, unsigned int listSize=0)
vtkFieldData * Fields
Definition: vtkFieldData.h:557
Iterator(const Iterator &source)
Iterator & operator=(const Iterator &source)
vtkDataArray * Next()
Definition: vtkFieldData.h:539
represent and manipulate fields of data
Definition: vtkFieldData.h:61
vtkTypeBool Allocate(vtkIdType sz, vtkIdType ext=1000)
Allocate data for each array.
int GetFlag(const char *field)
vtkAbstractArray ** Data
Definition: vtkFieldData.h:435
static vtkFieldData * ExtendedNew()
int GetNumberOfArrays()
Get the number of arrays of data available.
Definition: vtkFieldData.h:105
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)
~vtkFieldData() override
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 InsertTuple(vtkIdType i, vtkIdType j, vtkFieldData *source)
Insert the jth tuple in source field data at the ith location.
bool GetFiniteRange(const char *name, double range[2], int comp=0)
Computes the range of the input data array (specified through its name or the index in this field dat...
bool HasAnyGhostBitSet(int bitFlag)
Helper function that tests if any of the values in ghost array has been set.
std::vector< std::array< CachedGhostRangeType, 2 > > FiniteRanges
Ranges and FiniteRanges store cached ranges for arrays stored in this field data.
Definition: vtkFieldData.h:483
virtual void SetGhostsToSkip(unsigned char)
Set / Get the binary mask filtering out certain types of ghosts when calling GetRange.
void AllocateArrays(int num)
AllocateArrays actually sets the number of vtkAbstractArray pointers in the vtkFieldData object,...
virtual void RemoveArray(int index)
Remove an array (with the given index) from the list of arrays.
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
virtual void InitializeFields()
Release all data but do not delete object.
bool GetRange(const char *name, double range[2], int comp=0)
Computes the range of the input data array (specified through its name or the index in this field dat...
int GetNumberOfComponents()
Get the number of components in the field.
vtkMTimeType GetMTime() override
Check object's components for modified times.
std::vector< std::array< CachedGhostRangeType, 2 > > Ranges
Ranges and FiniteRanges store cached ranges for arrays stored in this field data.
Definition: vtkFieldData.h:482
std::tuple< vtkMTimeType, vtkMTimeType, std::vector< double > > CachedGhostRangeType
Definition: vtkFieldData.h:470
virtual void RemoveArray(const char *name)
Remove an array (with the given name) from the list of arrays.
unsigned char GhostsToSkip
Definition: vtkFieldData.h:471
const char * GetArrayName(int i)
Get the name of ith array.
Definition: vtkFieldData.h:217
void SetTuple(vtkIdType i, vtkIdType j, vtkFieldData *source)
Set the jth tuple in source field data at the ith location.
virtual void CopyAllOn(int unused=0)
Turn on copying of all data.
CopyFieldFlag * CopyFieldFlags
Definition: vtkFieldData.h:453
void SetNumberOfTuples(vtkIdType number)
Set the number of tuples for each data array in the field.
vtkDataArray * GetArray(int i)
Not recommended for use.
vtkAbstractArray * GetAbstractArray(const char *arrayName)
Return the array with the name given.
Definition: vtkFieldData.h:192
virtual unsigned long GetActualMemorySize()
Return the memory in kibibytes (1024 bytes) consumed by this field data.
int GetArrayContainingComponent(int i, int &arrayComp)
Return the array containing the ith component of the field.
void ClearFieldFlags()
int FindFlag(const char *field)
vtkDataArray * GetArray(const char *arrayName)
Not recommended for use.
Definition: vtkFieldData.h:164
virtual void Initialize()
Release all data but do not delete object.
virtual void CopyAllOff(int unused=0)
Turn off copying of all data.
bool GetRange(int index, double range[2], int comp=0)
Computes the range of the input data array (specified through its name or the index in this field dat...
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:239
bool GetFiniteRange(int index, double range[2], int comp=0)
Computes the range of the input data array (specified through its name or the index in this field dat...
vtkUnsignedCharArray * GhostArray
Definition: vtkFieldData.h:472
void CopyFieldOff(const char *name)
Definition: vtkFieldData.h:240
vtkAbstractArray * GetAbstractArray(int i)
Returns the ith array in the field.
vtkIdType GetNumberOfTuples()
Get the number of tuples in the field.
void Squeeze()
Squeezes each data array in the field (Squeeze() reclaims unused memory.)
vtkIdType InsertNextTuple(vtkIdType j, vtkFieldData *source)
Insert the jth tuple in source field data at the end of the tuple matrix.
void NullData(vtkIdType id)
Sets every vtkDataArray at index id to a null tuple.
void GetField(vtkIdList *ptId, vtkFieldData *f)
Get a field from a list of ids.
void CopyFieldOnOff(const char *name, int onOff)
int NumberOfActiveArrays
Definition: vtkFieldData.h:434
virtual void PassData(vtkFieldData *fd)
Pass entire arrays of input data through to output.
vtkTypeBool HasArray(const char *name)
Return 1 if an array with the given name could be found.
Definition: vtkFieldData.h:203
void CopyStructure(vtkFieldData *)
Copy data array structure from a given field.
vtkDataArray * GetArray(const char *arrayName, int &index)
Not recommended for use.
void SetArray(int i, vtkAbstractArray *array)
Set an array to define the field.
int NumberOfFieldFlags
Definition: vtkFieldData.h:454
vtkAbstractArray * GetAbstractArray(const char *arrayName, int &index)
Return the array with the name given.
list of point or cell ids
Definition: vtkIdList.h:32
a simple class to control print indentation
Definition: vtkIndent.h:38
abstract base class for most VTK objects
Definition: vtkObject.h:61
dynamic, self-adjusting array of unsigned char
@ field
Definition: vtkX3D.h:177
@ range
Definition: vtkX3D.h:238
@ name
Definition: vtkX3D.h:219
@ index
Definition: vtkX3D.h:246
int vtkTypeBool
Definition: vtkABI.h:64
boost::graph_traits< vtkGraph * >::vertex_descriptor source(boost::graph_traits< vtkGraph * >::edge_descriptor e, vtkGraph *)
int vtkIdType
Definition: vtkType.h:315
vtkTypeUInt32 vtkMTimeType
Definition: vtkType.h:270