VTK  9.2.20230207
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 =========================================================================*/
155 #ifndef vtkFieldData_h
156 #define vtkFieldData_h
157 
158 #include "vtkCommonDataModelModule.h" // For export macro
159 #include "vtkObject.h"
160 
161 #include "vtkAbstractArray.h" // Needed for inline methods.
162 
163 #include <array> // For CachedGhostRangeType
164 #include <tuple> // For CachedGhostRangeType
165 #include <vector> // For list indices
166 
167 VTK_ABI_NAMESPACE_BEGIN
168 class vtkIdList;
169 class vtkDoubleArray;
171 
172 class VTKCOMMONDATAMODEL_EXPORT vtkFieldData : public vtkObject
173 {
174 public:
175  static vtkFieldData* New();
177 
178  vtkTypeMacro(vtkFieldData, vtkObject);
179  void PrintSelf(ostream& os, vtkIndent indent) override;
180 
185  virtual void Initialize();
186 
192 
199 
209  void AllocateArrays(int num);
210 
217  int GetNumberOfArrays() { return this->NumberOfActiveArrays; }
218 
226 
230  void NullData(vtkIdType id);
231 
233 
236  virtual void RemoveArray(const char* name);
237 
241  virtual void RemoveArray(int index);
243 
253 
264  vtkDataArray* GetArray(const char* arrayName, int& index);
265 
267 
276  vtkDataArray* GetArray(const char* arrayName)
277  {
278  int i;
279  return this->GetArray(arrayName, i);
280  }
282 
289 
296  vtkAbstractArray* GetAbstractArray(const char* arrayName, int& index);
297 
299 
304  vtkAbstractArray* GetAbstractArray(const char* arrayName)
305  {
306  int i;
307  return this->GetAbstractArray(arrayName, i);
308  }
310 
312 
315  int HasArray(const char* name)
316  {
317  int i;
318  vtkAbstractArray* array = this->GetAbstractArray(name, i);
319  return array ? 1 : 0;
320  }
322 
324 
329  const char* GetArrayName(int i)
330  {
331  vtkAbstractArray* da = this->GetAbstractArray(i);
332  return da ? da->GetName() : nullptr;
333  }
335 
340  virtual void PassData(vtkFieldData* fd);
341 
351  void CopyFieldOn(const char* name) { this->CopyFieldOnOff(name, 1); }
352  void CopyFieldOff(const char* name) { this->CopyFieldOnOff(name, 0); }
353 
363  virtual void CopyAllOn(int unused = 0);
364 
374  virtual void CopyAllOff(int unused = 0);
375 
379  virtual void DeepCopy(vtkFieldData* da);
380 
384  virtual void ShallowCopy(vtkFieldData* da);
385 
389  void Squeeze();
390 
395  void Reset();
396 
403  virtual unsigned long GetActualMemorySize();
404 
408  vtkMTimeType GetMTime() override;
409 
419  void GetField(vtkIdList* ptId, vtkFieldData* f);
420 
428  int GetArrayContainingComponent(int i, int& arrayComp);
429 
440 
452 
461  void SetNumberOfTuples(const vtkIdType number);
462 
468  void SetTuple(const vtkIdType i, const vtkIdType j, vtkFieldData* source);
469 
475 
482 
484 
503  bool GetRange(const char* name, double range[2], int comp = 0);
504  bool GetRange(int index, double range[2], int comp = 0);
505  bool GetFiniteRange(const char* name, double range[2], int comp = 0);
506  bool GetFiniteRange(int index, double range[2], int comp = 0);
508 
510 
521  vtkGetMacro(GhostsToSkip, unsigned char);
522  virtual void SetGhostsToSkip(unsigned char);
524 
529  bool HasAnyGhostBitSet(int bitFlag);
530 
539  vtkGetObjectMacro(GhostArray, vtkUnsignedCharArray);
540 
541 protected:
543  ~vtkFieldData() override;
544 
548 
552  void SetArray(int i, vtkAbstractArray* array);
553 
557  virtual void InitializeFields();
558 
560  {
561  char* ArrayName;
562  int IsCopied;
563  };
564 
565  CopyFieldFlag* CopyFieldFlags; // the names of fields not to be copied
566  int NumberOfFieldFlags; // the number of fields not to be copied
567  void CopyFieldOnOff(const char* name, int onOff);
569  int FindFlag(const char* field);
570  int GetFlag(const char* field);
574 
575  /*
576  * This tuple holds: [array time stamp, ghost array time stamp, cached ranges].
577  * Those time stamps are used to decide whether the cached range should be recomputed or not.
578  * when requesting the range of an array.
579  *
580  * When there is no ghost array, the ghost array time stamp is defined as equal to 0.
581  */
582  using CachedGhostRangeType = std::tuple<vtkMTimeType, vtkMTimeType, std::vector<double>>;
583  unsigned char GhostsToSkip;
585 
587 
594  std::vector<std::array<CachedGhostRangeType, 2>> Ranges;
595  std::vector<std::array<CachedGhostRangeType, 2>> FiniteRanges;
597 
598 private:
599  vtkFieldData(const vtkFieldData&) = delete;
600  void operator=(const vtkFieldData&) = delete;
601 
602 public:
603  class VTKCOMMONDATAMODEL_EXPORT BasicIterator
604  {
605  public:
606  BasicIterator() = default;
608  BasicIterator(const int* list, unsigned int listSize);
610  virtual ~BasicIterator() = default;
611  void PrintSelf(ostream& os, vtkIndent indent);
612 
613  int GetListSize() const { return static_cast<int>(this->List.size()); }
614  int GetCurrentIndex() { return this->List[this->Position]; }
616  {
617  this->Position = -1;
618  return this->NextIndex();
619  }
620  int End() const { return (this->Position >= static_cast<int>(this->List.size())); }
621  int NextIndex()
622  {
623  this->Position++;
624  return (this->End() ? -1 : this->List[this->Position]);
625  }
626 
627  // Support C++ range-for loops; e.g, code like
628  // "for (const auto& i : basicIterator)".
629  std::vector<int>::const_iterator begin() { return this->List.begin(); }
630  std::vector<int>::const_iterator end() { return this->List.end(); }
631 
632  protected:
633  std::vector<int> List;
634  int Position;
635  };
636 
637  class VTKCOMMONDATAMODEL_EXPORT Iterator : public BasicIterator
638  {
639  public:
642  ~Iterator() override;
643  Iterator(vtkFieldData* dsa, const int* list = nullptr, unsigned int listSize = 0);
644 
646  {
647  this->Position = -1;
648  return this->Next();
649  }
650 
652  {
653  this->Position++;
654  if (this->End())
655  {
656  return nullptr;
657  }
658 
659  // vtkFieldData::GetArray() can return null, which implies that
660  // a the array at the given index in not a vtkDataArray subclass.
661  // This iterator skips such arrays.
662  vtkDataArray* cur = Fields->GetArray(this->List[this->Position]);
663  return (cur ? cur : this->Next());
664  }
665 
667 
668  protected:
670  int Detached;
671  };
672 };
673 
674 VTK_ABI_NAMESPACE_END
675 #endif
Abstract superclass for all arrays.
virtual char * GetName()
Set/get array's name.
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:166
dynamic, self-adjusting array of double
BasicIterator(const BasicIterator &source)
std::vector< int >::const_iterator begin()
Definition: vtkFieldData.h:629
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:633
std::vector< int >::const_iterator end()
Definition: vtkFieldData.h:630
vtkDataArray * Begin()
Definition: vtkFieldData.h:645
Iterator(vtkFieldData *dsa, const int *list=nullptr, unsigned int listSize=0)
vtkFieldData * Fields
Definition: vtkFieldData.h:669
Iterator(const Iterator &source)
Iterator & operator=(const Iterator &source)
vtkDataArray * Next()
Definition: vtkFieldData.h:651
represent and manipulate fields of data
Definition: vtkFieldData.h:173
vtkTypeBool Allocate(vtkIdType sz, vtkIdType ext=1000)
Allocate data for each array.
int GetFlag(const char *field)
vtkAbstractArray ** Data
Definition: vtkFieldData.h:547
static vtkFieldData * ExtendedNew()
int GetNumberOfArrays()
Get the number of arrays of data available.
Definition: vtkFieldData.h:217
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...
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:595
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)
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:594
std::tuple< vtkMTimeType, vtkMTimeType, std::vector< double > > CachedGhostRangeType
Definition: vtkFieldData.h:582
virtual void RemoveArray(const char *name)
Remove an array (with the given name) from the list of arrays.
unsigned char GhostsToSkip
Definition: vtkFieldData.h:583
const char * GetArrayName(int i)
Get the name of ith array.
Definition: vtkFieldData.h:329
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:565
vtkDataArray * GetArray(int i)
Not recommended for use.
vtkAbstractArray * GetAbstractArray(const char *arrayName)
Return the array with the name given.
Definition: vtkFieldData.h:304
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:276
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:351
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:584
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:352
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:546
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:315
int NumberOfFieldFlags
Definition: vtkFieldData.h:566
vtkAbstractArray * GetAbstractArray(const char *arrayName, int &index)
Return the array with the name given.
list of point or cell ids
Definition: vtkIdList.h:144
a simple class to control print indentation
Definition: vtkIndent.h:120
abstract base class for most VTK objects
Definition: vtkObject.h:83
dynamic, self-adjusting array of unsigned char
@ field
Definition: vtkX3D.h:189
@ range
Definition: vtkX3D.h:250
@ name
Definition: vtkX3D.h:231
@ index
Definition: vtkX3D.h:258
int vtkTypeBool
Definition: vtkABI.h:71
boost::graph_traits< vtkGraph * >::vertex_descriptor source(boost::graph_traits< vtkGraph * >::edge_descriptor e, vtkGraph *)
int vtkIdType
Definition: vtkType.h:327
vtkTypeUInt32 vtkMTimeType
Definition: vtkType.h:282