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
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 
36 VTK_ABI_NAMESPACE_BEGIN
37 class vtkDoubleArray;
38 class vtkIdList;
41 class vtkLookupTable;
42 class vtkPoints;
43 
44 class VTKCOMMONCORE_EXPORT vtkDataArray : public vtkAbstractArray
45 {
46 public:
48  void PrintSelf(ostream& os, vtkIndent indent) override;
49 
56  static vtkDataArray* FastDownCast(vtkAbstractArray* source);
57 
64  int IsNumeric() const override { return 1; }
65 
71  int GetElementComponentSize() const override { return this->GetDataTypeSize(); }
72 
73  // Reimplemented virtuals (doc strings are inherited from superclass):
75 
80  void InsertTuple(vtkIdType dstTupleIdx, vtkIdType srcTupleIdx, vtkAbstractArray* source) override;
82  void InsertTuples(vtkIdList* dstIds, vtkIdList* srcIds, vtkAbstractArray* source) override;
84  vtkIdType dstStart, vtkIdType n, vtkIdType srcStart, vtkAbstractArray* source) override;
86  vtkIdType dstStart, vtkIdList* srcIds, vtkAbstractArray* source) override;
87  void SetTuple(vtkIdType dstTupleIdx, vtkIdType srcTupleIdx, vtkAbstractArray* source) override;
89  void GetTuples(vtkIdList* tupleIds, vtkAbstractArray* output) override;
90  void GetTuples(vtkIdType p1, vtkIdType p2, vtkAbstractArray* output) override;
92  double* weights) override;
93  void InterpolateTuple(vtkIdType dstTupleIdx, vtkIdType srcTupleIdx1, vtkAbstractArray* source1,
94  vtkIdType srcTupleIdx2, vtkAbstractArray* source2, double t) override;
95 
101  virtual double* GetTuple(vtkIdType tupleIdx)
102  VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples()) = 0;
103 
109  virtual void GetTuple(vtkIdType tupleIdx, double* tuple)
110  VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples()) = 0;
111 
113 
118  double GetTuple1(vtkIdType tupleIdx) VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
119  double* GetTuple2(vtkIdType tupleIdx) VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples())
120  VTK_SIZEHINT(2);
121  double* GetTuple3(vtkIdType tupleIdx) VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples())
122  VTK_SIZEHINT(3);
123  double* GetTuple4(vtkIdType tupleIdx) VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples())
124  VTK_SIZEHINT(4);
125  double* GetTuple6(vtkIdType tupleIdx) VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples())
126  VTK_SIZEHINT(6);
127  double* GetTuple9(vtkIdType tupleIdx) VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples())
128  VTK_SIZEHINT(9);
130 
132 
137  virtual void SetTuple(vtkIdType tupleIdx, const float* tuple)
138  VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
139  virtual void SetTuple(vtkIdType tupleIdx, const double* tuple)
140  VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
142 
144 
149  void SetTuple1(vtkIdType tupleIdx, double value)
150  VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
151  void SetTuple2(vtkIdType tupleIdx, double val0, double val1)
152  VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
153  void SetTuple3(vtkIdType tupleIdx, double val0, double val1, double val2)
154  VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
155  void SetTuple4(vtkIdType tupleIdx, double val0, double val1, double val2, double val3)
156  VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
157  void SetTuple6(vtkIdType tupleIdx, double val0, double val1, double val2, double val3,
158  double val4, double val5) VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
159  void SetTuple9(vtkIdType tupleIdx, double val0, double val1, double val2, double val3,
160  double val4, double val5, double val6, double val7, double val8)
161  VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
163 
165 
169  virtual void InsertTuple(vtkIdType tupleIdx, const float* tuple) VTK_EXPECTS(0 <= tupleIdx) = 0;
170  virtual void InsertTuple(vtkIdType tupleIdx, const double* tuple) VTK_EXPECTS(0 <= tupleIdx) = 0;
172 
174 
179  void InsertTuple1(vtkIdType tupleIdx, double value) VTK_EXPECTS(0 <= tupleIdx);
180  void InsertTuple2(vtkIdType tupleIdx, double val0, double val1) VTK_EXPECTS(0 <= tupleIdx);
181  void InsertTuple3(vtkIdType tupleIdx, double val0, double val1, double val2)
182  VTK_EXPECTS(0 <= tupleIdx);
183  void InsertTuple4(vtkIdType tupleIdx, double val0, double val1, double val2, double val3)
184  VTK_EXPECTS(0 <= tupleIdx);
185  void InsertTuple6(vtkIdType tupleIdx, double val0, double val1, double val2, double val3,
186  double val4, double val5) VTK_EXPECTS(0 <= tupleIdx);
187  void InsertTuple9(vtkIdType tupleIdx, double val0, double val1, double val2, double val3,
188  double val4, double val5, double val6, double val7, double val8) VTK_EXPECTS(0 <= tupleIdx);
190 
192 
197  virtual vtkIdType InsertNextTuple(const float* tuple) = 0;
198  virtual vtkIdType InsertNextTuple(const double* tuple) = 0;
200 
202 
207  void InsertNextTuple1(double value);
208  void InsertNextTuple2(double val0, double val1);
209  void InsertNextTuple3(double val0, double val1, double val2);
210  void InsertNextTuple4(double val0, double val1, double val2, double val3);
211  void InsertNextTuple6(
212  double val0, double val1, double val2, double val3, double val4, double val5);
213  void InsertNextTuple9(double val0, double val1, double val2, double val3, double val4,
214  double val5, double val6, double val7, double val8);
216 
218 
223  virtual void RemoveTuple(vtkIdType tupleIdx)
224  VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples()) = 0;
225  virtual void RemoveFirstTuple() { this->RemoveTuple(0); }
226  virtual void RemoveLastTuple();
228 
233  virtual double GetComponent(vtkIdType tupleIdx, int compIdx) VTK_EXPECTS(0 <= tupleIdx &&
234  tupleIdx < GetNumberOfTuples()) VTK_EXPECTS(0 <= compIdx && compIdx < GetNumberOfComponents());
235 
243  virtual void SetComponent(vtkIdType tupleIdx, int compIdx, double value)
244  VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples())
245  VTK_EXPECTS(0 <= compIdx && compIdx < GetNumberOfComponents());
246 
251  virtual void InsertComponent(vtkIdType tupleIdx, int compIdx, double value)
252  VTK_EXPECTS(0 <= tupleIdx) VTK_EXPECTS(0 <= compIdx && compIdx < GetNumberOfComponents());
253 
262  virtual void GetData(
263  vtkIdType tupleMin, vtkIdType tupleMax, int compMin, int compMax, vtkDoubleArray* data);
264 
266 
270  void DeepCopy(vtkAbstractArray* aa) override;
271  virtual void DeepCopy(vtkDataArray* da);
273 
283  virtual void ShallowCopy(vtkDataArray* other);
284 
291  virtual void FillComponent(int compIdx, double value)
292  VTK_EXPECTS(0 <= compIdx && compIdx < GetNumberOfComponents());
293 
297  virtual void Fill(double value);
298 
307  virtual void CopyComponent(int dstComponent, vtkDataArray* src, int srcComponent);
308 
314  virtual void* WriteVoidPointer(vtkIdType valueIdx, vtkIdType numValues) = 0;
315 
324  unsigned long GetActualMemorySize() const override;
325 
330  void CreateDefaultLookupTable();
331 
333 
336  void SetLookupTable(vtkLookupTable* lut);
337  vtkGetObjectMacro(LookupTable, vtkLookupTable);
339 
341 
358  void GetRange(double range[2], int comp) { this->ComputeRange(range, comp); }
359  void GetRange(double range[2], int comp, const unsigned char* ghosts, unsigned char ghostsToSkip)
360  {
361  this->ComputeRange(range, comp, ghosts, ghostsToSkip);
362  }
364 
366 
374  double* GetRange(int comp) VTK_SIZEHINT(2)
375  {
376  this->GetRange(this->Range, comp);
377  return this->Range;
378  }
380 
388  double* GetRange() VTK_SIZEHINT(2) { return this->GetRange(0); }
389 
398  void GetRange(double range[2]) { this->GetRange(range, 0); }
399 
401 
419  void GetFiniteRange(double range[2], int comp) { this->ComputeFiniteRange(range, comp); }
421  double range[2], int comp, const unsigned char* ghosts, unsigned char ghostsToSkip)
422  {
423  this->ComputeFiniteRange(range, comp, ghosts, ghostsToSkip);
424  }
426 
428 
436  double* GetFiniteRange(int comp) VTK_SIZEHINT(2)
437  {
438  this->GetFiniteRange(this->FiniteRange, comp);
439  return this->FiniteRange;
440  }
442 
450  double* GetFiniteRange() VTK_SIZEHINT(2) { return this->GetFiniteRange(0); }
451 
460  void GetFiniteRange(double range[2]) { this->GetFiniteRange(range, 0); }
461 
463 
468  void GetDataTypeRange(double range[2]);
469  double GetDataTypeMin();
470  double GetDataTypeMax();
471  static void GetDataTypeRange(int type, double range[2]);
472  static double GetDataTypeMin(int type);
473  static double GetDataTypeMax(int type);
475 
480  virtual double GetMaxNorm();
481 
491  static vtkDataArray* CreateDataArray(int dataType);
492 
501 
510 
519 
523  void Modified() override;
524 
529 
537  int CopyInformation(vtkInformation* infoFrom, vtkTypeBool deep = 1) override;
538 
542  int GetArrayType() const override { return DataArray; }
543 
544 protected:
545  friend class vtkPoints;
546  friend class vtkFieldData;
547 
549 
565  virtual void ComputeRange(double range[2], int comp);
566  virtual void ComputeRange(
567  double range[2], int comp, const unsigned char* ghosts, unsigned char ghostsToSkip = 0xff);
569 
571 
587  virtual void ComputeFiniteRange(double range[2], int comp);
588  virtual void ComputeFiniteRange(
589  double range[2], int comp, const unsigned char* ghosts, unsigned char ghostsToSkip = 0xff);
591 
593 
608  virtual bool ComputeScalarRange(double* ranges);
609  virtual bool ComputeScalarRange(
610  double* ranges, const unsigned char* ghosts, unsigned char ghostsToSkip = 0xff);
612 
614 
626  virtual bool ComputeVectorRange(double range[2]);
627  virtual bool ComputeVectorRange(
628  double range[2], const unsigned char* ghosts, unsigned char ghostsToSkip = 0xff);
630 
632 
646  virtual bool ComputeFiniteScalarRange(double* ranges);
648  double* ranges, const unsigned char* ghosts, unsigned char ghostsToSkip = 0xff);
650 
652 
664  virtual bool ComputeFiniteVectorRange(double range[2]);
666  double range[2], const unsigned char* ghosts, unsigned char ghostsToSkip = 0xff);
668 
669  // Construct object with default tuple dimension (number of components) of 1.
671  ~vtkDataArray() override;
672 
674  double Range[2];
675  double FiniteRange[2];
676 
677 private:
678  double* GetTupleN(vtkIdType i, int n);
679 
680  vtkDataArray(const vtkDataArray&) = delete;
681  void operator=(const vtkDataArray&) = delete;
682 };
683 
684 //------------------------------------------------------------------------------
686 {
687  if (source)
688  {
689  switch (source->GetArrayType())
690  {
693  case ImplicitArray:
694  case TypedDataArray:
695  case DataArray:
696  case MappedDataArray:
697  return static_cast<vtkDataArray*>(source);
698  default:
699  break;
700  }
701  }
702  return nullptr;
703 }
704 
706 VTK_ABI_NAMESPACE_END
707 
708 // These are used by vtkDataArrayPrivate.txx, but need to be available to
709 // vtkGenericDataArray.h as well.
711 {
712 VTK_ABI_NAMESPACE_BEGIN
713 struct AllValues
714 {
715 };
717 {
718 };
719 VTK_ABI_NAMESPACE_END
720 }
721 
722 #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
Definition: vtkDataArray.h:45
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.
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...
static vtkInformationDoubleVectorKey * L2_NORM_RANGE()
This key is used to hold tight bounds on the $L_2$ norm of tuples in the array.
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.
Definition: vtkDataArray.h:64
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.
virtual bool ComputeScalarRange(double *ranges)
Computes the range for each component of an array, the length of ranges must be two times the number ...
double * GetFiniteRange(int comp)
Return the range of the data array values for the given component.
Definition: vtkDataArray.h:436
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.
Definition: vtkDataArray.h:542
int GetElementComponentSize() const override
Return the size, in bytes, of the lowest-level element of an array.
Definition: vtkDataArray.h:71
virtual bool ComputeFiniteVectorRange(double range[2])
Returns true if the range was computed.
virtual void RemoveLastTuple()
These methods remove tuples from the data array.
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...
Definition: vtkDataArray.h:419
double * GetRange(int comp)
Return the range of the data array values for the given component.
Definition: vtkDataArray.h:374
static vtkInformationStringKey * UNITS_LABEL()
A human-readable string indicating the units for the array data.
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.
static vtkInformationDoubleVectorKey * COMPONENT_RANGE()
This key is used to hold tight bounds on the range of one component over all tuples of the array.
void GetRange(double range[2])
The range of the data array values will be returned in the provided range array argument.
Definition: vtkDataArray.h:398
virtual double * GetTuple(vtkIdType tupleIdx)=0
Get the data tuple at tupleIdx.
static vtkDataArray * FastDownCast(vtkAbstractArray *source)
Perform a fast, safe cast from a vtkAbstractArray to a vtkDataArray.
Definition: vtkDataArray.h:685
double * GetRange()
Return the range of the data array.
Definition: vtkDataArray.h:388
double * GetFiniteRange()
Return the range of the data array.
Definition: vtkDataArray.h:450
static vtkInformationDoubleVectorKey * L2_NORM_FINITE_RANGE()
This key is used to hold tight bounds on the $L_2$ norm of tuples in the array.
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.
double * GetTuple2(vtkIdType tupleIdx)
These methods are included as convenience for the wrappers.
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...
Definition: vtkDataArray.h:359
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.
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...
Definition: vtkDataArray.h:420
void GetFiniteRange(double range[2])
The range of the data array values will be returned in the provided range array argument.
Definition: vtkDataArray.h:460
static vtkDataArray * CreateDataArray(int dataType)
Creates an array for dataType where dataType is one of VTK_BIT, VTK_CHAR, VTK_SIGNED_CHAR,...
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
Definition: vtkDataArray.h:673
dynamic, self-adjusting array of double
represent and manipulate fields of data
Definition: vtkFieldData.h:52
list of point or cell ids
Definition: vtkIdList.h:23
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:29
vtkSmartPointer< vtkDataArray > GetData(const Ioss::GroupingEntity *entity, const std::string &fieldname, Ioss::Transform *transform=nullptr, Cache *cache=nullptr, const std::string &cachekey=std::string())
Returns a VTK array for a given field (fieldname) on the chosen block (or set) entity.
@ value
Definition: vtkX3D.h:220
@ range
Definition: vtkX3D.h:238
@ type
Definition: vtkX3D.h:516
@ data
Definition: vtkX3D.h:315
auto Range(IterablePtr iterable, Options &&... opts) -> typename detail::IterableTraits< typename detail::StripPointers< IterablePtr >::type >::RangeType
Generate an iterable STL proxy object for a VTK container.
Definition: vtkRange.h:74
int vtkTypeBool
Definition: vtkABI.h:64
boost::graph_traits< vtkGraph * >::vertex_descriptor source(boost::graph_traits< vtkGraph * >::edge_descriptor e, vtkGraph *)
#define vtkDataArray
Definition: vtkCharArray.h:37
vtkArrayDownCast_FastCastMacro(vtkDataArray)
int vtkIdType
Definition: vtkType.h:315
#define VTK_SIZEHINT(...)
#define VTK_EXPECTS(x)
#define VTK_NEWINSTANCE