VTK  9.3.20240726
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 "vtkVTK_USE_SCALED_SOA_ARRAYS.h" // For #define of VTK_USE_SCALED_SOA_ARRAYS
144#include "vtkWrappingHints.h" // For VTK_MARSHALMANUAL
145
146VTK_ABI_NAMESPACE_BEGIN
147class vtkDoubleArray;
148class vtkIdList;
151class vtkLookupTable;
152class vtkPoints;
153
154class VTKCOMMONCORE_EXPORT VTK_MARSHALMANUAL vtkDataArray : public vtkAbstractArray
155{
156public:
158 void PrintSelf(ostream& os, vtkIndent indent) override;
159
166 static vtkDataArray* FastDownCast(vtkAbstractArray* source);
167
174 int IsNumeric() const override { return 1; }
175
181 int GetElementComponentSize() const override { return this->GetDataTypeSize(); }
182
183 // Reimplemented virtuals (doc strings are inherited from superclass):
185
190 void InsertTuple(vtkIdType dstTupleIdx, vtkIdType srcTupleIdx, vtkAbstractArray* source) override;
192 void InsertTuples(vtkIdList* dstIds, vtkIdList* srcIds, vtkAbstractArray* source) override;
194 vtkIdType dstStart, vtkIdType n, vtkIdType srcStart, vtkAbstractArray* source) override;
196 vtkIdType dstStart, vtkIdList* srcIds, vtkAbstractArray* source) override;
197 void SetTuple(vtkIdType dstTupleIdx, vtkIdType srcTupleIdx, vtkAbstractArray* source) override;
199 void GetTuples(vtkIdList* tupleIds, vtkAbstractArray* output) override;
200 void GetTuples(vtkIdType p1, vtkIdType p2, vtkAbstractArray* output) override;
202 double* weights) override;
203 void InterpolateTuple(vtkIdType dstTupleIdx, vtkIdType srcTupleIdx1, vtkAbstractArray* source1,
204 vtkIdType srcTupleIdx2, vtkAbstractArray* source2, double t) override;
205
211 virtual double* GetTuple(vtkIdType tupleIdx)
212 VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples()) = 0;
213
219 virtual void GetTuple(vtkIdType tupleIdx, double* tuple)
220 VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples()) = 0;
221
223
232 virtual void GetIntegerTuple(vtkIdType tupleIdx, vtkTypeInt64* tuple)
233 VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
234 virtual void SetIntegerTuple(vtkIdType tupleIdx, vtkTypeInt64* tuple)
235 VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
237
239
248 virtual void GetUnsignedTuple(vtkIdType tupleIdx, vtkTypeUInt64* tuple)
249 VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
250 virtual void SetUnsignedTuple(vtkIdType tupleIdx, vtkTypeUInt64* tuple)
251 VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
253
255
260 double GetTuple1(vtkIdType tupleIdx) VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
261 double* GetTuple2(vtkIdType tupleIdx) VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples())
262 VTK_SIZEHINT(2);
263 double* GetTuple3(vtkIdType tupleIdx) VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples())
264 VTK_SIZEHINT(3);
265 double* GetTuple4(vtkIdType tupleIdx) VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples())
266 VTK_SIZEHINT(4);
267 double* GetTuple6(vtkIdType tupleIdx) VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples())
268 VTK_SIZEHINT(6);
269 double* GetTuple9(vtkIdType tupleIdx) VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples())
270 VTK_SIZEHINT(9);
272
274
279 virtual void SetTuple(vtkIdType tupleIdx, const float* tuple)
280 VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
281 virtual void SetTuple(vtkIdType tupleIdx, const double* tuple)
282 VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
284
286
291 void SetTuple1(vtkIdType tupleIdx, double value)
292 VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
293 void SetTuple2(vtkIdType tupleIdx, double val0, double val1)
294 VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
295 void SetTuple3(vtkIdType tupleIdx, double val0, double val1, double val2)
296 VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
297 void SetTuple4(vtkIdType tupleIdx, double val0, double val1, double val2, double val3)
298 VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
299 void SetTuple6(vtkIdType tupleIdx, double val0, double val1, double val2, double val3,
300 double val4, double val5) VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
301 void SetTuple9(vtkIdType tupleIdx, double val0, double val1, double val2, double val3,
302 double val4, double val5, double val6, double val7, double val8)
303 VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
305
307
311 virtual void InsertTuple(vtkIdType tupleIdx, const float* tuple) VTK_EXPECTS(0 <= tupleIdx) = 0;
312 virtual void InsertTuple(vtkIdType tupleIdx, const double* tuple) VTK_EXPECTS(0 <= tupleIdx) = 0;
314
316
321 void InsertTuple1(vtkIdType tupleIdx, double value) VTK_EXPECTS(0 <= tupleIdx);
322 void InsertTuple2(vtkIdType tupleIdx, double val0, double val1) VTK_EXPECTS(0 <= tupleIdx);
323 void InsertTuple3(vtkIdType tupleIdx, double val0, double val1, double val2)
324 VTK_EXPECTS(0 <= tupleIdx);
325 void InsertTuple4(vtkIdType tupleIdx, double val0, double val1, double val2, double val3)
326 VTK_EXPECTS(0 <= tupleIdx);
327 void InsertTuple6(vtkIdType tupleIdx, double val0, double val1, double val2, double val3,
328 double val4, double val5) VTK_EXPECTS(0 <= tupleIdx);
329 void InsertTuple9(vtkIdType tupleIdx, double val0, double val1, double val2, double val3,
330 double val4, double val5, double val6, double val7, double val8) VTK_EXPECTS(0 <= tupleIdx);
332
334
339 virtual vtkIdType InsertNextTuple(const float* tuple) = 0;
340 virtual vtkIdType InsertNextTuple(const double* tuple) = 0;
342
344
349 void InsertNextTuple1(double value);
350 void InsertNextTuple2(double val0, double val1);
351 void InsertNextTuple3(double val0, double val1, double val2);
352 void InsertNextTuple4(double val0, double val1, double val2, double val3);
353 void InsertNextTuple6(
354 double val0, double val1, double val2, double val3, double val4, double val5);
355 void InsertNextTuple9(double val0, double val1, double val2, double val3, double val4,
356 double val5, double val6, double val7, double val8);
358
360
365 virtual void RemoveTuple(vtkIdType tupleIdx)
366 VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples()) = 0;
367 virtual void RemoveFirstTuple() { this->RemoveTuple(0); }
368 virtual void RemoveLastTuple();
370
375 virtual double GetComponent(vtkIdType tupleIdx, int compIdx) VTK_EXPECTS(0 <= tupleIdx &&
376 tupleIdx < GetNumberOfTuples()) VTK_EXPECTS(0 <= compIdx && compIdx < GetNumberOfComponents());
377
385 virtual void SetComponent(vtkIdType tupleIdx, int compIdx, double value)
386 VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples())
387 VTK_EXPECTS(0 <= compIdx && compIdx < GetNumberOfComponents());
388
393 virtual void InsertComponent(vtkIdType tupleIdx, int compIdx, double value)
394 VTK_EXPECTS(0 <= tupleIdx) VTK_EXPECTS(0 <= compIdx && compIdx < GetNumberOfComponents());
395
404 virtual void GetData(
405 vtkIdType tupleMin, vtkIdType tupleMax, int compMin, int compMax, vtkDoubleArray* data);
406
408
412 void DeepCopy(vtkAbstractArray* aa) override;
413 virtual void DeepCopy(vtkDataArray* da);
415
425 virtual void ShallowCopy(vtkDataArray* other);
426
433 virtual void FillComponent(int compIdx, double value)
434 VTK_EXPECTS(0 <= compIdx && compIdx < GetNumberOfComponents());
435
439 virtual void Fill(double value);
440
449 virtual void CopyComponent(int dstComponent, vtkDataArray* src, int srcComponent);
450
456 virtual void* WriteVoidPointer(vtkIdType valueIdx, vtkIdType numValues) = 0;
457
466 unsigned long GetActualMemorySize() const override;
467
472 void CreateDefaultLookupTable();
473
475
478 void SetLookupTable(vtkLookupTable* lut);
479 vtkGetObjectMacro(LookupTable, vtkLookupTable);
481
483
500 void GetRange(double range[2], int comp) { this->ComputeRange(range, comp); }
501 void GetRange(double range[2], int comp, const unsigned char* ghosts, unsigned char ghostsToSkip)
502 {
503 this->ComputeRange(range, comp, ghosts, ghostsToSkip);
504 }
506
508
516 double* GetRange(int comp) VTK_SIZEHINT(2)
517 {
518 this->GetRange(this->Range, comp);
519 return this->Range;
520 }
522
530 double* GetRange() VTK_SIZEHINT(2) { return this->GetRange(0); }
531
540 void GetRange(double range[2]) { this->GetRange(range, 0); }
541
543
561 void GetFiniteRange(double range[2], int comp) { this->ComputeFiniteRange(range, comp); }
563 double range[2], int comp, const unsigned char* ghosts, unsigned char ghostsToSkip)
564 {
565 this->ComputeFiniteRange(range, comp, ghosts, ghostsToSkip);
566 }
568
570
578 double* GetFiniteRange(int comp) VTK_SIZEHINT(2)
579 {
580 this->GetFiniteRange(this->FiniteRange, comp);
581 return this->FiniteRange;
582 }
584
592 double* GetFiniteRange() VTK_SIZEHINT(2) { return this->GetFiniteRange(0); }
593
602 void GetFiniteRange(double range[2]) { this->GetFiniteRange(range, 0); }
603
605
610 void GetDataTypeRange(double range[2]);
613 static void GetDataTypeRange(int type, double range[2]);
614 static double GetDataTypeMin(int type);
615 static double GetDataTypeMax(int type);
617
622 virtual double GetMaxNorm();
623
633 static vtkDataArray* CreateDataArray(int dataType);
634
643
652
661
665 void Modified() override;
666
671
679 int CopyInformation(vtkInformation* infoFrom, vtkTypeBool deep = 1) override;
680
684 int GetArrayType() const override { return DataArray; }
685
686protected:
687 friend class vtkPoints;
688 friend class vtkFieldData;
689
691
707 virtual void ComputeRange(double range[2], int comp);
708 virtual void ComputeRange(
709 double range[2], int comp, const unsigned char* ghosts, unsigned char ghostsToSkip = 0xff);
711
713
729 virtual void ComputeFiniteRange(double range[2], int comp);
730 virtual void ComputeFiniteRange(
731 double range[2], int comp, const unsigned char* ghosts, unsigned char ghostsToSkip = 0xff);
733
735
750 virtual bool ComputeScalarRange(double* ranges);
751 virtual bool ComputeScalarRange(
752 double* ranges, const unsigned char* ghosts, unsigned char ghostsToSkip = 0xff);
754
756
768 virtual bool ComputeVectorRange(double range[2]);
769 virtual bool ComputeVectorRange(
770 double range[2], const unsigned char* ghosts, unsigned char ghostsToSkip = 0xff);
772
774
788 virtual bool ComputeFiniteScalarRange(double* ranges);
790 double* ranges, const unsigned char* ghosts, unsigned char ghostsToSkip = 0xff);
792
794
806 virtual bool ComputeFiniteVectorRange(double range[2]);
808 double range[2], const unsigned char* ghosts, unsigned char ghostsToSkip = 0xff);
810
811 // Construct object with default tuple dimension (number of components) of 1.
813 ~vtkDataArray() override;
814
816 double Range[2];
817 double FiniteRange[2];
818
819private:
820 double* GetTupleN(vtkIdType i, int n);
821
822 vtkDataArray(const vtkDataArray&) = delete;
823 void operator=(const vtkDataArray&) = delete;
824};
825
826//------------------------------------------------------------------------------
828{
829 if (source)
830 {
831 switch (source->GetArrayType())
832 {
835 case ImplicitArray:
836 case TypedDataArray:
837 case DataArray:
838 case MappedDataArray:
839 return static_cast<vtkDataArray*>(source);
840 default:
841 break;
842 }
843 }
844 return nullptr;
845}
846
848VTK_ABI_NAMESPACE_END
849
850// These are used by vtkDataArrayPrivate.txx, but need to be available to
851// vtkGenericDataArray.h as well.
853{
854VTK_ABI_NAMESPACE_BEGIN
856{
857};
859{
860};
861VTK_ABI_NAMESPACE_END
862}
863
864#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 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: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
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