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 =========================================================================*/
46 #ifndef vtkFieldData_h
47 #define vtkFieldData_h
48 
49 #include "vtkCommonDataModelModule.h" // For export macro
50 #include "vtkObject.h"
51 
52 #include "vtkAbstractArray.h" // Needed for inline methods.
53 
54 #include <array> // For CachedGhostRangeType
55 #include <tuple> // For CachedGhostRangeType
56 #include <vector> // For list indices
57 
58 class vtkDoubleArray;
59 class vtkIdList;
61 
62 class VTKCOMMONDATAMODEL_EXPORT vtkFieldData : public vtkObject
63 {
64 public:
65  static vtkFieldData* New();
66  static vtkFieldData* ExtendedNew();
67 
68  vtkTypeMacro(vtkFieldData, vtkObject);
69  void PrintSelf(ostream& os, vtkIndent indent) override;
70 
75  virtual void Initialize();
76 
81  vtkTypeBool Allocate(vtkIdType sz, vtkIdType ext = 1000);
82 
88  void CopyStructure(vtkFieldData*);
89 
99  void AllocateArrays(int num);
100 
107  int GetNumberOfArrays() { return this->NumberOfActiveArrays; }
108 
114  int AddArray(vtkAbstractArray* array);
115 
119  void NullData(vtkIdType id);
120 
122 
125  virtual void RemoveArray(const char* name);
126  virtual void RemoveArray(int index);
128 
137  vtkDataArray* GetArray(int i);
138 
149  vtkDataArray* GetArray(const char* arrayName, int& index);
150 
152 
161  vtkDataArray* GetArray(const char* arrayName)
162  {
163  int i;
164  return this->GetArray(arrayName, i);
165  }
167 
173  vtkAbstractArray* GetAbstractArray(int i);
174 
181  vtkAbstractArray* GetAbstractArray(const char* arrayName, int& index);
182 
184 
189  vtkAbstractArray* GetAbstractArray(const char* arrayName)
190  {
191  int i;
192  return this->GetAbstractArray(arrayName, i);
193  }
195 
197 
200  int HasArray(const char* name)
201  {
202  int i;
203  vtkAbstractArray* array = this->GetAbstractArray(name, i);
204  // assert( i == -1);
205  return array ? 1 : 0;
206  }
208 
210 
215  const char* GetArrayName(int i)
216  {
217  vtkAbstractArray* da = this->GetAbstractArray(i);
218  return da ? da->GetName() : nullptr;
219  }
221 
226  virtual void PassData(vtkFieldData* fd);
227 
237  void CopyFieldOn(const char* name) { this->CopyFieldOnOff(name, 1); }
238  void CopyFieldOff(const char* name) { this->CopyFieldOnOff(name, 0); }
239 
249  virtual void CopyAllOn(int unused = 0);
250 
260  virtual void CopyAllOff(int unused = 0);
261 
265  virtual void DeepCopy(vtkFieldData* da);
266 
270  virtual void ShallowCopy(vtkFieldData* da);
271 
275  void Squeeze();
276 
281  void Reset();
282 
289  virtual unsigned long GetActualMemorySize();
290 
294  vtkMTimeType GetMTime() override;
295 
305  void GetField(vtkIdList* ptId, vtkFieldData* f);
306 
314  int GetArrayContainingComponent(int i, int& arrayComp);
315 
325  int GetNumberOfComponents();
326 
337  vtkIdType GetNumberOfTuples();
338 
347  void SetNumberOfTuples(const vtkIdType number);
348 
354  void SetTuple(const vtkIdType i, const vtkIdType j, vtkFieldData* source);
355 
360  void InsertTuple(const vtkIdType i, const vtkIdType j, vtkFieldData* source);
361 
367  vtkIdType InsertNextTuple(const vtkIdType j, vtkFieldData* source);
368 
370 
389  bool GetRange(const char* name, double range[2], int comp = 0);
390  bool GetRange(int index, double range[2], int comp = 0);
391  bool GetFiniteRange(const char* name, double range[2], int comp = 0);
392  bool GetFiniteRange(int index, double range[2], int comp = 0);
394 
396 
407  vtkGetMacro(GhostsToSkip, unsigned char);
408  virtual void SetGhostsToSkip(unsigned char);
410 
419  vtkGetObjectMacro(GhostArray, vtkUnsignedCharArray);
420 
421 protected:
422  vtkFieldData();
423  ~vtkFieldData() override;
424 
428 
432  void SetArray(int i, vtkAbstractArray* array);
433 
437  virtual void InitializeFields();
438 
440  {
441  char* ArrayName;
442  int IsCopied;
443  };
444 
445  CopyFieldFlag* CopyFieldFlags; // the names of fields not to be copied
446  int NumberOfFieldFlags; // the number of fields not to be copied
447  void CopyFieldOnOff(const char* name, int onOff);
448  void ClearFieldFlags();
449  int FindFlag(const char* field);
450  int GetFlag(const char* field);
451  void CopyFlags(const vtkFieldData* source);
454 
455  /*
456  * This tuple holds: [array time stamp, ghost array time stamp, cached ranges].
457  * Those time stamps are used to decide whether the cached range should be recomputed or not.
458  * when requesting the range of an array.
459  *
460  * When there is no ghost array, the ghost array time stamp is defined as equal to 0.
461  */
462  using CachedGhostRangeType = std::tuple<vtkMTimeType, vtkMTimeType, std::vector<double>>;
463  unsigned char GhostsToSkip;
465 
467 
474  std::vector<std::array<CachedGhostRangeType, 2>> Ranges;
475  std::vector<std::array<CachedGhostRangeType, 2>> FiniteRanges;
477 
478 private:
479  vtkFieldData(const vtkFieldData&) = delete;
480  void operator=(const vtkFieldData&) = delete;
481 
482 public:
483  class VTKCOMMONDATAMODEL_EXPORT BasicIterator
484  {
485  public:
486  BasicIterator() = default;
488  BasicIterator(const int* list, unsigned int listSize);
489  BasicIterator& operator=(const BasicIterator& source);
490  virtual ~BasicIterator() = default;
491  void PrintSelf(ostream& os, vtkIndent indent);
492 
493  int GetListSize() const { return static_cast<int>(this->List.size()); }
494  int GetCurrentIndex() { return this->List[this->Position]; }
496  {
497  this->Position = -1;
498  return this->NextIndex();
499  }
500  int End() const { return (this->Position >= static_cast<int>(this->List.size())); }
501  int NextIndex()
502  {
503  this->Position++;
504  return (this->End() ? -1 : this->List[this->Position]);
505  }
506 
507  // Support C++ range-for loops; e.g, code like
508  // "for (const auto& i : basicIterator)".
509  std::vector<int>::const_iterator begin() { return this->List.begin(); }
510  std::vector<int>::const_iterator end() { return this->List.end(); }
511 
512  protected:
513  std::vector<int> List;
514  int Position;
515  };
516 
517  class VTKCOMMONDATAMODEL_EXPORT Iterator : public BasicIterator
518  {
519  public:
520  Iterator(const Iterator& source);
521  Iterator& operator=(const Iterator& source);
522  ~Iterator() override;
523  Iterator(vtkFieldData* dsa, const int* list = nullptr, unsigned int listSize = 0);
524 
526  {
527  this->Position = -1;
528  return this->Next();
529  }
530 
532  {
533  this->Position++;
534  if (this->End())
535  {
536  return nullptr;
537  }
538 
539  // vtkFieldData::GetArray() can return null, which implies that
540  // a the array at the given index in not a vtkDataArray subclass.
541  // This iterator skips such arrays.
542  vtkDataArray* cur = Fields->GetArray(this->List[this->Position]);
543  return (cur ? cur : this->Next());
544  }
545 
546  void DetachFieldData();
547 
548  protected:
550  int Detached;
551  };
552 };
553 
554 #endif
vtkFieldData * Fields
Definition: vtkFieldData.h:549
std::vector< int > List
Definition: vtkFieldData.h:513
vtkUnsignedCharArray * GhostArray
Definition: vtkFieldData.h:464
vtkDataArray * GetArray(const char *arrayName)
Not recommended for use.
Definition: vtkFieldData.h:161
std::tuple< vtkMTimeType, vtkMTimeType, std::vector< double >> CachedGhostRangeType
Definition: vtkFieldData.h:462
abstract base class for most VTK objects
Definition: vtkObject.h:62
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
vtkTypeUInt32 vtkMTimeType
Definition: vtkType.h:287
Abstract superclass for all arrays.
CopyFieldFlag * CopyFieldFlags
Definition: vtkFieldData.h:445
int vtkIdType
Definition: vtkType.h:332
std::vector< std::array< CachedGhostRangeType, 2 > > Ranges
Ranges and FiniteRanges store cached ranges for arrays stored in this field data. ...
Definition: vtkFieldData.h:474
void CopyFieldOn(const char *name)
Turn on/off the copying of the field specified by name.
Definition: vtkFieldData.h:237
dynamic, self-adjusting array of double
BasicIterator & operator=(const BasicIterator &source)
int vtkTypeBool
Definition: vtkABI.h:69
std::vector< std::array< CachedGhostRangeType, 2 > > FiniteRanges
Ranges and FiniteRanges store cached ranges for arrays stored in this field data. ...
Definition: vtkFieldData.h:475
unsigned char GhostsToSkip
Definition: vtkFieldData.h:463
a simple class to control print indentation
Definition: vtkIndent.h:39
vtkAbstractArray * GetAbstractArray(const char *arrayName)
Return the array with the name given.
Definition: vtkFieldData.h:189
list of point or cell ids
Definition: vtkIdList.h:33
std::vector< int >::const_iterator begin()
Definition: vtkFieldData.h:509
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:55
virtual vtkMTimeType GetMTime()
Return this object's modified time.
virtual char * GetName()
Set/get array's name.
int NumberOfFieldFlags
Definition: vtkFieldData.h:446
const char * GetArrayName(int i)
Get the name of ith array.
Definition: vtkFieldData.h:215
int HasArray(const char *name)
Return 1 if an array with the given name could be found.
Definition: vtkFieldData.h:200
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:426
void CopyFieldOff(const char *name)
Definition: vtkFieldData.h:238
std::vector< int >::const_iterator end()
Definition: vtkFieldData.h:510
vtkAbstractArray ** Data
Definition: vtkFieldData.h:427
vtkDataArray * Begin()
Definition: vtkFieldData.h:525
int GetNumberOfArrays()
Get the number of arrays of data available.
Definition: vtkFieldData.h:107
static vtkObject * New()
Create an object with Debug turned off, modified time initialized to zero, and reference counting on...
vtkDataArray * Next()
Definition: vtkFieldData.h:531
represent and manipulate fields of data
Definition: vtkFieldData.h:62