VTK  9.2.20220703
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 class vtkDoubleArray;
168 class vtkIdList;
170 
171 class VTKCOMMONDATAMODEL_EXPORT vtkFieldData : public vtkObject
172 {
173 public:
174  static vtkFieldData* New();
176 
177  vtkTypeMacro(vtkFieldData, vtkObject);
178  void PrintSelf(ostream& os, vtkIndent indent) override;
179 
184  virtual void Initialize();
185 
191 
198 
208  void AllocateArrays(int num);
209 
216  int GetNumberOfArrays() { return this->NumberOfActiveArrays; }
217 
224 
228  void NullData(vtkIdType id);
229 
231 
234  virtual void RemoveArray(const char* name);
235  virtual void RemoveArray(int index);
237 
247 
258  vtkDataArray* GetArray(const char* arrayName, int& index);
259 
261 
270  vtkDataArray* GetArray(const char* arrayName)
271  {
272  int i;
273  return this->GetArray(arrayName, i);
274  }
276 
283 
290  vtkAbstractArray* GetAbstractArray(const char* arrayName, int& index);
291 
293 
298  vtkAbstractArray* GetAbstractArray(const char* arrayName)
299  {
300  int i;
301  return this->GetAbstractArray(arrayName, i);
302  }
304 
306 
309  int HasArray(const char* name)
310  {
311  int i;
312  vtkAbstractArray* array = this->GetAbstractArray(name, i);
313  // assert( i == -1);
314  return array ? 1 : 0;
315  }
317 
319 
324  const char* GetArrayName(int i)
325  {
326  vtkAbstractArray* da = this->GetAbstractArray(i);
327  return da ? da->GetName() : nullptr;
328  }
330 
335  virtual void PassData(vtkFieldData* fd);
336 
346  void CopyFieldOn(const char* name) { this->CopyFieldOnOff(name, 1); }
347  void CopyFieldOff(const char* name) { this->CopyFieldOnOff(name, 0); }
348 
358  virtual void CopyAllOn(int unused = 0);
359 
369  virtual void CopyAllOff(int unused = 0);
370 
374  virtual void DeepCopy(vtkFieldData* da);
375 
379  virtual void ShallowCopy(vtkFieldData* da);
380 
384  void Squeeze();
385 
390  void Reset();
391 
398  virtual unsigned long GetActualMemorySize();
399 
403  vtkMTimeType GetMTime() override;
404 
414  void GetField(vtkIdList* ptId, vtkFieldData* f);
415 
423  int GetArrayContainingComponent(int i, int& arrayComp);
424 
435 
447 
456  void SetNumberOfTuples(const vtkIdType number);
457 
463  void SetTuple(const vtkIdType i, const vtkIdType j, vtkFieldData* source);
464 
470 
477 
479 
498  bool GetRange(const char* name, double range[2], int comp = 0);
499  bool GetRange(int index, double range[2], int comp = 0);
500  bool GetFiniteRange(const char* name, double range[2], int comp = 0);
501  bool GetFiniteRange(int index, double range[2], int comp = 0);
503 
505 
516  vtkGetMacro(GhostsToSkip, unsigned char);
517  virtual void SetGhostsToSkip(unsigned char);
519 
528  vtkGetObjectMacro(GhostArray, vtkUnsignedCharArray);
529 
530 protected:
532  ~vtkFieldData() override;
533 
537 
541  void SetArray(int i, vtkAbstractArray* array);
542 
546  virtual void InitializeFields();
547 
549  {
550  char* ArrayName;
551  int IsCopied;
552  };
553 
554  CopyFieldFlag* CopyFieldFlags; // the names of fields not to be copied
555  int NumberOfFieldFlags; // the number of fields not to be copied
556  void CopyFieldOnOff(const char* name, int onOff);
558  int FindFlag(const char* field);
559  int GetFlag(const char* field);
563 
564  /*
565  * This tuple holds: [array time stamp, ghost array time stamp, cached ranges].
566  * Those time stamps are used to decide whether the cached range should be recomputed or not.
567  * when requesting the range of an array.
568  *
569  * When there is no ghost array, the ghost array time stamp is defined as equal to 0.
570  */
571  using CachedGhostRangeType = std::tuple<vtkMTimeType, vtkMTimeType, std::vector<double>>;
572  unsigned char GhostsToSkip;
574 
576 
583  std::vector<std::array<CachedGhostRangeType, 2>> Ranges;
584  std::vector<std::array<CachedGhostRangeType, 2>> FiniteRanges;
586 
587 private:
588  vtkFieldData(const vtkFieldData&) = delete;
589  void operator=(const vtkFieldData&) = delete;
590 
591 public:
592  class VTKCOMMONDATAMODEL_EXPORT BasicIterator
593  {
594  public:
595  BasicIterator() = default;
597  BasicIterator(const int* list, unsigned int listSize);
599  virtual ~BasicIterator() = default;
600  void PrintSelf(ostream& os, vtkIndent indent);
601 
602  int GetListSize() const { return static_cast<int>(this->List.size()); }
603  int GetCurrentIndex() { return this->List[this->Position]; }
605  {
606  this->Position = -1;
607  return this->NextIndex();
608  }
609  int End() const { return (this->Position >= static_cast<int>(this->List.size())); }
610  int NextIndex()
611  {
612  this->Position++;
613  return (this->End() ? -1 : this->List[this->Position]);
614  }
615 
616  // Support C++ range-for loops; e.g, code like
617  // "for (const auto& i : basicIterator)".
618  std::vector<int>::const_iterator begin() { return this->List.begin(); }
619  std::vector<int>::const_iterator end() { return this->List.end(); }
620 
621  protected:
622  std::vector<int> List;
623  int Position;
624  };
625 
626  class VTKCOMMONDATAMODEL_EXPORT Iterator : public BasicIterator
627  {
628  public:
631  ~Iterator() override;
632  Iterator(vtkFieldData* dsa, const int* list = nullptr, unsigned int listSize = 0);
633 
635  {
636  this->Position = -1;
637  return this->Next();
638  }
639 
641  {
642  this->Position++;
643  if (this->End())
644  {
645  return nullptr;
646  }
647 
648  // vtkFieldData::GetArray() can return null, which implies that
649  // a the array at the given index in not a vtkDataArray subclass.
650  // This iterator skips such arrays.
651  vtkDataArray* cur = Fields->GetArray(this->List[this->Position]);
652  return (cur ? cur : this->Next());
653  }
654 
656 
657  protected:
659  int Detached;
660  };
661 };
662 
663 #endif
Abstract superclass for all arrays.
virtual char * GetName()
Set/get array's name.
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:165
dynamic, self-adjusting array of double
BasicIterator(const BasicIterator &source)
std::vector< int >::const_iterator begin()
Definition: vtkFieldData.h:618
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:622
std::vector< int >::const_iterator end()
Definition: vtkFieldData.h:619
vtkDataArray * Begin()
Definition: vtkFieldData.h:634
Iterator(vtkFieldData *dsa, const int *list=nullptr, unsigned int listSize=0)
vtkFieldData * Fields
Definition: vtkFieldData.h:658
Iterator(const Iterator &source)
Iterator & operator=(const Iterator &source)
vtkDataArray * Next()
Definition: vtkFieldData.h:640
represent and manipulate fields of data
Definition: vtkFieldData.h:172
vtkTypeBool Allocate(vtkIdType sz, vtkIdType ext=1000)
Allocate data for each array.
int GetFlag(const char *field)
vtkAbstractArray ** Data
Definition: vtkFieldData.h:536
static vtkFieldData * ExtendedNew()
int GetNumberOfArrays()
Get the number of arrays of data available.
Definition: vtkFieldData.h:216
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:584
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:583
std::tuple< vtkMTimeType, vtkMTimeType, std::vector< double > > CachedGhostRangeType
Definition: vtkFieldData.h:571
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:572
const char * GetArrayName(int i)
Get the name of ith array.
Definition: vtkFieldData.h:324
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:554
vtkDataArray * GetArray(int i)
Not recommended for use.
vtkAbstractArray * GetAbstractArray(const char *arrayName)
Return the array with the name given.
Definition: vtkFieldData.h:298
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:270
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:346
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:573
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:347
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:535
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:309
int NumberOfFieldFlags
Definition: vtkFieldData.h:555
vtkAbstractArray * GetAbstractArray(const char *arrayName, int &index)
Return the array with the name given.
list of point or cell ids
Definition: vtkIdList.h:143
a simple class to control print indentation
Definition: vtkIndent.h:119
abstract base class for most VTK objects
Definition: vtkObject.h:82
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:325
vtkTypeUInt32 vtkMTimeType
Definition: vtkType.h:280