VTK  9.1.0
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 =========================================================================*/
43 #ifndef vtkFieldData_h
44 #define vtkFieldData_h
45 
46 #include "vtkCommonDataModelModule.h" // For export macro
47 #include "vtkObject.h"
48 #include <vector> // For list indices
49 
50 #include "vtkAbstractArray.h" // Needed for inline methods.
51 
52 class vtkIdList;
53 
54 class VTKCOMMONDATAMODEL_EXPORT vtkFieldData : public vtkObject
55 {
56 public:
57  static vtkFieldData* New();
59 
60  vtkTypeMacro(vtkFieldData, vtkObject);
61  void PrintSelf(ostream& os, vtkIndent indent) override;
62 
67  virtual void Initialize();
68 
74 
81 
91  void AllocateArrays(int num);
92 
99  int GetNumberOfArrays() { return this->NumberOfActiveArrays; }
100 
107 
111  void NullData(vtkIdType id);
112 
114 
117  virtual void RemoveArray(const char* name);
118  virtual void RemoveArray(int index);
120 
130 
141  vtkDataArray* GetArray(const char* arrayName, int& index);
142 
144 
153  vtkDataArray* GetArray(const char* arrayName)
154  {
155  int i;
156  return this->GetArray(arrayName, i);
157  }
159 
166 
173  vtkAbstractArray* GetAbstractArray(const char* arrayName, int& index);
174 
176 
181  vtkAbstractArray* GetAbstractArray(const char* arrayName)
182  {
183  int i;
184  return this->GetAbstractArray(arrayName, i);
185  }
187 
189 
192  int HasArray(const char* name)
193  {
194  int i;
195  vtkAbstractArray* array = this->GetAbstractArray(name, i);
196  // assert( i == -1);
197  return array ? 1 : 0;
198  }
200 
202 
207  const char* GetArrayName(int i)
208  {
209  vtkAbstractArray* da = this->GetAbstractArray(i);
210  return da ? da->GetName() : nullptr;
211  }
213 
218  virtual void PassData(vtkFieldData* fd);
219 
229  void CopyFieldOn(const char* name) { this->CopyFieldOnOff(name, 1); }
230  void CopyFieldOff(const char* name) { this->CopyFieldOnOff(name, 0); }
231 
241  virtual void CopyAllOn(int unused = 0);
242 
252  virtual void CopyAllOff(int unused = 0);
253 
257  virtual void DeepCopy(vtkFieldData* da);
258 
262  virtual void ShallowCopy(vtkFieldData* da);
263 
267  void Squeeze();
268 
273  void Reset();
274 
281  virtual unsigned long GetActualMemorySize();
282 
286  vtkMTimeType GetMTime() override;
287 
297  void GetField(vtkIdList* ptId, vtkFieldData* f);
298 
306  int GetArrayContainingComponent(int i, int& arrayComp);
307 
318 
330 
339  void SetNumberOfTuples(const vtkIdType number);
340 
346  void SetTuple(const vtkIdType i, const vtkIdType j, vtkFieldData* source);
347 
353 
360 
361 protected:
363  ~vtkFieldData() override;
364 
368 
372  void SetArray(int i, vtkAbstractArray* array);
373 
377  virtual void InitializeFields();
378 
380  {
381  char* ArrayName;
382  int IsCopied;
383  };
384 
385  CopyFieldFlag* CopyFieldFlags; // the names of fields not to be copied
386  int NumberOfFieldFlags; // the number of fields not to be copied
387  void CopyFieldOnOff(const char* name, int onOff);
389  int FindFlag(const char* field);
390  int GetFlag(const char* field);
394 
395 private:
396  vtkFieldData(const vtkFieldData&) = delete;
397  void operator=(const vtkFieldData&) = delete;
398 
399 public:
400  class VTKCOMMONDATAMODEL_EXPORT BasicIterator
401  {
402  public:
403  BasicIterator() = default;
405  BasicIterator(const int* list, unsigned int listSize);
407  virtual ~BasicIterator() = default;
408  void PrintSelf(ostream& os, vtkIndent indent);
409 
410  int GetListSize() const { return static_cast<int>(this->List.size()); }
411  int GetCurrentIndex() { return this->List[this->Position]; }
413  {
414  this->Position = -1;
415  return this->NextIndex();
416  }
417  int End() const { return (this->Position >= static_cast<int>(this->List.size())); }
418  int NextIndex()
419  {
420  this->Position++;
421  return (this->End() ? -1 : this->List[this->Position]);
422  }
423 
424  // Support C++ range-for loops; e.g, code like
425  // "for (const auto& i : basicIterator)".
426  std::vector<int>::const_iterator begin() { return this->List.begin(); }
427  std::vector<int>::const_iterator end() { return this->List.end(); }
428 
429  protected:
430  std::vector<int> List;
431  int Position;
432  };
433 
434  class VTKCOMMONDATAMODEL_EXPORT Iterator : public BasicIterator
435  {
436  public:
439  ~Iterator() override;
440  Iterator(vtkFieldData* dsa, const int* list = nullptr, unsigned int listSize = 0);
441 
443  {
444  this->Position = -1;
445  return this->Next();
446  }
447 
449  {
450  this->Position++;
451  if (this->End())
452  {
453  return nullptr;
454  }
455 
456  // vtkFieldData::GetArray() can return null, which implies that
457  // a the array at the given index in not a vtkDataArray subclass.
458  // This iterator skips such arrays.
459  vtkDataArray* cur = Fields->GetArray(this->List[this->Position]);
460  return (cur ? cur : this->Next());
461  }
462 
464 
465  protected:
467  int Detached;
468  };
469 };
470 
471 #endif
Abstract superclass for all arrays.
virtual char * GetName()
Set/get array's name.
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:50
BasicIterator(const BasicIterator &source)
std::vector< int >::const_iterator begin()
Definition: vtkFieldData.h:426
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:430
std::vector< int >::const_iterator end()
Definition: vtkFieldData.h:427
vtkDataArray * Begin()
Definition: vtkFieldData.h:442
Iterator(vtkFieldData *dsa, const int *list=nullptr, unsigned int listSize=0)
vtkFieldData * Fields
Definition: vtkFieldData.h:466
Iterator(const Iterator &source)
Iterator & operator=(const Iterator &source)
vtkDataArray * Next()
Definition: vtkFieldData.h:448
represent and manipulate fields of data
Definition: vtkFieldData.h:55
vtkTypeBool Allocate(vtkIdType sz, vtkIdType ext=1000)
Allocate data for each array.
int GetFlag(const char *field)
vtkAbstractArray ** Data
Definition: vtkFieldData.h:367
static vtkFieldData * ExtendedNew()
int GetNumberOfArrays()
Get the number of arrays of data available.
Definition: vtkFieldData.h:99
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...
void SetTuple(const vtkIdType i, const vtkIdType j, vtkFieldData *source)
Set the jth tuple in source field data at the ith location.
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.
int GetNumberOfComponents()
Get the number of components in the field.
vtkMTimeType GetMTime() override
Check object's components for modified times.
virtual void RemoveArray(const char *name)
Remove an array (with the given name or index) from the list of arrays.
const char * GetArrayName(int i)
Get the name of ith array.
Definition: vtkFieldData.h:207
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:385
vtkDataArray * GetArray(int i)
Not recommended for use.
vtkAbstractArray * GetAbstractArray(const char *arrayName)
Return the array with the name given.
Definition: vtkFieldData.h:181
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:153
virtual void Initialize()
Release all data but do not delete object.
virtual void CopyAllOff(int unused=0)
Turn off copying of all data.
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:229
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:230
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:366
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:192
int NumberOfFieldFlags
Definition: vtkFieldData.h:386
vtkAbstractArray * GetAbstractArray(const char *arrayName, int &index)
Return the array with the name given.
list of point or cell ids
Definition: vtkIdList.h:31
a simple class to control print indentation
Definition: vtkIndent.h:34
abstract base class for most VTK objects
Definition: vtkObject.h:63
@ field
Definition: vtkX3D.h:183
@ 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