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=========================================================================*/
55#ifndef vtkFieldData_h
56#define vtkFieldData_h
57
58#include "vtkCommonDataModelModule.h" // For export macro
59#include "vtkObject.h"
60
61#include "vtkAbstractArray.h" // Needed for inline methods.
62
63#include <array> // For CachedGhostRangeType
64#include <tuple> // For CachedGhostRangeType
65#include <vector> // For list indices
66
67class vtkDoubleArray;
68class vtkIdList;
70
71class VTKCOMMONDATAMODEL_EXPORT vtkFieldData : public vtkObject
72{
73public:
74 static vtkFieldData* New();
76
77 vtkTypeMacro(vtkFieldData, vtkObject);
78 void PrintSelf(ostream& os, vtkIndent indent) override;
79
84 virtual void Initialize();
85
91
98
108 void AllocateArrays(int num);
109
116 int GetNumberOfArrays() { return this->NumberOfActiveArrays; }
117
124
129
131
134 virtual void RemoveArray(const char* name);
135 virtual void RemoveArray(int index);
137
147
158 vtkDataArray* GetArray(const char* arrayName, int& index);
159
161
170 vtkDataArray* GetArray(const char* arrayName)
171 {
172 int i;
173 return this->GetArray(arrayName, i);
174 }
176
183
190 vtkAbstractArray* GetAbstractArray(const char* arrayName, int& index);
191
193
198 vtkAbstractArray* GetAbstractArray(const char* arrayName)
199 {
200 int i;
201 return this->GetAbstractArray(arrayName, i);
202 }
204
206
209 int HasArray(const char* name)
210 {
211 int i;
212 vtkAbstractArray* array = this->GetAbstractArray(name, i);
213 // assert( i == -1);
214 return array ? 1 : 0;
215 }
217
219
224 const char* GetArrayName(int i)
225 {
226 vtkAbstractArray* da = this->GetAbstractArray(i);
227 return da ? da->GetName() : nullptr;
228 }
230
235 virtual void PassData(vtkFieldData* fd);
236
246 void CopyFieldOn(const char* name) { this->CopyFieldOnOff(name, 1); }
247 void CopyFieldOff(const char* name) { this->CopyFieldOnOff(name, 0); }
248
258 virtual void CopyAllOn(int unused = 0);
259
269 virtual void CopyAllOff(int unused = 0);
270
274 virtual void DeepCopy(vtkFieldData* da);
275
279 virtual void ShallowCopy(vtkFieldData* da);
280
284 void Squeeze();
285
290 void Reset();
291
298 virtual unsigned long GetActualMemorySize();
299
304
315
323 int GetArrayContainingComponent(int i, int& arrayComp);
324
335
347
356 void SetNumberOfTuples(const vtkIdType number);
357
364
370
377
379
398 bool GetRange(const char* name, double range[2], int comp = 0);
399 bool GetRange(int index, double range[2], int comp = 0);
400 bool GetFiniteRange(const char* name, double range[2], int comp = 0);
401 bool GetFiniteRange(int index, double range[2], int comp = 0);
403
405
416 vtkGetMacro(GhostsToSkip, unsigned char);
417 virtual void SetGhostsToSkip(unsigned char);
419
428 vtkGetObjectMacro(GhostArray, vtkUnsignedCharArray);
429
430protected:
432 ~vtkFieldData() override;
433
437
441 void SetArray(int i, vtkAbstractArray* array);
442
446 virtual void InitializeFields();
447
449 {
452 };
453
454 CopyFieldFlag* CopyFieldFlags; // the names of fields not to be copied
455 int NumberOfFieldFlags; // the number of fields not to be copied
456 void CopyFieldOnOff(const char* name, int onOff);
458 int FindFlag(const char* field);
459 int GetFlag(const char* field);
463
464 /*
465 * This tuple holds: [array time stamp, ghost array time stamp, cached ranges].
466 * Those time stamps are used to decide whether the cached range should be recomputed or not.
467 * when requesting the range of an array.
468 *
469 * When there is no ghost array, the ghost array time stamp is defined as equal to 0.
470 */
471 using CachedGhostRangeType = std::tuple<vtkMTimeType, vtkMTimeType, std::vector<double>>;
472 unsigned char GhostsToSkip;
474
476
483 std::vector<std::array<CachedGhostRangeType, 2>> Ranges;
484 std::vector<std::array<CachedGhostRangeType, 2>> FiniteRanges;
486
487private:
488 vtkFieldData(const vtkFieldData&) = delete;
489 void operator=(const vtkFieldData&) = delete;
490
491public:
492 class VTKCOMMONDATAMODEL_EXPORT BasicIterator
493 {
494 public:
495 BasicIterator() = default;
497 BasicIterator(const int* list, unsigned int listSize);
499 virtual ~BasicIterator() = default;
500 void PrintSelf(ostream& os, vtkIndent indent);
501
502 int GetListSize() const { return static_cast<int>(this->List.size()); }
503 int GetCurrentIndex() { return this->List[this->Position]; }
505 {
506 this->Position = -1;
507 return this->NextIndex();
508 }
509 int End() const { return (this->Position >= static_cast<int>(this->List.size())); }
511 {
512 this->Position++;
513 return (this->End() ? -1 : this->List[this->Position]);
514 }
515
516 // Support C++ range-for loops; e.g, code like
517 // "for (const auto& i : basicIterator)".
518 std::vector<int>::const_iterator begin() { return this->List.begin(); }
519 std::vector<int>::const_iterator end() { return this->List.end(); }
520
521 protected:
522 std::vector<int> List;
524 };
525
526 class VTKCOMMONDATAMODEL_EXPORT Iterator : public BasicIterator
527 {
528 public:
531 ~Iterator() override;
532 Iterator(vtkFieldData* dsa, const int* list = nullptr, unsigned int listSize = 0);
533
535 {
536 this->Position = -1;
537 return this->Next();
538 }
539
541 {
542 this->Position++;
543 if (this->End())
544 {
545 return nullptr;
546 }
547
548 // vtkFieldData::GetArray() can return null, which implies that
549 // a the array at the given index in not a vtkDataArray subclass.
550 // This iterator skips such arrays.
551 vtkDataArray* cur = Fields->GetArray(this->List[this->Position]);
552 return (cur ? cur : this->Next());
553 }
554
556
557 protected:
560 };
561};
562
563#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...
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...
std::vector< std::array< CachedGhostRangeType, 2 > > FiniteRanges
Ranges and FiniteRanges store cached ranges for arrays stored in this field data.
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.
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 or index) from the list of arrays.
unsigned char GhostsToSkip
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
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
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)
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.
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.
vtkDataArray * GetArray(const char *arrayName)
Not recommended for use.
void CopyStructure(vtkFieldData *)
Copy data array structure from a given field.
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.
vtkAbstractArray * GetAbstractArray(const char *arrayName, int &index)
Return the array with the name given.
int HasArray(const char *name)
Return 1 if an array with the given name could be found.
list of point or cell ids
Definition vtkIdList.h:43
a simple class to control print indentation
Definition vtkIndent.h:49
abstract base class for most VTK objects
Definition vtkObject.h:72
dynamic, self-adjusting array of unsigned char
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