VTK  9.3.0
vtkDataArray.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
38#ifndef vtkDataArray_h
39#define vtkDataArray_h
40
41#include "vtkAbstractArray.h"
42#include "vtkCommonCoreModule.h" // For export macro
43#include "vtkVTK_USE_SCALED_SOA_ARRAYS.h" // For #define of VTK_USE_SCALED_SOA_ARRAYS
44
45VTK_ABI_NAMESPACE_BEGIN
46class vtkDoubleArray;
47class vtkIdList;
50class vtkLookupTable;
51class vtkPoints;
52
53class VTKCOMMONCORE_EXPORT vtkDataArray : public vtkAbstractArray
54{
55public:
57 void PrintSelf(ostream& os, vtkIndent indent) override;
58
65 static vtkDataArray* FastDownCast(vtkAbstractArray* source);
66
73 int IsNumeric() const override { return 1; }
74
80 int GetElementComponentSize() const override { return this->GetDataTypeSize(); }
81
82 // Reimplemented virtuals (doc strings are inherited from superclass):
84
89 void InsertTuple(vtkIdType dstTupleIdx, vtkIdType srcTupleIdx, vtkAbstractArray* source) override;
91 void InsertTuples(vtkIdList* dstIds, vtkIdList* srcIds, vtkAbstractArray* source) override;
93 vtkIdType dstStart, vtkIdType n, vtkIdType srcStart, vtkAbstractArray* source) override;
95 vtkIdType dstStart, vtkIdList* srcIds, vtkAbstractArray* source) override;
96 void SetTuple(vtkIdType dstTupleIdx, vtkIdType srcTupleIdx, vtkAbstractArray* source) override;
98 void GetTuples(vtkIdList* tupleIds, vtkAbstractArray* output) override;
99 void GetTuples(vtkIdType p1, vtkIdType p2, vtkAbstractArray* output) override;
101 double* weights) override;
102 void InterpolateTuple(vtkIdType dstTupleIdx, vtkIdType srcTupleIdx1, vtkAbstractArray* source1,
103 vtkIdType srcTupleIdx2, vtkAbstractArray* source2, double t) override;
104
110 virtual double* GetTuple(vtkIdType tupleIdx)
111 VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples()) = 0;
112
118 virtual void GetTuple(vtkIdType tupleIdx, double* tuple)
119 VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples()) = 0;
120
122
127 double GetTuple1(vtkIdType tupleIdx) VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
128 double* GetTuple2(vtkIdType tupleIdx) VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples())
129 VTK_SIZEHINT(2);
130 double* GetTuple3(vtkIdType tupleIdx) VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples())
131 VTK_SIZEHINT(3);
132 double* GetTuple4(vtkIdType tupleIdx) VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples())
133 VTK_SIZEHINT(4);
134 double* GetTuple6(vtkIdType tupleIdx) VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples())
135 VTK_SIZEHINT(6);
136 double* GetTuple9(vtkIdType tupleIdx) VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples())
137 VTK_SIZEHINT(9);
139
141
146 virtual void SetTuple(vtkIdType tupleIdx, const float* tuple)
147 VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
148 virtual void SetTuple(vtkIdType tupleIdx, const double* tuple)
149 VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
151
153
158 void SetTuple1(vtkIdType tupleIdx, double value)
159 VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
160 void SetTuple2(vtkIdType tupleIdx, double val0, double val1)
161 VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
162 void SetTuple3(vtkIdType tupleIdx, double val0, double val1, double val2)
163 VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
164 void SetTuple4(vtkIdType tupleIdx, double val0, double val1, double val2, double val3)
165 VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
166 void SetTuple6(vtkIdType tupleIdx, double val0, double val1, double val2, double val3,
167 double val4, double val5) VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
168 void SetTuple9(vtkIdType tupleIdx, double val0, double val1, double val2, double val3,
169 double val4, double val5, double val6, double val7, double val8)
170 VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
172
174
178 virtual void InsertTuple(vtkIdType tupleIdx, const float* tuple) VTK_EXPECTS(0 <= tupleIdx) = 0;
179 virtual void InsertTuple(vtkIdType tupleIdx, const double* tuple) VTK_EXPECTS(0 <= tupleIdx) = 0;
181
183
188 void InsertTuple1(vtkIdType tupleIdx, double value) VTK_EXPECTS(0 <= tupleIdx);
189 void InsertTuple2(vtkIdType tupleIdx, double val0, double val1) VTK_EXPECTS(0 <= tupleIdx);
190 void InsertTuple3(vtkIdType tupleIdx, double val0, double val1, double val2)
191 VTK_EXPECTS(0 <= tupleIdx);
192 void InsertTuple4(vtkIdType tupleIdx, double val0, double val1, double val2, double val3)
193 VTK_EXPECTS(0 <= tupleIdx);
194 void InsertTuple6(vtkIdType tupleIdx, double val0, double val1, double val2, double val3,
195 double val4, double val5) VTK_EXPECTS(0 <= tupleIdx);
196 void InsertTuple9(vtkIdType tupleIdx, double val0, double val1, double val2, double val3,
197 double val4, double val5, double val6, double val7, double val8) VTK_EXPECTS(0 <= tupleIdx);
199
201
206 virtual vtkIdType InsertNextTuple(const float* tuple) = 0;
207 virtual vtkIdType InsertNextTuple(const double* tuple) = 0;
209
211
216 void InsertNextTuple1(double value);
217 void InsertNextTuple2(double val0, double val1);
218 void InsertNextTuple3(double val0, double val1, double val2);
219 void InsertNextTuple4(double val0, double val1, double val2, double val3);
220 void InsertNextTuple6(
221 double val0, double val1, double val2, double val3, double val4, double val5);
222 void InsertNextTuple9(double val0, double val1, double val2, double val3, double val4,
223 double val5, double val6, double val7, double val8);
225
227
232 virtual void RemoveTuple(vtkIdType tupleIdx)
233 VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples()) = 0;
234 virtual void RemoveFirstTuple() { this->RemoveTuple(0); }
235 virtual void RemoveLastTuple();
237
242 virtual double GetComponent(vtkIdType tupleIdx, int compIdx) VTK_EXPECTS(0 <= tupleIdx &&
243 tupleIdx < GetNumberOfTuples()) VTK_EXPECTS(0 <= compIdx && compIdx < GetNumberOfComponents());
244
252 virtual void SetComponent(vtkIdType tupleIdx, int compIdx, double value)
253 VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples())
254 VTK_EXPECTS(0 <= compIdx && compIdx < GetNumberOfComponents());
255
260 virtual void InsertComponent(vtkIdType tupleIdx, int compIdx, double value)
261 VTK_EXPECTS(0 <= tupleIdx) VTK_EXPECTS(0 <= compIdx && compIdx < GetNumberOfComponents());
262
271 virtual void GetData(
272 vtkIdType tupleMin, vtkIdType tupleMax, int compMin, int compMax, vtkDoubleArray* data);
273
275
279 void DeepCopy(vtkAbstractArray* aa) override;
280 virtual void DeepCopy(vtkDataArray* da);
282
292 virtual void ShallowCopy(vtkDataArray* other);
293
300 virtual void FillComponent(int compIdx, double value)
301 VTK_EXPECTS(0 <= compIdx && compIdx < GetNumberOfComponents());
302
306 virtual void Fill(double value);
307
316 virtual void CopyComponent(int dstComponent, vtkDataArray* src, int srcComponent);
317
323 virtual void* WriteVoidPointer(vtkIdType valueIdx, vtkIdType numValues) = 0;
324
333 unsigned long GetActualMemorySize() const override;
334
339 void CreateDefaultLookupTable();
340
342
345 void SetLookupTable(vtkLookupTable* lut);
346 vtkGetObjectMacro(LookupTable, vtkLookupTable);
348
350
367 void GetRange(double range[2], int comp) { this->ComputeRange(range, comp); }
368 void GetRange(double range[2], int comp, const unsigned char* ghosts, unsigned char ghostsToSkip)
369 {
370 this->ComputeRange(range, comp, ghosts, ghostsToSkip);
371 }
373
375
383 double* GetRange(int comp) VTK_SIZEHINT(2)
384 {
385 this->GetRange(this->Range, comp);
386 return this->Range;
387 }
389
397 double* GetRange() VTK_SIZEHINT(2) { return this->GetRange(0); }
398
407 void GetRange(double range[2]) { this->GetRange(range, 0); }
408
410
428 void GetFiniteRange(double range[2], int comp) { this->ComputeFiniteRange(range, comp); }
430 double range[2], int comp, const unsigned char* ghosts, unsigned char ghostsToSkip)
431 {
432 this->ComputeFiniteRange(range, comp, ghosts, ghostsToSkip);
433 }
435
437
445 double* GetFiniteRange(int comp) VTK_SIZEHINT(2)
446 {
447 this->GetFiniteRange(this->FiniteRange, comp);
448 return this->FiniteRange;
449 }
451
459 double* GetFiniteRange() VTK_SIZEHINT(2) { return this->GetFiniteRange(0); }
460
469 void GetFiniteRange(double range[2]) { this->GetFiniteRange(range, 0); }
470
472
477 void GetDataTypeRange(double range[2]);
480 static void GetDataTypeRange(int type, double range[2]);
481 static double GetDataTypeMin(int type);
482 static double GetDataTypeMax(int type);
484
489 virtual double GetMaxNorm();
490
500 static vtkDataArray* CreateDataArray(int dataType);
501
510
519
528
532 void Modified() override;
533
538
546 int CopyInformation(vtkInformation* infoFrom, vtkTypeBool deep = 1) override;
547
551 int GetArrayType() const override { return DataArray; }
552
553protected:
554 friend class vtkPoints;
555 friend class vtkFieldData;
556
558
574 virtual void ComputeRange(double range[2], int comp);
575 virtual void ComputeRange(
576 double range[2], int comp, const unsigned char* ghosts, unsigned char ghostsToSkip = 0xff);
578
580
596 virtual void ComputeFiniteRange(double range[2], int comp);
597 virtual void ComputeFiniteRange(
598 double range[2], int comp, const unsigned char* ghosts, unsigned char ghostsToSkip = 0xff);
600
602
617 virtual bool ComputeScalarRange(double* ranges);
618 virtual bool ComputeScalarRange(
619 double* ranges, const unsigned char* ghosts, unsigned char ghostsToSkip = 0xff);
621
623
635 virtual bool ComputeVectorRange(double range[2]);
636 virtual bool ComputeVectorRange(
637 double range[2], const unsigned char* ghosts, unsigned char ghostsToSkip = 0xff);
639
641
655 virtual bool ComputeFiniteScalarRange(double* ranges);
657 double* ranges, const unsigned char* ghosts, unsigned char ghostsToSkip = 0xff);
659
661
673 virtual bool ComputeFiniteVectorRange(double range[2]);
675 double range[2], const unsigned char* ghosts, unsigned char ghostsToSkip = 0xff);
677
678 // Construct object with default tuple dimension (number of components) of 1.
680 ~vtkDataArray() override;
681
683 double Range[2];
684 double FiniteRange[2];
685
686private:
687 double* GetTupleN(vtkIdType i, int n);
688
689 vtkDataArray(const vtkDataArray&) = delete;
690 void operator=(const vtkDataArray&) = delete;
691};
692
693//------------------------------------------------------------------------------
695{
696 if (source)
697 {
698 switch (source->GetArrayType())
699 {
702 case ImplicitArray:
703 case TypedDataArray:
704 case DataArray:
705 case MappedDataArray:
706 return static_cast<vtkDataArray*>(source);
707 default:
708 break;
709 }
710 }
711 return nullptr;
712}
713
715VTK_ABI_NAMESPACE_END
716
717// These are used by vtkDataArrayPrivate.txx, but need to be available to
718// vtkGenericDataArray.h as well.
720{
721VTK_ABI_NAMESPACE_BEGIN
722struct AllValues
723{
724};
725struct FiniteValues
726{
727};
728VTK_ABI_NAMESPACE_END
729}
730
731#endif
Abstract superclass for all arrays.
vtkIdType GetNumberOfTuples() const
Get the number of complete tuples (a component group) in the array.
virtual int GetDataTypeSize() const =0
Return the size of the underlying data type.
abstract superclass for arrays of numeric data
virtual double * GetTuple(vtkIdType tupleIdx)=0
Get the data tuple at tupleIdx.
double * GetRange()
Return the range of the data array.
virtual void ComputeRange(double range[2], int comp, const unsigned char *ghosts, unsigned char ghostsToSkip=0xff)
Compute the range for a specific component.
static double GetDataTypeMin(int type)
These methods return the Min and Max possible range of the native data type.
double * GetTuple2(vtkIdType tupleIdx)
These methods are included as convenience for the wrappers.
void InterpolateTuple(vtkIdType dstTupleIdx, vtkIdList *ptIndices, vtkAbstractArray *source, double *weights) override
Set the tuple at dstTupleIdx in this array to the interpolated tuple value, given the ptIndices in th...
virtual bool ComputeScalarRange(double *ranges, const unsigned char *ghosts, unsigned char ghostsToSkip=0xff)
Computes the range for each component of an array, the length of ranges must be two times the number ...
virtual bool ComputeVectorRange(double range[2])
Returns true if the range was computed.
int IsNumeric() const override
This method is here to make backward compatibility easier.
void SetTuple(vtkIdType dstTupleIdx, vtkIdType srcTupleIdx, vtkAbstractArray *source) override
See documentation from parent class.
void GetDataTypeRange(double range[2])
These methods return the Min and Max possible range of the native data type.
void InterpolateTuple(vtkIdType dstTupleIdx, vtkIdType srcTupleIdx1, vtkAbstractArray *source1, vtkIdType srcTupleIdx2, vtkAbstractArray *source2, double t) override
Insert the tuple at dstTupleIdx in this array to the tuple interpolated from the two tuple indices,...
virtual void ComputeRange(double range[2], int comp)
Compute the range for a specific component.
double * GetFiniteRange()
Return the range of the data array.
virtual bool ComputeScalarRange(double *ranges)
Computes the range for each component of an array, the length of ranges must be two times the number ...
void InsertTuples(vtkIdList *dstIds, vtkIdList *srcIds, vtkAbstractArray *source) override
See documentation from parent class.
virtual bool ComputeFiniteVectorRange(double range[2], const unsigned char *ghosts, unsigned char ghostsToSkip=0xff)
Returns true if the range was computed.
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
virtual bool ComputeVectorRange(double range[2], const unsigned char *ghosts, unsigned char ghostsToSkip=0xff)
Returns true if the range was computed.
~vtkDataArray() override
int GetArrayType() const override
Method for type-checking in FastDownCast implementations.
int GetElementComponentSize() const override
Return the size, in bytes, of the lowest-level element of an array.
virtual bool ComputeFiniteVectorRange(double range[2])
Returns true if the range was computed.
static vtkInformationDoubleVectorKey * COMPONENT_RANGE()
This key is used to hold tight bounds on the range of one component over all tuples of the array.
virtual void RemoveLastTuple()
These methods remove tuples from the data array.
double * GetRange(int comp)
Return the range of the data array values for the given component.
void GetFiniteRange(double range[2], int comp)
The range of the data array values for the given component will be returned in the provided range arr...
void GetTuples(vtkIdType p1, vtkIdType p2, vtkAbstractArray *output) override
Get the tuples for the range of tuple ids specified (i.e., p1->p2 inclusive).
static vtkInformationDoubleVectorKey * L2_NORM_RANGE()
This key is used to hold tight bounds on the $L_2$ norm of tuples in the array.
double GetDataTypeMin()
These methods return the Min and Max possible range of the native data type.
void InsertTuplesStartingAt(vtkIdType dstStart, vtkIdList *srcIds, vtkAbstractArray *source) override
See documentation from parent class.
void GetTuples(vtkIdList *tupleIds, vtkAbstractArray *output) override
Given a list of tuple ids, return an array of tuples.
virtual void GetTuple(vtkIdType tupleIdx, double *tuple)=0
Get the data tuple at tupleIdx by filling in a user-provided array, Make sure that your array is larg...
double GetTuple1(vtkIdType tupleIdx)
These methods are included as convenience for the wrappers.
static vtkInformationDoubleVectorKey * L2_NORM_FINITE_RANGE()
This key is used to hold tight bounds on the $L_2$ norm of tuples in the array.
double GetDataTypeMax()
These methods return the Min and Max possible range of the native data type.
void GetRange(double range[2])
The range of the data array values will be returned in the provided range array argument.
static vtkDataArray * FastDownCast(vtkAbstractArray *source)
Perform a fast, safe cast from a vtkAbstractArray to a vtkDataArray.
virtual double GetComponent(vtkIdType tupleIdx, int compIdx)
Return the data component at the location specified by tupleIdx and compIdx.
int CopyInformation(vtkInformation *infoFrom, vtkTypeBool deep=1) override
Copy information instance.
vtkIdType InsertNextTuple(vtkIdType srcTupleIdx, vtkAbstractArray *source) override
See documentation from parent class.
virtual void ComputeFiniteRange(double range[2], int comp)
Compute the range for a specific component.
virtual double GetMaxNorm()
Return the maximum norm for the tuples.
void InsertTuple(vtkIdType dstTupleIdx, vtkIdType srcTupleIdx, vtkAbstractArray *source) override
See documentation from parent class.
void GetRange(double range[2], int comp, const unsigned char *ghosts, unsigned char ghostsToSkip)
The range of the data array values for the given component will be returned in the provided range arr...
static void GetDataTypeRange(int type, double range[2])
These methods return the Min and Max possible range of the native data type.
virtual bool ComputeFiniteScalarRange(double *ranges, const unsigned char *ghosts, unsigned char ghostsToSkip=0xff)
Computes the range for each component of an array, the length of ranges must be two times the number ...
virtual void ComputeFiniteRange(double range[2], int comp, const unsigned char *ghosts, unsigned char ghostsToSkip=0xff)
Compute the range for a specific component.
static vtkDataArray * CreateDataArray(int dataType)
Creates an array for dataType where dataType is one of VTK_BIT, VTK_CHAR, VTK_SIGNED_CHAR,...
void GetFiniteRange(double range[2], int comp, const unsigned char *ghosts, unsigned char ghostsToSkip)
The range of the data array values for the given component will be returned in the provided range arr...
void GetFiniteRange(double range[2])
The range of the data array values will be returned in the provided range array argument.
double * GetFiniteRange(int comp)
Return the range of the data array values for the given component.
void InsertTuples(vtkIdType dstStart, vtkIdType n, vtkIdType srcStart, vtkAbstractArray *source) override
See documentation from parent class.
static vtkInformationStringKey * UNITS_LABEL()
A human-readable string indicating the units for the array data.
virtual bool ComputeFiniteScalarRange(double *ranges)
Computes the range for each component of an array, the length of ranges must be two times the number ...
void Modified() override
Removes out-of-date L2_NORM_RANGE() and L2_NORM_FINITE_RANGE() values.
static double GetDataTypeMax(int type)
These methods return the Min and Max possible range of the native data type.
vtkLookupTable * LookupTable
dynamic, self-adjusting array of double
represent and manipulate fields of data
list of point or cell ids
Definition vtkIdList.h:32
a simple class to control print indentation
Definition vtkIndent.h:38
Key for string values in vtkInformation.
Store vtkAlgorithm input/output information.
map scalar values into colors via a lookup table
represent and manipulate 3D points
Definition vtkPoints.h:38
int vtkTypeBool
Definition vtkABI.h:64
#define vtkArrayDownCast_FastCastMacro(ArrayT)
This macro is used to tell vtkArrayDownCast to use FastDownCast instead of SafeDownCast.
boost::graph_traits< vtkGraph * >::vertex_descriptor source(boost::graph_traits< vtkGraph * >::edge_descriptor e, vtkGraph *)
#define vtkDataArray
int vtkIdType
Definition vtkType.h:315
#define VTK_SIZEHINT(...)
#define VTK_EXPECTS(x)
#define VTK_NEWINSTANCE