VTK  9.3.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 "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;
83  void InsertTuples(
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;
91  void InterpolateTuple(vtkIdType dstTupleIdx, vtkIdList* ptIndices, vtkAbstractArray* source,
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 
500  static vtkInformationDoubleVectorKey* COMPONENT_RANGE();
501 
509  static vtkInformationDoubleVectorKey* L2_NORM_RANGE();
510 
518  static vtkInformationDoubleVectorKey* L2_NORM_FINITE_RANGE();
519 
523  void Modified() override;
524 
528  static vtkInformationStringKey* UNITS_LABEL();
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);
647  virtual bool ComputeFiniteScalarRange(
648  double* ranges, const unsigned char* ghosts, unsigned char ghostsToSkip = 0xff);
650 
652 
664  virtual bool ComputeFiniteVectorRange(double range[2]);
665  virtual bool ComputeFiniteVectorRange(
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.
670  vtkDataArray();
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
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:398
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
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:542
Store vtkAlgorithm input/output information.
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:420
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
int vtkIdType
Definition: vtkType.h:315
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:71
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
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:436
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:374
int vtkTypeBool
Definition: vtkABI.h:64
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:37
Key for double vector values.
double * GetFiniteRange()
Return the range of the data array.
Definition: vtkDataArray.h:450
a simple class to control print indentation
Definition: vtkIndent.h:28
double * GetRange()
Return the range of the data array.
Definition: vtkDataArray.h:388
virtual int CopyInformation(vtkInformation *infoFrom, vtkTypeBool deep=1)
Copy information instance.
list of point or cell ids
Definition: vtkIdList.h:22
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:44
vtkLookupTable * LookupTable
Definition: vtkDataArray.h:673
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 *)
virtual int GetArrayType() const
Method for type-checking in FastDownCast implementations.
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.
int IsNumeric() const override
This method is here to make backward compatibility easier.
Definition: vtkDataArray.h:64
virtual vtkIdType InsertNextTuple(vtkIdType srcTupleIdx, vtkAbstractArray *source)=0
Insert the tuple from srcTupleIdx in the source array at the end of this array.
static vtkDataArray * FastDownCast(vtkAbstractArray *source)
Perform a fast, safe cast from a vtkAbstractArray to a vtkDataArray.
Definition: vtkDataArray.h:685
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...
vtkArrayDownCast_FastCastMacro(vtkDataArray)
#define VTK_EXPECTS(x)
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:28
represent and manipulate fields of data
Definition: vtkFieldData.h:51
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.