Thanks to visit codestin.com
Credit goes to vtk.org

VTK  9.5.20251005
vtkAbstractArray.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2// SPDX-License-Identifier: BSD-3-Clause
3//
65#ifndef vtkAbstractArray_h
66#define vtkAbstractArray_h
67
68#include "vtkCommonCoreModule.h" // For export macro
69#include "vtkIdList.h" // For InsertTuples
70#include "vtkObject.h"
71#include "vtkVariant.h" // for variant arguments
72#include "vtkWrappingHints.h" // For VTK_MARSHALAUTO
73
74VTK_ABI_NAMESPACE_BEGIN
76class vtkDataArray;
77class vtkIdList;
78class vtkIdTypeArray;
79class vtkInformation;
84class vtkVariantArray;
85
86class VTKCOMMONCORE_EXPORT VTK_MARSHALAUTO vtkAbstractArray : public vtkObject
87{
88public:
90 void PrintSelf(ostream& os, vtkIndent indent) override;
91 using ArrayTypeTag = std::integral_constant<int, vtkArrayTypes::AbstractArray>;
92 using DataTypeTag = std::integral_constant<int, VTK_OPAQUE>;
93
97 void PrintValues(ostream& os);
98
107 virtual vtkTypeBool Allocate(vtkIdType numValues, vtkIdType ext = 1000) = 0;
108
112 virtual void Initialize() = 0;
113
118 virtual int GetDataType() const { return vtkAbstractArray::DataTypeTag::value; };
119
121
126 virtual int GetDataTypeSize() const = 0;
127 static int GetDataTypeSize(int type);
129
137 virtual int GetElementComponentSize() const = 0;
138
140
144 vtkSetClampMacro(NumberOfComponents, int, 1, VTK_INT_MAX);
145 int GetNumberOfComponents() const { return this->NumberOfComponents; }
147
151 void SetComponentName(vtkIdType component, const char* name);
152
157 const char* GetComponentName(vtkIdType component) const;
158
162 bool HasAComponentName() const;
163
169
184 virtual bool CopyComponent(int dstComponent, vtkAbstractArray* src, int srcComponent) = 0;
185
193 virtual void SetNumberOfTuples(vtkIdType numTuples) = 0;
194
202 virtual bool SetNumberOfValues(vtkIdType numValues);
203
207 vtkIdType GetNumberOfTuples() const { return (this->MaxId + 1) / this->NumberOfComponents; }
208
216 vtkIdType GetNumberOfValues() const { return (this->MaxId + 1); }
217
224 virtual void SetTuple(vtkIdType dstTupleIdx, vtkIdType srcTupleIdx, vtkAbstractArray* source) = 0;
225
231 virtual void InsertTuple(
232 vtkIdType dstTupleIdx, vtkIdType srcTupleIdx, vtkAbstractArray* source) = 0;
233
239 virtual void InsertTuples(vtkIdList* dstIds, vtkIdList* srcIds, vtkAbstractArray* source) = 0;
240
247 vtkIdType dstStart, vtkIdList* srcIds, vtkAbstractArray* source) = 0;
248
254 virtual void InsertTuples(
255 vtkIdType dstStart, vtkIdType n, vtkIdType srcStart, vtkAbstractArray* source) = 0;
256
263
269 virtual void GetTuples(vtkIdList* tupleIds, vtkAbstractArray* output);
270
276 virtual void GetTuples(vtkIdType p1, vtkIdType p2, vtkAbstractArray* output);
277
284 virtual bool HasStandardMemoryLayout() const;
285
293 virtual void* GetVoidPointer(vtkIdType valueIdx) = 0;
294
303 virtual void DeepCopy(vtkAbstractArray* da);
304
312 virtual void InterpolateTuple(
313 vtkIdType dstTupleIdx, vtkIdList* ptIndices, vtkAbstractArray* source, double* weights) = 0;
314
323 virtual void InterpolateTuple(vtkIdType dstTupleIdx, vtkIdType srcTupleIdx1,
324 vtkAbstractArray* source1, vtkIdType srcTupleIdx2, vtkAbstractArray* source2, double t) = 0;
325
331 virtual void Squeeze() = 0;
332
342 virtual vtkTypeBool Resize(vtkIdType numTuples) = 0;
343
345
348 void Reset()
349 {
350 this->MaxId = -1;
351 this->DataChanged();
352 }
354
359 vtkIdType GetSize() const { return this->Size; }
360
364 vtkIdType GetMaxId() const { return this->MaxId; }
365
367 {
371 VTK_DATA_ARRAY_USER_DEFINED
372 };
373
375
392 virtual void SetVoidArray(
393 void* vtkNotUsed(array), vtkIdType vtkNotUsed(size), int vtkNotUsed(save)) = 0;
394 virtual void SetVoidArray(void* array, vtkIdType size, int save, int vtkNotUsed(deleteMethod))
395 {
396 this->SetVoidArray(array, size, save);
397 }
399
406 virtual void SetArrayFreeFunction(void (*callback)(void*)) = 0;
407
413 virtual void ExportToVoidPointer(void* out_ptr);
414
423 virtual unsigned long GetActualMemorySize() const = 0;
424
426
429 vtkSetStringMacro(Name);
430 vtkGetStringMacro(Name);
432
436 virtual const char* GetDataTypeAsString() const
437 {
438 return vtkImageScalarTypeNameMacro(this->GetDataType());
439 }
440
451 static vtkAbstractArray* CreateArray(int dataType);
452
457 virtual int IsNumeric() const = 0;
458
462 virtual bool IsIntegral() const;
463
470
477 virtual vtkIdType GetDataSize() const
478 {
479 return this->GetNumberOfComponents() * this->GetNumberOfTuples();
480 }
481
483
490 virtual vtkIdType LookupValue(vtkVariant value) = 0;
491 virtual void LookupValue(vtkVariant value, vtkIdList* valueIds) = 0;
493
498 VTK_EXPECTS(0 <= valueIdx && valueIdx < GetNumberOfValues());
499
504 virtual void InsertVariantValue(vtkIdType valueIdx, vtkVariant value)
505 VTK_EXPECTS(0 <= valueIdx) = 0;
506
511 virtual void SetVariantValue(vtkIdType valueIdx, vtkVariant value)
512 VTK_EXPECTS(0 <= valueIdx && valueIdx < GetNumberOfValues()) = 0;
513
522 virtual void DataChanged() = 0;
523
529 virtual void ClearLookup() = 0;
530
583 virtual void GetProminentComponentValues(int comp, vtkVariantArray* values,
584 double uncertainty = 1.e-6, double minimumProminence = 1.e-3);
585
586 // TODO: Implement these lookup functions also.
587 // virtual void LookupRange(vtkVariant min, vtkVariant max, vtkIdList* ids,
588 // bool includeMin = true, bool includeMax = true) = 0;
589 // virtual void LookupGreaterThan(vtkVariant min, vtkIdList* ids, bool includeMin = false) = 0;
590 // virtual void LookupLessThan(vtkVariant max, vtkIdList* ids, bool includeMax = false) = 0;
591
602 bool HasInformation() const { return this->Information != nullptr; }
603
615 virtual int CopyInformation(vtkInformation* infoFrom, vtkTypeBool deep = 1);
616
623
638
653
657 void Modified() override;
658
666
676
677 enum
678 {
679 MAX_DISCRETE_VALUES = 32
680 };
681
683
687 vtkGetMacro(MaxDiscreteValues, unsigned int);
688 vtkSetMacro(MaxDiscreteValues, unsigned int);
690
692 "Use vtkArrayTypes::AbstractArray") = vtkArrayTypes::AbstractArray;
693 static constexpr int DataArray VTK_DEPRECATED_IN_9_6_0(
694 "Use vtkArrayTypes::DataArray") = vtkArrayTypes::DataArray;
696 "Use vtkArrayTypes::AoSDataArrayTemplate") = vtkArrayTypes::AoSDataArrayTemplate;
698 "Use vtkArrayTypes::SoADataArrayTemplate") = vtkArrayTypes::SoADataArrayTemplate;
699 static constexpr int TypedDataArray VTK_DEPRECATED_IN_9_5_0(
700 "TypedDataArray has been deprecated") = vtkArrayTypes::NumArrayTypes;
701 static constexpr int MappedDataArray VTK_DEPRECATED_IN_9_5_0(
702 "MappedDataArray has been deprecated") = vtkArrayTypes::NumArrayTypes + 1;
704 "Use vtkArrayTypes::ScaledSoADataArrayTemplate") = vtkArrayTypes::ScaledSoADataArrayTemplate;
706 "Use vtkArrayTypes::ImplicitArray") = vtkArrayTypes::ImplicitArray;
707 static constexpr int DataArrayTemplate VTK_DEPRECATED_IN_9_6_0(
708 "DataArrayTemplate has been deprecated") = vtkArrayTypes::AoSDataArrayTemplate;
709 static constexpr int ScaleSoADataArrayTemplate VTK_DEPRECATED_IN_9_6_0(
710 "ScaleSoADataArrayTemplate has been renamed to ScaledSoADataArrayTemplate") =
712
717 virtual int GetArrayType() const { return vtkAbstractArray::ArrayTypeTag::value; }
718
720
723 static const char* GetArrayTypeAsString(int arrayType);
724 const char* GetArrayTypeAsString() const
725 {
726 return vtkAbstractArray::GetArrayTypeAsString(this->GetArrayType());
727 }
729
730protected:
731 // Construct object with default tuple dimension (number of components) of 1.
734
741
753 virtual void UpdateDiscreteValueSet(double uncertainty, double minProminence);
754
755 vtkIdType Size; // allocated size of data
756 vtkIdType MaxId; // maximum index inserted thus far
757 int NumberOfComponents; // the number of components per tuple
758
759 // maximum number of prominent values before array is considered continuous.
760 unsigned int MaxDiscreteValues;
761
762 char* Name;
763
764 bool RebuildArray; // whether to rebuild the fast lookup data structure.
765
767
768 class vtkInternalComponentNames;
769 vtkInternalComponentNames* ComponentNames; // names for each component
770
771private:
772 vtkAbstractArray(const vtkAbstractArray&) = delete;
773 void operator=(const vtkAbstractArray&) = delete;
774};
775
777
782template <typename ArrayT>
784{
785 ArrayT* operator()(vtkAbstractArray* array) { return ArrayT::SafeDownCast(array); }
786};
788
806template <typename ArrayT>
808{
809 // The default vtkArrayDownCast_impl struct uses SafeDownCast, but is
810 // specialized for arrays that support FastDownCast.
811 return vtkArrayDownCast_impl<ArrayT>()(array);
812}
813
814VTK_ABI_NAMESPACE_END
815
817
821#define vtkArrayDownCast_FastCastMacro(ArrayT) \
822 template <> \
823 struct vtkArrayDownCast_impl<ArrayT> \
824 { \
825 inline ArrayT* operator()(vtkAbstractArray* array) \
826 { \
827 return ArrayT::FastDownCast(array); \
828 } \
829 }
831
833
839#define vtkArrayDownCast_TemplateFastCastMacro(ArrayT) \
840 template <typename ValueT> \
841 struct vtkArrayDownCast_impl<ArrayT<ValueT>> \
842 { \
843 inline ArrayT<ValueT>* operator()(vtkAbstractArray* array) \
844 { \
845 return ArrayT<ValueT>::FastDownCast(array); \
846 } \
847 }
849
851
857#define vtkArrayDownCast_Template2FastCastMacro(ArrayT) \
858 template <typename ValueT, int ArrayType> \
859 struct vtkArrayDownCast_impl<ArrayT<ValueT, ArrayType>> \
860 { \
861 inline ArrayT<ValueT, ArrayType>* operator()(vtkAbstractArray* array) \
862 { \
863 return ArrayT<ValueT, ArrayType>::FastDownCast(array); \
864 } \
865 }
867#endif
Abstract superclass for all arrays.
virtual void GetTuples(vtkIdList *tupleIds, vtkAbstractArray *output)
Given a list of tuple ids, return an array of tuples.
bool HasInformation() const
Inquire if this array has an instance of vtkInformation already associated with it.
const char * GetArrayTypeAsString() const
Get the name for the array type as string.
virtual int IsNumeric() const =0
This method is here to make backward compatibility easier.
virtual void Initialize()=0
Release storage and reset array to initial state.
void PrintValues(ostream &os)
Print the array values to an ostream object.
virtual void DeepCopy(vtkAbstractArray *da)
Deep copy of data.
vtkInformation * GetInformation()
Get an information object that can be used to annotate the array.
virtual int GetElementComponentSize() const =0
Return the size, in bytes, of the lowest-level element of an array.
static const char * GetArrayTypeAsString(int arrayType)
Get the name for the array type as string.
virtual void SetInformation(vtkInformation *)
Set an information object that can be used to annotate the array.
virtual void SetVoidArray(void *array, vtkIdType size, int save)=0
This method lets the user specify data to be held by the array.
virtual void InterpolateTuple(vtkIdType dstTupleIdx, vtkIdType srcTupleIdx1, vtkAbstractArray *source1, vtkIdType srcTupleIdx2, vtkAbstractArray *source2, double t)=0
Insert the tuple at dstTupleIdx in this array to the tuple interpolated from the two tuple indices,...
virtual bool CopyComponent(int dstComponent, vtkAbstractArray *src, int srcComponent)=0
Copy a component from one array into a component on this array.
virtual void UpdateDiscreteValueSet(double uncertainty, double minProminence)
Obtain the set of unique values taken on by each component of the array, as well as by the tuples of ...
virtual vtkTypeBool Allocate(vtkIdType numValues, vtkIdType ext=1000)=0
Allocate memory for this array.
virtual unsigned long GetActualMemorySize() const =0
Return the memory in kibibytes (1024 bytes) consumed by this data array.
int GetNumberOfComponents() const
Set/Get the dimension (n) of the components.
vtkIdType GetSize() const
Get the capacity of the array.
unsigned int MaxDiscreteValues
vtkInternalComponentNames * ComponentNames
virtual vtkArrayIterator * NewIterator()=0
Subclasses must override this method and provide the right kind of templated vtkArrayIteratorTemplate...
static int GetDataTypeSize(int type)
Return the size of the underlying data type.
void SetComponentName(vtkIdType component, const char *name)
Set the name for a component.
virtual vtkTypeBool Resize(vtkIdType numTuples)=0
Resize the array to the requested number of tuples and preserve data.
virtual vtkIdType GetDataSize() const
Returns the size of the data in DataTypeSize units.
static vtkAbstractArray * CreateArray(int dataType)
Creates an array for dataType where dataType is one of VTK_BIT, VTK_CHAR, VTK_UNSIGNED_CHAR,...
virtual int GetDataType() const
Return the underlying data type.
virtual vtkVariant GetVariantValue(vtkIdType valueIdx)
Retrieve value from the array as a variant.
vtkIdType GetMaxId() const
What is the maximum id currently in the array.
virtual void SetNumberOfTuples(vtkIdType numTuples)=0
Set the number of tuples (a component group) in the array.
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 void ClearLookup()=0
Delete the associated fast lookup data structure on this array, if it exists.
virtual int GetDataTypeSize() const =0
Return the size of the underlying data type.
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...
virtual void InsertTuplesStartingAt(vtkIdType dstStart, vtkIdList *srcIds, vtkAbstractArray *source)=0
Copy the tuples indexed in srcIds from the source array to the tuple locations starting at index dstS...
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 PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
vtkInformation * Information
void Reset()
Reset to an empty state, without freeing any memory.
virtual void SetArrayFreeFunction(void(*callback)(void *))=0
This method allows the user to specify a custom free function to be called when the array is dealloca...
int CopyComponentNames(vtkAbstractArray *da)
Copies the component names from the inputted array to the current array make sure that the current ar...
void Modified() override
Removes out-of-date PER_COMPONENT() and PER_FINITE_COMPONENT() values.
virtual void ExportToVoidPointer(void *out_ptr)
This method copies the array data to the void pointer specified by the user.
std::integral_constant< int, vtkArrayTypes::AbstractArray > ArrayTypeTag
std::integral_constant< int, VTK_OPAQUE > DataTypeTag
virtual void InsertTuples(vtkIdType dstStart, vtkIdType n, vtkIdType srcStart, vtkAbstractArray *source)=0
Copy n consecutive tuples starting at srcStart from the source array to this array,...
virtual void SetVariantValue(vtkIdType valueIdx, vtkVariant value)=0
Set a value in the array from a variant.
virtual void InsertTuple(vtkIdType dstTupleIdx, vtkIdType srcTupleIdx, vtkAbstractArray *source)=0
Insert the tuple at srcTupleIdx in the source array into this array at dstTupleIdx.
virtual bool HasStandardMemoryLayout() const
Returns true if this array uses the standard memory layout defined in the VTK user guide,...
virtual bool IsIntegral() const
This method will return true if and only if an array contains integer-valued data.
bool HasAComponentName() const
Returns if any component has had a name assigned.
virtual void * GetVoidPointer(vtkIdType valueIdx)=0
Return a void pointer.
virtual void GetTuples(vtkIdType p1, vtkIdType p2, vtkAbstractArray *output)
Get the tuples for the range of tuple ids specified (i.e., p1->p2 inclusive).
virtual int GetArrayType() const
Method for type-checking in FastDownCast implementations.
virtual vtkIdType LookupValue(vtkVariant value)=0
Return the value indices where a specific value appears.
~vtkAbstractArray() override
const char * GetComponentName(vtkIdType component) const
Get the component name for a given component.
virtual void LookupValue(vtkVariant value, vtkIdList *valueIds)=0
Return the value indices where a specific value appears.
virtual void InsertVariantValue(vtkIdType valueIdx, vtkVariant value)=0
Insert a value into the array from a variant.
virtual const char * GetDataTypeAsString() const
Get the name of a data type as a string.
virtual vtkIdType InsertNextTuple(vtkIdType srcTupleIdx, vtkAbstractArray *source)=0
Insert the tuple from srcTupleIdx in the source array at the end of this array.
virtual void Squeeze()=0
Free any unnecessary memory.
virtual void SetVoidArray(void *array, vtkIdType size, int save, int deleteMethod)
This method lets the user specify data to be held by the array.
virtual void GetProminentComponentValues(int comp, vtkVariantArray *values, double uncertainty=1.e-6, double minimumProminence=1.e-3)
Populate the given vtkVariantArray with a set of distinct values taken on by the requested component ...
virtual void DataChanged()=0
Tell the array explicitly that the data has changed.
virtual int CopyInformation(vtkInformation *infoFrom, vtkTypeBool deep=1)
Copy information instance.
Abstract superclass to iterate over elements in an vtkAbstractArray.
abstract superclass for arrays of numeric data
list of point or cell ids
Definition vtkIdList.h:133
dynamic, self-adjusting array of vtkIdType
a simple class to control print indentation
Definition vtkIndent.h:108
Key for integer values in vtkInformation.
Store vtkAlgorithm input/output information.
abstract base class for most VTK objects
Definition vtkObject.h:162
An array holding vtkVariants.
A type representing the union of many types.
Definition vtkVariant.h:162
static vtkInformationInformationVectorKey * PER_FINITE_COMPONENT()
This key is used to hold a vector of COMPONENT_VALUES (and, for vtkDataArray subclasses,...
static vtkInformationInformationVectorKey * PER_COMPONENT()
This key is used to hold a vector of COMPONENT_VALUES (and, for vtkDataArray subclasses,...
static vtkInformationVariantVectorKey * DISCRETE_VALUES()
A key used to hold discrete values taken on either by the tuples of the array (when present in this->...
static vtkInformationDoubleVectorKey * DISCRETE_VALUE_SAMPLE_PARAMETERS()
A key used to hold conditions under which cached discrete values were generated; the value is a 2-vec...
static vtkInformationIntegerKey * GUI_HIDE()
This key is a hint to end user interface that this array is internal and should not be shown to the e...
Implementation of vtkArrayDownCast.
ArrayT * operator()(vtkAbstractArray *array)
int vtkTypeBool
Definition vtkABI.h:64
ArrayT * vtkArrayDownCast(vtkAbstractArray *array)
vtkArrayDownCast is to be used by generic (e.g.
boost::graph_traits< vtkGraph * >::vertex_descriptor source(boost::graph_traits< vtkGraph * >::edge_descriptor e, vtkGraph *)
#define VTK_DEPRECATED_IN_9_6_0(reason)
#define VTK_DEPRECATED_IN_9_5_0(reason)
int vtkIdType
Definition vtkType.h:367
@ DataArray
Definition vtkType.h:75
@ ScaledSoADataArrayTemplate
Definition vtkType.h:85
@ SoADataArrayTemplate
Definition vtkType.h:84
@ ImplicitArray
Definition vtkType.h:88
@ NumArrayTypes
Definition vtkType.h:99
@ AoSDataArrayTemplate
Definition vtkType.h:83
@ AbstractArray
Definition vtkType.h:72
#define VTK_INT_MAX
Definition vtkType.h:196
void save(Archiver &ar, const std::string &str, const unsigned int version)
#define VTK_MARSHAL_EXCLUDE_REASON_IS_INTERNAL
#define VTK_EXPECTS(x)
#define VTK_MARSHALAUTO
#define VTK_MARSHALEXCLUDE(reason)
#define VTK_NEWINSTANCE