VTK  9.2.20230205
vtkDataArray.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkDataArray.h
5 
6  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7  All rights reserved.
8  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10  This software is distributed WITHOUT ANY WARRANTY; without even
11  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12  PURPOSE. See the above copyright notice for more information.
13 
14 =========================================================================*/
150 #ifndef vtkDataArray_h
151 #define vtkDataArray_h
152 
153 #include "vtkAbstractArray.h"
154 #include "vtkCommonCoreModule.h" // For export macro
155 #include "vtkVTK_USE_SCALED_SOA_ARRAYS.h" // For #define of VTK_USE_SCALED_SOA_ARRAYS
156 
157 VTK_ABI_NAMESPACE_BEGIN
158 class vtkDoubleArray;
159 class vtkIdList;
162 class vtkLookupTable;
163 class vtkPoints;
164 
165 class VTKCOMMONCORE_EXPORT vtkDataArray : public vtkAbstractArray
166 {
167 public:
169  void PrintSelf(ostream& os, vtkIndent indent) override;
170 
177  static vtkDataArray* FastDownCast(vtkAbstractArray* source);
178 
185  int IsNumeric() const override { return 1; }
186 
192  int GetElementComponentSize() const override { return this->GetDataTypeSize(); }
193 
194  // Reimplemented virtuals (doc strings are inherited from superclass):
196 
201  void InsertTuple(vtkIdType dstTupleIdx, vtkIdType srcTupleIdx, vtkAbstractArray* source) override;
203  void InsertTuples(vtkIdList* dstIds, vtkIdList* srcIds, vtkAbstractArray* source) override;
205  vtkIdType dstStart, vtkIdType n, vtkIdType srcStart, vtkAbstractArray* source) override;
207  vtkIdType dstStart, vtkIdList* srcIds, vtkAbstractArray* source) override;
208  void SetTuple(vtkIdType dstTupleIdx, vtkIdType srcTupleIdx, vtkAbstractArray* source) override;
210  void GetTuples(vtkIdList* tupleIds, vtkAbstractArray* output) override;
211  void GetTuples(vtkIdType p1, vtkIdType p2, vtkAbstractArray* output) override;
213  double* weights) override;
214  void InterpolateTuple(vtkIdType dstTupleIdx, vtkIdType srcTupleIdx1, vtkAbstractArray* source1,
215  vtkIdType srcTupleIdx2, vtkAbstractArray* source2, double t) override;
216 
222  virtual double* GetTuple(vtkIdType tupleIdx)
223  VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples()) = 0;
224 
230  virtual void GetTuple(vtkIdType tupleIdx, double* tuple)
231  VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples()) = 0;
232 
234 
239  double GetTuple1(vtkIdType tupleIdx) VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
240  double* GetTuple2(vtkIdType tupleIdx) VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples())
241  VTK_SIZEHINT(2);
242  double* GetTuple3(vtkIdType tupleIdx) VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples())
243  VTK_SIZEHINT(3);
244  double* GetTuple4(vtkIdType tupleIdx) VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples())
245  VTK_SIZEHINT(4);
246  double* GetTuple6(vtkIdType tupleIdx) VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples())
247  VTK_SIZEHINT(6);
248  double* GetTuple9(vtkIdType tupleIdx) VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples())
249  VTK_SIZEHINT(9);
251 
253 
258  virtual void SetTuple(vtkIdType tupleIdx, const float* tuple)
259  VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
260  virtual void SetTuple(vtkIdType tupleIdx, const double* tuple)
261  VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
263 
265 
270  void SetTuple1(vtkIdType tupleIdx, double value)
271  VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
272  void SetTuple2(vtkIdType tupleIdx, double val0, double val1)
273  VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
274  void SetTuple3(vtkIdType tupleIdx, double val0, double val1, double val2)
275  VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
276  void SetTuple4(vtkIdType tupleIdx, double val0, double val1, double val2, double val3)
277  VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
278  void SetTuple6(vtkIdType tupleIdx, double val0, double val1, double val2, double val3,
279  double val4, double val5) VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
280  void SetTuple9(vtkIdType tupleIdx, double val0, double val1, double val2, double val3,
281  double val4, double val5, double val6, double val7, double val8)
282  VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
284 
286 
290  virtual void InsertTuple(vtkIdType tupleIdx, const float* tuple) VTK_EXPECTS(0 <= tupleIdx) = 0;
291  virtual void InsertTuple(vtkIdType tupleIdx, const double* tuple) VTK_EXPECTS(0 <= tupleIdx) = 0;
293 
295 
300  void InsertTuple1(vtkIdType tupleIdx, double value) VTK_EXPECTS(0 <= tupleIdx);
301  void InsertTuple2(vtkIdType tupleIdx, double val0, double val1) VTK_EXPECTS(0 <= tupleIdx);
302  void InsertTuple3(vtkIdType tupleIdx, double val0, double val1, double val2)
303  VTK_EXPECTS(0 <= tupleIdx);
304  void InsertTuple4(vtkIdType tupleIdx, double val0, double val1, double val2, double val3)
305  VTK_EXPECTS(0 <= tupleIdx);
306  void InsertTuple6(vtkIdType tupleIdx, double val0, double val1, double val2, double val3,
307  double val4, double val5) VTK_EXPECTS(0 <= tupleIdx);
308  void InsertTuple9(vtkIdType tupleIdx, double val0, double val1, double val2, double val3,
309  double val4, double val5, double val6, double val7, double val8) VTK_EXPECTS(0 <= tupleIdx);
311 
313 
318  virtual vtkIdType InsertNextTuple(const float* tuple) = 0;
319  virtual vtkIdType InsertNextTuple(const double* tuple) = 0;
321 
323 
328  void InsertNextTuple1(double value);
329  void InsertNextTuple2(double val0, double val1);
330  void InsertNextTuple3(double val0, double val1, double val2);
331  void InsertNextTuple4(double val0, double val1, double val2, double val3);
332  void InsertNextTuple6(
333  double val0, double val1, double val2, double val3, double val4, double val5);
334  void InsertNextTuple9(double val0, double val1, double val2, double val3, double val4,
335  double val5, double val6, double val7, double val8);
337 
339 
344  virtual void RemoveTuple(vtkIdType tupleIdx)
345  VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples()) = 0;
346  virtual void RemoveFirstTuple() { this->RemoveTuple(0); }
347  virtual void RemoveLastTuple();
349 
354  virtual double GetComponent(vtkIdType tupleIdx, int compIdx) VTK_EXPECTS(0 <= tupleIdx &&
355  tupleIdx < GetNumberOfTuples()) VTK_EXPECTS(0 <= compIdx && compIdx < GetNumberOfComponents());
356 
364  virtual void SetComponent(vtkIdType tupleIdx, int compIdx, double value)
365  VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples())
366  VTK_EXPECTS(0 <= compIdx && compIdx < GetNumberOfComponents());
367 
372  virtual void InsertComponent(vtkIdType tupleIdx, int compIdx, double value)
373  VTK_EXPECTS(0 <= tupleIdx) VTK_EXPECTS(0 <= compIdx && compIdx < GetNumberOfComponents());
374 
383  virtual void GetData(
384  vtkIdType tupleMin, vtkIdType tupleMax, int compMin, int compMax, vtkDoubleArray* data);
385 
387 
391  void DeepCopy(vtkAbstractArray* aa) override;
392  virtual void DeepCopy(vtkDataArray* da);
394 
404  virtual void ShallowCopy(vtkDataArray* other);
405 
412  virtual void FillComponent(int compIdx, double value)
413  VTK_EXPECTS(0 <= compIdx && compIdx < GetNumberOfComponents());
414 
418  virtual void Fill(double value);
419 
428  virtual void CopyComponent(int dstComponent, vtkDataArray* src, int srcComponent);
429 
435  virtual void* WriteVoidPointer(vtkIdType valueIdx, vtkIdType numValues) = 0;
436 
445  unsigned long GetActualMemorySize() const override;
446 
451  void CreateDefaultLookupTable();
452 
454 
457  void SetLookupTable(vtkLookupTable* lut);
458  vtkGetObjectMacro(LookupTable, vtkLookupTable);
460 
462 
479  void GetRange(double range[2], int comp) { this->ComputeRange(range, comp); }
480  void GetRange(double range[2], int comp, const unsigned char* ghosts, unsigned char ghostsToSkip)
481  {
482  this->ComputeRange(range, comp, ghosts, ghostsToSkip);
483  }
485 
487 
495  double* GetRange(int comp) VTK_SIZEHINT(2)
496  {
497  this->GetRange(this->Range, comp);
498  return this->Range;
499  }
501 
509  double* GetRange() VTK_SIZEHINT(2) { return this->GetRange(0); }
510 
519  void GetRange(double range[2]) { this->GetRange(range, 0); }
520 
522 
540  void GetFiniteRange(double range[2], int comp) { this->ComputeFiniteRange(range, comp); }
542  double range[2], int comp, const unsigned char* ghosts, unsigned char ghostsToSkip)
543  {
544  this->ComputeFiniteRange(range, comp, ghosts, ghostsToSkip);
545  }
547 
549 
557  double* GetFiniteRange(int comp) VTK_SIZEHINT(2)
558  {
559  this->GetFiniteRange(this->FiniteRange, comp);
560  return this->FiniteRange;
561  }
563 
571  double* GetFiniteRange() VTK_SIZEHINT(2) { return this->GetFiniteRange(0); }
572 
581  void GetFiniteRange(double range[2]) { this->GetFiniteRange(range, 0); }
582 
584 
589  void GetDataTypeRange(double range[2]);
590  double GetDataTypeMin();
591  double GetDataTypeMax();
592  static void GetDataTypeRange(int type, double range[2]);
593  static double GetDataTypeMin(int type);
594  static double GetDataTypeMax(int type);
596 
601  virtual double GetMaxNorm();
602 
612  static vtkDataArray* CreateDataArray(int dataType);
613 
622 
631 
640 
644  void Modified() override;
645 
650 
658  int CopyInformation(vtkInformation* infoFrom, int deep = 1) override;
659 
663  int GetArrayType() const override { return DataArray; }
664 
665 protected:
666  friend class vtkPoints;
667  friend class vtkFieldData;
668 
670 
686  virtual void ComputeRange(double range[2], int comp);
687  virtual void ComputeRange(
688  double range[2], int comp, const unsigned char* ghosts, unsigned char ghostsToSkip = 0xff);
690 
692 
708  virtual void ComputeFiniteRange(double range[2], int comp);
709  virtual void ComputeFiniteRange(
710  double range[2], int comp, const unsigned char* ghosts, unsigned char ghostsToSkip = 0xff);
712 
714 
729  virtual bool ComputeScalarRange(double* ranges);
730  virtual bool ComputeScalarRange(
731  double* ranges, const unsigned char* ghosts, unsigned char ghostsToSkip = 0xff);
733 
735 
747  virtual bool ComputeVectorRange(double range[2]);
748  virtual bool ComputeVectorRange(
749  double range[2], const unsigned char* ghosts, unsigned char ghostsToSkip = 0xff);
751 
753 
767  virtual bool ComputeFiniteScalarRange(double* ranges);
769  double* ranges, const unsigned char* ghosts, unsigned char ghostsToSkip = 0xff);
771 
773 
785  virtual bool ComputeFiniteVectorRange(double range[2]);
787  double range[2], const unsigned char* ghosts, unsigned char ghostsToSkip = 0xff);
789 
790  // Construct object with default tuple dimension (number of components) of 1.
792  ~vtkDataArray() override;
793 
795  double Range[2];
796  double FiniteRange[2];
797 
798 private:
799  double* GetTupleN(vtkIdType i, int n);
800 
801 private:
802  vtkDataArray(const vtkDataArray&) = delete;
803  void operator=(const vtkDataArray&) = delete;
804 };
805 
806 //------------------------------------------------------------------------------
808 {
809  if (source)
810  {
811  switch (source->GetArrayType())
812  {
815  case ImplicitArray:
816  case TypedDataArray:
817  case DataArray:
818  case MappedDataArray:
819  return static_cast<vtkDataArray*>(source);
820  default:
821  break;
822  }
823  }
824  return nullptr;
825 }
826 
828 VTK_ABI_NAMESPACE_END
829 
830 // These are used by vtkDataArrayPrivate.txx, but need to be available to
831 // vtkGenericDataArray.h as well.
833 {
834 VTK_ABI_NAMESPACE_BEGIN
835 struct AllValues
836 {
837 };
839 {
840 };
841 VTK_ABI_NAMESPACE_END
842 }
843 
844 #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:166
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:185
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:557
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:663
int GetElementComponentSize() const override
Return the size, in bytes, of the lowest-level element of an array.
Definition: vtkDataArray.h:192
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:540
double * GetRange(int comp)
Return the range of the data array values for the given component.
Definition: vtkDataArray.h:495
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.
int CopyInformation(vtkInformation *infoFrom, int deep=1) override
Copy information instance.
void GetRange(double range[2])
The range of the data array values will be returned in the provided range array argument.
Definition: vtkDataArray.h:519
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:807
double * GetRange()
Return the range of the data array.
Definition: vtkDataArray.h:509
double * GetFiniteRange()
Return the range of the data array.
Definition: vtkDataArray.h:571
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.
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:480
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:541
void GetFiniteRange(double range[2])
The range of the data array values will be returned in the provided range array argument.
Definition: vtkDataArray.h:581
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:794
dynamic, self-adjusting array of double
represent and manipulate fields of data
Definition: vtkFieldData.h:173
list of point or cell ids
Definition: vtkIdList.h:144
a simple class to control print indentation
Definition: vtkIndent.h:120
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:150
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:232
@ range
Definition: vtkX3D.h:250
@ type
Definition: vtkX3D.h:528
@ data
Definition: vtkX3D.h:327
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:86
boost::graph_traits< vtkGraph * >::vertex_descriptor source(boost::graph_traits< vtkGraph * >::edge_descriptor e, vtkGraph *)
#define vtkDataArray
Definition: vtkCharArray.h:68
vtkArrayDownCast_FastCastMacro(vtkDataArray)
int vtkIdType
Definition: vtkType.h:327
#define VTK_SIZEHINT(...)
#define VTK_EXPECTS(x)
#define VTK_NEWINSTANCE