VTK  9.2.6
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 =========================================================================*/
55 #ifndef vtkFieldData_h
56 #define vtkFieldData_h
57 
58 #include "vtkCommonDataModelModule.h" // For export macro
59 #include "vtkObject.h"
60 
61 #include "vtkAbstractArray.h" // Needed for inline methods.
62 
63 #include <array> // For CachedGhostRangeType
64 #include <tuple> // For CachedGhostRangeType
65 #include <vector> // For list indices
66 
67 class vtkDoubleArray;
68 class vtkIdList;
70 
71 class VTKCOMMONDATAMODEL_EXPORT vtkFieldData : public vtkObject
72 {
73 public:
74  static vtkFieldData* New();
76 
77  vtkTypeMacro(vtkFieldData, vtkObject);
78  void PrintSelf(ostream& os, vtkIndent indent) override;
79 
84  virtual void Initialize();
85 
91 
98 
108  void AllocateArrays(int num);
109 
116  int GetNumberOfArrays() { return this->NumberOfActiveArrays; }
117 
124 
128  void NullData(vtkIdType id);
129 
131 
134  virtual void RemoveArray(const char* name);
135  virtual void RemoveArray(int index);
137 
147 
158  vtkDataArray* GetArray(const char* arrayName, int& index);
159 
161 
170  vtkDataArray* GetArray(const char* arrayName)
171  {
172  int i;
173  return this->GetArray(arrayName, i);
174  }
176 
183 
190  vtkAbstractArray* GetAbstractArray(const char* arrayName, int& index);
191 
193 
198  vtkAbstractArray* GetAbstractArray(const char* arrayName)
199  {
200  int i;
201  return this->GetAbstractArray(arrayName, i);
202  }
204 
206 
209  int HasArray(const char* name)
210  {
211  int i;
212  vtkAbstractArray* array = this->GetAbstractArray(name, i);
213  // assert( i == -1);
214  return array ? 1 : 0;
215  }
217 
219 
224  const char* GetArrayName(int i)
225  {
226  vtkAbstractArray* da = this->GetAbstractArray(i);
227  return da ? da->GetName() : nullptr;
228  }
230 
235  virtual void PassData(vtkFieldData* fd);
236 
246  void CopyFieldOn(const char* name) { this->CopyFieldOnOff(name, 1); }
247  void CopyFieldOff(const char* name) { this->CopyFieldOnOff(name, 0); }
248 
258  virtual void CopyAllOn(int unused = 0);
259 
269  virtual void CopyAllOff(int unused = 0);
270 
274  virtual void DeepCopy(vtkFieldData* da);
275 
279  virtual void ShallowCopy(vtkFieldData* da);
280 
284  void Squeeze();
285 
290  void Reset();
291 
298  virtual unsigned long GetActualMemorySize();
299 
303  vtkMTimeType GetMTime() override;
304 
314  void GetField(vtkIdList* ptId, vtkFieldData* f);
315 
323  int GetArrayContainingComponent(int i, int& arrayComp);
324 
335 
347 
356  void SetNumberOfTuples(const vtkIdType number);
357 
363  void SetTuple(const vtkIdType i, const vtkIdType j, vtkFieldData* source);
364 
370 
377 
379 
398  bool GetRange(const char* name, double range[2], int comp = 0);
399  bool GetRange(int index, double range[2], int comp = 0);
400  bool GetFiniteRange(const char* name, double range[2], int comp = 0);
401  bool GetFiniteRange(int index, double range[2], int comp = 0);
403 
405 
416  vtkGetMacro(GhostsToSkip, unsigned char);
417  virtual void SetGhostsToSkip(unsigned char);
419 
428  vtkGetObjectMacro(GhostArray, vtkUnsignedCharArray);
429 
430 protected:
432  ~vtkFieldData() override;
433 
437 
441  void SetArray(int i, vtkAbstractArray* array);
442 
446  virtual void InitializeFields();
447 
449  {
450  char* ArrayName;
451  int IsCopied;
452  };
453 
454  CopyFieldFlag* CopyFieldFlags; // the names of fields not to be copied
455  int NumberOfFieldFlags; // the number of fields not to be copied
456  void CopyFieldOnOff(const char* name, int onOff);
458  int FindFlag(const char* field);
459  int GetFlag(const char* field);
463 
464  /*
465  * This tuple holds: [array time stamp, ghost array time stamp, cached ranges].
466  * Those time stamps are used to decide whether the cached range should be recomputed or not.
467  * when requesting the range of an array.
468  *
469  * When there is no ghost array, the ghost array time stamp is defined as equal to 0.
470  */
471  using CachedGhostRangeType = std::tuple<vtkMTimeType, vtkMTimeType, std::vector<double>>;
472  unsigned char GhostsToSkip;
474 
476 
483  std::vector<std::array<CachedGhostRangeType, 2>> Ranges;
484  std::vector<std::array<CachedGhostRangeType, 2>> FiniteRanges;
486 
487 private:
488  vtkFieldData(const vtkFieldData&) = delete;
489  void operator=(const vtkFieldData&) = delete;
490 
491 public:
492  class VTKCOMMONDATAMODEL_EXPORT BasicIterator
493  {
494  public:
495  BasicIterator() = default;
497  BasicIterator(const int* list, unsigned int listSize);
499  virtual ~BasicIterator() = default;
500  void PrintSelf(ostream& os, vtkIndent indent);
501 
502  int GetListSize() const { return static_cast<int>(this->List.size()); }
503  int GetCurrentIndex() { return this->List[this->Position]; }
505  {
506  this->Position = -1;
507  return this->NextIndex();
508  }
509  int End() const { return (this->Position >= static_cast<int>(this->List.size())); }
510  int NextIndex()
511  {
512  this->Position++;
513  return (this->End() ? -1 : this->List[this->Position]);
514  }
515 
516  // Support C++ range-for loops; e.g, code like
517  // "for (const auto& i : basicIterator)".
518  std::vector<int>::const_iterator begin() { return this->List.begin(); }
519  std::vector<int>::const_iterator end() { return this->List.end(); }
520 
521  protected:
522  std::vector<int> List;
523  int Position;
524  };
525 
526  class VTKCOMMONDATAMODEL_EXPORT Iterator : public BasicIterator
527  {
528  public:
531  ~Iterator() override;
532  Iterator(vtkFieldData* dsa, const int* list = nullptr, unsigned int listSize = 0);
533 
535  {
536  this->Position = -1;
537  return this->Next();
538  }
539 
541  {
542  this->Position++;
543  if (this->End())
544  {
545  return nullptr;
546  }
547 
548  // vtkFieldData::GetArray() can return null, which implies that
549  // a the array at the given index in not a vtkDataArray subclass.
550  // This iterator skips such arrays.
551  vtkDataArray* cur = Fields->GetArray(this->List[this->Position]);
552  return (cur ? cur : this->Next());
553  }
554 
556 
557  protected:
559  int Detached;
560  };
561 };
562 
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:65
dynamic, self-adjusting array of double
BasicIterator(const BasicIterator &source)
std::vector< int >::const_iterator begin()
Definition: vtkFieldData.h:518
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:522
std::vector< int >::const_iterator end()
Definition: vtkFieldData.h:519
vtkDataArray * Begin()
Definition: vtkFieldData.h:534
Iterator(vtkFieldData *dsa, const int *list=nullptr, unsigned int listSize=0)
vtkFieldData * Fields
Definition: vtkFieldData.h:558
Iterator(const Iterator &source)
Iterator & operator=(const Iterator &source)
vtkDataArray * Next()
Definition: vtkFieldData.h:540
represent and manipulate fields of data
Definition: vtkFieldData.h:72
vtkTypeBool Allocate(vtkIdType sz, vtkIdType ext=1000)
Allocate data for each array.
int GetFlag(const char *field)
vtkAbstractArray ** Data
Definition: vtkFieldData.h:436
static vtkFieldData * ExtendedNew()
int GetNumberOfArrays()
Get the number of arrays of data available.
Definition: vtkFieldData.h:116
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...
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...
std::vector< std::array< CachedGhostRangeType, 2 > > FiniteRanges
Ranges and FiniteRanges store cached ranges for arrays stored in this field data.
Definition: vtkFieldData.h:484
void SetTuple(const vtkIdType i, const vtkIdType j, vtkFieldData *source)
Set the jth tuple in source field data at the ith location.
virtual void SetGhostsToSkip(unsigned char)
Set / Get the binary mask filtering out certain types of ghosts when calling GetRange.
void AllocateArrays(int num)
AllocateOfArrays actually sets the number of vtkAbstractArray pointers in the vtkFieldData object,...
virtual void RemoveArray(int index)
Remove an array (with the given name or 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:483
std::tuple< vtkMTimeType, vtkMTimeType, std::vector< double > > CachedGhostRangeType
Definition: vtkFieldData.h:471
virtual void RemoveArray(const char *name)
Remove an array (with the given name or index) from the list of arrays.
unsigned char GhostsToSkip
Definition: vtkFieldData.h:472
const char * GetArrayName(int i)
Get the name of ith array.
Definition: vtkFieldData.h:224
virtual void CopyAllOn(int unused=0)
Turn on copying of all data.
void SetNumberOfTuples(const vtkIdType number)
Set the number of tuples for each data array in the field.
CopyFieldFlag * CopyFieldFlags
Definition: vtkFieldData.h:454
vtkDataArray * GetArray(int i)
Not recommended for use.
vtkAbstractArray * GetAbstractArray(const char *arrayName)
Return the array with the name given.
Definition: vtkFieldData.h:198
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:170
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:246
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:473
vtkIdType InsertNextTuple(const vtkIdType j, vtkFieldData *source)
Insert the jth tuple in source field data at the end of the tuple matrix.
void CopyFieldOff(const char *name)
Definition: vtkFieldData.h:247
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.)
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:435
virtual void PassData(vtkFieldData *fd)
Pass entire arrays of input data through to output.
void CopyStructure(vtkFieldData *)
Copy data array structure from a given field.
vtkDataArray * GetArray(const char *arrayName, int &index)
Not recommended for use.
void InsertTuple(const vtkIdType i, const vtkIdType j, vtkFieldData *source)
Insert the jth tuple in source field data at the ith location.
void SetArray(int i, vtkAbstractArray *array)
Set an array to define the field.
int HasArray(const char *name)
Return 1 if an array with the given name could be found.
Definition: vtkFieldData.h:209
int NumberOfFieldFlags
Definition: vtkFieldData.h:455
vtkAbstractArray * GetAbstractArray(const char *arrayName, int &index)
Return the array with the name given.
list of point or cell ids
Definition: vtkIdList.h:43
a simple class to control print indentation
Definition: vtkIndent.h:49
abstract base class for most VTK objects
Definition: vtkObject.h:72
dynamic, self-adjusting array of unsigned char
@ field
Definition: vtkX3D.h:183
@ range
Definition: vtkX3D.h:244
@ name
Definition: vtkX3D.h:225
@ index
Definition: vtkX3D.h:252
int vtkTypeBool
Definition: vtkABI.h:69
boost::graph_traits< vtkGraph * >::vertex_descriptor source(boost::graph_traits< vtkGraph * >::edge_descriptor e, vtkGraph *)
int vtkIdType
Definition: vtkType.h:332
vtkTypeUInt32 vtkMTimeType
Definition: vtkType.h:287