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 =========================================================================*/
41 #ifndef vtkDataArray_h
42 #define vtkDataArray_h
43 
44 #include "vtkCommonCoreModule.h" // For export macro
45 #include "vtkAbstractArray.h"
46 
47 class vtkDoubleArray;
48 class vtkIdList;
51 class vtkLookupTable;
52 class vtkPoints;
53 
54 class VTKCOMMONCORE_EXPORT vtkDataArray : public vtkAbstractArray
55 {
56 public:
58  void PrintSelf(ostream& os, vtkIndent indent) override;
59 
66  static vtkDataArray* FastDownCast(vtkAbstractArray *source);
67 
74  int IsNumeric() override
75  { return 1; }
76 
82  int GetElementComponentSize() override
83  { return this->GetDataTypeSize(); }
84 
85  // Reimplemented virtuals (doc strings are inherited from superclass):
86  void InsertTuple(vtkIdType dstTupleIdx, vtkIdType srcTupleIdx,
87  vtkAbstractArray* source) override;
89  vtkAbstractArray* source) override;
90  void InsertTuples(vtkIdList *dstIds, vtkIdList *srcIds,
91  vtkAbstractArray *source) override;
92  void InsertTuples(vtkIdType dstStart, vtkIdType n, vtkIdType srcStart,
93  vtkAbstractArray* source) override;
94  void GetTuples(vtkIdList *tupleIds, vtkAbstractArray *output) override;
95  void GetTuples(vtkIdType p1, vtkIdType p2, vtkAbstractArray *output) override;
96  void InterpolateTuple(vtkIdType dstTupleIdx, vtkIdList *ptIndices,
97  vtkAbstractArray* source, double* weights) override;
98  void InterpolateTuple(vtkIdType dstTupleIdx,
99  vtkIdType srcTupleIdx1, vtkAbstractArray* source1,
100  vtkIdType srcTupleIdx2, vtkAbstractArray* source2, double t) override;
101 
107  virtual double *GetTuple(vtkIdType tupleIdx)
108  VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples()) = 0;
109 
115  virtual void GetTuple(vtkIdType tupleIdx, double * tuple)
116  VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples()) = 0;
117 
119 
124  double GetTuple1(vtkIdType tupleIdx)
125  VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
126  double* GetTuple2(vtkIdType tupleIdx)
127  VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
128  double* GetTuple3(vtkIdType tupleIdx)
129  VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
130  double* GetTuple4(vtkIdType tupleIdx)
131  VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
132  double* GetTuple6(vtkIdType tupleIdx)
133  VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
134  double* GetTuple9(vtkIdType tupleIdx)
135  VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
137 
138  void SetTuple(vtkIdType dstTupleIdx, vtkIdType srcTupleIdx,
139  vtkAbstractArray* source) override;
140 
142 
147  virtual void SetTuple(vtkIdType tupleIdx, const float * tuple)
148  VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
149  virtual void SetTuple(vtkIdType tupleIdx, const double * tuple)
150  VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
152 
154 
159  void SetTuple1(vtkIdType tupleIdx, double value)
160  VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
161  void SetTuple2(vtkIdType tupleIdx, double val0, double val1)
162  VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
163  void SetTuple3(vtkIdType tupleIdx, double val0, double val1, double val2)
164  VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
165  void SetTuple4(vtkIdType tupleIdx, double val0, double val1, double val2,
166  double val3)
167  VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
168  void SetTuple6(vtkIdType tupleIdx, double val0, double val1, double val2,
169  double val3, double val4, double val5)
170  VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
171  void SetTuple9(vtkIdType tupleIdx, double val0, double val1, double val2,
172  double val3, double val4, double val5, double val6,
173  double val7, double val8)
174  VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
176 
178 
182  virtual void InsertTuple(vtkIdType tupleIdx, const float * tuple)
183  VTK_EXPECTS(0 <= tupleIdx) = 0;
184  virtual void InsertTuple(vtkIdType tupleIdx, const double * tuple)
185  VTK_EXPECTS(0 <= tupleIdx) = 0;
187 
189 
194  void InsertTuple1(vtkIdType tupleIdx, double value)
195  VTK_EXPECTS(0 <= tupleIdx);
196  void InsertTuple2(vtkIdType tupleIdx, double val0, double val1)
197  VTK_EXPECTS(0 <= tupleIdx);
198  void InsertTuple3(vtkIdType tupleIdx, double val0, double val1, double val2)
199  VTK_EXPECTS(0 <= tupleIdx);
200  void InsertTuple4(vtkIdType tupleIdx, double val0, double val1, double val2,
201  double val3)
202  VTK_EXPECTS(0 <= tupleIdx);
203  void InsertTuple6(vtkIdType tupleIdx, double val0, double val1, double val2,
204  double val3, double val4, double val5)
205  VTK_EXPECTS(0 <= tupleIdx);
206  void InsertTuple9(vtkIdType tupleIdx, double val0, double val1, double val2,
207  double val3, double val4, double val5, double val6,
208  double val7, double val8)
209  VTK_EXPECTS(0 <= tupleIdx);
211 
213 
218  virtual vtkIdType InsertNextTuple(const float * tuple) = 0;
219  virtual vtkIdType InsertNextTuple(const double * tuple) = 0;
221 
223 
228  void InsertNextTuple1(double value);
229  void InsertNextTuple2(double val0, double val1);
230  void InsertNextTuple3(double val0, double val1, double val2);
231  void InsertNextTuple4(double val0, double val1, double val2,
232  double val3);
233  void InsertNextTuple6(double val0, double val1, double val2,
234  double val3, double val4, double val5);
235  void InsertNextTuple9(double val0, double val1, double val2,
236  double val3, double val4, double val5, double val6,
237  double val7, double val8);
239 
241 
246  virtual void RemoveTuple(vtkIdType tupleIdx)
247  VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples()) = 0;
248  virtual void RemoveFirstTuple() { this->RemoveTuple(0); }
249  virtual void RemoveLastTuple();
251 
256  virtual double GetComponent(vtkIdType tupleIdx, int compIdx)
257  VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples())
258  VTK_EXPECTS(0 <= compIdx && compIdx < GetNumberOfComponents());
259 
267  virtual void SetComponent(vtkIdType tupleIdx, int compIdx, double value)
268  VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples())
269  VTK_EXPECTS(0 <= compIdx && compIdx < GetNumberOfComponents());
270 
275  virtual void InsertComponent(vtkIdType tupleIdx, int compIdx, double value)
276  VTK_EXPECTS(0 <= tupleIdx)
277  VTK_EXPECTS(0 <= compIdx && compIdx < GetNumberOfComponents());
278 
287  virtual void GetData(vtkIdType tupleMin, vtkIdType tupleMax, int compMin,
288  int compMax, vtkDoubleArray* data);
289 
291 
295  void DeepCopy(vtkAbstractArray *aa) override;
296  virtual void DeepCopy(vtkDataArray *da);
298 
308  virtual void ShallowCopy(vtkDataArray *other);
309 
316  virtual void FillComponent(int compIdx, double value)
317  VTK_EXPECTS(0 <= compIdx && compIdx < GetNumberOfComponents());
318 
322  virtual void Fill(double value);
323 
332  virtual void CopyComponent(int dstComponent, vtkDataArray *src,
333  int srcComponent);
334 
340  virtual void* WriteVoidPointer(vtkIdType valueIdx, vtkIdType numValues) = 0;
341 
350  unsigned long GetActualMemorySize() override;
351 
356  void CreateDefaultLookupTable();
357 
359 
362  void SetLookupTable(vtkLookupTable *lut);
363  vtkGetObjectMacro(LookupTable,vtkLookupTable);
365 
375  void GetRange(double range[2], int comp)
376  {
377  this->ComputeRange(range, comp);
378  }
379 
381 
389  double* GetRange(int comp)
390  {
391  this->GetRange(this->Range, comp);
392  return this->Range;
393  }
395 
403  double* GetRange()
404  {
405  return this->GetRange(0);
406  }
407 
416  void GetRange(double range[2])
417  {
418  this->GetRange(range,0);
419  }
420 
430  void GetFiniteRange(double range[2], int comp)
431  {
432  this->ComputeFiniteRange(range, comp);
433  }
434 
436 
444  double *GetFiniteRange(int comp)
445  {
446  this->GetFiniteRange(this->FiniteRange, comp);
447  return this->FiniteRange;
448  }
450 
458  double *GetFiniteRange()
459  {
460  return this->GetFiniteRange(0);
461  }
462 
471  void GetFiniteRange(double range[2])
472  {
473  this->GetFiniteRange(range, 0);
474  }
475 
477 
482  void GetDataTypeRange(double range[2]);
483  double GetDataTypeMin();
484  double GetDataTypeMax();
485  static void GetDataTypeRange(int type, double range[2]);
486  static double GetDataTypeMin(int type);
487  static double GetDataTypeMax(int type);
489 
494  virtual double GetMaxNorm();
495 
505  static vtkDataArray* CreateDataArray(int dataType);
506 
514  static vtkInformationDoubleVectorKey* COMPONENT_RANGE();
515 
523  static vtkInformationDoubleVectorKey* L2_NORM_RANGE();
524 
532  static vtkInformationDoubleVectorKey* L2_NORM_FINITE_RANGE();
533 
537  void Modified() override;
538 
542  static vtkInformationStringKey *UNITS_LABEL();
543 
551  int CopyInformation(vtkInformation *infoFrom, int deep=1) override;
552 
556  int GetArrayType() override { return DataArray; }
557 
558 protected:
559 
560  friend class vtkPoints;
561 
569  virtual void ComputeRange(double range[2], int comp);
570 
578  virtual void ComputeFiniteRange(double range[2], int comp);
579 
586  virtual bool ComputeScalarRange(double* ranges);
587 
588  // Returns true if the range was computed. Will return false
589  // if you try to compute the range of an array of length zero.
590  virtual bool ComputeVectorRange(double range[2]);
591 
598  virtual bool ComputeFiniteScalarRange(double* ranges);
599 
600  // Returns true if the range was computed. Will return false
601  // if you try to compute the range of an array of length zero.
602  virtual bool ComputeFiniteVectorRange(double range[2]);
603 
604  // Construct object with default tuple dimension (number of components) of 1.
605  vtkDataArray();
606  ~vtkDataArray() override;
607 
609  double Range[2];
610  double FiniteRange[2];
611 
612 private:
613  double* GetTupleN(vtkIdType i, int n);
614 
615 private:
616  vtkDataArray(const vtkDataArray&) = delete;
617  void operator=(const vtkDataArray&) = delete;
618 };
619 
620 //------------------------------------------------------------------------------
622 {
623  if (source)
624  {
625  switch (source->GetArrayType())
626  {
629  case TypedDataArray:
630  case DataArray:
631  case MappedDataArray:
632  return static_cast<vtkDataArray*>(source);
633  default:
634  break;
635  }
636  }
637  return nullptr;
638 }
639 
641 
642 #endif
void Modified() override
Removes out-of-date PER_COMPONENT() and PER_FINITE_COMPONENT() values.
void GetRange(double range[2])
The the range of the data array values will be returned in the provided range array argument.
Definition: vtkDataArray.h:416
#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:430
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 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.
int GetArrayType() override
Method for type-checking in FastDownCast implementations.
Definition: vtkDataArray.h:556
double * GetFiniteRange(int comp)
Return the range of the data array values for the given component.
Definition: vtkDataArray.h:444
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:389
#define vtkDataArray
Definition: vtkCharArray.h:36
double * GetFiniteRange()
Return the range of the data array.
Definition: vtkDataArray.h:458
a simple class to control print indentation
Definition: vtkIndent.h:39
double * GetRange()
Return the range of the data array.
Definition: vtkDataArray.h:403
list of point or cell ids
Definition: vtkIdList.h:36
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:54
int GetElementComponentSize() override
Return the size, in bytes, of the lowest-level element of an array.
Definition: vtkDataArray.h:82
vtkLookupTable * LookupTable
Definition: vtkDataArray.h:608
#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:74
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:621
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.
#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
virtual void RemoveFirstTuple()
These methods remove tuples from the data array.
Definition: vtkDataArray.h:248
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.