VTK
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 "vtkCommonCoreModule.h" // For export macro
39 #include "vtkAbstractArray.h"
40 
41 class vtkDoubleArray;
42 class vtkIdList;
45 class vtkLookupTable;
46 class vtkPoints;
47 
48 class VTKCOMMONCORE_EXPORT vtkDataArray : public vtkAbstractArray
49 {
50 public:
52  void PrintSelf(ostream& os, vtkIndent indent) override;
53 
60  static vtkDataArray* FastDownCast(vtkAbstractArray *source);
61 
68  int IsNumeric() override
69  { return 1; }
70 
76  int GetElementComponentSize() override
77  { return this->GetDataTypeSize(); }
78 
79  // Reimplemented virtuals (doc strings are inherited from superclass):
80  void InsertTuple(vtkIdType dstTupleIdx, vtkIdType srcTupleIdx,
81  vtkAbstractArray* source) override;
83  vtkAbstractArray* source) override;
84  void InsertTuples(vtkIdList *dstIds, vtkIdList *srcIds,
85  vtkAbstractArray *source) override;
86  void InsertTuples(vtkIdType dstStart, vtkIdType n, vtkIdType srcStart,
87  vtkAbstractArray* source) override;
88  void GetTuples(vtkIdList *tupleIds, vtkAbstractArray *output) override;
89  void GetTuples(vtkIdType p1, vtkIdType p2, vtkAbstractArray *output) override;
90  void InterpolateTuple(vtkIdType dstTupleIdx, vtkIdList *ptIndices,
91  vtkAbstractArray* source, double* weights) override;
92  void InterpolateTuple(vtkIdType dstTupleIdx,
93  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)
119  VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
120  double* GetTuple2(vtkIdType tupleIdx)
121  VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples())
122  VTK_SIZEHINT(2);
123  double* GetTuple3(vtkIdType tupleIdx)
124  VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples())
125  VTK_SIZEHINT(3);
126  double* GetTuple4(vtkIdType tupleIdx)
127  VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples())
128  VTK_SIZEHINT(4);
129  double* GetTuple6(vtkIdType tupleIdx)
130  VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples())
131  VTK_SIZEHINT(6);
132  double* GetTuple9(vtkIdType tupleIdx)
133  VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples())
134  VTK_SIZEHINT(9);
136 
137  void SetTuple(vtkIdType dstTupleIdx, vtkIdType srcTupleIdx,
138  vtkAbstractArray* source) override;
139 
141 
146  virtual void SetTuple(vtkIdType tupleIdx, const float * tuple)
147  VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
148  virtual void SetTuple(vtkIdType tupleIdx, const double * tuple)
149  VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
151 
153 
158  void SetTuple1(vtkIdType tupleIdx, double value)
159  VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
160  void SetTuple2(vtkIdType tupleIdx, double val0, double val1)
161  VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
162  void SetTuple3(vtkIdType tupleIdx, double val0, double val1, double val2)
163  VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
164  void SetTuple4(vtkIdType tupleIdx, double val0, double val1, double val2,
165  double val3)
166  VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
167  void SetTuple6(vtkIdType tupleIdx, double val0, double val1, double val2,
168  double val3, double val4, double val5)
169  VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
170  void SetTuple9(vtkIdType tupleIdx, double val0, double val1, double val2,
171  double val3, double val4, double val5, double val6,
172  double val7, double val8)
173  VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
175 
177 
181  virtual void InsertTuple(vtkIdType tupleIdx, const float * tuple)
182  VTK_EXPECTS(0 <= tupleIdx) = 0;
183  virtual void InsertTuple(vtkIdType tupleIdx, const double * tuple)
184  VTK_EXPECTS(0 <= tupleIdx) = 0;
186 
188 
193  void InsertTuple1(vtkIdType tupleIdx, double value)
194  VTK_EXPECTS(0 <= tupleIdx);
195  void InsertTuple2(vtkIdType tupleIdx, double val0, double val1)
196  VTK_EXPECTS(0 <= tupleIdx);
197  void InsertTuple3(vtkIdType tupleIdx, double val0, double val1, double val2)
198  VTK_EXPECTS(0 <= tupleIdx);
199  void InsertTuple4(vtkIdType tupleIdx, double val0, double val1, double val2,
200  double val3)
201  VTK_EXPECTS(0 <= tupleIdx);
202  void InsertTuple6(vtkIdType tupleIdx, double val0, double val1, double val2,
203  double val3, double val4, double val5)
204  VTK_EXPECTS(0 <= tupleIdx);
205  void InsertTuple9(vtkIdType tupleIdx, double val0, double val1, double val2,
206  double val3, double val4, double val5, double val6,
207  double val7, double val8)
208  VTK_EXPECTS(0 <= tupleIdx);
210 
212 
217  virtual vtkIdType InsertNextTuple(const float * tuple) = 0;
218  virtual vtkIdType InsertNextTuple(const double * tuple) = 0;
220 
222 
227  void InsertNextTuple1(double value);
228  void InsertNextTuple2(double val0, double val1);
229  void InsertNextTuple3(double val0, double val1, double val2);
230  void InsertNextTuple4(double val0, double val1, double val2,
231  double val3);
232  void InsertNextTuple6(double val0, double val1, double val2,
233  double val3, double val4, double val5);
234  void InsertNextTuple9(double val0, double val1, double val2,
235  double val3, double val4, double val5, double val6,
236  double val7, double val8);
238 
240 
245  virtual void RemoveTuple(vtkIdType tupleIdx)
246  VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples()) = 0;
247  virtual void RemoveFirstTuple() { this->RemoveTuple(0); }
248  virtual void RemoveLastTuple();
250 
255  virtual double GetComponent(vtkIdType tupleIdx, int compIdx)
256  VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples())
257  VTK_EXPECTS(0 <= compIdx && compIdx < GetNumberOfComponents());
258 
266  virtual void SetComponent(vtkIdType tupleIdx, int compIdx, double value)
267  VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples())
268  VTK_EXPECTS(0 <= compIdx && compIdx < GetNumberOfComponents());
269 
274  virtual void InsertComponent(vtkIdType tupleIdx, int compIdx, double value)
275  VTK_EXPECTS(0 <= tupleIdx)
276  VTK_EXPECTS(0 <= compIdx && compIdx < GetNumberOfComponents());
277 
286  virtual void GetData(vtkIdType tupleMin, vtkIdType tupleMax, int compMin,
287  int compMax, vtkDoubleArray* data);
288 
290 
294  void DeepCopy(vtkAbstractArray *aa) override;
295  virtual void DeepCopy(vtkDataArray *da);
297 
307  virtual void ShallowCopy(vtkDataArray *other);
308 
315  virtual void FillComponent(int compIdx, double value)
316  VTK_EXPECTS(0 <= compIdx && compIdx < GetNumberOfComponents());
317 
321  virtual void Fill(double value);
322 
331  virtual void CopyComponent(int dstComponent, vtkDataArray *src,
332  int srcComponent);
333 
339  virtual void* WriteVoidPointer(vtkIdType valueIdx, vtkIdType numValues) = 0;
340 
349  unsigned long GetActualMemorySize() override;
350 
355  void CreateDefaultLookupTable();
356 
358 
361  void SetLookupTable(vtkLookupTable *lut);
362  vtkGetObjectMacro(LookupTable,vtkLookupTable);
364 
374  void GetRange(double range[2], int comp)
375  {
376  this->ComputeRange(range, comp);
377  }
378 
380 
388  double* GetRange(int comp) VTK_SIZEHINT(2)
389  {
390  this->GetRange(this->Range, comp);
391  return this->Range;
392  }
394 
402  double* GetRange() VTK_SIZEHINT(2)
403  {
404  return this->GetRange(0);
405  }
406 
415  void GetRange(double range[2])
416  {
417  this->GetRange(range,0);
418  }
419 
429  void GetFiniteRange(double range[2], int comp)
430  {
431  this->ComputeFiniteRange(range, comp);
432  }
433 
435 
443  double *GetFiniteRange(int comp) VTK_SIZEHINT(2)
444  {
445  this->GetFiniteRange(this->FiniteRange, comp);
446  return this->FiniteRange;
447  }
449 
458  {
459  return this->GetFiniteRange(0);
460  }
461 
470  void GetFiniteRange(double range[2])
471  {
472  this->GetFiniteRange(range, 0);
473  }
474 
476 
481  void GetDataTypeRange(double range[2]);
482  double GetDataTypeMin();
483  double GetDataTypeMax();
484  static void GetDataTypeRange(int type, double range[2]);
485  static double GetDataTypeMin(int type);
486  static double GetDataTypeMax(int type);
488 
493  virtual double GetMaxNorm();
494 
504  static vtkDataArray* CreateDataArray(int dataType);
505 
513  static vtkInformationDoubleVectorKey* COMPONENT_RANGE();
514 
522  static vtkInformationDoubleVectorKey* L2_NORM_RANGE();
523 
531  static vtkInformationDoubleVectorKey* L2_NORM_FINITE_RANGE();
532 
536  void Modified() override;
537 
541  static vtkInformationStringKey *UNITS_LABEL();
542 
550  int CopyInformation(vtkInformation *infoFrom, int deep=1) override;
551 
555  int GetArrayType() override { return DataArray; }
556 
557 protected:
558 
559  friend class vtkPoints;
560 
568  virtual void ComputeRange(double range[2], int comp);
569 
577  virtual void ComputeFiniteRange(double range[2], int comp);
578 
585  virtual bool ComputeScalarRange(double* ranges);
586 
587  // Returns true if the range was computed. Will return false
588  // if you try to compute the range of an array of length zero.
589  virtual bool ComputeVectorRange(double range[2]);
590 
597  virtual bool ComputeFiniteScalarRange(double* ranges);
598 
599  // Returns true if the range was computed. Will return false
600  // if you try to compute the range of an array of length zero.
601  virtual bool ComputeFiniteVectorRange(double range[2]);
602 
603  // Construct object with default tuple dimension (number of components) of 1.
604  vtkDataArray();
605  ~vtkDataArray() override;
606 
608  double Range[2];
609  double FiniteRange[2];
610 
611 private:
612  double* GetTupleN(vtkIdType i, int n);
613 
614 private:
615  vtkDataArray(const vtkDataArray&) = delete;
616  void operator=(const vtkDataArray&) = delete;
617 };
618 
619 //------------------------------------------------------------------------------
621 {
622  if (source)
623  {
624  switch (source->GetArrayType())
625  {
628  case TypedDataArray:
629  case DataArray:
630  case MappedDataArray:
631  return static_cast<vtkDataArray*>(source);
632  default:
633  break;
634  }
635  }
636  return nullptr;
637 }
638 
640 
641 #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:415
#define vtkArrayDownCast_FastCastMacro(ArrayT)
This macro is used to tell vtkArrayDownCast to use FastDownCast instead of SafeDownCast.
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:429
Store vtkAlgorithm input/output information.
vtkIdType GetNumberOfTuples()
Get the number of complete tuples (a component group) in the array.
virtual void GetTuples(vtkIdList *tupleIds, vtkAbstractArray *output)
Given a list of tuple ids, return an array of tuples.
Abstract superclass for all arrays.
virtual int GetDataTypeSize()=0
Return the size of the underlying data type.
map scalar values into colors via a lookup table
int vtkIdType
Definition: vtkType.h:345
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:470
Key for string values in vtkInformation.
int GetArrayType() override
Method for type-checking in FastDownCast implementations.
Definition: vtkDataArray.h:555
double * GetFiniteRange(int comp)
Return the range of the data array values for the given component.
Definition: vtkDataArray.h:443
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:388
#define vtkDataArray
Definition: vtkCharArray.h:33
Key for double vector values.
double * GetFiniteRange()
Return the range of the data array.
Definition: vtkDataArray.h:457
a simple class to control print indentation
Definition: vtkIndent.h:33
double * GetRange()
Return the range of the data array.
Definition: vtkDataArray.h:402
list of point or cell ids
Definition: vtkIdList.h:30
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:48
int GetElementComponentSize() override
Return the size, in bytes, of the lowest-level element of an array.
Definition: vtkDataArray.h:76
vtkLookupTable * LookupTable
Definition: vtkDataArray.h:607
#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.
int IsNumeric() override
This method is here to make backward compatibility easier.
Definition: vtkDataArray.h:68
boost::graph_traits< vtkGraph *>::vertex_descriptor source(boost::graph_traits< vtkGraph * >::edge_descriptor e, vtkGraph *)
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:620
#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:33
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.