VTK  9.1.20220518
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 class vtkDoubleArray;
158 class vtkIdList;
161 class vtkLookupTable;
162 class vtkPoints;
163 
164 class VTKCOMMONCORE_EXPORT vtkDataArray : public vtkAbstractArray
165 {
166 public:
168  void PrintSelf(ostream& os, vtkIndent indent) override;
169 
176  static vtkDataArray* FastDownCast(vtkAbstractArray* source);
177 
184  int IsNumeric() const override { return 1; }
185 
191  int GetElementComponentSize() const override { return this->GetDataTypeSize(); }
192 
193  // Reimplemented virtuals (doc strings are inherited from superclass):
195 
200  void InsertTuple(vtkIdType dstTupleIdx, vtkIdType srcTupleIdx, vtkAbstractArray* source) override;
202  void InsertTuples(vtkIdList* dstIds, vtkIdList* srcIds, vtkAbstractArray* source) override;
204  vtkIdType dstStart, vtkIdType n, vtkIdType srcStart, vtkAbstractArray* source) override;
206  vtkIdType dstStart, vtkIdList* srcIds, vtkAbstractArray* source) override;
207  void SetTuple(vtkIdType dstTupleIdx, vtkIdType srcTupleIdx, vtkAbstractArray* source) override;
209  void GetTuples(vtkIdList* tupleIds, vtkAbstractArray* output) override;
210  void GetTuples(vtkIdType p1, vtkIdType p2, vtkAbstractArray* output) override;
212  double* weights) override;
213  void InterpolateTuple(vtkIdType dstTupleIdx, vtkIdType srcTupleIdx1, vtkAbstractArray* source1,
214  vtkIdType srcTupleIdx2, vtkAbstractArray* source2, double t) override;
215 
221  virtual double* GetTuple(vtkIdType tupleIdx)
222  VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples()) = 0;
223 
229  virtual void GetTuple(vtkIdType tupleIdx, double* tuple)
230  VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples()) = 0;
231 
233 
238  double GetTuple1(vtkIdType tupleIdx) VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
239  double* GetTuple2(vtkIdType tupleIdx) VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples())
240  VTK_SIZEHINT(2);
241  double* GetTuple3(vtkIdType tupleIdx) VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples())
242  VTK_SIZEHINT(3);
243  double* GetTuple4(vtkIdType tupleIdx) VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples())
244  VTK_SIZEHINT(4);
245  double* GetTuple6(vtkIdType tupleIdx) VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples())
246  VTK_SIZEHINT(6);
247  double* GetTuple9(vtkIdType tupleIdx) VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples())
248  VTK_SIZEHINT(9);
250 
252 
257  virtual void SetTuple(vtkIdType tupleIdx, const float* tuple)
258  VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
259  virtual void SetTuple(vtkIdType tupleIdx, const double* tuple)
260  VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
262 
264 
269  void SetTuple1(vtkIdType tupleIdx, double value)
270  VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
271  void SetTuple2(vtkIdType tupleIdx, double val0, double val1)
272  VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
273  void SetTuple3(vtkIdType tupleIdx, double val0, double val1, double val2)
274  VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
275  void SetTuple4(vtkIdType tupleIdx, double val0, double val1, double val2, double val3)
276  VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
277  void SetTuple6(vtkIdType tupleIdx, double val0, double val1, double val2, double val3,
278  double val4, double val5) VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
279  void SetTuple9(vtkIdType tupleIdx, double val0, double val1, double val2, double val3,
280  double val4, double val5, double val6, double val7, double val8)
281  VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
283 
285 
289  virtual void InsertTuple(vtkIdType tupleIdx, const float* tuple) VTK_EXPECTS(0 <= tupleIdx) = 0;
290  virtual void InsertTuple(vtkIdType tupleIdx, const double* tuple) VTK_EXPECTS(0 <= tupleIdx) = 0;
292 
294 
299  void InsertTuple1(vtkIdType tupleIdx, double value) VTK_EXPECTS(0 <= tupleIdx);
300  void InsertTuple2(vtkIdType tupleIdx, double val0, double val1) VTK_EXPECTS(0 <= tupleIdx);
301  void InsertTuple3(vtkIdType tupleIdx, double val0, double val1, double val2)
302  VTK_EXPECTS(0 <= tupleIdx);
303  void InsertTuple4(vtkIdType tupleIdx, double val0, double val1, double val2, double val3)
304  VTK_EXPECTS(0 <= tupleIdx);
305  void InsertTuple6(vtkIdType tupleIdx, double val0, double val1, double val2, double val3,
306  double val4, double val5) VTK_EXPECTS(0 <= tupleIdx);
307  void InsertTuple9(vtkIdType tupleIdx, double val0, double val1, double val2, double val3,
308  double val4, double val5, double val6, double val7, double val8) VTK_EXPECTS(0 <= tupleIdx);
310 
312 
317  virtual vtkIdType InsertNextTuple(const float* tuple) = 0;
318  virtual vtkIdType InsertNextTuple(const double* tuple) = 0;
320 
322 
327  void InsertNextTuple1(double value);
328  void InsertNextTuple2(double val0, double val1);
329  void InsertNextTuple3(double val0, double val1, double val2);
330  void InsertNextTuple4(double val0, double val1, double val2, double val3);
331  void InsertNextTuple6(
332  double val0, double val1, double val2, double val3, double val4, double val5);
333  void InsertNextTuple9(double val0, double val1, double val2, double val3, double val4,
334  double val5, double val6, double val7, double val8);
336 
338 
343  virtual void RemoveTuple(vtkIdType tupleIdx)
344  VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples()) = 0;
345  virtual void RemoveFirstTuple() { this->RemoveTuple(0); }
346  virtual void RemoveLastTuple();
348 
353  virtual double GetComponent(vtkIdType tupleIdx, int compIdx) VTK_EXPECTS(0 <= tupleIdx &&
354  tupleIdx < GetNumberOfTuples()) VTK_EXPECTS(0 <= compIdx && compIdx < GetNumberOfComponents());
355 
363  virtual void SetComponent(vtkIdType tupleIdx, int compIdx, double value)
364  VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples())
365  VTK_EXPECTS(0 <= compIdx && compIdx < GetNumberOfComponents());
366 
371  virtual void InsertComponent(vtkIdType tupleIdx, int compIdx, double value)
372  VTK_EXPECTS(0 <= tupleIdx) VTK_EXPECTS(0 <= compIdx && compIdx < GetNumberOfComponents());
373 
382  virtual void GetData(
383  vtkIdType tupleMin, vtkIdType tupleMax, int compMin, int compMax, vtkDoubleArray* data);
384 
386 
390  void DeepCopy(vtkAbstractArray* aa) override;
391  virtual void DeepCopy(vtkDataArray* da);
393 
403  virtual void ShallowCopy(vtkDataArray* other);
404 
411  virtual void FillComponent(int compIdx, double value)
412  VTK_EXPECTS(0 <= compIdx && compIdx < GetNumberOfComponents());
413 
417  virtual void Fill(double value);
418 
427  virtual void CopyComponent(int dstComponent, vtkDataArray* src, int srcComponent);
428 
434  virtual void* WriteVoidPointer(vtkIdType valueIdx, vtkIdType numValues) = 0;
435 
444  unsigned long GetActualMemorySize() const override;
445 
450  void CreateDefaultLookupTable();
451 
453 
456  void SetLookupTable(vtkLookupTable* lut);
457  vtkGetObjectMacro(LookupTable, vtkLookupTable);
459 
461 
478  void GetRange(double range[2], int comp) { this->ComputeRange(range, comp); }
479  void GetRange(double range[2], int comp, const unsigned char* ghosts, unsigned char ghostsToSkip)
480  {
481  this->ComputeRange(range, comp, ghosts, ghostsToSkip);
482  }
484 
486 
494  double* GetRange(int comp) VTK_SIZEHINT(2)
495  {
496  this->GetRange(this->Range, comp);
497  return this->Range;
498  }
500 
508  double* GetRange() VTK_SIZEHINT(2) { return this->GetRange(0); }
509 
518  void GetRange(double range[2]) { this->GetRange(range, 0); }
519 
521 
539  void GetFiniteRange(double range[2], int comp) { this->ComputeFiniteRange(range, comp); }
541  double range[2], int comp, const unsigned char* ghosts, unsigned char ghostsToSkip)
542  {
543  this->ComputeFiniteRange(range, comp, ghosts, ghostsToSkip);
544  }
546 
548 
556  double* GetFiniteRange(int comp) VTK_SIZEHINT(2)
557  {
558  this->GetFiniteRange(this->FiniteRange, comp);
559  return this->FiniteRange;
560  }
562 
570  double* GetFiniteRange() VTK_SIZEHINT(2) { return this->GetFiniteRange(0); }
571 
580  void GetFiniteRange(double range[2]) { this->GetFiniteRange(range, 0); }
581 
583 
588  void GetDataTypeRange(double range[2]);
589  double GetDataTypeMin();
590  double GetDataTypeMax();
591  static void GetDataTypeRange(int type, double range[2]);
592  static double GetDataTypeMin(int type);
593  static double GetDataTypeMax(int type);
595 
600  virtual double GetMaxNorm();
601 
611  static vtkDataArray* CreateDataArray(int dataType);
612 
621 
630 
639 
643  void Modified() override;
644 
649 
657  int CopyInformation(vtkInformation* infoFrom, int deep = 1) override;
658 
662  int GetArrayType() const override { return DataArray; }
663 
664 protected:
665  friend class vtkPoints;
666  friend class vtkFieldData;
667 
669 
685  virtual void ComputeRange(double range[2], int comp);
686  virtual void ComputeRange(
687  double range[2], int comp, const unsigned char* ghosts, unsigned char ghostsToSkip = 0xff);
689 
691 
707  virtual void ComputeFiniteRange(double range[2], int comp);
708  virtual void ComputeFiniteRange(
709  double range[2], int comp, const unsigned char* ghosts, unsigned char ghostsToSkip = 0xff);
711 
713 
728  virtual bool ComputeScalarRange(double* ranges);
729  virtual bool ComputeScalarRange(
730  double* ranges, const unsigned char* ghosts, unsigned char ghostsToSkip = 0xff);
732 
734 
746  virtual bool ComputeVectorRange(double range[2]);
747  virtual bool ComputeVectorRange(
748  double range[2], const unsigned char* ghosts, unsigned char ghostsToSkip = 0xff);
750 
752 
766  virtual bool ComputeFiniteScalarRange(double* ranges);
768  double* ranges, const unsigned char* ghosts, unsigned char ghostsToSkip = 0xff);
770 
772 
784  virtual bool ComputeFiniteVectorRange(double range[2]);
786  double range[2], const unsigned char* ghosts, unsigned char ghostsToSkip = 0xff);
788 
789  // Construct object with default tuple dimension (number of components) of 1.
791  ~vtkDataArray() override;
792 
794  double Range[2];
795  double FiniteRange[2];
796 
797 private:
798  double* GetTupleN(vtkIdType i, int n);
799 
800 private:
801  vtkDataArray(const vtkDataArray&) = delete;
802  void operator=(const vtkDataArray&) = delete;
803 };
804 
805 //------------------------------------------------------------------------------
807 {
808  if (source)
809  {
810  switch (source->GetArrayType())
811  {
814  case TypedDataArray:
815  case DataArray:
816  case MappedDataArray:
817  return static_cast<vtkDataArray*>(source);
818  default:
819  break;
820  }
821  }
822  return nullptr;
823 }
824 
826 
827 // These are used by vtkDataArrayPrivate.txx, but need to be available to
828 // vtkGenericDataArray.h as well.
830 {
831 struct AllValues
832 {
833 };
835 {
836 };
837 }
838 
839 #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:165
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:184
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:556
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:662
int GetElementComponentSize() const override
Return the size, in bytes, of the lowest-level element of an array.
Definition: vtkDataArray.h:191
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:539
double * GetRange(int comp)
Return the range of the data array values for the given component.
Definition: vtkDataArray.h:494
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:518
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:806
double * GetRange()
Return the range of the data array.
Definition: vtkDataArray.h:508
double * GetFiniteRange()
Return the range of the data array.
Definition: vtkDataArray.h:570
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:479
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:540
void GetFiniteRange(double range[2])
The range of the data array values will be returned in the provided range array argument.
Definition: vtkDataArray.h:580
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:793
dynamic, self-adjusting array of double
represent and manipulate fields of data
Definition: vtkFieldData.h:172
list of point or cell ids
Definition: vtkIdList.h:143
a simple class to control print indentation
Definition: vtkIndent.h:119
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:149
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:226
@ range
Definition: vtkX3D.h:244
@ type
Definition: vtkX3D.h:522
@ data
Definition: vtkX3D.h:321
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:85
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:332
#define VTK_SIZEHINT(...)
#define VTK_EXPECTS(x)
#define VTK_NEWINSTANCE