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  VTK_SIZEHINT(2);
129  double* GetTuple3(vtkIdType tupleIdx)
130  VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples())
131  VTK_SIZEHINT(3);
132  double* GetTuple4(vtkIdType tupleIdx)
133  VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples())
134  VTK_SIZEHINT(4);
135  double* GetTuple6(vtkIdType tupleIdx)
136  VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples())
137  VTK_SIZEHINT(6);
138  double* GetTuple9(vtkIdType tupleIdx)
139  VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples())
140  VTK_SIZEHINT(9);
142 
143  void SetTuple(vtkIdType dstTupleIdx, vtkIdType srcTupleIdx,
144  vtkAbstractArray* source) override;
145 
147 
152  virtual void SetTuple(vtkIdType tupleIdx, const float * tuple)
153  VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
154  virtual void SetTuple(vtkIdType tupleIdx, const double * tuple)
155  VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
157 
159 
164  void SetTuple1(vtkIdType tupleIdx, double value)
165  VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
166  void SetTuple2(vtkIdType tupleIdx, double val0, double val1)
167  VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
168  void SetTuple3(vtkIdType tupleIdx, double val0, double val1, double val2)
169  VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
170  void SetTuple4(vtkIdType tupleIdx, double val0, double val1, double val2,
171  double val3)
172  VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
173  void SetTuple6(vtkIdType tupleIdx, double val0, double val1, double val2,
174  double val3, double val4, double val5)
175  VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
176  void SetTuple9(vtkIdType tupleIdx, double val0, double val1, double val2,
177  double val3, double val4, double val5, double val6,
178  double val7, double val8)
179  VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
181 
183 
187  virtual void InsertTuple(vtkIdType tupleIdx, const float * tuple)
188  VTK_EXPECTS(0 <= tupleIdx) = 0;
189  virtual void InsertTuple(vtkIdType tupleIdx, const double * tuple)
190  VTK_EXPECTS(0 <= tupleIdx) = 0;
192 
194 
199  void InsertTuple1(vtkIdType tupleIdx, double value)
200  VTK_EXPECTS(0 <= tupleIdx);
201  void InsertTuple2(vtkIdType tupleIdx, double val0, double val1)
202  VTK_EXPECTS(0 <= tupleIdx);
203  void InsertTuple3(vtkIdType tupleIdx, double val0, double val1, double val2)
204  VTK_EXPECTS(0 <= tupleIdx);
205  void InsertTuple4(vtkIdType tupleIdx, double val0, double val1, double val2,
206  double val3)
207  VTK_EXPECTS(0 <= tupleIdx);
208  void InsertTuple6(vtkIdType tupleIdx, double val0, double val1, double val2,
209  double val3, double val4, double val5)
210  VTK_EXPECTS(0 <= tupleIdx);
211  void InsertTuple9(vtkIdType tupleIdx, double val0, double val1, double val2,
212  double val3, double val4, double val5, double val6,
213  double val7, double val8)
214  VTK_EXPECTS(0 <= tupleIdx);
216 
218 
223  virtual vtkIdType InsertNextTuple(const float * tuple) = 0;
224  virtual vtkIdType InsertNextTuple(const double * tuple) = 0;
226 
228 
233  void InsertNextTuple1(double value);
234  void InsertNextTuple2(double val0, double val1);
235  void InsertNextTuple3(double val0, double val1, double val2);
236  void InsertNextTuple4(double val0, double val1, double val2,
237  double val3);
238  void InsertNextTuple6(double val0, double val1, double val2,
239  double val3, double val4, double val5);
240  void InsertNextTuple9(double val0, double val1, double val2,
241  double val3, double val4, double val5, double val6,
242  double val7, double val8);
244 
246 
251  virtual void RemoveTuple(vtkIdType tupleIdx)
252  VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples()) = 0;
253  virtual void RemoveFirstTuple() { this->RemoveTuple(0); }
254  virtual void RemoveLastTuple();
256 
261  virtual double GetComponent(vtkIdType tupleIdx, int compIdx)
262  VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples())
263  VTK_EXPECTS(0 <= compIdx && compIdx < GetNumberOfComponents());
264 
272  virtual void SetComponent(vtkIdType tupleIdx, int compIdx, double value)
273  VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples())
274  VTK_EXPECTS(0 <= compIdx && compIdx < GetNumberOfComponents());
275 
280  virtual void InsertComponent(vtkIdType tupleIdx, int compIdx, double value)
281  VTK_EXPECTS(0 <= tupleIdx)
282  VTK_EXPECTS(0 <= compIdx && compIdx < GetNumberOfComponents());
283 
292  virtual void GetData(vtkIdType tupleMin, vtkIdType tupleMax, int compMin,
293  int compMax, vtkDoubleArray* data);
294 
296 
300  void DeepCopy(vtkAbstractArray *aa) override;
301  virtual void DeepCopy(vtkDataArray *da);
303 
313  virtual void ShallowCopy(vtkDataArray *other);
314 
321  virtual void FillComponent(int compIdx, double value)
322  VTK_EXPECTS(0 <= compIdx && compIdx < GetNumberOfComponents());
323 
327  virtual void Fill(double value);
328 
337  virtual void CopyComponent(int dstComponent, vtkDataArray *src,
338  int srcComponent);
339 
345  virtual void* WriteVoidPointer(vtkIdType valueIdx, vtkIdType numValues) = 0;
346 
355  unsigned long GetActualMemorySize() override;
356 
361  void CreateDefaultLookupTable();
362 
364 
367  void SetLookupTable(vtkLookupTable *lut);
368  vtkGetObjectMacro(LookupTable,vtkLookupTable);
370 
380  void GetRange(double range[2], int comp)
381  {
382  this->ComputeRange(range, comp);
383  }
384 
386 
394  double* GetRange(int comp) VTK_SIZEHINT(2)
395  {
396  this->GetRange(this->Range, comp);
397  return this->Range;
398  }
400 
408  double* GetRange() VTK_SIZEHINT(2)
409  {
410  return this->GetRange(0);
411  }
412 
421  void GetRange(double range[2])
422  {
423  this->GetRange(range,0);
424  }
425 
435  void GetFiniteRange(double range[2], int comp)
436  {
437  this->ComputeFiniteRange(range, comp);
438  }
439 
441 
449  double *GetFiniteRange(int comp) VTK_SIZEHINT(2)
450  {
451  this->GetFiniteRange(this->FiniteRange, comp);
452  return this->FiniteRange;
453  }
455 
463  double *GetFiniteRange() VTK_SIZEHINT(2)
464  {
465  return this->GetFiniteRange(0);
466  }
467 
476  void GetFiniteRange(double range[2])
477  {
478  this->GetFiniteRange(range, 0);
479  }
480 
482 
487  void GetDataTypeRange(double range[2]);
488  double GetDataTypeMin();
489  double GetDataTypeMax();
490  static void GetDataTypeRange(int type, double range[2]);
491  static double GetDataTypeMin(int type);
492  static double GetDataTypeMax(int type);
494 
499  virtual double GetMaxNorm();
500 
510  static vtkDataArray* CreateDataArray(int dataType);
511 
519  static vtkInformationDoubleVectorKey* COMPONENT_RANGE();
520 
528  static vtkInformationDoubleVectorKey* L2_NORM_RANGE();
529 
537  static vtkInformationDoubleVectorKey* L2_NORM_FINITE_RANGE();
538 
542  void Modified() override;
543 
547  static vtkInformationStringKey *UNITS_LABEL();
548 
556  int CopyInformation(vtkInformation *infoFrom, int deep=1) override;
557 
561  int GetArrayType() override { return DataArray; }
562 
563 protected:
564 
565  friend class vtkPoints;
566 
574  virtual void ComputeRange(double range[2], int comp);
575 
583  virtual void ComputeFiniteRange(double range[2], int comp);
584 
591  virtual bool ComputeScalarRange(double* ranges);
592 
593  // Returns true if the range was computed. Will return false
594  // if you try to compute the range of an array of length zero.
595  virtual bool ComputeVectorRange(double range[2]);
596 
603  virtual bool ComputeFiniteScalarRange(double* ranges);
604 
605  // Returns true if the range was computed. Will return false
606  // if you try to compute the range of an array of length zero.
607  virtual bool ComputeFiniteVectorRange(double range[2]);
608 
609  // Construct object with default tuple dimension (number of components) of 1.
610  vtkDataArray();
611  ~vtkDataArray() override;
612 
614  double Range[2];
615  double FiniteRange[2];
616 
617 private:
618  double* GetTupleN(vtkIdType i, int n);
619 
620 private:
621  vtkDataArray(const vtkDataArray&) = delete;
622  void operator=(const vtkDataArray&) = delete;
623 };
624 
625 //------------------------------------------------------------------------------
627 {
628  if (source)
629  {
630  switch (source->GetArrayType())
631  {
632  case AoSDataArrayTemplate:
633  case SoADataArrayTemplate:
634  case TypedDataArray:
635  case DataArray:
636  case MappedDataArray:
637  return static_cast<vtkDataArray*>(source);
638  default:
639  break;
640  }
641  }
642  return nullptr;
643 }
644 
646 
647 #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:421
#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:435
virtual void DeepCopy(vtkAbstractArray *da)
Deep copy of data.
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
virtual int GetArrayType()
Method for type-checking in FastDownCast implementations.
int vtkIdType
Definition: vtkType.h:347
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 GetNumberOfComponents()
Set/Get the dimension (n) of the components.
void GetFiniteRange(double range[2])
The range of the data array values will be returned in the provided range array argument.
Definition: vtkDataArray.h:476
Key for string values in vtkInformation.
void GetRange(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:380
int GetArrayType() override
Method for type-checking in FastDownCast implementations.
Definition: vtkDataArray.h:561
double * GetFiniteRange(int comp)
Return the range of the data array values for the given component.
Definition: vtkDataArray.h:449
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:394
#define vtkDataArray
Definition: vtkCharArray.h:36
Key for double vector values.
double * GetFiniteRange()
Return the range of the data array.
Definition: vtkDataArray.h:463
a simple class to control print indentation
Definition: vtkIndent.h:39
double * GetRange()
Return the range of the data array.
Definition: vtkDataArray.h:408
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:613
#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: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:626
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...
virtual unsigned long GetActualMemorySize()=0
Return the memory in kibibytes (1024 bytes) consumed by this data 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:253
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.