VTK  9.2.6
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 =========================================================================*/
41 #ifndef vtkDataArray_h
42 #define vtkDataArray_h
43 
44 #include "vtkAbstractArray.h"
45 #include "vtkCommonCoreModule.h" // For export macro
46 #include "vtkVTK_USE_SCALED_SOA_ARRAYS.h" // For #define of VTK_USE_SCALED_SOA_ARRAYS
47 
48 class vtkDoubleArray;
49 class vtkIdList;
52 class vtkLookupTable;
53 class vtkPoints;
54 
55 class VTKCOMMONCORE_EXPORT vtkDataArray : public vtkAbstractArray
56 {
57 public:
59  void PrintSelf(ostream& os, vtkIndent indent) override;
60 
67  static vtkDataArray* FastDownCast(vtkAbstractArray* source);
68 
75  int IsNumeric() const override { return 1; }
76 
82  int GetElementComponentSize() const override { return this->GetDataTypeSize(); }
83 
84  // Reimplemented virtuals (doc strings are inherited from superclass):
86 
91  void InsertTuple(vtkIdType dstTupleIdx, vtkIdType srcTupleIdx, vtkAbstractArray* source) override;
93  void InsertTuples(vtkIdList* dstIds, vtkIdList* srcIds, vtkAbstractArray* source) override;
94  void InsertTuples(
95  vtkIdType dstStart, vtkIdType n, vtkIdType srcStart, vtkAbstractArray* source) override;
97  vtkIdType dstStart, vtkIdList* srcIds, vtkAbstractArray* source) override;
98  void SetTuple(vtkIdType dstTupleIdx, vtkIdType srcTupleIdx, vtkAbstractArray* source) override;
100  void GetTuples(vtkIdList* tupleIds, vtkAbstractArray* output) override;
101  void GetTuples(vtkIdType p1, vtkIdType p2, vtkAbstractArray* output) override;
102  void InterpolateTuple(vtkIdType dstTupleIdx, vtkIdList* ptIndices, vtkAbstractArray* source,
103  double* weights) override;
104  void InterpolateTuple(vtkIdType dstTupleIdx, vtkIdType srcTupleIdx1, vtkAbstractArray* source1,
105  vtkIdType srcTupleIdx2, vtkAbstractArray* source2, double t) override;
106 
112  virtual double* GetTuple(vtkIdType tupleIdx)
113  VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples()) = 0;
114 
120  virtual void GetTuple(vtkIdType tupleIdx, double* tuple)
121  VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples()) = 0;
122 
124 
129  double GetTuple1(vtkIdType tupleIdx) VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
130  double* GetTuple2(vtkIdType tupleIdx) VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples())
131  VTK_SIZEHINT(2);
132  double* GetTuple3(vtkIdType tupleIdx) VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples())
133  VTK_SIZEHINT(3);
134  double* GetTuple4(vtkIdType tupleIdx) VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples())
135  VTK_SIZEHINT(4);
136  double* GetTuple6(vtkIdType tupleIdx) VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples())
137  VTK_SIZEHINT(6);
138  double* GetTuple9(vtkIdType tupleIdx) VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples())
139  VTK_SIZEHINT(9);
141 
143 
148  virtual void SetTuple(vtkIdType tupleIdx, const float* tuple)
149  VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
150  virtual void SetTuple(vtkIdType tupleIdx, const double* tuple)
151  VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
153 
155 
160  void SetTuple1(vtkIdType tupleIdx, double value)
161  VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
162  void SetTuple2(vtkIdType tupleIdx, double val0, double val1)
163  VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
164  void SetTuple3(vtkIdType tupleIdx, double val0, double val1, double val2)
165  VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
166  void SetTuple4(vtkIdType tupleIdx, double val0, double val1, double val2, double val3)
167  VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
168  void SetTuple6(vtkIdType tupleIdx, double val0, double val1, double val2, double val3,
169  double val4, double val5) VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
170  void SetTuple9(vtkIdType tupleIdx, double val0, double val1, double val2, double val3,
171  double val4, double val5, double val6, double val7, double val8)
172  VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
174 
176 
180  virtual void InsertTuple(vtkIdType tupleIdx, const float* tuple) VTK_EXPECTS(0 <= tupleIdx) = 0;
181  virtual void InsertTuple(vtkIdType tupleIdx, const double* tuple) VTK_EXPECTS(0 <= tupleIdx) = 0;
183 
185 
190  void InsertTuple1(vtkIdType tupleIdx, double value) VTK_EXPECTS(0 <= tupleIdx);
191  void InsertTuple2(vtkIdType tupleIdx, double val0, double val1) VTK_EXPECTS(0 <= tupleIdx);
192  void InsertTuple3(vtkIdType tupleIdx, double val0, double val1, double val2)
193  VTK_EXPECTS(0 <= tupleIdx);
194  void InsertTuple4(vtkIdType tupleIdx, double val0, double val1, double val2, double val3)
195  VTK_EXPECTS(0 <= tupleIdx);
196  void InsertTuple6(vtkIdType tupleIdx, double val0, double val1, double val2, double val3,
197  double val4, double val5) VTK_EXPECTS(0 <= tupleIdx);
198  void InsertTuple9(vtkIdType tupleIdx, double val0, double val1, double val2, double val3,
199  double val4, double val5, double val6, double val7, double val8) VTK_EXPECTS(0 <= tupleIdx);
201 
203 
208  virtual vtkIdType InsertNextTuple(const float* tuple) = 0;
209  virtual vtkIdType InsertNextTuple(const double* tuple) = 0;
211 
213 
218  void InsertNextTuple1(double value);
219  void InsertNextTuple2(double val0, double val1);
220  void InsertNextTuple3(double val0, double val1, double val2);
221  void InsertNextTuple4(double val0, double val1, double val2, double val3);
222  void InsertNextTuple6(
223  double val0, double val1, double val2, double val3, double val4, double val5);
224  void InsertNextTuple9(double val0, double val1, double val2, double val3, double val4,
225  double val5, double val6, double val7, double val8);
227 
229 
234  virtual void RemoveTuple(vtkIdType tupleIdx)
235  VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples()) = 0;
236  virtual void RemoveFirstTuple() { this->RemoveTuple(0); }
237  virtual void RemoveLastTuple();
239 
244  virtual double GetComponent(vtkIdType tupleIdx, int compIdx) VTK_EXPECTS(0 <= tupleIdx &&
245  tupleIdx < GetNumberOfTuples()) VTK_EXPECTS(0 <= compIdx && compIdx < GetNumberOfComponents());
246 
254  virtual void SetComponent(vtkIdType tupleIdx, int compIdx, double value)
255  VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples())
256  VTK_EXPECTS(0 <= compIdx && compIdx < GetNumberOfComponents());
257 
262  virtual void InsertComponent(vtkIdType tupleIdx, int compIdx, double value)
263  VTK_EXPECTS(0 <= tupleIdx) VTK_EXPECTS(0 <= compIdx && compIdx < GetNumberOfComponents());
264 
273  virtual void GetData(
274  vtkIdType tupleMin, vtkIdType tupleMax, int compMin, int compMax, vtkDoubleArray* data);
275 
277 
281  void DeepCopy(vtkAbstractArray* aa) override;
282  virtual void DeepCopy(vtkDataArray* da);
284 
294  virtual void ShallowCopy(vtkDataArray* other);
295 
302  virtual void FillComponent(int compIdx, double value)
303  VTK_EXPECTS(0 <= compIdx && compIdx < GetNumberOfComponents());
304 
308  virtual void Fill(double value);
309 
318  virtual void CopyComponent(int dstComponent, vtkDataArray* src, int srcComponent);
319 
325  virtual void* WriteVoidPointer(vtkIdType valueIdx, vtkIdType numValues) = 0;
326 
335  unsigned long GetActualMemorySize() const override;
336 
341  void CreateDefaultLookupTable();
342 
344 
347  void SetLookupTable(vtkLookupTable* lut);
348  vtkGetObjectMacro(LookupTable, vtkLookupTable);
350 
352 
369  void GetRange(double range[2], int comp) { this->ComputeRange(range, comp); }
370  void GetRange(double range[2], int comp, const unsigned char* ghosts, unsigned char ghostsToSkip)
371  {
372  this->ComputeRange(range, comp, ghosts, ghostsToSkip);
373  }
375 
377 
385  double* GetRange(int comp) VTK_SIZEHINT(2)
386  {
387  this->GetRange(this->Range, comp);
388  return this->Range;
389  }
391 
399  double* GetRange() VTK_SIZEHINT(2) { return this->GetRange(0); }
400 
409  void GetRange(double range[2]) { this->GetRange(range, 0); }
410 
412 
430  void GetFiniteRange(double range[2], int comp) { this->ComputeFiniteRange(range, comp); }
432  double range[2], int comp, const unsigned char* ghosts, unsigned char ghostsToSkip)
433  {
434  this->ComputeFiniteRange(range, comp, ghosts, ghostsToSkip);
435  }
437 
439 
447  double* GetFiniteRange(int comp) VTK_SIZEHINT(2)
448  {
449  this->GetFiniteRange(this->FiniteRange, comp);
450  return this->FiniteRange;
451  }
453 
461  double* GetFiniteRange() VTK_SIZEHINT(2) { return this->GetFiniteRange(0); }
462 
471  void GetFiniteRange(double range[2]) { this->GetFiniteRange(range, 0); }
472 
474 
479  void GetDataTypeRange(double range[2]);
480  double GetDataTypeMin();
481  double GetDataTypeMax();
482  static void GetDataTypeRange(int type, double range[2]);
483  static double GetDataTypeMin(int type);
484  static double GetDataTypeMax(int type);
486 
491  virtual double GetMaxNorm();
492 
502  static vtkDataArray* CreateDataArray(int dataType);
503 
511  static vtkInformationDoubleVectorKey* COMPONENT_RANGE();
512 
520  static vtkInformationDoubleVectorKey* L2_NORM_RANGE();
521 
529  static vtkInformationDoubleVectorKey* L2_NORM_FINITE_RANGE();
530 
534  void Modified() override;
535 
539  static vtkInformationStringKey* UNITS_LABEL();
540 
548  int CopyInformation(vtkInformation* infoFrom, int deep = 1) override;
549 
553  int GetArrayType() const override { return DataArray; }
554 
555 protected:
556  friend class vtkPoints;
557  friend class vtkFieldData;
558 
560 
576  virtual void ComputeRange(double range[2], int comp);
577  virtual void ComputeRange(
578  double range[2], int comp, const unsigned char* ghosts, unsigned char ghostsToSkip = 0xff);
580 
582 
598  virtual void ComputeFiniteRange(double range[2], int comp);
599  virtual void ComputeFiniteRange(
600  double range[2], int comp, const unsigned char* ghosts, unsigned char ghostsToSkip = 0xff);
602 
604 
619  virtual bool ComputeScalarRange(double* ranges);
620  virtual bool ComputeScalarRange(
621  double* ranges, const unsigned char* ghosts, unsigned char ghostsToSkip = 0xff);
623 
625 
637  virtual bool ComputeVectorRange(double range[2]);
638  virtual bool ComputeVectorRange(
639  double range[2], const unsigned char* ghosts, unsigned char ghostsToSkip = 0xff);
641 
643 
657  virtual bool ComputeFiniteScalarRange(double* ranges);
658  virtual bool ComputeFiniteScalarRange(
659  double* ranges, const unsigned char* ghosts, unsigned char ghostsToSkip = 0xff);
661 
663 
675  virtual bool ComputeFiniteVectorRange(double range[2]);
676  virtual bool ComputeFiniteVectorRange(
677  double range[2], const unsigned char* ghosts, unsigned char ghostsToSkip = 0xff);
679 
680  // Construct object with default tuple dimension (number of components) of 1.
681  vtkDataArray();
682  ~vtkDataArray() override;
683 
685  double Range[2];
686  double FiniteRange[2];
687 
688 private:
689  double* GetTupleN(vtkIdType i, int n);
690 
691 private:
692  vtkDataArray(const vtkDataArray&) = delete;
693  void operator=(const vtkDataArray&) = delete;
694 };
695 
696 //------------------------------------------------------------------------------
698 {
699  if (source)
700  {
701  switch (source->GetArrayType())
702  {
705  case TypedDataArray:
706  case DataArray:
707  case MappedDataArray:
708  return static_cast<vtkDataArray*>(source);
709  default:
710  break;
711  }
712  }
713  return nullptr;
714 }
715 
717 
718 // These are used by vtkDataArrayPrivate.txx, but need to be available to
719 // vtkGenericDataArray.h as well.
721 {
722 struct AllValues
723 {
724 };
726 {
727 };
728 }
729 
730 #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:409
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:430
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:553
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:431
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:370
int vtkIdType
Definition: vtkType.h:332
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:82
void GetFiniteRange(double range[2])
The range of the data array values will be returned in the provided range array argument.
Definition: vtkDataArray.h:471
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:447
virtual int CopyInformation(vtkInformation *infoFrom, int deep=1)
Copy information instance.
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:385
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
virtual int GetDataTypeSize() const =0
Return the size of the underlying data type.
#define vtkDataArray
Definition: vtkCharArray.h:49
Key for double vector values.
double * GetFiniteRange()
Return the range of the data array.
Definition: vtkDataArray.h:461
a simple class to control print indentation
Definition: vtkIndent.h:39
double * GetRange()
Return the range of the data array.
Definition: vtkDataArray.h:399
list of point or cell ids
Definition: vtkIdList.h:33
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:55
vtkLookupTable * LookupTable
Definition: vtkDataArray.h:684
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:75
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:697
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:39
represent and manipulate fields of data
Definition: vtkFieldData.h:62
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.