VTK  9.4.20251203
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
29#ifndef vtkDataArray_h
30#define vtkDataArray_h
31
32#include "vtkAbstractArray.h"
33#include "vtkCommonCoreModule.h" // For export macro
34#include "vtkVTK_USE_SCALED_SOA_ARRAYS.h" // For #define of VTK_USE_SCALED_SOA_ARRAYS
35#include "vtkWrappingHints.h" // For VTK_MARSHALMANUAL
36
37VTK_ABI_NAMESPACE_BEGIN
38class vtkDoubleArray;
39class vtkIdList;
42class vtkLookupTable;
43class vtkPoints;
44
45class VTKCOMMONCORE_EXPORT VTK_MARSHALMANUAL vtkDataArray : public vtkAbstractArray
46{
47public:
49 void PrintSelf(ostream& os, vtkIndent indent) override;
50
57 static vtkDataArray* FastDownCast(vtkAbstractArray* source);
58
65 int IsNumeric() const override { return 1; }
66
72 int GetElementComponentSize() const override { return this->GetDataTypeSize(); }
73
74 // Reimplemented virtuals (doc strings are inherited from superclass):
76
81 void InsertTuple(vtkIdType dstTupleIdx, vtkIdType srcTupleIdx, vtkAbstractArray* source) override;
83 void InsertTuples(vtkIdList* dstIds, vtkIdList* srcIds, vtkAbstractArray* source) override;
85 vtkIdType dstStart, vtkIdType n, vtkIdType srcStart, vtkAbstractArray* source) override;
87 vtkIdType dstStart, vtkIdList* srcIds, vtkAbstractArray* source) override;
88 void SetTuple(vtkIdType dstTupleIdx, vtkIdType srcTupleIdx, vtkAbstractArray* source) override;
90 void GetTuples(vtkIdList* tupleIds, vtkAbstractArray* output) override;
91 void GetTuples(vtkIdType p1, vtkIdType p2, vtkAbstractArray* output) override;
93 double* weights) override;
94 void InterpolateTuple(vtkIdType dstTupleIdx, vtkIdType srcTupleIdx1, vtkAbstractArray* source1,
95 vtkIdType srcTupleIdx2, vtkAbstractArray* source2, double t) override;
96
102 virtual double* GetTuple(vtkIdType tupleIdx)
103 VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples()) = 0;
104
110 virtual void GetTuple(vtkIdType tupleIdx, double* tuple)
111 VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples()) = 0;
112
114
123 virtual void GetIntegerTuple(vtkIdType tupleIdx, vtkTypeInt64* tuple)
124 VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
125 virtual void SetIntegerTuple(vtkIdType tupleIdx, vtkTypeInt64* tuple)
126 VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
128
130
139 virtual void GetUnsignedTuple(vtkIdType tupleIdx, vtkTypeUInt64* tuple)
140 VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
141 virtual void SetUnsignedTuple(vtkIdType tupleIdx, vtkTypeUInt64* tuple)
142 VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
144
146
151 double GetTuple1(vtkIdType tupleIdx) VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
152 double* GetTuple2(vtkIdType tupleIdx) VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples())
153 VTK_SIZEHINT(2);
154 double* GetTuple3(vtkIdType tupleIdx) VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples())
155 VTK_SIZEHINT(3);
156 double* GetTuple4(vtkIdType tupleIdx) VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples())
157 VTK_SIZEHINT(4);
158 double* GetTuple6(vtkIdType tupleIdx) VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples())
159 VTK_SIZEHINT(6);
160 double* GetTuple9(vtkIdType tupleIdx) VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples())
161 VTK_SIZEHINT(9);
163
165
170 virtual void SetTuple(vtkIdType tupleIdx, const float* tuple)
171 VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
172 virtual void SetTuple(vtkIdType tupleIdx, const double* tuple)
173 VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
175
177
182 void SetTuple1(vtkIdType tupleIdx, double value)
183 VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
184 void SetTuple2(vtkIdType tupleIdx, double val0, double val1)
185 VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
186 void SetTuple3(vtkIdType tupleIdx, double val0, double val1, double val2)
187 VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
188 void SetTuple4(vtkIdType tupleIdx, double val0, double val1, double val2, double val3)
189 VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
190 void SetTuple6(vtkIdType tupleIdx, double val0, double val1, double val2, double val3,
191 double val4, double val5) VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
192 void SetTuple9(vtkIdType tupleIdx, double val0, double val1, double val2, double val3,
193 double val4, double val5, double val6, double val7, double val8)
194 VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
196
198
202 virtual void InsertTuple(vtkIdType tupleIdx, const float* tuple) VTK_EXPECTS(0 <= tupleIdx) = 0;
203 virtual void InsertTuple(vtkIdType tupleIdx, const double* tuple) VTK_EXPECTS(0 <= tupleIdx) = 0;
205
207
212 void InsertTuple1(vtkIdType tupleIdx, double value) VTK_EXPECTS(0 <= tupleIdx);
213 void InsertTuple2(vtkIdType tupleIdx, double val0, double val1) VTK_EXPECTS(0 <= tupleIdx);
214 void InsertTuple3(vtkIdType tupleIdx, double val0, double val1, double val2)
215 VTK_EXPECTS(0 <= tupleIdx);
216 void InsertTuple4(vtkIdType tupleIdx, double val0, double val1, double val2, double val3)
217 VTK_EXPECTS(0 <= tupleIdx);
218 void InsertTuple6(vtkIdType tupleIdx, double val0, double val1, double val2, double val3,
219 double val4, double val5) VTK_EXPECTS(0 <= tupleIdx);
220 void InsertTuple9(vtkIdType tupleIdx, double val0, double val1, double val2, double val3,
221 double val4, double val5, double val6, double val7, double val8) VTK_EXPECTS(0 <= tupleIdx);
223
225
230 virtual vtkIdType InsertNextTuple(const float* tuple) = 0;
231 virtual vtkIdType InsertNextTuple(const double* tuple) = 0;
233
235
240 void InsertNextTuple1(double value);
241 void InsertNextTuple2(double val0, double val1);
242 void InsertNextTuple3(double val0, double val1, double val2);
243 void InsertNextTuple4(double val0, double val1, double val2, double val3);
244 void InsertNextTuple6(
245 double val0, double val1, double val2, double val3, double val4, double val5);
246 void InsertNextTuple9(double val0, double val1, double val2, double val3, double val4,
247 double val5, double val6, double val7, double val8);
249
251
256 virtual void RemoveTuple(vtkIdType tupleIdx)
257 VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples()) = 0;
258 virtual void RemoveFirstTuple() { this->RemoveTuple(0); }
259 virtual void RemoveLastTuple();
261
266 virtual double GetComponent(vtkIdType tupleIdx, int compIdx)
267 VTK_EXPECTS(0 <= tupleIdx && GetNumberOfComponents() * tupleIdx + compIdx < GetNumberOfValues())
268 VTK_EXPECTS(0 <= compIdx && compIdx < GetNumberOfComponents());
269
277 virtual void SetComponent(vtkIdType tupleIdx, int compIdx, double value)
278 VTK_EXPECTS(0 <= tupleIdx && GetNumberOfComponents() * tupleIdx + compIdx < GetNumberOfValues())
279 VTK_EXPECTS(0 <= compIdx && compIdx < GetNumberOfComponents());
280
285 virtual void InsertComponent(vtkIdType tupleIdx, int compIdx, double value)
286 VTK_EXPECTS(0 <= tupleIdx) VTK_EXPECTS(0 <= compIdx && compIdx < GetNumberOfComponents());
287
296 virtual void GetData(
297 vtkIdType tupleMin, vtkIdType tupleMax, int compMin, int compMax, vtkDoubleArray* data);
298
300
304 void DeepCopy(vtkAbstractArray* aa) override;
305 virtual void DeepCopy(vtkDataArray* da);
307
317 virtual void ShallowCopy(vtkDataArray* other);
318
325 virtual void FillComponent(int compIdx, double value)
326 VTK_EXPECTS(0 <= compIdx && compIdx < GetNumberOfComponents());
327
331 virtual void Fill(double value);
332
341 virtual void CopyComponent(int dstComponent, vtkDataArray* src, int srcComponent);
342
348 virtual void* WriteVoidPointer(vtkIdType valueIdx, vtkIdType numValues) = 0;
349
358 unsigned long GetActualMemorySize() const override;
359
364 void CreateDefaultLookupTable();
365
367
370 void SetLookupTable(vtkLookupTable* lut);
371 vtkGetObjectMacro(LookupTable, vtkLookupTable);
373
375
392 void GetRange(double range[2], int comp) { this->ComputeRange(range, comp); }
393 void GetRange(double range[2], int comp, const unsigned char* ghosts, unsigned char ghostsToSkip)
394 {
395 this->ComputeRange(range, comp, ghosts, ghostsToSkip);
396 }
398
400
408 double* GetRange(int comp) VTK_SIZEHINT(2)
409 {
410 this->GetRange(this->Range, comp);
411 return this->Range;
412 }
414
422 double* GetRange() VTK_SIZEHINT(2) { return this->GetRange(0); }
423
432 void GetRange(double range[2]) { this->GetRange(range, 0); }
433
435
453 void GetFiniteRange(double range[2], int comp) { this->ComputeFiniteRange(range, comp); }
455 double range[2], int comp, const unsigned char* ghosts, unsigned char ghostsToSkip)
456 {
457 this->ComputeFiniteRange(range, comp, ghosts, ghostsToSkip);
458 }
460
462
470 double* GetFiniteRange(int comp) VTK_SIZEHINT(2)
471 {
472 this->GetFiniteRange(this->FiniteRange, comp);
473 return this->FiniteRange;
474 }
476
484 double* GetFiniteRange() VTK_SIZEHINT(2) { return this->GetFiniteRange(0); }
485
494 void GetFiniteRange(double range[2]) { this->GetFiniteRange(range, 0); }
495
497
502 void GetDataTypeRange(double range[2]);
505 static void GetDataTypeRange(int type, double range[2]);
506 static double GetDataTypeMin(int type);
507 static double GetDataTypeMax(int type);
509
514 virtual double GetMaxNorm();
515
525 static vtkDataArray* CreateDataArray(int dataType);
526
535
544
553
557 void Modified() override;
558
563
571 int CopyInformation(vtkInformation* infoFrom, vtkTypeBool deep = 1) override;
572
576 int GetArrayType() const override { return DataArray; }
577
578protected:
579 friend class vtkPoints;
580 friend class vtkFieldData;
581
583
599 virtual void ComputeRange(double range[2], int comp);
600 virtual void ComputeRange(
601 double range[2], int comp, const unsigned char* ghosts, unsigned char ghostsToSkip = 0xff);
603
605
621 virtual void ComputeFiniteRange(double range[2], int comp);
622 virtual void ComputeFiniteRange(
623 double range[2], int comp, const unsigned char* ghosts, unsigned char ghostsToSkip = 0xff);
625
627
642 virtual bool ComputeScalarRange(double* ranges);
643 virtual bool ComputeScalarRange(
644 double* ranges, const unsigned char* ghosts, unsigned char ghostsToSkip = 0xff);
646
648
660 virtual bool ComputeVectorRange(double range[2]);
661 virtual bool ComputeVectorRange(
662 double range[2], const unsigned char* ghosts, unsigned char ghostsToSkip = 0xff);
664
666
680 virtual bool ComputeFiniteScalarRange(double* ranges);
682 double* ranges, const unsigned char* ghosts, unsigned char ghostsToSkip = 0xff);
684
686
698 virtual bool ComputeFiniteVectorRange(double range[2]);
700 double range[2], const unsigned char* ghosts, unsigned char ghostsToSkip = 0xff);
702
703 // Construct object with default tuple dimension (number of components) of 1.
705 ~vtkDataArray() override;
706
708 double Range[2];
709 double FiniteRange[2];
710
711private:
712 double* GetTupleN(vtkIdType i, int n);
713
714 vtkDataArray(const vtkDataArray&) = delete;
715 void operator=(const vtkDataArray&) = delete;
716};
717
718//------------------------------------------------------------------------------
720{
721 if (source)
722 {
723 switch (source->GetArrayType())
724 {
727 case ImplicitArray:
728 case TypedDataArray:
729 case DataArray:
730 case MappedDataArray:
731 return static_cast<vtkDataArray*>(source);
732 default:
733 break;
734 }
735 }
736 return nullptr;
737}
738
740VTK_ABI_NAMESPACE_END
741
742// These are used by vtkDataArrayPrivate.txx, but need to be available to
743// vtkGenericDataArray.h as well.
745{
746VTK_ABI_NAMESPACE_BEGIN
748{
749};
751{
752};
753VTK_ABI_NAMESPACE_END
754}
755
756#endif
Abstract superclass for all arrays.
int GetNumberOfComponents() const
Set/Get the dimension (n) of the components.
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.
vtkIdType GetNumberOfValues() const
Get the total number of values in the array.
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 void GetIntegerTuple(vtkIdType tupleIdx, vtkTypeInt64 *tuple)
Get/set the data at tupleIdx by filling in a user-provided array of integers.
virtual void SetIntegerTuple(vtkIdType tupleIdx, vtkTypeInt64 *tuple)
Get/set the data at tupleIdx by filling in a user-provided array of integers.
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 SetUnsignedTuple(vtkIdType tupleIdx, vtkTypeUInt64 *tuple)
Get/set the data at tupleIdx by filling in a user-provided array of unsigned integers.
virtual void GetUnsignedTuple(vtkIdType tupleIdx, vtkTypeUInt64 *tuple)
Get/set the data at tupleIdx by filling in a user-provided array of unsigned integers.
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:24
a simple class to control print indentation
Definition vtkIndent.h:29
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:30
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_MARSHALMANUAL
#define VTK_NEWINSTANCE