VTK  9.3.0
vtkFieldData.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2// SPDX-License-Identifier: BSD-3-Clause
34#ifndef vtkFieldData_h
35#define vtkFieldData_h
36
37#include "vtkCommonDataModelModule.h" // For export macro
38#include "vtkObject.h"
39
40#include "vtkAbstractArray.h" // Needed for inline methods.
41
42#include <array> // For CachedGhostRangeType
43#include <tuple> // For CachedGhostRangeType
44#include <vector> // For list indices
45
46VTK_ABI_NAMESPACE_BEGIN
47class vtkIdList;
48class vtkDoubleArray;
50
51class VTKCOMMONDATAMODEL_EXPORT vtkFieldData : public vtkObject
52{
53public:
54 static vtkFieldData* New();
56
57 vtkTypeMacro(vtkFieldData, vtkObject);
58 void PrintSelf(ostream& os, vtkIndent indent) override;
59
64 virtual void Initialize();
65
71
78
88 void AllocateArrays(int num);
89
96 int GetNumberOfArrays() { return this->NumberOfActiveArrays; }
97
105
110
112
115 virtual void RemoveArray(const char* name);
116
120 virtual void RemoveArray(int index);
122
132
143 vtkDataArray* GetArray(const char* arrayName, int& index);
144
146
155 vtkDataArray* GetArray(const char* arrayName)
156 {
157 int i;
158 return this->GetArray(arrayName, i);
159 }
161
168
175 vtkAbstractArray* GetAbstractArray(const char* arrayName, int& index);
176
178
183 vtkAbstractArray* GetAbstractArray(const char* arrayName)
184 {
185 int i;
186 return this->GetAbstractArray(arrayName, i);
187 }
189
191
194 vtkTypeBool HasArray(const char* name)
195 {
196 int i;
197 vtkAbstractArray* array = this->GetAbstractArray(name, i);
198 return array ? 1 : 0;
199 }
201
203
208 const char* GetArrayName(int i)
209 {
210 vtkAbstractArray* da = this->GetAbstractArray(i);
211 return da ? da->GetName() : nullptr;
212 }
214
219 virtual void PassData(vtkFieldData* fd);
220
230 void CopyFieldOn(const char* name) { this->CopyFieldOnOff(name, 1); }
231 void CopyFieldOff(const char* name) { this->CopyFieldOnOff(name, 0); }
232
242 virtual void CopyAllOn(int unused = 0);
243
253 virtual void CopyAllOff(int unused = 0);
254
258 virtual void DeepCopy(vtkFieldData* da);
259
263 virtual void ShallowCopy(vtkFieldData* da);
264
268 void Squeeze();
269
274 void Reset();
275
282 virtual unsigned long GetActualMemorySize();
283
288
299
307 int GetArrayContainingComponent(int i, int& arrayComp);
308
319
331
341
348
354
361
363
382 bool GetRange(const char* name, double range[2], int comp = 0);
383 bool GetRange(int index, double range[2], int comp = 0);
384 bool GetFiniteRange(const char* name, double range[2], int comp = 0);
385 bool GetFiniteRange(int index, double range[2], int comp = 0);
387
389
400 vtkGetMacro(GhostsToSkip, unsigned char);
401 virtual void SetGhostsToSkip(unsigned char);
403
408 bool HasAnyGhostBitSet(int bitFlag);
409
418 vtkGetObjectMacro(GhostArray, vtkUnsignedCharArray);
419
420protected:
422 ~vtkFieldData() override;
423
427
431 void SetArray(int i, vtkAbstractArray* array);
432
436 virtual void InitializeFields();
437
439 {
442 };
443
444 CopyFieldFlag* CopyFieldFlags; // the names of fields not to be copied
445 int NumberOfFieldFlags; // the number of fields not to be copied
446 void CopyFieldOnOff(const char* name, int onOff);
448 int FindFlag(const char* field);
449 int GetFlag(const char* field);
453
454 /*
455 * This tuple holds: [array time stamp, ghost array time stamp, cached ranges].
456 * Those time stamps are used to decide whether the cached range should be recomputed or not.
457 * when requesting the range of an array.
458 *
459 * When there is no ghost array, the ghost array time stamp is defined as equal to 0.
460 */
461 using CachedGhostRangeType = std::tuple<vtkMTimeType, vtkMTimeType, std::vector<double>>;
462 unsigned char GhostsToSkip;
464
466
473 std::vector<std::array<CachedGhostRangeType, 2>> Ranges;
474 std::vector<std::array<CachedGhostRangeType, 2>> FiniteRanges;
476
477private:
478 vtkFieldData(const vtkFieldData&) = delete;
479 void operator=(const vtkFieldData&) = delete;
480
481public:
482 class VTKCOMMONDATAMODEL_EXPORT BasicIterator
483 {
484 public:
485 BasicIterator() = default;
487 BasicIterator(const int* list, unsigned int listSize);
489 virtual ~BasicIterator() = default;
490 void PrintSelf(ostream& os, vtkIndent indent);
491
492 int GetListSize() const { return static_cast<int>(this->List.size()); }
493 int GetCurrentIndex() { return this->List[this->Position]; }
495 {
496 this->Position = -1;
497 return this->NextIndex();
498 }
499 int End() const { return (this->Position >= static_cast<int>(this->List.size())); }
501 {
502 this->Position++;
503 return (this->End() ? -1 : this->List[this->Position]);
504 }
505
506 // Support C++ range-for loops; e.g, code like
507 // "for (const auto& i : basicIterator)".
508 std::vector<int>::const_iterator begin() { return this->List.begin(); }
509 std::vector<int>::const_iterator end() { return this->List.end(); }
510
511 protected:
512 std::vector<int> List;
514 };
515
516 class VTKCOMMONDATAMODEL_EXPORT Iterator : public BasicIterator
517 {
518 public:
521 ~Iterator() override;
522 Iterator(vtkFieldData* dsa, const int* list = nullptr, unsigned int listSize = 0);
523
525 {
526 this->Position = -1;
527 return this->Next();
528 }
529
531 {
532 this->Position++;
533 if (this->End())
534 {
535 return nullptr;
536 }
537
538 // vtkFieldData::GetArray() can return null, which implies that
539 // a the array at the given index in not a vtkDataArray subclass.
540 // This iterator skips such arrays.
541 vtkDataArray* cur = Fields->GetArray(this->List[this->Position]);
542 return (cur ? cur : this->Next());
543 }
544
546
547 protected:
550 };
551};
552
553VTK_ABI_NAMESPACE_END
554#endif
Abstract superclass for all arrays.
virtual char * GetName()
Set/get array's name.
abstract superclass for arrays of numeric data
dynamic, self-adjusting array of double
BasicIterator(const BasicIterator &source)
BasicIterator & operator=(const BasicIterator &source)
BasicIterator(const int *list, unsigned int listSize)
virtual ~BasicIterator()=default
void PrintSelf(ostream &os, vtkIndent indent)
std::vector< int >::const_iterator end()
std::vector< int > List
std::vector< int >::const_iterator begin()
vtkDataArray * Begin()
Iterator(vtkFieldData *dsa, const int *list=nullptr, unsigned int listSize=0)
vtkFieldData * Fields
vtkDataArray * Next()
Iterator & operator=(const Iterator &source)
Iterator(const Iterator &source)
represent and manipulate fields of data
vtkTypeBool Allocate(vtkIdType sz, vtkIdType ext=1000)
Allocate data for each array.
int GetFlag(const char *field)
vtkAbstractArray ** Data
int GetNumberOfArrays()
Get the number of arrays of data available.
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
void Reset()
Resets each data array in the field (Reset() does not release memory but it makes the arrays look lik...
void InsertTuple(vtkIdType i, vtkIdType j, vtkFieldData *source)
Insert the jth tuple in source field data at the ith location.
vtkAbstractArray * GetAbstractArray(const char *arrayName)
Return the array with the name given.
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.
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.
static vtkFieldData * ExtendedNew()
std::vector< std::array< CachedGhostRangeType, 2 > > Ranges
Ranges and FiniteRanges store cached ranges for arrays stored in this field data.
std::tuple< vtkMTimeType, vtkMTimeType, std::vector< double > > CachedGhostRangeType
virtual void RemoveArray(const char *name)
Remove an array (with the given name) from the list of arrays.
unsigned char GhostsToSkip
void SetTuple(vtkIdType i, vtkIdType j, vtkFieldData *source)
Set the jth tuple in source field data at the ith location.
virtual void CopyAllOn(int unused=0)
Turn on copying of all data.
CopyFieldFlag * CopyFieldFlags
void SetNumberOfTuples(vtkIdType number)
Set the number of tuples for each data array in the field.
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)
virtual void Initialize()
Release all data but do not delete object.
vtkDataArray * GetArray(int i)
Not recommended for use.
virtual void CopyAllOff(int unused=0)
Turn off copying of all data.
const char * GetArrayName(int i)
Get the name of ith array.
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.
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
void CopyFieldOff(const char *name)
vtkDataArray * GetArray(const char *arrayName, int &index)
Not recommended for use.
vtkIdType GetNumberOfTuples()
Get the number of tuples in the field.
static vtkFieldData * New()
void Squeeze()
Squeezes each data array in the field (Squeeze() reclaims unused memory.)
vtkAbstractArray * GetAbstractArray(int i)
Returns the ith array in the field.
vtkIdType InsertNextTuple(vtkIdType j, vtkFieldData *source)
Insert the jth tuple in source field data at the end of the tuple matrix.
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
virtual void PassData(vtkFieldData *fd)
Pass entire arrays of input data through to output.
vtkTypeBool HasArray(const char *name)
Return 1 if an array with the given name could be found.
vtkDataArray * GetArray(const char *arrayName)
Not recommended for use.
void CopyStructure(vtkFieldData *)
Copy data array structure from a given field.
void SetArray(int i, vtkAbstractArray *array)
Set an array to define the field.
vtkAbstractArray * GetAbstractArray(const char *arrayName, int &index)
Return the array with the name given.
list of point or cell ids
Definition vtkIdList.h:23
a simple class to control print indentation
Definition vtkIndent.h:29
abstract base class for most VTK objects
Definition vtkObject.h:49
dynamic, self-adjusting array of unsigned char
int vtkTypeBool
Definition vtkABI.h:64
boost::graph_traits< vtkGraph * >::vertex_descriptor source(boost::graph_traits< vtkGraph * >::edge_descriptor e, vtkGraph *)
int vtkIdType
Definition vtkType.h:315
vtkTypeUInt32 vtkMTimeType
Definition vtkType.h:270