VTK  9.0.1
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 =========================================================================*/
35 #ifndef vtkDataArray_h
36 #define vtkDataArray_h
37 
38 #include "vtkAbstractArray.h"
39 #include "vtkCommonCoreModule.h" // For export macro
40 #include "vtkVTK_USE_SCALED_SOA_ARRAYS.h" // For #define of VTK_USE_SCALED_SOA_ARRAYS
41 
42 class vtkDoubleArray;
43 class vtkIdList;
46 class vtkLookupTable;
47 class vtkPoints;
48 
49 class VTKCOMMONCORE_EXPORT vtkDataArray : public vtkAbstractArray
50 {
51 public:
53  void PrintSelf(ostream& os, vtkIndent indent) override;
54 
61  static vtkDataArray* FastDownCast(vtkAbstractArray* source);
62 
69  int IsNumeric() const override { return 1; }
70 
76  int GetElementComponentSize() const override { return this->GetDataTypeSize(); }
77 
78  // Reimplemented virtuals (doc strings are inherited from superclass):
79  void InsertTuple(vtkIdType dstTupleIdx, vtkIdType srcTupleIdx, vtkAbstractArray* source) override;
81  void InsertTuples(vtkIdList* dstIds, vtkIdList* srcIds, vtkAbstractArray* source) override;
82  void InsertTuples(
83  vtkIdType dstStart, vtkIdType n, vtkIdType srcStart, vtkAbstractArray* source) override;
84  void GetTuples(vtkIdList* tupleIds, vtkAbstractArray* output) override;
85  void GetTuples(vtkIdType p1, vtkIdType p2, vtkAbstractArray* output) override;
86  void InterpolateTuple(vtkIdType dstTupleIdx, vtkIdList* ptIndices, vtkAbstractArray* source,
87  double* weights) override;
88  void InterpolateTuple(vtkIdType dstTupleIdx, vtkIdType srcTupleIdx1, vtkAbstractArray* source1,
89  vtkIdType srcTupleIdx2, vtkAbstractArray* source2, double t) override;
90 
96  virtual double* GetTuple(vtkIdType tupleIdx)
97  VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples()) = 0;
98 
104  virtual void GetTuple(vtkIdType tupleIdx, double* tuple)
105  VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples()) = 0;
106 
108 
113  double GetTuple1(vtkIdType tupleIdx) VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
114  double* GetTuple2(vtkIdType tupleIdx) VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples())
115  VTK_SIZEHINT(2);
116  double* GetTuple3(vtkIdType tupleIdx) VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples())
117  VTK_SIZEHINT(3);
118  double* GetTuple4(vtkIdType tupleIdx) VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples())
119  VTK_SIZEHINT(4);
120  double* GetTuple6(vtkIdType tupleIdx) VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples())
121  VTK_SIZEHINT(6);
122  double* GetTuple9(vtkIdType tupleIdx) VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples())
123  VTK_SIZEHINT(9);
125 
126  void SetTuple(vtkIdType dstTupleIdx, vtkIdType srcTupleIdx, vtkAbstractArray* source) override;
127 
129 
134  virtual void SetTuple(vtkIdType tupleIdx, const float* tuple)
135  VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
136  virtual void SetTuple(vtkIdType tupleIdx, const double* tuple)
137  VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
139 
141 
146  void SetTuple1(vtkIdType tupleIdx, double value)
147  VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
148  void SetTuple2(vtkIdType tupleIdx, double val0, double val1)
149  VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
150  void SetTuple3(vtkIdType tupleIdx, double val0, double val1, double val2)
151  VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
152  void SetTuple4(vtkIdType tupleIdx, double val0, double val1, double val2, double val3)
153  VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
154  void SetTuple6(vtkIdType tupleIdx, double val0, double val1, double val2, double val3,
155  double val4, double val5) VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
156  void SetTuple9(vtkIdType tupleIdx, double val0, double val1, double val2, double val3,
157  double val4, double val5, double val6, double val7, double val8)
158  VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
160 
162 
166  virtual void InsertTuple(vtkIdType tupleIdx, const float* tuple) VTK_EXPECTS(0 <= tupleIdx) = 0;
167  virtual void InsertTuple(vtkIdType tupleIdx, const double* tuple) VTK_EXPECTS(0 <= tupleIdx) = 0;
169 
171 
176  void InsertTuple1(vtkIdType tupleIdx, double value) VTK_EXPECTS(0 <= tupleIdx);
177  void InsertTuple2(vtkIdType tupleIdx, double val0, double val1) VTK_EXPECTS(0 <= tupleIdx);
178  void InsertTuple3(vtkIdType tupleIdx, double val0, double val1, double val2)
179  VTK_EXPECTS(0 <= tupleIdx);
180  void InsertTuple4(vtkIdType tupleIdx, double val0, double val1, double val2, double val3)
181  VTK_EXPECTS(0 <= tupleIdx);
182  void InsertTuple6(vtkIdType tupleIdx, double val0, double val1, double val2, double val3,
183  double val4, double val5) VTK_EXPECTS(0 <= tupleIdx);
184  void InsertTuple9(vtkIdType tupleIdx, double val0, double val1, double val2, double val3,
185  double val4, double val5, double val6, double val7, double val8) VTK_EXPECTS(0 <= tupleIdx);
187 
189 
194  virtual vtkIdType InsertNextTuple(const float* tuple) = 0;
195  virtual vtkIdType InsertNextTuple(const double* tuple) = 0;
197 
199 
204  void InsertNextTuple1(double value);
205  void InsertNextTuple2(double val0, double val1);
206  void InsertNextTuple3(double val0, double val1, double val2);
207  void InsertNextTuple4(double val0, double val1, double val2, double val3);
208  void InsertNextTuple6(
209  double val0, double val1, double val2, double val3, double val4, double val5);
210  void InsertNextTuple9(double val0, double val1, double val2, double val3, double val4,
211  double val5, double val6, double val7, double val8);
213 
215 
220  virtual void RemoveTuple(vtkIdType tupleIdx)
221  VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples()) = 0;
222  virtual void RemoveFirstTuple() { this->RemoveTuple(0); }
223  virtual void RemoveLastTuple();
225 
230  virtual double GetComponent(vtkIdType tupleIdx, int compIdx) VTK_EXPECTS(0 <= tupleIdx &&
231  tupleIdx < GetNumberOfTuples()) VTK_EXPECTS(0 <= compIdx && compIdx < GetNumberOfComponents());
232 
240  virtual void SetComponent(vtkIdType tupleIdx, int compIdx, double value)
241  VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples())
242  VTK_EXPECTS(0 <= compIdx && compIdx < GetNumberOfComponents());
243 
248  virtual void InsertComponent(vtkIdType tupleIdx, int compIdx, double value)
249  VTK_EXPECTS(0 <= tupleIdx) VTK_EXPECTS(0 <= compIdx && compIdx < GetNumberOfComponents());
250 
259  virtual void GetData(
260  vtkIdType tupleMin, vtkIdType tupleMax, int compMin, int compMax, vtkDoubleArray* data);
261 
263 
267  void DeepCopy(vtkAbstractArray* aa) override;
268  virtual void DeepCopy(vtkDataArray* da);
270 
280  virtual void ShallowCopy(vtkDataArray* other);
281 
288  virtual void FillComponent(int compIdx, double value)
289  VTK_EXPECTS(0 <= compIdx && compIdx < GetNumberOfComponents());
290 
294  virtual void Fill(double value);
295 
304  virtual void CopyComponent(int dstComponent, vtkDataArray* src, int srcComponent);
305 
311  virtual void* WriteVoidPointer(vtkIdType valueIdx, vtkIdType numValues) = 0;
312 
321  unsigned long GetActualMemorySize() const override;
322 
327  void CreateDefaultLookupTable();
328 
330 
333  void SetLookupTable(vtkLookupTable* lut);
334  vtkGetObjectMacro(LookupTable, vtkLookupTable);
336 
346  void GetRange(double range[2], int comp) { this->ComputeRange(range, comp); }
347 
349 
357  double* GetRange(int comp) VTK_SIZEHINT(2)
358  {
359  this->GetRange(this->Range, comp);
360  return this->Range;
361  }
363 
371  double* GetRange() VTK_SIZEHINT(2) { return this->GetRange(0); }
372 
381  void GetRange(double range[2]) { this->GetRange(range, 0); }
382 
392  void GetFiniteRange(double range[2], int comp) { this->ComputeFiniteRange(range, comp); }
393 
395 
403  double* GetFiniteRange(int comp) VTK_SIZEHINT(2)
404  {
405  this->GetFiniteRange(this->FiniteRange, comp);
406  return this->FiniteRange;
407  }
409 
417  double* GetFiniteRange() VTK_SIZEHINT(2) { return this->GetFiniteRange(0); }
418 
427  void GetFiniteRange(double range[2]) { this->GetFiniteRange(range, 0); }
428 
430 
435  void GetDataTypeRange(double range[2]);
436  double GetDataTypeMin();
437  double GetDataTypeMax();
438  static void GetDataTypeRange(int type, double range[2]);
439  static double GetDataTypeMin(int type);
440  static double GetDataTypeMax(int type);
442 
447  virtual double GetMaxNorm();
448 
458  static vtkDataArray* CreateDataArray(int dataType);
459 
467  static vtkInformationDoubleVectorKey* COMPONENT_RANGE();
468 
476  static vtkInformationDoubleVectorKey* L2_NORM_RANGE();
477 
485  static vtkInformationDoubleVectorKey* L2_NORM_FINITE_RANGE();
486 
490  void Modified() override;
491 
495  static vtkInformationStringKey* UNITS_LABEL();
496 
504  int CopyInformation(vtkInformation* infoFrom, int deep = 1) override;
505 
509  int GetArrayType() const override { return DataArray; }
510 
511 protected:
512  friend class vtkPoints;
513 
521  virtual void ComputeRange(double range[2], int comp);
522 
530  virtual void ComputeFiniteRange(double range[2], int comp);
531 
538  virtual bool ComputeScalarRange(double* ranges);
539 
544  virtual bool ComputeVectorRange(double range[2]);
545 
552  virtual bool ComputeFiniteScalarRange(double* ranges);
553 
558  virtual bool ComputeFiniteVectorRange(double range[2]);
559 
560  // Construct object with default tuple dimension (number of components) of 1.
561  vtkDataArray();
562  ~vtkDataArray() override;
563 
565  double Range[2];
566  double FiniteRange[2];
567 
568 private:
569  double* GetTupleN(vtkIdType i, int n);
570 
571 private:
572  vtkDataArray(const vtkDataArray&) = delete;
573  void operator=(const vtkDataArray&) = delete;
574 };
575 
576 //------------------------------------------------------------------------------
578 {
579  if (source)
580  {
581  switch (source->GetArrayType())
582  {
585  case TypedDataArray:
586  case DataArray:
587  case MappedDataArray:
588  return static_cast<vtkDataArray*>(source);
589  default:
590  break;
591  }
592  }
593  return nullptr;
594 }
595 
597 
598 // These are used by vtkDataArrayPrivate.txx, but need to be available to
599 // vtkGenericDataArray.h as well.
601 {
603 {
604 };
606 {
607 };
608 }
609 
610 #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:381
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:392
vtkIdType GetNumberOfTuples() const
Get the number of complete tuples (a component group) in the array.
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.
int IsNumeric() const override
This method is here to make backward compatibility easier.
Definition: vtkDataArray.h:69
map scalar values into colors via a lookup table
int vtkIdType
Definition: vtkType.h:338
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...
void GetFiniteRange(double range[2])
The range of the data array values will be returned in the provided range array argument.
Definition: vtkDataArray.h:427
Key for string values in vtkInformation.
boost::graph_traits< vtkGraph * >::vertex_descriptor source(boost::graph_traits< vtkGraph *>::edge_descriptor e, vtkGraph *)
int GetArrayType() const override
Method for type-checking in FastDownCast implementations.
Definition: vtkDataArray.h:509
double * GetFiniteRange(int comp)
Return the range of the data array values for the given component.
Definition: vtkDataArray.h:403
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:357
#define vtkDataArray
Definition: vtkCharArray.h:33
Key for double vector values.
double * GetFiniteRange()
Return the range of the data array.
Definition: vtkDataArray.h:417
a simple class to control print indentation
Definition: vtkIndent.h:33
double * GetRange()
Return the range of the data array.
Definition: vtkDataArray.h:371
list of point or cell ids
Definition: vtkIdList.h:30
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:49
vtkLookupTable * LookupTable
Definition: vtkDataArray.h:564
#define VTK_SIZEHINT(...)
#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.
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:577
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
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...
int GetElementComponentSize() const override
Return the size, in bytes, of the lowest-level element of an array.
Definition: vtkDataArray.h:76
represent and manipulate 3D points
Definition: vtkPoints.h:33
virtual int GetDataTypeSize() const =0
Return the size of the underlying data type.
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.