VTK  9.7.1
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 "vtkWrappingHints.h" // For VTK_MARSHALMANUAL
35 
36 VTK_ABI_NAMESPACE_BEGIN
37 class vtkDoubleArray;
38 class vtkIdList;
41 class vtkLookupTable;
42 class vtkPoints;
43 
44 class VTKCOMMONCORE_EXPORT VTK_MARSHALMANUAL vtkDataArray : public vtkAbstractArray
45 {
46 public:
48  void PrintSelf(ostream& os, vtkIndent indent) override;
49  using ArrayTypeTag = std::integral_constant<int, vtkArrayTypes::VTK_DATA_ARRAY>;
50  using typename vtkAbstractArray::DataTypeTag;
51 
58  static vtkDataArray* FastDownCast(vtkAbstractArray* source);
59 
66  int IsNumeric() const override { return 1; }
67 
73  int GetElementComponentSize() const override { return this->GetDataTypeSize(); }
74 
75  // Reimplemented virtuals (doc strings are inherited from superclass):
77 
82  void InsertTuple(vtkIdType dstTupleIdx, vtkIdType srcTupleIdx, vtkAbstractArray* source) override;
84  void InsertTuples(vtkIdList* dstIds, vtkIdList* srcIds, vtkAbstractArray* source) override;
85  void InsertTuples(
86  vtkIdType dstStart, vtkIdType n, vtkIdType srcStart, vtkAbstractArray* source) override;
88  vtkIdType dstStart, vtkIdList* srcIds, vtkAbstractArray* source) override;
89  void SetTuple(vtkIdType dstTupleIdx, vtkIdType srcTupleIdx, vtkAbstractArray* source) override;
91  void GetTuples(vtkIdList* tupleIds, vtkAbstractArray* output) override;
92  void GetTuples(vtkIdType p1, vtkIdType p2, vtkAbstractArray* output) override;
93  void InterpolateTuple(vtkIdType dstTupleIdx, vtkIdList* ptIndices, vtkAbstractArray* source,
94  double* weights) override;
95  void InterpolateTuple(vtkIdType dstTupleIdx, vtkIdType srcTupleIdx1, vtkAbstractArray* source1,
96  vtkIdType srcTupleIdx2, vtkAbstractArray* source2, double t) override;
97 
103  virtual double* GetTuple(vtkIdType tupleIdx)
104  VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples()) = 0;
105 
111  virtual void GetTuple(vtkIdType tupleIdx, double* tuple)
112  VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples()) = 0;
113 
115 
124  virtual void GetIntegerTuple(vtkIdType tupleIdx, vtkTypeInt64* tuple)
125  VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
126  virtual void SetIntegerTuple(vtkIdType tupleIdx, vtkTypeInt64* tuple)
127  VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
129 
131 
140  virtual void GetUnsignedTuple(vtkIdType tupleIdx, vtkTypeUInt64* tuple)
141  VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
142  virtual void SetUnsignedTuple(vtkIdType tupleIdx, vtkTypeUInt64* tuple)
143  VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
145 
147 
152  double GetTuple1(vtkIdType tupleIdx) VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
153  double* GetTuple2(vtkIdType tupleIdx) VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples())
154  VTK_SIZEHINT(2);
155  double* GetTuple3(vtkIdType tupleIdx) VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples())
156  VTK_SIZEHINT(3);
157  double* GetTuple4(vtkIdType tupleIdx) VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples())
158  VTK_SIZEHINT(4);
159  double* GetTuple6(vtkIdType tupleIdx) VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples())
160  VTK_SIZEHINT(6);
161  double* GetTuple9(vtkIdType tupleIdx) VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples())
162  VTK_SIZEHINT(9);
164 
166 
171  virtual void SetTuple(vtkIdType tupleIdx, const float* tuple)
172  VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
173  virtual void SetTuple(vtkIdType tupleIdx, const double* tuple)
174  VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
176 
178 
183  void SetTuple1(vtkIdType tupleIdx, double value)
184  VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
185  void SetTuple2(vtkIdType tupleIdx, double val0, double val1)
186  VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
187  void SetTuple3(vtkIdType tupleIdx, double val0, double val1, double val2)
188  VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
189  void SetTuple4(vtkIdType tupleIdx, double val0, double val1, double val2, double val3)
190  VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
191  void SetTuple6(vtkIdType tupleIdx, double val0, double val1, double val2, double val3,
192  double val4, double val5) VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
193  void SetTuple9(vtkIdType tupleIdx, double val0, double val1, double val2, double val3,
194  double val4, double val5, double val6, double val7, double val8)
195  VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
197 
199 
203  virtual void InsertTuple(vtkIdType tupleIdx, const float* tuple) VTK_EXPECTS(0 <= tupleIdx) = 0;
204  virtual void InsertTuple(vtkIdType tupleIdx, const double* tuple) VTK_EXPECTS(0 <= tupleIdx) = 0;
206 
208 
213  void InsertTuple1(vtkIdType tupleIdx, double value) VTK_EXPECTS(0 <= tupleIdx);
214  void InsertTuple2(vtkIdType tupleIdx, double val0, double val1) VTK_EXPECTS(0 <= tupleIdx);
215  void InsertTuple3(vtkIdType tupleIdx, double val0, double val1, double val2)
216  VTK_EXPECTS(0 <= tupleIdx);
217  void InsertTuple4(vtkIdType tupleIdx, double val0, double val1, double val2, double val3)
218  VTK_EXPECTS(0 <= tupleIdx);
219  void InsertTuple6(vtkIdType tupleIdx, double val0, double val1, double val2, double val3,
220  double val4, double val5) VTK_EXPECTS(0 <= tupleIdx);
221  void InsertTuple9(vtkIdType tupleIdx, double val0, double val1, double val2, double val3,
222  double val4, double val5, double val6, double val7, double val8) VTK_EXPECTS(0 <= tupleIdx);
224 
226 
231  virtual vtkIdType InsertNextTuple(const float* tuple) = 0;
232  virtual vtkIdType InsertNextTuple(const double* tuple) = 0;
234 
236 
241  void InsertNextTuple1(double value);
242  void InsertNextTuple2(double val0, double val1);
243  void InsertNextTuple3(double val0, double val1, double val2);
244  void InsertNextTuple4(double val0, double val1, double val2, double val3);
245  void InsertNextTuple6(
246  double val0, double val1, double val2, double val3, double val4, double val5);
247  void InsertNextTuple9(double val0, double val1, double val2, double val3, double val4,
248  double val5, double val6, double val7, double val8);
250 
252 
257  virtual void RemoveTuple(vtkIdType tupleIdx)
258  VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples()) = 0;
259  virtual void RemoveFirstTuple() { this->RemoveTuple(0); }
260  virtual void RemoveLastTuple();
262 
267  virtual double GetComponent(vtkIdType tupleIdx, int compIdx)
268  VTK_EXPECTS(0 <= tupleIdx && GetNumberOfComponents() * tupleIdx + compIdx < GetNumberOfValues())
269  VTK_EXPECTS(0 <= compIdx && compIdx < GetNumberOfComponents());
270 
278  virtual void SetComponent(vtkIdType tupleIdx, int compIdx, double value)
279  VTK_EXPECTS(0 <= tupleIdx && GetNumberOfComponents() * tupleIdx + compIdx < GetNumberOfValues())
280  VTK_EXPECTS(0 <= compIdx && compIdx < GetNumberOfComponents());
281 
286  virtual void InsertComponent(vtkIdType tupleIdx, int compIdx, double value)
287  VTK_EXPECTS(0 <= tupleIdx) VTK_EXPECTS(0 <= compIdx && compIdx < GetNumberOfComponents());
288 
297  virtual void GetData(
298  vtkIdType tupleMin, vtkIdType tupleMax, int compMin, int compMax, vtkDoubleArray* data);
299 
301 
305  void DeepCopy(vtkAbstractArray* aa) override;
306  virtual void DeepCopy(vtkDataArray* da);
308 
310 
318  virtual void ShallowCopy(vtkDataArray* other);
319  void ShallowCopy(vtkAbstractArray* other) override;
321 
328  virtual void FillComponent(int compIdx, double value)
329  VTK_EXPECTS(0 <= compIdx && compIdx < GetNumberOfComponents());
330 
334  virtual void Fill(double value);
335 
337 
348  bool CopyComponent(int dstComponent, vtkAbstractArray* src, int srcComponent) override;
349  virtual bool CopyComponent(int dstComponent, vtkDataArray* src, int srcComponent);
351 
357  VTK_DEPRECATED_IN_9_7_0("Use vtkAOSDataArrayTemplate::WritePointer(valueIdx, numValues) or "
358  "vtkAbstractArray::SetNumberOf[Values/Tuples]() instead")
359  virtual void* WriteVoidPointer(vtkIdType valueIdx, vtkIdType numValues) = 0;
360 
369  unsigned long GetActualMemorySize() const override;
370 
375  void CreateDefaultLookupTable();
376 
378 
381  void SetLookupTable(vtkLookupTable* lut);
382  vtkGetObjectMacro(LookupTable, vtkLookupTable);
384 
386 
403  void GetRange(double range[2], int comp) { this->ComputeRange(range, comp); }
404  void GetRange(double range[2], int comp, const unsigned char* ghosts, unsigned char ghostsToSkip)
405  {
406  this->ComputeRange(range, comp, ghosts, ghostsToSkip);
407  }
409 
411 
419  double* GetRange(int comp) VTK_SIZEHINT(2)
420  {
421  this->GetRange(this->Range, comp);
422  return this->Range;
423  }
425 
433  double* GetRange() VTK_SIZEHINT(2) { return this->GetRange(0); }
434 
443  void GetRange(double range[2]) { this->GetRange(range, 0); }
444 
446 
464  void GetFiniteRange(double range[2], int comp) { this->ComputeFiniteRange(range, comp); }
466  double range[2], int comp, const unsigned char* ghosts, unsigned char ghostsToSkip)
467  {
468  this->ComputeFiniteRange(range, comp, ghosts, ghostsToSkip);
469  }
471 
473 
481  double* GetFiniteRange(int comp) VTK_SIZEHINT(2)
482  {
483  this->GetFiniteRange(this->FiniteRange, comp);
484  return this->FiniteRange;
485  }
487 
495  double* GetFiniteRange() VTK_SIZEHINT(2) { return this->GetFiniteRange(0); }
496 
505  void GetFiniteRange(double range[2]) { this->GetFiniteRange(range, 0); }
506 
508 
513  void GetDataTypeRange(double range[2]);
514  double GetDataTypeMin();
515  double GetDataTypeMax();
516  static void GetDataTypeRange(int type, double range[2]);
517  static double GetDataTypeMin(int type);
518  static double GetDataTypeMax(int type);
520 
525  virtual double GetMaxNorm();
526 
536  static vtkDataArray* CreateDataArray(int dataType);
537 
543  vtkSmartPointer<vtkDataArray> ToAOSDataArray();
544 
553  static vtkInformationDoubleVectorKey* COMPONENT_RANGE();
554 
563  static vtkInformationDoubleVectorKey* L2_NORM_RANGE();
564 
573  static vtkInformationDoubleVectorKey* L2_NORM_FINITE_RANGE();
574 
578  void Modified() override;
579 
584  static vtkInformationStringKey* UNITS_LABEL();
585 
593  int CopyInformation(vtkInformation* infoFrom, vtkTypeBool deep = 1) override;
594 
598  int GetArrayType() const override { return vtkDataArray::ArrayTypeTag::value; }
599 
601  {
602  HostMemory, // CPU memory
603  CudaDeviceMemory, // NVIDIA GPU via CUDA
604  HipDeviceMemory, // AMD GPU via HIP
605  };
606 
610  virtual MemorySpace GetMemorySpace() { return MemorySpace::HostMemory; }
611 
616  virtual void* GetDeviceVoidPointer(vtkIdType vtkNotUsed(valueIdx)) { return nullptr; }
617 
618 protected:
619  friend class vtkPoints;
620  friend class vtkFieldData;
621 
623 
639  virtual void ComputeRange(double range[2], int comp);
640  virtual void ComputeRange(
641  double range[2], int comp, const unsigned char* ghosts, unsigned char ghostsToSkip = 0xff);
643 
645 
661  virtual void ComputeFiniteRange(double range[2], int comp);
662  virtual void ComputeFiniteRange(
663  double range[2], int comp, const unsigned char* ghosts, unsigned char ghostsToSkip = 0xff);
665 
667 
682  virtual bool ComputeScalarRange(double* ranges);
683  virtual bool ComputeScalarRange(
684  double* ranges, const unsigned char* ghosts, unsigned char ghostsToSkip = 0xff);
686 
688 
700  virtual bool ComputeVectorRange(double range[2]);
701  virtual bool ComputeVectorRange(
702  double range[2], const unsigned char* ghosts, unsigned char ghostsToSkip = 0xff);
704 
706 
720  virtual bool ComputeFiniteScalarRange(double* ranges);
721  virtual bool ComputeFiniteScalarRange(
722  double* ranges, const unsigned char* ghosts, unsigned char ghostsToSkip = 0xff);
724 
726 
738  virtual bool ComputeFiniteVectorRange(double range[2]);
739  virtual bool ComputeFiniteVectorRange(
740  double range[2], const unsigned char* ghosts, unsigned char ghostsToSkip = 0xff);
742 
743  // Construct object with default tuple dimension (number of components) of 1.
744  vtkDataArray();
745  ~vtkDataArray() override;
746 
748  double Range[2];
749  double FiniteRange[2];
750 
751 private:
752  double* GetTupleN(vtkIdType i, int n);
753 
754  vtkDataArray(const vtkDataArray&) = delete;
755  void operator=(const vtkDataArray&) = delete;
756 };
757 
759 VTK_ABI_NAMESPACE_END
760 
761 // These are used by vtkDataArrayPrivate.txx, but need to be available to
762 // vtkGenericDataArray.h as well.
763 namespace vtkDataArrayPrivate
764 {
765 VTK_ABI_NAMESPACE_BEGIN
766 struct AllValues
767 {
768 };
770 {
771 };
772 VTK_ABI_NAMESPACE_END
773 }
774 
775 #endif
void Modified() override
Removes out-of-date PER_COMPONENT() and PER_FINITE_COMPONENT() values.
void GetRange(double range[2])
The range of the data array values will be returned in the provided range array argument.
Definition: vtkDataArray.h:443
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:464
virtual void InsertTuplesStartingAt(vtkIdType dstStart, vtkIdList *srcIds, vtkAbstractArray *source)=0
Copy the tuples indexed in srcIds from the source array to the tuple locations starting at index dstS...
int GetArrayType() const override
Method for type-checking in FastDownCast implementations.
Definition: vtkDataArray.h:598
Store vtkAlgorithm input/output information.
int GetNumberOfComponents() const
Set/Get the dimension (n) of the components.
virtual void GetTuples(vtkIdList *tupleIds, vtkAbstractArray *output)
Given a list of tuple ids, return an array of tuples.
Abstract superclass for all arrays.
map scalar values into colors via a lookup table
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:465
virtual MemorySpace GetMemorySpace()
Return the MemorySpace of where the data is stored.
Definition: vtkDataArray.h:610
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:404
int vtkIdType
Definition: vtkType.h:363
virtual void InterpolateTuple(vtkIdType dstTupleIdx, vtkIdList *ptIndices, vtkAbstractArray *source, double *weights)=0
Set the tuple at dstTupleIdx in this array to the interpolated tuple value, given the ptIndices in th...
int GetElementComponentSize() const override
Return the size, in bytes, of the lowest-level element of an array.
Definition: vtkDataArray.h:73
void GetFiniteRange(double range[2])
The range of the data array values will be returned in the provided range array argument.
Definition: vtkDataArray.h:505
Key for string values in vtkInformation.
double * GetFiniteRange(int comp)
Return the range of the data array values for the given component.
Definition: vtkDataArray.h:481
dynamic, self-adjusting array of double
double * GetRange(int comp)
Return the range of the data array values for the given component.
Definition: vtkDataArray.h:419
int vtkTypeBool
Definition: vtkABI.h:64
vtkIdType GetNumberOfValues() const
Get the total number of values in the array.
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
virtual int GetDataTypeSize() const =0
Return the size of the underlying data type.
#define vtkDataArray
Definition: vtkCharArray.h:41
Key for double vector values.
#define VTK_MARSHALMANUAL
double * GetFiniteRange()
Return the range of the data array.
Definition: vtkDataArray.h:495
a simple class to control print indentation
Definition: vtkIndent.h:28
double * GetRange()
Return the range of the data array.
Definition: vtkDataArray.h:433
virtual int CopyInformation(vtkInformation *infoFrom, vtkTypeBool deep=1)
Copy information instance.
Array-Of-Structs implementation of vtkGenericDataArray.
list of point or cell ids
Definition: vtkIdList.h:25
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:44
vtkLookupTable * LookupTable
Definition: vtkDataArray.h:747
vtkIdType GetNumberOfTuples() const
Get the number of complete tuples (a component group) in the array.
#define VTK_SIZEHINT(...)
boost::graph_traits< vtkGraph * >::vertex_descriptor source(boost::graph_traits< vtkGraph * >::edge_descriptor e, vtkGraph *)
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.
#define VTK_NEWINSTANCE
virtual void InsertTuple(vtkIdType dstTupleIdx, vtkIdType srcTupleIdx, vtkAbstractArray *source)=0
Insert the tuple at srcTupleIdx in the source array into this array at dstTupleIdx.
std::integral_constant< int, VTK_OPAQUE > DataTypeTag
int IsNumeric() const override
This method is here to make backward compatibility easier.
Definition: vtkDataArray.h:66
virtual vtkIdType InsertNextTuple(vtkIdType srcTupleIdx, vtkAbstractArray *source)=0
Insert the tuple from srcTupleIdx in the source array at the end of this array.
virtual void SetTuple(vtkIdType dstTupleIdx, vtkIdType srcTupleIdx, vtkAbstractArray *source)=0
Set the tuple at dstTupleIdx in this array to the tuple at srcTupleIdx in the source array...
std::integral_constant< int, vtkArrayTypes::VTK_ABSTRACT_ARRAY > ArrayTypeTag
vtkArrayDownCast_FastCastMacro(vtkDataArray)
virtual void * GetDeviceVoidPointer(vtkIdType valueIdx)
Return a pointer to the data that live on a device (CUDA or HIP).
Definition: vtkDataArray.h:616
#define VTK_EXPECTS(x)
#define VTK_DEPRECATED_IN_9_7_0(reason)
virtual void InsertTuples(vtkIdList *dstIds, vtkIdList *srcIds, vtkAbstractArray *source)=0
Copy the tuples indexed in srcIds from the source array to the tuple locations indexed by dstIds in t...
represent and manipulate 3D points
Definition: vtkPoints.h:30
Represents and manipulates a collection of data arrays.
Definition: vtkFieldData.h:51
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.