VTK  9.2.6
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=========================================================================*/
50#ifndef vtkDataArray_h
51#define vtkDataArray_h
52
53#include "vtkAbstractArray.h"
54#include "vtkCommonCoreModule.h" // For export macro
55#include "vtkVTK_USE_SCALED_SOA_ARRAYS.h" // For #define of VTK_USE_SCALED_SOA_ARRAYS
56
57class vtkDoubleArray;
58class vtkIdList;
61class vtkLookupTable;
62class vtkPoints;
63
64class VTKCOMMONCORE_EXPORT vtkDataArray : public vtkAbstractArray
65{
66public:
68 void PrintSelf(ostream& os, vtkIndent indent) override;
69
76 static vtkDataArray* FastDownCast(vtkAbstractArray* source);
77
84 int IsNumeric() const override { return 1; }
85
91 int GetElementComponentSize() const override { return this->GetDataTypeSize(); }
92
93 // Reimplemented virtuals (doc strings are inherited from superclass):
95
100 void InsertTuple(vtkIdType dstTupleIdx, vtkIdType srcTupleIdx, vtkAbstractArray* source) override;
102 void InsertTuples(vtkIdList* dstIds, vtkIdList* srcIds, vtkAbstractArray* source) override;
104 vtkIdType dstStart, vtkIdType n, vtkIdType srcStart, vtkAbstractArray* source) override;
106 vtkIdType dstStart, vtkIdList* srcIds, vtkAbstractArray* source) override;
107 void SetTuple(vtkIdType dstTupleIdx, vtkIdType srcTupleIdx, vtkAbstractArray* source) override;
109 void GetTuples(vtkIdList* tupleIds, vtkAbstractArray* output) override;
110 void GetTuples(vtkIdType p1, vtkIdType p2, vtkAbstractArray* output) override;
112 double* weights) override;
113 void InterpolateTuple(vtkIdType dstTupleIdx, vtkIdType srcTupleIdx1, vtkAbstractArray* source1,
114 vtkIdType srcTupleIdx2, vtkAbstractArray* source2, double t) override;
115
121 virtual double* GetTuple(vtkIdType tupleIdx)
122 VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples()) = 0;
123
129 virtual void GetTuple(vtkIdType tupleIdx, double* tuple)
130 VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples()) = 0;
131
133
138 double GetTuple1(vtkIdType tupleIdx) VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
139 double* GetTuple2(vtkIdType tupleIdx) VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples())
140 VTK_SIZEHINT(2);
141 double* GetTuple3(vtkIdType tupleIdx) VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples())
142 VTK_SIZEHINT(3);
143 double* GetTuple4(vtkIdType tupleIdx) VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples())
144 VTK_SIZEHINT(4);
145 double* GetTuple6(vtkIdType tupleIdx) VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples())
146 VTK_SIZEHINT(6);
147 double* GetTuple9(vtkIdType tupleIdx) VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples())
148 VTK_SIZEHINT(9);
150
152
157 virtual void SetTuple(vtkIdType tupleIdx, const float* tuple)
158 VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
159 virtual void SetTuple(vtkIdType tupleIdx, const double* tuple)
160 VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
162
164
169 void SetTuple1(vtkIdType tupleIdx, double value)
170 VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
171 void SetTuple2(vtkIdType tupleIdx, double val0, double val1)
172 VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
173 void SetTuple3(vtkIdType tupleIdx, double val0, double val1, double val2)
174 VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
175 void SetTuple4(vtkIdType tupleIdx, double val0, double val1, double val2, double val3)
176 VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
177 void SetTuple6(vtkIdType tupleIdx, double val0, double val1, double val2, double val3,
178 double val4, double val5) VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
179 void SetTuple9(vtkIdType tupleIdx, double val0, double val1, double val2, double val3,
180 double val4, double val5, double val6, double val7, double val8)
181 VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples());
183
185
189 virtual void InsertTuple(vtkIdType tupleIdx, const float* tuple) VTK_EXPECTS(0 <= tupleIdx) = 0;
190 virtual void InsertTuple(vtkIdType tupleIdx, const double* tuple) VTK_EXPECTS(0 <= tupleIdx) = 0;
192
194
199 void InsertTuple1(vtkIdType tupleIdx, double value) VTK_EXPECTS(0 <= tupleIdx);
200 void InsertTuple2(vtkIdType tupleIdx, double val0, double val1) VTK_EXPECTS(0 <= tupleIdx);
201 void InsertTuple3(vtkIdType tupleIdx, double val0, double val1, double val2)
202 VTK_EXPECTS(0 <= tupleIdx);
203 void InsertTuple4(vtkIdType tupleIdx, double val0, double val1, double val2, double val3)
204 VTK_EXPECTS(0 <= tupleIdx);
205 void InsertTuple6(vtkIdType tupleIdx, double val0, double val1, double val2, double val3,
206 double val4, double val5) VTK_EXPECTS(0 <= tupleIdx);
207 void InsertTuple9(vtkIdType tupleIdx, double val0, double val1, double val2, double val3,
208 double val4, double val5, double val6, double val7, double val8) 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, double val3);
231 void InsertNextTuple6(
232 double val0, double val1, double val2, double val3, double val4, double val5);
233 void InsertNextTuple9(double val0, double val1, double val2, double val3, double val4,
234 double val5, double val6, double val7, double val8);
236
238
243 virtual void RemoveTuple(vtkIdType tupleIdx)
244 VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples()) = 0;
245 virtual void RemoveFirstTuple() { this->RemoveTuple(0); }
246 virtual void RemoveLastTuple();
248
253 virtual double GetComponent(vtkIdType tupleIdx, int compIdx) VTK_EXPECTS(0 <= tupleIdx &&
254 tupleIdx < GetNumberOfTuples()) VTK_EXPECTS(0 <= compIdx && compIdx < GetNumberOfComponents());
255
263 virtual void SetComponent(vtkIdType tupleIdx, int compIdx, double value)
264 VTK_EXPECTS(0 <= tupleIdx && tupleIdx < GetNumberOfTuples())
265 VTK_EXPECTS(0 <= compIdx && compIdx < GetNumberOfComponents());
266
271 virtual void InsertComponent(vtkIdType tupleIdx, int compIdx, double value)
272 VTK_EXPECTS(0 <= tupleIdx) VTK_EXPECTS(0 <= compIdx && compIdx < GetNumberOfComponents());
273
282 virtual void GetData(
283 vtkIdType tupleMin, vtkIdType tupleMax, int compMin, int compMax, vtkDoubleArray* data);
284
286
290 void DeepCopy(vtkAbstractArray* aa) override;
291 virtual void DeepCopy(vtkDataArray* da);
293
303 virtual void ShallowCopy(vtkDataArray* other);
304
311 virtual void FillComponent(int compIdx, double value)
312 VTK_EXPECTS(0 <= compIdx && compIdx < GetNumberOfComponents());
313
317 virtual void Fill(double value);
318
327 virtual void CopyComponent(int dstComponent, vtkDataArray* src, int srcComponent);
328
334 virtual void* WriteVoidPointer(vtkIdType valueIdx, vtkIdType numValues) = 0;
335
344 unsigned long GetActualMemorySize() const override;
345
350 void CreateDefaultLookupTable();
351
353
356 void SetLookupTable(vtkLookupTable* lut);
357 vtkGetObjectMacro(LookupTable, vtkLookupTable);
359
361
378 void GetRange(double range[2], int comp) { this->ComputeRange(range, comp); }
379 void GetRange(double range[2], int comp, const unsigned char* ghosts, unsigned char ghostsToSkip)
380 {
381 this->ComputeRange(range, comp, ghosts, ghostsToSkip);
382 }
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) { return this->GetRange(0); }
409
418 void GetRange(double range[2]) { this->GetRange(range, 0); }
419
421
439 void GetFiniteRange(double range[2], int comp) { this->ComputeFiniteRange(range, comp); }
441 double range[2], int comp, const unsigned char* ghosts, unsigned char ghostsToSkip)
442 {
443 this->ComputeFiniteRange(range, comp, ghosts, ghostsToSkip);
444 }
446
448
456 double* GetFiniteRange(int comp) VTK_SIZEHINT(2)
457 {
458 this->GetFiniteRange(this->FiniteRange, comp);
459 return this->FiniteRange;
460 }
462
470 double* GetFiniteRange() VTK_SIZEHINT(2) { return this->GetFiniteRange(0); }
471
480 void GetFiniteRange(double range[2]) { this->GetFiniteRange(range, 0); }
481
483
488 void GetDataTypeRange(double range[2]);
491 static void GetDataTypeRange(int type, double range[2]);
492 static double GetDataTypeMin(int type);
493 static double GetDataTypeMax(int type);
495
500 virtual double GetMaxNorm();
501
511 static vtkDataArray* CreateDataArray(int dataType);
512
521
530
539
543 void Modified() override;
544
549
557 int CopyInformation(vtkInformation* infoFrom, int deep = 1) override;
558
562 int GetArrayType() const override { return DataArray; }
563
564protected:
565 friend class vtkPoints;
566 friend class vtkFieldData;
567
569
585 virtual void ComputeRange(double range[2], int comp);
586 virtual void ComputeRange(
587 double range[2], int comp, const unsigned char* ghosts, unsigned char ghostsToSkip = 0xff);
589
591
607 virtual void ComputeFiniteRange(double range[2], int comp);
608 virtual void ComputeFiniteRange(
609 double range[2], int comp, const unsigned char* ghosts, unsigned char ghostsToSkip = 0xff);
611
613
628 virtual bool ComputeScalarRange(double* ranges);
629 virtual bool ComputeScalarRange(
630 double* ranges, const unsigned char* ghosts, unsigned char ghostsToSkip = 0xff);
632
634
646 virtual bool ComputeVectorRange(double range[2]);
647 virtual bool ComputeVectorRange(
648 double range[2], const unsigned char* ghosts, unsigned char ghostsToSkip = 0xff);
650
652
666 virtual bool ComputeFiniteScalarRange(double* ranges);
668 double* ranges, const unsigned char* ghosts, unsigned char ghostsToSkip = 0xff);
670
672
684 virtual bool ComputeFiniteVectorRange(double range[2]);
686 double range[2], const unsigned char* ghosts, unsigned char ghostsToSkip = 0xff);
688
689 // Construct object with default tuple dimension (number of components) of 1.
691 ~vtkDataArray() override;
692
694 double Range[2];
695 double FiniteRange[2];
696
697private:
698 double* GetTupleN(vtkIdType i, int n);
699
700private:
701 vtkDataArray(const vtkDataArray&) = delete;
702 void operator=(const vtkDataArray&) = delete;
703};
704
705//------------------------------------------------------------------------------
707{
708 if (source)
709 {
710 switch (source->GetArrayType())
711 {
714 case TypedDataArray:
715 case DataArray:
716 case MappedDataArray:
717 return static_cast<vtkDataArray*>(source);
718 default:
719 break;
720 }
721 }
722 return nullptr;
723}
724
726
727// These are used by vtkDataArrayPrivate.txx, but need to be available to
728// vtkGenericDataArray.h as well.
730{
732{
733};
735{
736};
737}
738
739#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
virtual double * GetTuple(vtkIdType tupleIdx)=0
Get the data tuple at tupleIdx.
double * GetRange()
Return the range of the data array.
virtual void ComputeRange(double range[2], int comp, const unsigned char *ghosts, unsigned char ghostsToSkip=0xff)
Compute the range for a specific component.
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 ComputeScalarRange(double *ranges, const unsigned char *ghosts, unsigned char ghostsToSkip=0xff)
Computes the range for each component of an array, the length of ranges must be two times the number ...
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.
void SetTuple(vtkIdType dstTupleIdx, vtkIdType srcTupleIdx, vtkAbstractArray *source) override
See documentation from parent class.
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.
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
See documentation from parent class.
virtual bool ComputeFiniteVectorRange(double range[2], const unsigned char *ghosts, unsigned char ghostsToSkip=0xff)
Returns true if the range was computed.
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
virtual bool ComputeVectorRange(double range[2], const unsigned char *ghosts, unsigned char ghostsToSkip=0xff)
Returns true if the range was computed.
~vtkDataArray() override
int GetArrayType() const override
Method for type-checking in FastDownCast implementations.
int GetElementComponentSize() const override
Return the size, in bytes, of the lowest-level element of an array.
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.
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...
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 InsertTuplesStartingAt(vtkIdType dstStart, vtkIdList *srcIds, vtkAbstractArray *source) override
See documentation from parent class.
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.
static vtkDataArray * FastDownCast(vtkAbstractArray *source)
Perform a fast, safe cast from a vtkAbstractArray to a vtkDataArray.
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
See documentation from parent class.
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
See documentation from parent class.
void GetRange(double range[2], int comp, const unsigned char *ghosts, unsigned char ghostsToSkip)
The range of the data array values for the given component will be returned in the provided range arr...
static void GetDataTypeRange(int type, double range[2])
These methods return the Min and Max possible range of the native data type.
virtual bool ComputeFiniteScalarRange(double *ranges, const unsigned char *ghosts, unsigned char ghostsToSkip=0xff)
Computes the range for each component of an array, the length of ranges must be two times the number ...
virtual void ComputeFiniteRange(double range[2], int comp, const unsigned char *ghosts, unsigned char ghostsToSkip=0xff)
Compute the range for a specific component.
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], int comp, const unsigned char *ghosts, unsigned char ghostsToSkip)
The range of the data array values for the given component will be returned in the provided range arr...
void GetFiniteRange(double range[2])
The range of the data array values will be returned in the provided range array argument.
double * GetFiniteRange(int comp)
Return the range of the data array values for the given component.
void InsertTuples(vtkIdType dstStart, vtkIdType n, vtkIdType srcStart, vtkAbstractArray *source) override
See documentation from parent class.
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
dynamic, self-adjusting array of double
represent and manipulate fields of data
list of point or cell ids
Definition vtkIdList.h:43
a simple class to control print indentation
Definition vtkIndent.h:49
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:49
#define vtkArrayDownCast_FastCastMacro(ArrayT)
This macro is used to tell vtkArrayDownCast to use FastDownCast instead of SafeDownCast.
boost::graph_traits< vtkGraph * >::vertex_descriptor source(boost::graph_traits< vtkGraph * >::edge_descriptor e, vtkGraph *)
#define vtkDataArray
int vtkIdType
Definition vtkType.h:332
#define VTK_SIZEHINT(...)
#define VTK_EXPECTS(x)
#define VTK_NEWINSTANCE