VTK  9.1.0
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=========================================================================*/
44#ifndef vtkDataArray_h
45#define vtkDataArray_h
46
47#include "vtkAbstractArray.h"
48#include "vtkCommonCoreModule.h" // For export macro
49#include "vtkVTK_USE_SCALED_SOA_ARRAYS.h" // For #define of VTK_USE_SCALED_SOA_ARRAYS
50
51class vtkDoubleArray;
52class vtkIdList;
55class vtkLookupTable;
56class vtkPoints;
57
58class VTKCOMMONCORE_EXPORT vtkDataArray : public vtkAbstractArray
59{
60public:
62 void PrintSelf(ostream& os, vtkIndent indent) override;
63
70 static vtkDataArray* FastDownCast(vtkAbstractArray* source);
71
78 int IsNumeric() const override { return 1; }
79
85 int GetElementComponentSize() const override { return this->GetDataTypeSize(); }
86
87 // Reimplemented virtuals (doc strings are inherited from superclass):
88 void InsertTuple(vtkIdType dstTupleIdx, vtkIdType srcTupleIdx, vtkAbstractArray* source) override;
90 void InsertTuples(vtkIdList* dstIds, vtkIdList* srcIds, vtkAbstractArray* source) override;
92 vtkIdType dstStart, vtkIdType n, vtkIdType srcStart, vtkAbstractArray* source) override;
93 void GetTuples(vtkIdList* tupleIds, vtkAbstractArray* output) override;
94 void GetTuples(vtkIdType p1, vtkIdType p2, vtkAbstractArray* output) override;
96 double* weights) override;
97 void InterpolateTuple(vtkIdType dstTupleIdx, vtkIdType srcTupleIdx1, vtkAbstractArray* source1,
98 vtkIdType srcTupleIdx2, vtkAbstractArray* source2, double t) override;
99
105 virtual double* GetTuple(vtkIdType tupleIdx)
106 VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples()) = 0;
107
113 virtual void GetTuple(vtkIdType tupleIdx, double* tuple)
114 VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples()) = 0;
115
117
122 double GetTuple1(vtkIdType tupleIdx) VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
123 double* GetTuple2(vtkIdType tupleIdx) VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples())
124 VTK_SIZEHINT(2);
125 double* GetTuple3(vtkIdType tupleIdx) VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples())
126 VTK_SIZEHINT(3);
127 double* GetTuple4(vtkIdType tupleIdx) VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples())
128 VTK_SIZEHINT(4);
129 double* GetTuple6(vtkIdType tupleIdx) VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples())
130 VTK_SIZEHINT(6);
131 double* GetTuple9(vtkIdType tupleIdx) VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples())
132 VTK_SIZEHINT(9);
134
135 void SetTuple(vtkIdType dstTupleIdx, vtkIdType srcTupleIdx, vtkAbstractArray* source) override;
136
138
143 virtual void SetTuple(vtkIdType tupleIdx, const float* tuple)
144 VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
145 virtual void SetTuple(vtkIdType tupleIdx, const double* tuple)
146 VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
148
150
155 void SetTuple1(vtkIdType tupleIdx, double value)
156 VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
157 void SetTuple2(vtkIdType tupleIdx, double val0, double val1)
158 VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
159 void SetTuple3(vtkIdType tupleIdx, double val0, double val1, double val2)
160 VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
161 void SetTuple4(vtkIdType tupleIdx, double val0, double val1, double val2, double val3)
162 VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
163 void SetTuple6(vtkIdType tupleIdx, double val0, double val1, double val2, double val3,
164 double val4, double val5) VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
165 void SetTuple9(vtkIdType tupleIdx, double val0, double val1, double val2, double val3,
166 double val4, double val5, double val6, double val7, double val8)
167 VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
169
171
175 virtual void InsertTuple(vtkIdType tupleIdx, const float* tuple) VTK_EXPECTS(0 <= tupleIdx) = 0;
176 virtual void InsertTuple(vtkIdType tupleIdx, const double* tuple) VTK_EXPECTS(0 <= tupleIdx) = 0;
178
180
185 void InsertTuple1(vtkIdType tupleIdx, double value) VTK_EXPECTS(0 <= tupleIdx);
186 void InsertTuple2(vtkIdType tupleIdx, double val0, double val1) VTK_EXPECTS(0 <= tupleIdx);
187 void InsertTuple3(vtkIdType tupleIdx, double val0, double val1, double val2)
188 VTK_EXPECTS(0 <= tupleIdx);
189 void InsertTuple4(vtkIdType tupleIdx, double val0, double val1, double val2, double val3)
190 VTK_EXPECTS(0 <= tupleIdx);
191 void InsertTuple6(vtkIdType tupleIdx, double val0, double val1, double val2, double val3,
192 double val4, double val5) VTK_EXPECTS(0 <= tupleIdx);
193 void InsertTuple9(vtkIdType tupleIdx, double val0, double val1, double val2, double val3,
194 double val4, double val5, double val6, double val7, double val8) VTK_EXPECTS(0 <= tupleIdx);
196
198
203 virtual vtkIdType InsertNextTuple(const float* tuple) = 0;
204 virtual vtkIdType InsertNextTuple(const double* tuple) = 0;
206
208
213 void InsertNextTuple1(double value);
214 void InsertNextTuple2(double val0, double val1);
215 void InsertNextTuple3(double val0, double val1, double val2);
216 void InsertNextTuple4(double val0, double val1, double val2, double val3);
217 void InsertNextTuple6(
218 double val0, double val1, double val2, double val3, double val4, double val5);
219 void InsertNextTuple9(double val0, double val1, double val2, double val3, double val4,
220 double val5, double val6, double val7, double val8);
222
224
229 virtual void RemoveTuple(vtkIdType tupleIdx)
230 VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples()) = 0;
231 virtual void RemoveFirstTuple() { this->RemoveTuple(0); }
232 virtual void RemoveLastTuple();
234
239 virtual double GetComponent(vtkIdType tupleIdx, int compIdx) VTK_EXPECTS(0 <= tupleIdx &&
240 tupleIdx < GetNumberOfTuples()) VTK_EXPECTS(0 <= compIdx && compIdx < GetNumberOfComponents());
241
249 virtual void SetComponent(vtkIdType tupleIdx, int compIdx, double value)
250 VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples())
251 VTK_EXPECTS(0 <= compIdx && compIdx < GetNumberOfComponents());
252
257 virtual void InsertComponent(vtkIdType tupleIdx, int compIdx, double value)
258 VTK_EXPECTS(0 <= tupleIdx) VTK_EXPECTS(0 <= compIdx && compIdx < GetNumberOfComponents());
259
268 virtual void GetData(
269 vtkIdType tupleMin, vtkIdType tupleMax, int compMin, int compMax, vtkDoubleArray* data);
270
272
276 void DeepCopy(vtkAbstractArray* aa) override;
277 virtual void DeepCopy(vtkDataArray* da);
279
289 virtual void ShallowCopy(vtkDataArray* other);
290
297 virtual void FillComponent(int compIdx, double value)
298 VTK_EXPECTS(0 <= compIdx && compIdx < GetNumberOfComponents());
299
303 virtual void Fill(double value);
304
313 virtual void CopyComponent(int dstComponent, vtkDataArray* src, int srcComponent);
314
320 virtual void* WriteVoidPointer(vtkIdType valueIdx, vtkIdType numValues) = 0;
321
330 unsigned long GetActualMemorySize() const override;
331
336 void CreateDefaultLookupTable();
337
339
342 void SetLookupTable(vtkLookupTable* lut);
343 vtkGetObjectMacro(LookupTable, vtkLookupTable);
345
355 void GetRange(double range[2], int comp) { this->ComputeRange(range, comp); }
356
358
366 double* GetRange(int comp) VTK_SIZEHINT(2)
367 {
368 this->GetRange(this->Range, comp);
369 return this->Range;
370 }
372
380 double* GetRange() VTK_SIZEHINT(2) { return this->GetRange(0); }
381
390 void GetRange(double range[2]) { this->GetRange(range, 0); }
391
401 void GetFiniteRange(double range[2], int comp) { this->ComputeFiniteRange(range, comp); }
402
404
412 double* GetFiniteRange(int comp) VTK_SIZEHINT(2)
413 {
414 this->GetFiniteRange(this->FiniteRange, comp);
415 return this->FiniteRange;
416 }
418
426 double* GetFiniteRange() VTK_SIZEHINT(2) { return this->GetFiniteRange(0); }
427
436 void GetFiniteRange(double range[2]) { this->GetFiniteRange(range, 0); }
437
439
444 void GetDataTypeRange(double range[2]);
447 static void GetDataTypeRange(int type, double range[2]);
448 static double GetDataTypeMin(int type);
449 static double GetDataTypeMax(int type);
451
456 virtual double GetMaxNorm();
457
467 static vtkDataArray* CreateDataArray(int dataType);
468
477
486
495
499 void Modified() override;
500
505
513 int CopyInformation(vtkInformation* infoFrom, int deep = 1) override;
514
518 int GetArrayType() const override { return DataArray; }
519
520protected:
521 friend class vtkPoints;
522
530 virtual void ComputeRange(double range[2], int comp);
531
539 virtual void ComputeFiniteRange(double range[2], int comp);
540
547 virtual bool ComputeScalarRange(double* ranges);
548
553 virtual bool ComputeVectorRange(double range[2]);
554
561 virtual bool ComputeFiniteScalarRange(double* ranges);
562
567 virtual bool ComputeFiniteVectorRange(double range[2]);
568
569 // Construct object with default tuple dimension (number of components) of 1.
571 ~vtkDataArray() override;
572
574 double Range[2];
575 double FiniteRange[2];
576
577private:
578 double* GetTupleN(vtkIdType i, int n);
579
580private:
581 vtkDataArray(const vtkDataArray&) = delete;
582 void operator=(const vtkDataArray&) = delete;
583};
584
585//------------------------------------------------------------------------------
587{
588 if (source)
589 {
590 switch (source->GetArrayType())
591 {
594 case TypedDataArray:
595 case DataArray:
596 case MappedDataArray:
597 return static_cast<vtkDataArray*>(source);
598 default:
599 break;
600 }
601 }
602 return nullptr;
603}
604
606
607// These are used by vtkDataArrayPrivate.txx, but need to be available to
608// vtkGenericDataArray.h as well.
610{
612{
613};
615{
616};
617}
618
619#endif
Abstract superclass for all arrays.
vtkIdType GetNumberOfTuples() const
Get the number of complete tuples (a component group) in the array.
virtual int GetDataTypeSize() const =0
Return the size of the underlying data type.
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:59
virtual double * GetTuple(vtkIdType tupleIdx)=0
Get the data tuple at tupleIdx.
double * GetRange()
Return the range of the data array.
Definition: vtkDataArray.h:380
static double GetDataTypeMin(int type)
These methods return the Min and Max possible range of the native data type.
double * GetTuple2(vtkIdType tupleIdx)
These methods are included as convenience for the wrappers.
void InterpolateTuple(vtkIdType dstTupleIdx, vtkIdList *ptIndices, vtkAbstractArray *source, double *weights) override
Set the tuple at dstTupleIdx in this array to the interpolated tuple value, given the ptIndices in th...
virtual bool ComputeVectorRange(double range[2])
Returns true if the range was computed.
int IsNumeric() const override
This method is here to make backward compatibility easier.
Definition: vtkDataArray.h:78
void GetDataTypeRange(double range[2])
These methods return the Min and Max possible range of the native data type.
void InterpolateTuple(vtkIdType dstTupleIdx, vtkIdType srcTupleIdx1, vtkAbstractArray *source1, vtkIdType srcTupleIdx2, vtkAbstractArray *source2, double t) override
Insert the tuple at dstTupleIdx in this array to the tuple interpolated from the two tuple indices,...
virtual void ComputeRange(double range[2], int comp)
Compute the range for a specific component.
double * GetFiniteRange()
Return the range of the data array.
Definition: vtkDataArray.h:426
virtual bool ComputeScalarRange(double *ranges)
Computes the range for each component of an array, the length of ranges must be two times the number ...
void InsertTuples(vtkIdList *dstIds, vtkIdList *srcIds, vtkAbstractArray *source) override
Copy the tuples indexed in srcIds from the source array to the tuple locations indexed by dstIds in t...
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
~vtkDataArray() override
int GetArrayType() const override
Method for type-checking in FastDownCast implementations.
Definition: vtkDataArray.h:518
int GetElementComponentSize() const override
Return the size, in bytes, of the lowest-level element of an array.
Definition: vtkDataArray.h:85
virtual bool ComputeFiniteVectorRange(double range[2])
Returns true if the range was computed.
static vtkInformationDoubleVectorKey * COMPONENT_RANGE()
This key is used to hold tight bounds on the range of one component over all tuples of the array.
virtual void RemoveLastTuple()
These methods remove tuples from the data array.
double * GetRange(int comp)
Return the range of the data array values for the given component.
Definition: vtkDataArray.h:366
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:401
void GetTuples(vtkIdType p1, vtkIdType p2, vtkAbstractArray *output) override
Get the tuples for the range of tuple ids specified (i.e., p1->p2 inclusive).
static vtkInformationDoubleVectorKey * L2_NORM_RANGE()
This key is used to hold tight bounds on the $L_2$ norm of tuples in the array.
double GetDataTypeMin()
These methods return the Min and Max possible range of the native data type.
void GetTuples(vtkIdList *tupleIds, vtkAbstractArray *output) override
Given a list of tuple ids, return an array of tuples.
virtual void GetTuple(vtkIdType tupleIdx, double *tuple)=0
Get the data tuple at tupleIdx by filling in a user-provided array, Make sure that your array is larg...
double GetTuple1(vtkIdType tupleIdx)
These methods are included as convenience for the wrappers.
static vtkInformationDoubleVectorKey * L2_NORM_FINITE_RANGE()
This key is used to hold tight bounds on the $L_2$ norm of tuples in the array.
double GetDataTypeMax()
These methods return the Min and Max possible range of the native data type.
int CopyInformation(vtkInformation *infoFrom, int deep=1) override
Copy information instance.
void GetRange(double range[2])
The range of the data array values will be returned in the provided range array argument.
Definition: vtkDataArray.h:390
static vtkDataArray * FastDownCast(vtkAbstractArray *source)
Perform a fast, safe cast from a vtkAbstractArray to a vtkDataArray.
Definition: vtkDataArray.h:586
virtual double GetComponent(vtkIdType tupleIdx, int compIdx)
Return the data component at the location specified by tupleIdx and compIdx.
vtkIdType InsertNextTuple(vtkIdType srcTupleIdx, vtkAbstractArray *source) override
Insert the tuple from srcTupleIdx in the source array at the end of this array.
virtual void ComputeFiniteRange(double range[2], int comp)
Compute the range for a specific component.
virtual double GetMaxNorm()
Return the maximum norm for the tuples.
void InsertTuple(vtkIdType dstTupleIdx, vtkIdType srcTupleIdx, vtkAbstractArray *source) override
Insert the tuple at srcTupleIdx in the source array into this array at dstTupleIdx.
static void GetDataTypeRange(int type, double range[2])
These methods return the Min and Max possible range of the native data type.
static vtkDataArray * CreateDataArray(int dataType)
Creates an array for dataType where dataType is one of VTK_BIT, VTK_CHAR, VTK_SIGNED_CHAR,...
void GetFiniteRange(double range[2])
The range of the data array values will be returned in the provided range array argument.
Definition: vtkDataArray.h:436
double * GetFiniteRange(int comp)
Return the range of the data array values for the given component.
Definition: vtkDataArray.h:412
void InsertTuples(vtkIdType dstStart, vtkIdType n, vtkIdType srcStart, vtkAbstractArray *source) override
Copy n consecutive tuples starting at srcStart from the source array to this array,...
static vtkInformationStringKey * UNITS_LABEL()
A human-readable string indicating the units for the array data.
virtual bool ComputeFiniteScalarRange(double *ranges)
Computes the range for each component of an array, the length of ranges must be two times the number ...
void Modified() override
Removes out-of-date L2_NORM_RANGE() and L2_NORM_FINITE_RANGE() values.
static double GetDataTypeMax(int type)
These methods return the Min and Max possible range of the native data type.
vtkLookupTable * LookupTable
Definition: vtkDataArray.h:573
dynamic, self-adjusting array of double
list of point or cell ids
Definition: vtkIdList.h:40
a simple class to control print indentation
Definition: vtkIndent.h:43
Key for string values in vtkInformation.
Store vtkAlgorithm input/output information.
map scalar values into colors via a lookup table
represent and manipulate 3D points
Definition: vtkPoints.h:43
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.
@ value
Definition: vtkX3D.h:226
@ range
Definition: vtkX3D.h:244
@ type
Definition: vtkX3D.h:522
@ data
Definition: vtkX3D.h:321
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
boost::graph_traits< vtkGraph * >::vertex_descriptor source(boost::graph_traits< vtkGraph * >::edge_descriptor e, vtkGraph *)
#define vtkDataArray
Definition: vtkCharArray.h:55
vtkArrayDownCast_FastCastMacro(vtkDataArray)
int vtkIdType
Definition: vtkType.h:332
#define VTK_SIZEHINT(...)
#define VTK_EXPECTS(x)
#define VTK_NEWINSTANCE