VTK  9.5.20250715
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
142#ifndef vtkFieldData_h
143#define vtkFieldData_h
144
145#include "vtkCommonDataModelModule.h" // For export macro
146#include "vtkObject.h"
147#include "vtkWrappingHints.h" // For VTK_MARSHALMANUAL
148
149#include "vtkAbstractArray.h" // Needed for inline methods.
150
151#include <array> // For CachedGhostRangeType
152#include <tuple> // For CachedGhostRangeType
153#include <vector> // For list indices
154
155VTK_ABI_NAMESPACE_BEGIN
156class vtkIdList;
157class vtkDoubleArray;
159
160class VTKCOMMONDATAMODEL_EXPORT VTK_MARSHALMANUAL vtkFieldData : public vtkObject
161{
162public:
163 static vtkFieldData* New();
165
166 vtkTypeMacro(vtkFieldData, vtkObject);
167 void PrintSelf(ostream& os, vtkIndent indent) override;
168
173 virtual void Initialize();
174
180
187
197 void AllocateArrays(int num);
198
205 int GetNumberOfArrays() { return this->NumberOfActiveArrays; }
206
214
219
221
224 virtual void RemoveArray(const char* name);
225
229 virtual void RemoveArray(int index);
231
241
252 vtkDataArray* GetArray(const char* arrayName, int& index);
253
255
264 vtkDataArray* GetArray(const char* arrayName)
265 {
266 int i;
267 return this->GetArray(arrayName, i);
268 }
270
277
284 vtkAbstractArray* GetAbstractArray(const char* arrayName, int& index);
285
287
292 vtkAbstractArray* GetAbstractArray(const char* arrayName)
293 {
294 int i;
295 return this->GetAbstractArray(arrayName, i);
296 }
298
300
303 vtkTypeBool HasArray(const char* name)
304 {
305 int i;
306 vtkAbstractArray* array = this->GetAbstractArray(name, i);
307 return array ? 1 : 0;
308 }
310
312
317 const char* GetArrayName(int i)
318 {
319 vtkAbstractArray* da = this->GetAbstractArray(i);
320 return da ? da->GetName() : nullptr;
321 }
323
328 virtual void PassData(vtkFieldData* fd);
329
339 void CopyFieldOn(const char* name) { this->CopyFieldOnOff(name, 1); }
340 void CopyFieldOff(const char* name) { this->CopyFieldOnOff(name, 0); }
341
351 virtual void CopyAllOn(int unused = 0);
352
362 virtual void CopyAllOff(int unused = 0);
363
367 virtual void DeepCopy(vtkFieldData* da);
368
372 virtual void ShallowCopy(vtkFieldData* da);
373
377 void Squeeze();
378
383 void Reset();
384
391 virtual unsigned long GetActualMemorySize();
392
397
408
416 int GetArrayContainingComponent(int i, int& arrayComp);
417
428
440
450
457
463
470
472
491 bool GetRange(const char* name, double range[2], int comp = 0);
492 bool GetRange(int index, double range[2], int comp = 0);
493 bool GetFiniteRange(const char* name, double range[2], int comp = 0);
494 bool GetFiniteRange(int index, double range[2], int comp = 0);
496
498
509 vtkGetMacro(GhostsToSkip, unsigned char);
510 virtual void SetGhostsToSkip(unsigned char);
512
517 bool HasAnyGhostBitSet(int bitFlag);
518
527 vtkGetObjectMacro(GhostArray, vtkUnsignedCharArray);
528
536 static const char* GhostArrayName() { return "vtkGhostType"; }
537
538protected:
540 ~vtkFieldData() override;
541
545
549 void SetArray(int i, vtkAbstractArray* array);
550
554 virtual void InitializeFields();
555
557 {
560 };
561
562 CopyFieldFlag* CopyFieldFlags; // the names of fields not to be copied
563 int NumberOfFieldFlags; // the number of fields not to be copied
564 void CopyFieldOnOff(const char* name, int onOff);
566 int FindFlag(const char* field);
567 int GetFlag(const char* field);
571
572 /*
573 * This tuple holds: [array time stamp, ghost array time stamp, cached ranges].
574 * Those time stamps are used to decide whether the cached range should be recomputed or not.
575 * when requesting the range of an array.
576 *
577 * When there is no ghost array, the ghost array time stamp is defined as equal to 0.
578 */
579 using CachedGhostRangeType = std::tuple<vtkMTimeType, vtkMTimeType, std::vector<double>>;
580 unsigned char GhostsToSkip;
582
584
591 std::vector<std::array<CachedGhostRangeType, 2>> Ranges;
592 std::vector<std::array<CachedGhostRangeType, 2>> FiniteRanges;
594
595private:
596 vtkFieldData(const vtkFieldData&) = delete;
597 void operator=(const vtkFieldData&) = delete;
598
599 friend class vtkFieldDataSerDesHelper; // for access to SetArray()
600
601public:
602 class VTKCOMMONDATAMODEL_EXPORT BasicIterator
603 {
604 public:
605 BasicIterator() = default;
607 BasicIterator(const int* list, unsigned int listSize);
609 virtual ~BasicIterator() = default;
610 void PrintSelf(ostream& os, vtkIndent indent);
611
612 int GetListSize() const { return static_cast<int>(this->List.size()); }
613 int GetCurrentIndex() { return this->List[this->Position]; }
615 {
616 this->Position = -1;
617 return this->NextIndex();
618 }
619 int End() const { return (this->Position >= static_cast<int>(this->List.size())); }
621 {
622 this->Position++;
623 return (this->End() ? -1 : this->List[this->Position]);
624 }
625
626 // Support C++ range-for loops; e.g, code like
627 // "for (const auto& i : basicIterator)".
628 std::vector<int>::const_iterator begin() { return this->List.begin(); }
629 std::vector<int>::const_iterator end() { return this->List.end(); }
630
631 protected:
632 std::vector<int> List;
634 };
635
636 class VTKCOMMONDATAMODEL_EXPORT Iterator : public BasicIterator
637 {
638 public:
641 ~Iterator() override;
642 Iterator(vtkFieldData* dsa, const int* list = nullptr, unsigned int listSize = 0);
643
645 {
646 this->Position = -1;
647 return this->Next();
648 }
649
651 {
652 this->Position++;
653 if (this->End())
654 {
655 return nullptr;
656 }
657
658 // vtkFieldData::GetArray() can return null, which implies that
659 // a the array at the given index in not a vtkDataArray subclass.
660 // This iterator skips such arrays.
661 vtkDataArray* cur = Fields->GetArray(this->List[this->Position]);
662 return (cur ? cur : this->Next());
663 }
664
666
667 protected:
670 };
671};
672
673VTK_ABI_NAMESPACE_END
674#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)
Represents and manipulates a collection of data arrays.
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.
static const char * GhostArrayName()
Return the name used for Ghost Arrays.
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:133
a simple class to control print indentation
Definition vtkIndent.h:108
abstract base class for most VTK objects
Definition vtkObject.h:162
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:332
vtkTypeUInt32 vtkMTimeType
Definition vtkType.h:287
#define VTK_MARSHALMANUAL