VTK  9.1.0
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=========================================================================*/
152#ifndef vtkFieldData_h
153#define vtkFieldData_h
154
155#include "vtkCommonDataModelModule.h" // For export macro
156#include "vtkObject.h"
157#include <vector> // For list indices
158
159#include "vtkAbstractArray.h" // Needed for inline methods.
160
161class vtkIdList;
162
163class VTKCOMMONDATAMODEL_EXPORT vtkFieldData : public vtkObject
164{
165public:
166 static vtkFieldData* New();
168
169 vtkTypeMacro(vtkFieldData, vtkObject);
170 void PrintSelf(ostream& os, vtkIndent indent) override;
171
176 virtual void Initialize();
177
183
190
200 void AllocateArrays(int num);
201
208 int GetNumberOfArrays() { return this->NumberOfActiveArrays; }
209
216
221
223
226 virtual void RemoveArray(const char* name);
227 virtual void RemoveArray(int index);
229
239
250 vtkDataArray* GetArray(const char* arrayName, int& index);
251
253
262 vtkDataArray* GetArray(const char* arrayName)
263 {
264 int i;
265 return this->GetArray(arrayName, i);
266 }
268
275
282 vtkAbstractArray* GetAbstractArray(const char* arrayName, int& index);
283
285
290 vtkAbstractArray* GetAbstractArray(const char* arrayName)
291 {
292 int i;
293 return this->GetAbstractArray(arrayName, i);
294 }
296
298
301 int HasArray(const char* name)
302 {
303 int i;
304 vtkAbstractArray* array = this->GetAbstractArray(name, i);
305 // assert( i == -1);
306 return array ? 1 : 0;
307 }
309
311
316 const char* GetArrayName(int i)
317 {
318 vtkAbstractArray* da = this->GetAbstractArray(i);
319 return da ? da->GetName() : nullptr;
320 }
322
327 virtual void PassData(vtkFieldData* fd);
328
338 void CopyFieldOn(const char* name) { this->CopyFieldOnOff(name, 1); }
339 void CopyFieldOff(const char* name) { this->CopyFieldOnOff(name, 0); }
340
350 virtual void CopyAllOn(int unused = 0);
351
361 virtual void CopyAllOff(int unused = 0);
362
366 virtual void DeepCopy(vtkFieldData* da);
367
371 virtual void ShallowCopy(vtkFieldData* da);
372
376 void Squeeze();
377
382 void Reset();
383
390 virtual unsigned long GetActualMemorySize();
391
396
407
415 int GetArrayContainingComponent(int i, int& arrayComp);
416
427
439
448 void SetNumberOfTuples(const vtkIdType number);
449
456
462
469
470protected:
472 ~vtkFieldData() override;
473
477
481 void SetArray(int i, vtkAbstractArray* array);
482
486 virtual void InitializeFields();
487
489 {
492 };
493
494 CopyFieldFlag* CopyFieldFlags; // the names of fields not to be copied
495 int NumberOfFieldFlags; // the number of fields not to be copied
496 void CopyFieldOnOff(const char* name, int onOff);
498 int FindFlag(const char* field);
499 int GetFlag(const char* field);
503
504private:
505 vtkFieldData(const vtkFieldData&) = delete;
506 void operator=(const vtkFieldData&) = delete;
507
508public:
509 class VTKCOMMONDATAMODEL_EXPORT BasicIterator
510 {
511 public:
512 BasicIterator() = default;
514 BasicIterator(const int* list, unsigned int listSize);
516 virtual ~BasicIterator() = default;
517 void PrintSelf(ostream& os, vtkIndent indent);
518
519 int GetListSize() const { return static_cast<int>(this->List.size()); }
520 int GetCurrentIndex() { return this->List[this->Position]; }
522 {
523 this->Position = -1;
524 return this->NextIndex();
525 }
526 int End() const { return (this->Position >= static_cast<int>(this->List.size())); }
528 {
529 this->Position++;
530 return (this->End() ? -1 : this->List[this->Position]);
531 }
532
533 // Support C++ range-for loops; e.g, code like
534 // "for (const auto& i : basicIterator)".
535 std::vector<int>::const_iterator begin() { return this->List.begin(); }
536 std::vector<int>::const_iterator end() { return this->List.end(); }
537
538 protected:
539 std::vector<int> List;
541 };
542
543 class VTKCOMMONDATAMODEL_EXPORT Iterator : public BasicIterator
544 {
545 public:
548 ~Iterator() override;
549 Iterator(vtkFieldData* dsa, const int* list = nullptr, unsigned int listSize = 0);
550
552 {
553 this->Position = -1;
554 return this->Next();
555 }
556
558 {
559 this->Position++;
560 if (this->End())
561 {
562 return nullptr;
563 }
564
565 // vtkFieldData::GetArray() can return null, which implies that
566 // a the array at the given index in not a vtkDataArray subclass.
567 // This iterator skips such arrays.
568 vtkDataArray* cur = Fields->GetArray(this->List[this->Position]);
569 return (cur ? cur : this->Next());
570 }
571
573
574 protected:
577 };
578};
579
580#endif
Abstract superclass for all arrays.
virtual char * GetName()
Set/get array's name.
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:159
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()
Definition: vtkFieldData.h:536
std::vector< int > List
Definition: vtkFieldData.h:539
std::vector< int >::const_iterator begin()
Definition: vtkFieldData.h:535
vtkDataArray * Begin()
Definition: vtkFieldData.h:551
Iterator(vtkFieldData *dsa, const int *list=nullptr, unsigned int listSize=0)
vtkFieldData * Fields
Definition: vtkFieldData.h:575
vtkDataArray * Next()
Definition: vtkFieldData.h:557
Iterator & operator=(const Iterator &source)
Iterator(const Iterator &source)
represent and manipulate fields of data
Definition: vtkFieldData.h:164
vtkTypeBool Allocate(vtkIdType sz, vtkIdType ext=1000)
Allocate data for each array.
int GetFlag(const char *field)
vtkAbstractArray ** Data
Definition: vtkFieldData.h:476
int GetNumberOfArrays()
Get the number of arrays of data available.
Definition: vtkFieldData.h:208
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.
Definition: vtkFieldData.h:290
void SetTuple(const vtkIdType i, const vtkIdType j, vtkFieldData *source)
Set the jth tuple in source field data at the ith location.
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.
int GetNumberOfComponents()
Get the number of components in the field.
vtkMTimeType GetMTime() override
Check object's components for modified times.
static vtkFieldData * ExtendedNew()
virtual void RemoveArray(const char *name)
Remove an array (with the given name or index) from the list of arrays.
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
Definition: vtkFieldData.h:494
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.
Definition: vtkFieldData.h:316
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.
Definition: vtkFieldData.h:338
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)
Definition: vtkFieldData.h:339
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
Definition: vtkFieldData.h:475
virtual void PassData(vtkFieldData *fd)
Pass entire arrays of input data through to output.
vtkDataArray * GetArray(const char *arrayName)
Not recommended for use.
Definition: vtkFieldData.h:262
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.
Definition: vtkFieldData.h:301
int NumberOfFieldFlags
Definition: vtkFieldData.h:495
list of point or cell ids
Definition: vtkIdList.h:140
a simple class to control print indentation
Definition: vtkIndent.h:113
abstract base class for most VTK objects
Definition: vtkObject.h:73
@ field
Definition: vtkX3D.h:183
@ name
Definition: vtkX3D.h:225
@ index
Definition: vtkX3D.h:252
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