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=========================================================================*/
43#ifndef vtkFieldData_h
44#define vtkFieldData_h
45
46#include "vtkCommonDataModelModule.h" // For export macro
47#include "vtkObject.h"
48
49#include "vtkAbstractArray.h" // Needed for inline methods.
50
51#include <array> // For CachedGhostRangeType
52#include <tuple> // For CachedGhostRangeType
53#include <vector> // For list indices
54
55class vtkDoubleArray;
56class vtkIdList;
58
59class VTKCOMMONDATAMODEL_EXPORT vtkFieldData : public vtkObject
60{
61public:
62 static vtkFieldData* New();
64
65 vtkTypeMacro(vtkFieldData, vtkObject);
66 void PrintSelf(ostream& os, vtkIndent indent) override;
67
72 virtual void Initialize();
73
79
86
96 void AllocateArrays(int num);
97
104 int GetNumberOfArrays() { return this->NumberOfActiveArrays; }
105
112
117
119
122 virtual void RemoveArray(const char* name);
123 virtual void RemoveArray(int index);
125
135
146 vtkDataArray* GetArray(const char* arrayName, int& index);
147
149
158 vtkDataArray* GetArray(const char* arrayName)
159 {
160 int i;
161 return this->GetArray(arrayName, i);
162 }
164
171
178 vtkAbstractArray* GetAbstractArray(const char* arrayName, int& index);
179
181
186 vtkAbstractArray* GetAbstractArray(const char* arrayName)
187 {
188 int i;
189 return this->GetAbstractArray(arrayName, i);
190 }
192
194
197 int HasArray(const char* name)
198 {
199 int i;
200 vtkAbstractArray* array = this->GetAbstractArray(name, i);
201 // assert( i == -1);
202 return array ? 1 : 0;
203 }
205
207
212 const char* GetArrayName(int i)
213 {
214 vtkAbstractArray* da = this->GetAbstractArray(i);
215 return da ? da->GetName() : nullptr;
216 }
218
223 virtual void PassData(vtkFieldData* fd);
224
234 void CopyFieldOn(const char* name) { this->CopyFieldOnOff(name, 1); }
235 void CopyFieldOff(const char* name) { this->CopyFieldOnOff(name, 0); }
236
246 virtual void CopyAllOn(int unused = 0);
247
257 virtual void CopyAllOff(int unused = 0);
258
262 virtual void DeepCopy(vtkFieldData* da);
263
267 virtual void ShallowCopy(vtkFieldData* da);
268
272 void Squeeze();
273
278 void Reset();
279
286 virtual unsigned long GetActualMemorySize();
287
292
303
311 int GetArrayContainingComponent(int i, int& arrayComp);
312
323
335
344 void SetNumberOfTuples(const vtkIdType number);
345
352
358
365
367
386 bool GetRange(const char* name, double range[2], int comp = 0);
387 bool GetRange(int index, double range[2], int comp = 0);
388 bool GetFiniteRange(const char* name, double range[2], int comp = 0);
389 bool GetFiniteRange(int index, double range[2], int comp = 0);
391
393
404 vtkGetMacro(GhostsToSkip, unsigned char);
405 virtual void SetGhostsToSkip(unsigned char);
407
416 vtkGetObjectMacro(GhostArray, vtkUnsignedCharArray);
417
418protected:
420 ~vtkFieldData() override;
421
425
429 void SetArray(int i, vtkAbstractArray* array);
430
434 virtual void InitializeFields();
435
437 {
440 };
441
442 CopyFieldFlag* CopyFieldFlags; // the names of fields not to be copied
443 int NumberOfFieldFlags; // the number of fields not to be copied
444 void CopyFieldOnOff(const char* name, int onOff);
446 int FindFlag(const char* field);
447 int GetFlag(const char* field);
451
452 /*
453 * This tuple holds: [array time stamp, ghost array time stamp, cached ranges].
454 * Those time stamps are used to decide whether the cached range should be recomputed or not.
455 * when requesting the range of an array.
456 *
457 * When there is no ghost array, the ghost array time stamp is defined as equal to 0.
458 */
459 using CachedGhostRangeType = std::tuple<vtkMTimeType, vtkMTimeType, std::vector<double>>;
460 unsigned char GhostsToSkip;
462
464
471 std::vector<std::array<CachedGhostRangeType, 2>> Ranges;
472 std::vector<std::array<CachedGhostRangeType, 2>> FiniteRanges;
474
475private:
476 vtkFieldData(const vtkFieldData&) = delete;
477 void operator=(const vtkFieldData&) = delete;
478
479public:
480 class VTKCOMMONDATAMODEL_EXPORT BasicIterator
481 {
482 public:
483 BasicIterator() = default;
485 BasicIterator(const int* list, unsigned int listSize);
487 virtual ~BasicIterator() = default;
488 void PrintSelf(ostream& os, vtkIndent indent);
489
490 int GetListSize() const { return static_cast<int>(this->List.size()); }
491 int GetCurrentIndex() { return this->List[this->Position]; }
493 {
494 this->Position = -1;
495 return this->NextIndex();
496 }
497 int End() const { return (this->Position >= static_cast<int>(this->List.size())); }
499 {
500 this->Position++;
501 return (this->End() ? -1 : this->List[this->Position]);
502 }
503
504 // Support C++ range-for loops; e.g, code like
505 // "for (const auto& i : basicIterator)".
506 std::vector<int>::const_iterator begin() { return this->List.begin(); }
507 std::vector<int>::const_iterator end() { return this->List.end(); }
508
509 protected:
510 std::vector<int> List;
512 };
513
514 class VTKCOMMONDATAMODEL_EXPORT Iterator : public BasicIterator
515 {
516 public:
519 ~Iterator() override;
520 Iterator(vtkFieldData* dsa, const int* list = nullptr, unsigned int listSize = 0);
521
523 {
524 this->Position = -1;
525 return this->Next();
526 }
527
529 {
530 this->Position++;
531 if (this->End())
532 {
533 return nullptr;
534 }
535
536 // vtkFieldData::GetArray() can return null, which implies that
537 // a the array at the given index in not a vtkDataArray subclass.
538 // This iterator skips such arrays.
539 vtkDataArray* cur = Fields->GetArray(this->List[this->Position]);
540 return (cur ? cur : this->Next());
541 }
542
544
545 protected:
548 };
549};
550
551#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:31
a simple class to control print indentation
Definition vtkIndent.h:34
abstract base class for most VTK objects
Definition vtkObject.h:57
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