VTK  9.6.20260403
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 "vtkObject.h"
70#include "vtkVariant.h" // for variant arguments
71#include "vtkWrappingHints.h" // For VTK_MARSHALAUTO
72
73VTK_ABI_NAMESPACE_BEGIN
77class vtkIdTypeArray;
78class vtkInformation;
83class vtkVariantArray;
84
85class VTKCOMMONCORE_EXPORT VTK_MARSHALAUTO vtkAbstractArray : public vtkObject
86{
87public:
89 void PrintSelf(ostream& os, vtkIndent indent) override;
90 using ArrayTypeTag = std::integral_constant<int, vtkArrayTypes::VTK_ABSTRACT_ARRAY>;
91 using DataTypeTag = std::integral_constant<int, VTK_OPAQUE>;
92
96 void PrintValues(ostream& os);
97
106 VTK_DEPRECATED_IN_9_7_0("Use ReserveValues/Tuples() to allocate or Initialize() to deallocate.")
107 virtual vtkTypeBool Allocate(vtkIdType numValues, vtkIdType ext = 1000);
108
119 virtual vtkTypeBool ReserveTuples(vtkIdType numTuples) = 0;
120
132
136 virtual void Initialize();
137
142 virtual int GetDataType() const { return vtkAbstractArray::DataTypeTag::value; };
143
145
150 virtual int GetDataTypeSize() const = 0;
151 static int GetDataTypeSize(int type);
153
161 virtual int GetElementComponentSize() const = 0;
162
164
168 vtkSetClampMacro(NumberOfComponents, int, 1, VTK_INT_MAX);
169 int GetNumberOfComponents() const { return this->NumberOfComponents; }
175 void SetComponentName(vtkIdType component, const char* name);
176
181 const char* GetComponentName(vtkIdType component) const;
182
186 bool HasAComponentName() const;
187
193
208 virtual bool CopyComponent(int dstComponent, vtkAbstractArray* src, int srcComponent) = 0;
209
215 virtual void SetNumberOfTuples(vtkIdType numTuples)
216 {
217 this->SetNumberOfValues(this->NumberOfComponents * numTuples);
218 }
219
227 virtual bool SetNumberOfValues(vtkIdType numValues);
228
232 vtkIdType GetNumberOfTuples() const { return (this->MaxId + 1) / this->NumberOfComponents; }
233
241 vtkIdType GetNumberOfValues() const { return (this->MaxId + 1); }
242
249 virtual void SetTuple(vtkIdType dstTupleIdx, vtkIdType srcTupleIdx, vtkAbstractArray* source) = 0;
250
256 virtual void InsertTuple(
257 vtkIdType dstTupleIdx, vtkIdType srcTupleIdx, vtkAbstractArray* source) = 0;
258
264 virtual void InsertTuples(vtkIdList* dstIds, vtkIdList* srcIds, vtkAbstractArray* source) = 0;
265
272 vtkIdType dstStart, vtkIdList* srcIds, vtkAbstractArray* source) = 0;
273
279 virtual void InsertTuples(
280 vtkIdType dstStart, vtkIdType n, vtkIdType srcStart, vtkAbstractArray* source) = 0;
281
288
294 virtual void GetTuples(vtkIdList* tupleIds, vtkAbstractArray* output);
295
301 virtual void GetTuples(vtkIdType p1, vtkIdType p2, vtkAbstractArray* output);
302
309 virtual bool HasStandardMemoryLayout() const;
310
318 virtual void* GetVoidPointer(vtkIdType valueIdx) = 0;
319
328 virtual void DeepCopy(vtkAbstractArray* da);
329
335 virtual void ShallowCopy(vtkAbstractArray* src);
336
344 virtual void InterpolateTuple(
345 vtkIdType dstTupleIdx, vtkIdList* ptIndices, vtkAbstractArray* source, double* weights) = 0;
346
355 virtual void InterpolateTuple(vtkIdType dstTupleIdx, vtkIdType srcTupleIdx1,
356 vtkAbstractArray* source1, vtkIdType srcTupleIdx2, vtkAbstractArray* source2, double t) = 0;
357
362 virtual void Squeeze() = 0;
363
374 VTK_DEPRECATED_IN_9_7_0("Use ReserveTuples, Squeeze or Initialize")
375 virtual vtkTypeBool Resize(vtkIdType numTuples);
376
378
381 void Reset()
382 {
383 this->MaxId = -1;
384 this->DataChanged();
385 }
386
387
392 vtkIdType GetCapacity() const { return this->Capacity; }
393
397 vtkIdType GetMaxId() const { return this->MaxId; }
398
406
408
425 virtual void SetVoidArray(
426 void* vtkNotUsed(array), vtkIdType vtkNotUsed(size), int vtkNotUsed(save)) = 0;
427 virtual void SetVoidArray(void* array, vtkIdType size, int save, int vtkNotUsed(deleteMethod))
428 {
429 this->SetVoidArray(array, size, save);
430 }
431
432
439 virtual void SetArrayFreeFunction(void (*callback)(void*)) = 0;
440
446 VTK_DEPRECATED_IN_9_7_0("Use DeepCopy with an vtkAOSDataArrayTemplate array")
447 virtual void ExportToVoidPointer(void* out_ptr);
448
457 virtual unsigned long GetActualMemorySize() const = 0;
458
460
463 vtkSetStringMacro(Name);
464 vtkGetStringMacro(Name);
466
470 virtual const char* GetDataTypeAsString() const
471 {
472 return vtkImageScalarTypeNameMacro(this->GetDataType());
473 }
474
485 static vtkAbstractArray* CreateArray(int dataType);
486
491 virtual int IsNumeric() const = 0;
492
496 virtual bool IsIntegral() const;
497
502 VTK_DEPRECATED_IN_9_7_0("Use vtk::DataArrayValueRange, or the array directly")
504
511 virtual vtkIdType GetDataSize() const
512 {
513 return this->GetNumberOfComponents() * this->GetNumberOfTuples();
514 }
515
517
524 virtual vtkIdType LookupValue(vtkVariant value) = 0;
525 virtual void LookupValue(vtkVariant value, vtkIdList* valueIds) = 0;
527
532 VTK_EXPECTS(0 <= valueIdx && valueIdx < GetNumberOfValues());
533
538 virtual void InsertVariantValue(vtkIdType valueIdx, vtkVariant value)
539 VTK_EXPECTS(0 <= valueIdx) = 0;
540
545 virtual void SetVariantValue(vtkIdType valueIdx, vtkVariant value)
546 VTK_EXPECTS(0 <= valueIdx && valueIdx < GetNumberOfValues()) = 0;
547
556 virtual void DataChanged() = 0;
557
563 virtual void ClearLookup() = 0;
564
617 virtual void GetProminentComponentValues(int comp, vtkVariantArray* values,
618 double uncertainty = 1.e-6, double minimumProminence = 1.e-3);
619
620 // TODO: Implement these lookup functions also.
621 // virtual void LookupRange(vtkVariant min, vtkVariant max, vtkIdList* ids,
622 // bool includeMin = true, bool includeMax = true) = 0;
623 // virtual void LookupGreaterThan(vtkVariant min, vtkIdList* ids, bool includeMin = false) = 0;
624 // virtual void LookupLessThan(vtkVariant max, vtkIdList* ids, bool includeMax = false) = 0;
625
636 bool HasInformation() const { return this->Information != nullptr; }
637
649 virtual int CopyInformation(vtkInformation* infoFrom, vtkTypeBool deep = 1);
650
657
672
687
691 void Modified() override;
692
700
710
711 enum
712 {
714 };
715
717
721 vtkGetMacro(MaxDiscreteValues, unsigned int);
722 vtkSetMacro(MaxDiscreteValues, unsigned int);
724
726 "Use vtkArrayTypes::VTK_ABSTRACT_ARRAY") = vtkArrayTypes::VTK_ABSTRACT_ARRAY;
727 static constexpr int DataArray VTK_DEPRECATED_IN_9_6_0(
728 "Use vtkArrayTypes::VTK_DATA_ARRAY") = vtkArrayTypes::VTK_DATA_ARRAY;
730 "Use vtkArrayTypes::VTK_AOS_DATA_ARRAY") = vtkArrayTypes::VTK_AOS_DATA_ARRAY;
732 "Use vtkArrayTypes::VTK_SOA_DATA_ARRAY") = vtkArrayTypes::VTK_SOA_DATA_ARRAY;
734 "Use vtkArrayTypes::VTK_SCALED_SOA_DATA_ARRAY") =
735 /*vtkArrayTypes::VTK_SCALED_SOA_DATA_ARRAY*/ 7;
737 "Use vtkArrayTypes::VTK_IMPLICIT_ARRAY") = vtkArrayTypes::VTK_IMPLICIT_ARRAY;
739 "DataArrayTemplate has been deprecated") = vtkArrayTypes::VTK_AOS_DATA_ARRAY;
741 "ScaleSoADataArrayTemplate has been renamed to ScaledSoADataArrayTemplate") =
742 /*vtkArrayTypes::VTK_SCALED_SOA_DATA_ARRAY*/ 7;
743
748 virtual int GetArrayType() const { return vtkAbstractArray::ArrayTypeTag::value; }
749
751
754 static const char* GetArrayTypeAsString(int arrayType);
755 const char* GetArrayTypeAsString() const
756 {
758 }
759
760
764 VTK_DEPRECATED_IN_9_7_0("Use GetCapacity() instead")
765 vtkIdType GetSize() const { return this->GetCapacity(); }
766
767protected:
768 // Construct object with default tuple dimension (number of components) of 1.
771
778
790 virtual void UpdateDiscreteValueSet(double uncertainty, double minProminence);
791
792 vtkIdType& Size VTK_DEPRECATED_IN_9_7_0("Use Capacity instead");
793
794 vtkIdType Capacity; // allocated capacity of the array
795 vtkIdType MaxId; // maximum index inserted thus far
796 int NumberOfComponents; // the number of components per tuple
797
798 // maximum number of prominent values before array is considered continuous.
799 unsigned int MaxDiscreteValues;
800
801 char* Name;
802
803 bool RebuildArray; // whether to rebuild the fast lookup data structure.
804
806
807 class vtkInternalComponentNames;
808 vtkInternalComponentNames* ComponentNames; // names for each component
809
810private:
811 vtkAbstractArray(const vtkAbstractArray&) = delete;
812 void operator=(const vtkAbstractArray&) = delete;
813};
814
816
821template <typename ArrayT>
823{
824 ArrayT* operator()(vtkAbstractArray* array) { return ArrayT::SafeDownCast(array); }
825};
826
827
845template <typename ArrayT>
847{
848 // The default vtkArrayDownCast_impl struct uses SafeDownCast, but is
849 // specialized for arrays that support FastDownCast.
850 return vtkArrayDownCast_impl<ArrayT>()(array);
851}
852
853VTK_ABI_NAMESPACE_END
854
856
860#define vtkArrayDownCast_FastCastMacro(ArrayT) \
861 template <> \
862 struct vtkArrayDownCast_impl<ArrayT> \
863 { \
864 inline ArrayT* operator()(vtkAbstractArray* array) \
865 { \
866 return ArrayT::FastDownCast(array); \
867 } \
868 }
869
870
872
878#define vtkArrayDownCast_TemplateFastCastMacro(ArrayT) \
879 template <typename ValueT> \
880 struct vtkArrayDownCast_impl<ArrayT<ValueT>> \
881 { \
882 inline ArrayT<ValueT>* operator()(vtkAbstractArray* array) \
883 { \
884 return ArrayT<ValueT>::FastDownCast(array); \
885 } \
886 }
887
888
890
896#define vtkArrayDownCast_Template2FastCastMacro(ArrayT) \
897 template <typename ValueT, int ArrayType> \
898 struct vtkArrayDownCast_impl<ArrayT<ValueT, ArrayType>> \
899 { \
900 inline ArrayT<ValueT, ArrayType>* operator()(vtkAbstractArray* array) \
901 { \
902 return ArrayT<ValueT, ArrayType>::FastDownCast(array); \
903 } \
904 }
905
906#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 SetNumberOfTuples(vtkIdType numTuples)
Set the number of tuples (a component group) in the array.
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 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
Deprecated method to get the array capacity, use GetCapacity() instead.
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 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.
vtkIdType GetNumberOfTuples() const
Get the number of complete 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.
static constexpr int ScaledSoADataArrayTemplate
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...
static constexpr int SoADataArrayTemplate
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...
static constexpr int ImplicitArray
int CopyComponentNames(vtkAbstractArray *da)
Copies the component names from the inputted array to the current array make sure that the current ar...
static constexpr int AoSDataArrayTemplate
virtual vtkTypeBool ReserveTuples(vtkIdType numTuples)=0
Reserve the array to the requested number of tuples and preserve data.
void Modified() override
Removes out-of-date PER_COMPONENT() and PER_FINITE_COMPONENT() values.
virtual vtkTypeBool Resize(vtkIdType numTuples)
Resize the array to the requested number of tuples and preserve data.
virtual void ExportToVoidPointer(void *out_ptr)
This method copies the array data to the void pointer specified by the user.
static constexpr int DataArray
virtual bool SetNumberOfValues(vtkIdType numValues)
Specify the number of values (tuples * components) for this object to hold.
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.
std::integral_constant< int, vtkArrayTypes::VTK_ABSTRACT_ARRAY > ArrayTypeTag
virtual void InsertTuple(vtkIdType dstTupleIdx, vtkIdType srcTupleIdx, vtkAbstractArray *source)=0
Insert the tuple at srcTupleIdx in the source array into this array at dstTupleIdx.
static constexpr int DataArrayTemplate
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.
virtual vtkTypeBool Allocate(vtkIdType numValues, vtkIdType ext=1000)
Allocate memory for this array.
static constexpr int AbstractArray
vtkIdType GetNumberOfValues() const
Get the total number of values in the array.
virtual void ShallowCopy(vtkAbstractArray *src)
This method will copy the data from the source array to this array.
vtkIdType GetCapacity() const
Get the capacity of the array.
virtual void Initialize()
Release storage and reset array to initial state.
bool HasAComponentName() const
Returns if any component has had a name assigned.
static constexpr int ScaleSoADataArrayTemplate
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.
vtkTypeBool ReserveValues(vtkIdType numValues)
Reserve the array to the requested number of values and preserve data.
virtual int CopyInformation(vtkInformation *infoFrom, vtkTypeBool deep=1)
Copy information instance.
Abstract superclass to iterate over elements in an vtkAbstractArray.
list of point or cell ids
Definition vtkIdList.h:135
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.
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 vtkDataArray
#define VTK_DEPRECATED_IN_9_7_0(reason)
#define VTK_DEPRECATED_IN_9_6_0(reason)
int vtkIdType
Definition vtkType.h:363
@ VTK_SOA_DATA_ARRAY
Definition vtkType.h:84
@ VTK_AOS_DATA_ARRAY
Definition vtkType.h:83
@ VTK_IMPLICIT_ARRAY
Definition vtkType.h:88
@ VTK_DATA_ARRAY
Definition vtkType.h:75
@ VTK_ABSTRACT_ARRAY
Definition vtkType.h:72
#define VTK_INT_MAX
Definition vtkType.h:192
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