VTK  9.5.20251103
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
138#ifndef vtkDataArray_h
139#define vtkDataArray_h
140
141#include "vtkAbstractArray.h"
142#include "vtkCommonCoreModule.h" // For export macro
143#include "vtkWrappingHints.h" // For VTK_MARSHALMANUAL
144
145VTK_ABI_NAMESPACE_BEGIN
146class vtkDoubleArray;
147class vtkIdList;
150class vtkLookupTable;
151class vtkPoints;
152
153class VTKCOMMONCORE_EXPORT VTK_MARSHALMANUAL vtkDataArray : public vtkAbstractArray
154{
155public:
157 void PrintSelf(ostream& os, vtkIndent indent) override;
158 using ArrayTypeTag = std::integral_constant<int, vtkArrayTypes::VTK_DATA_ARRAY>;
159 using typename vtkAbstractArray::DataTypeTag;
160
168
175 int IsNumeric() const override { return 1; }
176
182 int GetElementComponentSize() const override { return this->GetDataTypeSize(); }
183
184 // Reimplemented virtuals (doc strings are inherited from superclass):
186
191 void InsertTuple(vtkIdType dstTupleIdx, vtkIdType srcTupleIdx, vtkAbstractArray* source) override;
193 void InsertTuples(vtkIdList* dstIds, vtkIdList* srcIds, vtkAbstractArray* source) override;
195 vtkIdType dstStart, vtkIdType n, vtkIdType srcStart, vtkAbstractArray* source) override;
197 vtkIdType dstStart, vtkIdList* srcIds, vtkAbstractArray* source) override;
198 void SetTuple(vtkIdType dstTupleIdx, vtkIdType srcTupleIdx, vtkAbstractArray* source) override;
200 void GetTuples(vtkIdList* tupleIds, vtkAbstractArray* output) override;
201 void GetTuples(vtkIdType p1, vtkIdType p2, vtkAbstractArray* output) override;
203 double* weights) override;
204 void InterpolateTuple(vtkIdType dstTupleIdx, vtkIdType srcTupleIdx1, vtkAbstractArray* source1,
205 vtkIdType srcTupleIdx2, vtkAbstractArray* source2, double t) override;
206
212 virtual double* GetTuple(vtkIdType tupleIdx)
213 VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples()) = 0;
214
220 virtual void GetTuple(vtkIdType tupleIdx, double* tuple)
221 VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples()) = 0;
222
224
233 virtual void GetIntegerTuple(vtkIdType tupleIdx, vtkTypeInt64* tuple)
234 VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
235 virtual void SetIntegerTuple(vtkIdType tupleIdx, vtkTypeInt64* tuple)
236 VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
238
240
249 virtual void GetUnsignedTuple(vtkIdType tupleIdx, vtkTypeUInt64* tuple)
250 VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
251 virtual void SetUnsignedTuple(vtkIdType tupleIdx, vtkTypeUInt64* tuple)
252 VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
254
256
261 double GetTuple1(vtkIdType tupleIdx) VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
262 double* GetTuple2(vtkIdType tupleIdx) VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples())
263 VTK_SIZEHINT(2);
264 double* GetTuple3(vtkIdType tupleIdx) VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples())
265 VTK_SIZEHINT(3);
266 double* GetTuple4(vtkIdType tupleIdx) VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples())
267 VTK_SIZEHINT(4);
268 double* GetTuple6(vtkIdType tupleIdx) VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples())
269 VTK_SIZEHINT(6);
270 double* GetTuple9(vtkIdType tupleIdx) VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples())
271 VTK_SIZEHINT(9);
273
275
280 virtual void SetTuple(vtkIdType tupleIdx, const float* tuple)
281 VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
282 virtual void SetTuple(vtkIdType tupleIdx, const double* tuple)
283 VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
285
287
292 void SetTuple1(vtkIdType tupleIdx, double value)
293 VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
294 void SetTuple2(vtkIdType tupleIdx, double val0, double val1)
295 VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
296 void SetTuple3(vtkIdType tupleIdx, double val0, double val1, double val2)
297 VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
298 void SetTuple4(vtkIdType tupleIdx, double val0, double val1, double val2, double val3)
299 VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
300 void SetTuple6(vtkIdType tupleIdx, double val0, double val1, double val2, double val3,
301 double val4, double val5) VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
302 void SetTuple9(vtkIdType tupleIdx, double val0, double val1, double val2, double val3,
303 double val4, double val5, double val6, double val7, double val8)
304 VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
306
308
312 virtual void InsertTuple(vtkIdType tupleIdx, const float* tuple) VTK_EXPECTS(0 <= tupleIdx) = 0;
313 virtual void InsertTuple(vtkIdType tupleIdx, const double* tuple) VTK_EXPECTS(0 <= tupleIdx) = 0;
315
317
322 void InsertTuple1(vtkIdType tupleIdx, double value) VTK_EXPECTS(0 <= tupleIdx);
323 void InsertTuple2(vtkIdType tupleIdx, double val0, double val1) VTK_EXPECTS(0 <= tupleIdx);
324 void InsertTuple3(vtkIdType tupleIdx, double val0, double val1, double val2)
325 VTK_EXPECTS(0 <= tupleIdx);
326 void InsertTuple4(vtkIdType tupleIdx, double val0, double val1, double val2, double val3)
327 VTK_EXPECTS(0 <= tupleIdx);
328 void InsertTuple6(vtkIdType tupleIdx, double val0, double val1, double val2, double val3,
329 double val4, double val5) VTK_EXPECTS(0 <= tupleIdx);
330 void InsertTuple9(vtkIdType tupleIdx, double val0, double val1, double val2, double val3,
331 double val4, double val5, double val6, double val7, double val8) VTK_EXPECTS(0 <= tupleIdx);
333
335
340 virtual vtkIdType InsertNextTuple(const float* tuple) = 0;
341 virtual vtkIdType InsertNextTuple(const double* tuple) = 0;
343
345
350 void InsertNextTuple1(double value);
351 void InsertNextTuple2(double val0, double val1);
352 void InsertNextTuple3(double val0, double val1, double val2);
353 void InsertNextTuple4(double val0, double val1, double val2, double val3);
354 void InsertNextTuple6(
355 double val0, double val1, double val2, double val3, double val4, double val5);
356 void InsertNextTuple9(double val0, double val1, double val2, double val3, double val4,
357 double val5, double val6, double val7, double val8);
359
361
366 virtual void RemoveTuple(vtkIdType tupleIdx)
367 VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples()) = 0;
368 virtual void RemoveFirstTuple() { this->RemoveTuple(0); }
369 virtual void RemoveLastTuple();
371
376 virtual double GetComponent(vtkIdType tupleIdx, int compIdx)
377 VTK_EXPECTS(0 <= tupleIdx && GetNumberOfComponents() * tupleIdx + compIdx < GetNumberOfValues())
378 VTK_EXPECTS(0 <= compIdx && compIdx < GetNumberOfComponents());
379
387 virtual void SetComponent(vtkIdType tupleIdx, int compIdx, double value)
388 VTK_EXPECTS(0 <= tupleIdx && GetNumberOfComponents() * tupleIdx + compIdx < GetNumberOfValues())
389 VTK_EXPECTS(0 <= compIdx && compIdx < GetNumberOfComponents());
390
395 virtual void InsertComponent(vtkIdType tupleIdx, int compIdx, double value)
396 VTK_EXPECTS(0 <= tupleIdx) VTK_EXPECTS(0 <= compIdx && compIdx < GetNumberOfComponents());
397
406 virtual void GetData(
407 vtkIdType tupleMin, vtkIdType tupleMax, int compMin, int compMax, vtkDoubleArray* data);
408
410
414 void DeepCopy(vtkAbstractArray* aa) override;
415 virtual void DeepCopy(vtkDataArray* da);
417
427 virtual void ShallowCopy(vtkDataArray* other);
428
435 virtual void FillComponent(int compIdx, double value)
436 VTK_EXPECTS(0 <= compIdx && compIdx < GetNumberOfComponents());
437
441 virtual void Fill(double value);
442
444
455 bool CopyComponent(int dstComponent, vtkAbstractArray* src, int srcComponent) override;
456 virtual bool CopyComponent(int dstComponent, vtkDataArray* src, int srcComponent);
458
464 virtual void* WriteVoidPointer(vtkIdType valueIdx, vtkIdType numValues) = 0;
465
474 unsigned long GetActualMemorySize() const override;
475
480 void CreateDefaultLookupTable();
481
483
486 void SetLookupTable(vtkLookupTable* lut);
487 vtkGetObjectMacro(LookupTable, vtkLookupTable);
489
491
508 void GetRange(double range[2], int comp) { this->ComputeRange(range, comp); }
509 void GetRange(double range[2], int comp, const unsigned char* ghosts, unsigned char ghostsToSkip)
510 {
511 this->ComputeRange(range, comp, ghosts, ghostsToSkip);
512 }
514
516
524 double* GetRange(int comp) VTK_SIZEHINT(2)
525 {
526 this->GetRange(this->Range, comp);
527 return this->Range;
528 }
530
538 double* GetRange() VTK_SIZEHINT(2) { return this->GetRange(0); }
539
548 void GetRange(double range[2]) { this->GetRange(range, 0); }
549
551
569 void GetFiniteRange(double range[2], int comp) { this->ComputeFiniteRange(range, comp); }
571 double range[2], int comp, const unsigned char* ghosts, unsigned char ghostsToSkip)
572 {
573 this->ComputeFiniteRange(range, comp, ghosts, ghostsToSkip);
574 }
576
578
586 double* GetFiniteRange(int comp) VTK_SIZEHINT(2)
587 {
588 this->GetFiniteRange(this->FiniteRange, comp);
589 return this->FiniteRange;
590 }
592
600 double* GetFiniteRange() VTK_SIZEHINT(2) { return this->GetFiniteRange(0); }
601
610 void GetFiniteRange(double range[2]) { this->GetFiniteRange(range, 0); }
611
613
618 void GetDataTypeRange(double range[2]);
621 static void GetDataTypeRange(int type, double range[2]);
622 static double GetDataTypeMin(int type);
623 static double GetDataTypeMax(int type);
625
630 virtual double GetMaxNorm();
631
641 static vtkDataArray* CreateDataArray(int dataType);
642
652
662
672
676 void Modified() override;
677
683
691 int CopyInformation(vtkInformation* infoFrom, vtkTypeBool deep = 1) override;
692
696 int GetArrayType() const override { return vtkDataArray::ArrayTypeTag::value; }
697
698protected:
699 friend class vtkPoints;
700 friend class vtkFieldData;
701
703
719 virtual void ComputeRange(double range[2], int comp);
720 virtual void ComputeRange(
721 double range[2], int comp, const unsigned char* ghosts, unsigned char ghostsToSkip = 0xff);
723
725
741 virtual void ComputeFiniteRange(double range[2], int comp);
742 virtual void ComputeFiniteRange(
743 double range[2], int comp, const unsigned char* ghosts, unsigned char ghostsToSkip = 0xff);
745
747
762 virtual bool ComputeScalarRange(double* ranges);
763 virtual bool ComputeScalarRange(
764 double* ranges, const unsigned char* ghosts, unsigned char ghostsToSkip = 0xff);
766
768
780 virtual bool ComputeVectorRange(double range[2]);
781 virtual bool ComputeVectorRange(
782 double range[2], const unsigned char* ghosts, unsigned char ghostsToSkip = 0xff);
784
786
800 virtual bool ComputeFiniteScalarRange(double* ranges);
802 double* ranges, const unsigned char* ghosts, unsigned char ghostsToSkip = 0xff);
804
806
818 virtual bool ComputeFiniteVectorRange(double range[2]);
820 double range[2], const unsigned char* ghosts, unsigned char ghostsToSkip = 0xff);
822
823 // Construct object with default tuple dimension (number of components) of 1.
825 ~vtkDataArray() override;
826
828 double Range[2];
829 double FiniteRange[2];
830
831private:
832 double* GetTupleN(vtkIdType i, int n);
833
834 vtkDataArray(const vtkDataArray&) = delete;
835 void operator=(const vtkDataArray&) = delete;
836};
837
839VTK_ABI_NAMESPACE_END
840
841// These are used by vtkDataArrayPrivate.txx, but need to be available to
842// vtkGenericDataArray.h as well.
843namespace vtkDataArrayPrivate
844{
845VTK_ABI_NAMESPACE_BEGIN
847{
848};
850{
851};
852VTK_ABI_NAMESPACE_END
853}
854
855#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.
std::integral_constant< int, VTK_OPAQUE > DataTypeTag
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.
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.
static vtkDataArray * FastDownCast(vtkAbstractArray *source)
Perform a fast, safe cast from a vtkAbstractArray to a vtkDataArray.
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).
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.
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.
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.
std::integral_constant< int, vtkArrayTypes::VTK_DATA_ARRAY > ArrayTypeTag
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.
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
Represents and manipulates a collection of data arrays.
list of point or cell ids
Definition vtkIdList.h:133
a simple class to control print indentation
Definition vtkIndent.h:108
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:139
static vtkInformationDoubleVectorKey * COMPONENT_RANGE()
This key is used to hold tight bounds on the range of one component over all tuples of the array.
static vtkInformationDoubleVectorKey * L2_NORM_RANGE()
This key is used to hold tight bounds on the $L_2$ norm of tuples in the array.
static vtkInformationDoubleVectorKey * L2_NORM_FINITE_RANGE()
This key is used to hold tight bounds on the $L_2$ norm of tuples in the array.
static vtkInformationStringKey * UNITS_LABEL()
A human-readable string indicating the units for the array data.
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:367
#define VTK_SIZEHINT(...)
#define VTK_EXPECTS(x)
#define VTK_MARSHALMANUAL
#define VTK_NEWINSTANCE