VTK  9.7.1
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
33 #ifndef vtkFieldData_h
34 #define vtkFieldData_h
35 
36 #include "vtkCommonDataModelModule.h" // For export macro
37 #include "vtkObject.h"
38 #include "vtkWrappingHints.h" // For VTK_MARSHALMANUAL
39 
40 #include "vtkAbstractArray.h" // Needed for inline methods.
41 
42 #include <array> // For CachedGhostRangeType
43 #include <tuple> // For CachedGhostRangeType
44 #include <vector> // For list indices
45 
46 VTK_ABI_NAMESPACE_BEGIN
47 class vtkIdList;
48 class vtkDoubleArray;
50 
51 class VTKCOMMONDATAMODEL_EXPORT VTK_MARSHALMANUAL vtkFieldData : public vtkObject
52 {
53 public:
54  static vtkFieldData* New();
55  static vtkFieldData* ExtendedNew();
56 
57  vtkTypeMacro(vtkFieldData, vtkObject);
58  void PrintSelf(ostream& os, vtkIndent indent) override;
59 
64  virtual void Initialize();
65 
70  vtkTypeBool Allocate(vtkIdType sz, vtkIdType ext = 1000);
71 
77  void CopyStructure(vtkFieldData*);
78 
88  void AllocateArrays(int num);
89 
96  int GetNumberOfArrays() { return this->NumberOfActiveArrays; }
97 
104  int AddArray(vtkAbstractArray* array);
105 
109  void NullData(vtkIdType id);
110 
112 
115  virtual void RemoveArray(const char* name);
116 
120  virtual void RemoveArray(int index);
122 
131  vtkDataArray* GetArray(int i);
132 
143  vtkDataArray* GetArray(const char* arrayName, int& index);
144 
146 
155  vtkDataArray* GetArray(const char* arrayName)
156  {
157  int i;
158  return this->GetArray(arrayName, i);
159  }
161 
167  vtkAbstractArray* GetAbstractArray(int i);
168 
175  vtkAbstractArray* GetAbstractArray(const char* arrayName, int& index);
176 
178 
183  vtkAbstractArray* GetAbstractArray(const char* arrayName)
184  {
185  int i;
186  return this->GetAbstractArray(arrayName, i);
187  }
189 
191 
194  vtkTypeBool HasArray(const char* name)
195  {
196  int i;
197  vtkAbstractArray* array = this->GetAbstractArray(name, i);
198  return array ? 1 : 0;
199  }
201 
203 
208  const char* GetArrayName(int i)
209  {
210  vtkAbstractArray* da = this->GetAbstractArray(i);
211  return da ? da->GetName() : nullptr;
212  }
214 
219  virtual void PassData(vtkFieldData* fd);
220 
230  void CopyFieldOn(const char* name) { this->CopyFieldOnOff(name, 1); }
231  void CopyFieldOff(const char* name) { this->CopyFieldOnOff(name, 0); }
232 
242  virtual void CopyAllOn(int unused = 0);
243 
253  virtual void CopyAllOff(int unused = 0);
254 
258  virtual void DeepCopy(vtkFieldData* da);
259 
263  virtual void ShallowCopy(vtkFieldData* da);
264 
268  void Squeeze();
269 
274  void Reset();
275 
282  virtual unsigned long GetActualMemorySize();
283 
287  vtkMTimeType GetMTime() override;
288 
298  void GetField(vtkIdList* ptId, vtkFieldData* f);
299 
307  int GetArrayContainingComponent(int i, int& arrayComp);
308 
318  int GetNumberOfComponents();
319 
330  vtkIdType GetNumberOfTuples();
331 
340  void SetNumberOfTuples(vtkIdType number);
341 
347  void SetTuple(vtkIdType i, vtkIdType j, vtkFieldData* source);
348 
353  void InsertTuple(vtkIdType i, vtkIdType j, vtkFieldData* source);
354 
360  vtkIdType InsertNextTuple(vtkIdType j, vtkFieldData* source);
361 
363 
382  bool GetRange(const char* name, double range[2], int comp = 0);
383  bool GetRange(int index, double range[2], int comp = 0);
384  bool GetFiniteRange(const char* name, double range[2], int comp = 0);
385  bool GetFiniteRange(int index, double range[2], int comp = 0);
387 
389 
400  vtkGetMacro(GhostsToSkip, unsigned char);
401  virtual void SetGhostsToSkip(unsigned char);
403 
408  bool HasAnyGhostBitSet(int bitFlag);
409 
418  vtkGetObjectMacro(GhostArray, vtkUnsignedCharArray);
419 
427  static const char* GhostArrayName() { return "vtkGhostType"; }
428 
429 protected:
430  vtkFieldData();
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);
456  void ClearFieldFlags();
457  int FindFlag(const char* field);
458  int GetFlag(const char* field);
459  void CopyFlags(const vtkFieldData* source);
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  friend class vtkFieldDataSerDesHelper; // for access to SetArray()
491 
492 public:
493  class VTKCOMMONDATAMODEL_EXPORT BasicIterator
494  {
495  public:
496  BasicIterator() = default;
498  BasicIterator(const int* list, unsigned int listSize);
499  BasicIterator& operator=(const BasicIterator& source);
500  virtual ~BasicIterator() = default;
501  void PrintSelf(ostream& os, vtkIndent indent);
502 
503  int GetListSize() const { return static_cast<int>(this->List.size()); }
504  int GetCurrentIndex() { return this->List[this->Position]; }
506  {
507  this->Position = -1;
508  return this->NextIndex();
509  }
510  int End() const { return (this->Position >= static_cast<int>(this->List.size())); }
511  int NextIndex()
512  {
513  this->Position++;
514  return (this->End() ? -1 : this->List[this->Position]);
515  }
516 
517  // Support C++ range-for loops; e.g, code like
518  // "for (const auto& i : basicIterator)".
519  std::vector<int>::const_iterator begin() { return this->List.begin(); }
520  std::vector<int>::const_iterator end() { return this->List.end(); }
521 
522  protected:
523  std::vector<int> List;
524  int Position;
525  };
526 
527  class VTKCOMMONDATAMODEL_EXPORT Iterator : public BasicIterator
528  {
529  public:
530  Iterator(const Iterator& source);
531  Iterator& operator=(const Iterator& source);
532  ~Iterator() override;
533  Iterator(vtkFieldData* dsa, const int* list = nullptr, unsigned int listSize = 0);
534 
536  {
537  this->Position = -1;
538  return this->Next();
539  }
540 
542  {
543  this->Position++;
544  if (this->End())
545  {
546  return nullptr;
547  }
548 
549  // vtkFieldData::GetArray() can return null, which implies that
550  // a the array at the given index in not a vtkDataArray subclass.
551  // This iterator skips such arrays.
552  vtkDataArray* cur = Fields->GetArray(this->List[this->Position]);
553  return (cur ? cur : this->Next());
554  }
555 
556  void DetachFieldData();
557 
558  protected:
560  int Detached;
561  };
562 };
563 
564 VTK_ABI_NAMESPACE_END
565 #endif
vtkFieldData * Fields
Definition: vtkFieldData.h:559
std::vector< int > List
Definition: vtkFieldData.h:523
vtkUnsignedCharArray * GhostArray
Definition: vtkFieldData.h:472
vtkDataArray * GetArray(const char *arrayName)
Not recommended for use.
Definition: vtkFieldData.h:155
std::tuple< vtkMTimeType, vtkMTimeType, std::vector< double >> CachedGhostRangeType
Definition: vtkFieldData.h:470
abstract base class for most VTK objects
Definition: vtkObject.h:52
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
vtkTypeUInt32 vtkMTimeType
Definition: vtkType.h:318
Abstract superclass for all arrays.
CopyFieldFlag * CopyFieldFlags
Definition: vtkFieldData.h:453
int vtkIdType
Definition: vtkType.h:363
std::vector< std::array< CachedGhostRangeType, 2 > > Ranges
Ranges and FiniteRanges store cached ranges for arrays stored in this field data. ...
Definition: vtkFieldData.h:482
void CopyFieldOn(const char *name)
Turn on/off the copying of the field specified by name.
Definition: vtkFieldData.h:230
dynamic, self-adjusting array of double
BasicIterator & operator=(const BasicIterator &source)
int vtkTypeBool
Definition: vtkABI.h:64
std::vector< std::array< CachedGhostRangeType, 2 > > FiniteRanges
Ranges and FiniteRanges store cached ranges for arrays stored in this field data. ...
Definition: vtkFieldData.h:483
unsigned char GhostsToSkip
Definition: vtkFieldData.h:471
#define VTK_MARSHALMANUAL
a simple class to control print indentation
Definition: vtkIndent.h:28
vtkAbstractArray * GetAbstractArray(const char *arrayName)
Return the array with the name given.
Definition: vtkFieldData.h:183
list of point or cell ids
Definition: vtkIdList.h:25
std::vector< int >::const_iterator begin()
Definition: vtkFieldData.h:519
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:44
virtual vtkMTimeType GetMTime()
Return this object's modified time.
virtual char * GetName()
Set/get array's name.
int NumberOfFieldFlags
Definition: vtkFieldData.h:454
static const char * GhostArrayName()
Return the name used for Ghost Arrays.
Definition: vtkFieldData.h:427
const char * GetArrayName(int i)
Get the name of ith array.
Definition: vtkFieldData.h:208
boost::graph_traits< vtkGraph * >::vertex_descriptor source(boost::graph_traits< vtkGraph * >::edge_descriptor e, vtkGraph *)
dynamic, self-adjusting array of unsigned char
int NumberOfActiveArrays
Definition: vtkFieldData.h:434
void CopyFieldOff(const char *name)
Definition: vtkFieldData.h:231
std::vector< int >::const_iterator end()
Definition: vtkFieldData.h:520
vtkTypeBool HasArray(const char *name)
Return 1 if an array with the given name could be found.
Definition: vtkFieldData.h:194
vtkAbstractArray ** Data
Definition: vtkFieldData.h:435
vtkDataArray * Begin()
Definition: vtkFieldData.h:535
int GetNumberOfArrays()
Get the number of arrays of data available.
Definition: vtkFieldData.h:96
static vtkObject * New()
Create an object with Debug turned off, modified time initialized to zero, and reference counting on...
vtkDataArray * Next()
Definition: vtkFieldData.h:541
Represents and manipulates a collection of data arrays.
Definition: vtkFieldData.h:51