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=========================================================================*/
45
46#ifndef vtkFieldData_h
47#define vtkFieldData_h
48
49#include "vtkCommonDataModelModule.h" // For export macro
50#include "vtkObject.h"
51
52#include "vtkAbstractArray.h" // Needed for inline methods.
53
54#include <array> // For CachedGhostRangeType
55#include <tuple> // For CachedGhostRangeType
56#include <vector> // For list indices
57
58class vtkDoubleArray;
59class vtkIdList;
61
62class VTKCOMMONDATAMODEL_EXPORT vtkFieldData : public vtkObject
63{
64public:
65 static vtkFieldData* New();
67
68 vtkTypeMacro(vtkFieldData, vtkObject);
69 void PrintSelf(ostream& os, vtkIndent indent) override;
70
75 virtual void Initialize();
76
82
89
99 void AllocateArrays(int num);
100
108
115
120
122
125 virtual void RemoveArray(const char* name);
126 virtual void RemoveArray(int index);
128
138
149 vtkDataArray* GetArray(const char* arrayName, int& index);
150
152
161 vtkDataArray* GetArray(const char* arrayName)
162 {
163 int i;
164 return this->GetArray(arrayName, i);
165 }
166
167
174
181 vtkAbstractArray* GetAbstractArray(const char* arrayName, int& index);
182
184
189 vtkAbstractArray* GetAbstractArray(const char* arrayName)
190 {
191 int i;
192 return this->GetAbstractArray(arrayName, i);
193 }
194
195
197
200 int HasArray(const char* name)
201 {
202 int i;
203 vtkAbstractArray* array = this->GetAbstractArray(name, i);
204 // assert( i == -1);
205 return array ? 1 : 0;
206 }
207
208
210
215 const char* GetArrayName(int i)
216 {
217 vtkAbstractArray* da = this->GetAbstractArray(i);
218 return da ? da->GetName() : nullptr;
219 }
220
221
226 virtual void PassData(vtkFieldData* fd);
227
237 void CopyFieldOn(const char* name) { this->CopyFieldOnOff(name, 1); }
238 void CopyFieldOff(const char* name) { this->CopyFieldOnOff(name, 0); }
239
249 virtual void CopyAllOn(int unused = 0);
250
260 virtual void CopyAllOff(int unused = 0);
261
265 virtual void DeepCopy(vtkFieldData* da);
266
270 virtual void ShallowCopy(vtkFieldData* da);
271
275 void Squeeze();
276
281 void Reset();
282
289 virtual unsigned long GetActualMemorySize();
290
295
306
314 int GetArrayContainingComponent(int i, int& arrayComp);
315
326
338
347 void SetNumberOfTuples(const vtkIdType number);
348
355
361
368
370
389 bool GetRange(const char* name, double range[2], int comp = 0);
390 bool GetRange(int index, double range[2], int comp = 0);
391 bool GetFiniteRange(const char* name, double range[2], int comp = 0);
392 bool GetFiniteRange(int index, double range[2], int comp = 0);
394
396
407 vtkGetMacro(GhostsToSkip, unsigned char);
408 virtual void SetGhostsToSkip(unsigned char);
410
419 vtkGetObjectMacro(GhostArray, vtkUnsignedCharArray);
420
421protected:
423 ~vtkFieldData() override;
424
428
432 void SetArray(int i, vtkAbstractArray* array);
433
437 virtual void InitializeFields();
438
440 {
443 };
444
445 CopyFieldFlag* CopyFieldFlags; // the names of fields not to be copied
446 int NumberOfFieldFlags; // the number of fields not to be copied
447 void CopyFieldOnOff(const char* name, int onOff);
449 int FindFlag(const char* field);
450 int GetFlag(const char* field);
454
455 /*
456 * This tuple holds: [array time stamp, ghost array time stamp, cached ranges].
457 * Those time stamps are used to decide whether the cached range should be recomputed or not.
458 * when requesting the range of an array.
459 *
460 * When there is no ghost array, the ghost array time stamp is defined as equal to 0.
461 */
462 using CachedGhostRangeType = std::tuple<vtkMTimeType, vtkMTimeType, std::vector<double>>;
463 unsigned char GhostsToSkip;
465
467
474 std::vector<std::array<CachedGhostRangeType, 2>> Ranges;
475 std::vector<std::array<CachedGhostRangeType, 2>> FiniteRanges;
477
478private:
479 vtkFieldData(const vtkFieldData&) = delete;
480 void operator=(const vtkFieldData&) = delete;
481
482public:
483 class VTKCOMMONDATAMODEL_EXPORT BasicIterator
484 {
485 public:
486 BasicIterator() = default;
488 BasicIterator(const int* list, unsigned int listSize);
490 virtual ~BasicIterator() = default;
491 void PrintSelf(ostream& os, vtkIndent indent);
492
493 int GetListSize() const { return static_cast<int>(this->List.size()); }
494 int GetCurrentIndex() { return this->List[this->Position]; }
496 {
497 this->Position = -1;
498 return this->NextIndex();
499 }
500 int End() const { return (this->Position >= static_cast<int>(this->List.size())); }
502 {
503 this->Position++;
504 return (this->End() ? -1 : this->List[this->Position]);
505 }
506
507 // Support C++ range-for loops; e.g, code like
508 // "for (const auto& i : basicIterator)".
509 std::vector<int>::const_iterator begin() { return this->List.begin(); }
510 std::vector<int>::const_iterator end() { return this->List.end(); }
511
512 protected:
513 std::vector<int> List;
515 };
516
517 class VTKCOMMONDATAMODEL_EXPORT Iterator : public BasicIterator
518 {
519 public:
522 ~Iterator() override;
523 Iterator(vtkFieldData* dsa, const int* list = nullptr, unsigned int listSize = 0);
524
526 {
527 this->Position = -1;
528 return this->Next();
529 }
530
532 {
533 this->Position++;
534 if (this->End())
535 {
536 return nullptr;
537 }
538
539 // vtkFieldData::GetArray() can return null, which implies that
540 // a the array at the given index in not a vtkDataArray subclass.
541 // This iterator skips such arrays.
542 vtkDataArray* cur = Fields->GetArray(this->List[this->Position]);
543 return (cur ? cur : this->Next());
544 }
545
547
548 protected:
551 };
552};
553
554#endif
Abstract superclass for all arrays.
virtual char * GetName()
Set/get array's name.
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)
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.
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.
std::tuple< vtkMTimeType, vtkMTimeType, std::vector< double > > CachedGhostRangeType
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:34
a simple class to control print indentation
Definition vtkIndent.h:40
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 *)
#define vtkDataArray
int vtkIdType
Definition vtkType.h:332
vtkTypeUInt32 vtkMTimeType
Definition vtkType.h:287