VTK  9.4.20241108
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//
58#ifndef vtkAbstractArray_h
59#define vtkAbstractArray_h
60
61#include "vtkCommonCoreModule.h" // For export macro
62#include "vtkIdList.h" // For InsertTuples
63#include "vtkObject.h"
64#include "vtkVariant.h" // for variant arguments
65#include "vtkWrappingHints.h" // For VTK_MARSHALAUTO
66
67#include "vtk_nlohmannjson.h"
68#include VTK_NLOHMANN_JSON(json_fwd.hpp)
69
70VTK_ABI_NAMESPACE_BEGIN
72class vtkDataArray;
73class vtkIdList;
74class vtkIdTypeArray;
75class vtkInformation;
80class vtkVariantArray;
81
82class VTKCOMMONCORE_EXPORT VTK_MARSHALAUTO vtkAbstractArray : public vtkObject
83{
84public:
86 void PrintSelf(ostream& os, vtkIndent indent) override;
87 void PrintValues(ostream& os);
88 nlohmann::json SerializeValues();
89
98 virtual vtkTypeBool Allocate(vtkIdType numValues, vtkIdType ext = 1000) = 0;
99
103 virtual void Initialize() = 0;
104
109 virtual int GetDataType() const = 0;
110
112
117 virtual int GetDataTypeSize() const = 0;
118 static int GetDataTypeSize(int type);
120
128 virtual int GetElementComponentSize() const = 0;
129
131
135 vtkSetClampMacro(NumberOfComponents, int, 1, VTK_INT_MAX);
136 int GetNumberOfComponents() const { return this->NumberOfComponents; }
138
142 void SetComponentName(vtkIdType component, const char* name);
143
148 const char* GetComponentName(vtkIdType component) const;
149
153 bool HasAComponentName() const;
154
160
168 virtual void SetNumberOfTuples(vtkIdType numTuples) = 0;
169
177 virtual bool SetNumberOfValues(vtkIdType numValues);
178
182 vtkIdType GetNumberOfTuples() const { return (this->MaxId + 1) / this->NumberOfComponents; }
183
191 inline vtkIdType GetNumberOfValues() const { return (this->MaxId + 1); }
192
199 virtual void SetTuple(vtkIdType dstTupleIdx, vtkIdType srcTupleIdx, vtkAbstractArray* source) = 0;
200
206 virtual void InsertTuple(
207 vtkIdType dstTupleIdx, vtkIdType srcTupleIdx, vtkAbstractArray* source) = 0;
208
214 virtual void InsertTuples(vtkIdList* dstIds, vtkIdList* srcIds, vtkAbstractArray* source) = 0;
215
222 vtkIdType dstStart, vtkIdList* srcIds, vtkAbstractArray* source) = 0;
223
229 virtual void InsertTuples(
230 vtkIdType dstStart, vtkIdType n, vtkIdType srcStart, vtkAbstractArray* source) = 0;
231
238
244 virtual void GetTuples(vtkIdList* tupleIds, vtkAbstractArray* output);
245
251 virtual void GetTuples(vtkIdType p1, vtkIdType p2, vtkAbstractArray* output);
252
259 virtual bool HasStandardMemoryLayout() const;
260
268 virtual void* GetVoidPointer(vtkIdType valueIdx) = 0;
269
278 virtual void DeepCopy(vtkAbstractArray* da);
279
287 virtual void InterpolateTuple(
288 vtkIdType dstTupleIdx, vtkIdList* ptIndices, vtkAbstractArray* source, double* weights) = 0;
289
298 virtual void InterpolateTuple(vtkIdType dstTupleIdx, vtkIdType srcTupleIdx1,
299 vtkAbstractArray* source1, vtkIdType srcTupleIdx2, vtkAbstractArray* source2, double t) = 0;
300
306 virtual void Squeeze() = 0;
307
317 virtual vtkTypeBool Resize(vtkIdType numTuples) = 0;
318
320
323 void Reset()
324 {
325 this->MaxId = -1;
326 this->DataChanged();
327 }
329
333 vtkIdType GetSize() const { return this->Size; }
334
338 vtkIdType GetMaxId() const { return this->MaxId; }
339
341 {
345 VTK_DATA_ARRAY_USER_DEFINED
346 };
347
349
366 virtual void SetVoidArray(
367 void* vtkNotUsed(array), vtkIdType vtkNotUsed(size), int vtkNotUsed(save)) = 0;
368 virtual void SetVoidArray(void* array, vtkIdType size, int save, int vtkNotUsed(deleteMethod))
369 {
370 this->SetVoidArray(array, size, save);
371 }
373
380 virtual void SetArrayFreeFunction(void (*callback)(void*)) = 0;
381
387 virtual void ExportToVoidPointer(void* out_ptr);
388
397 virtual unsigned long GetActualMemorySize() const = 0;
398
400
403 vtkSetStringMacro(Name);
404 vtkGetStringMacro(Name);
406
410 virtual const char* GetDataTypeAsString() const
411 {
412 return vtkImageScalarTypeNameMacro(this->GetDataType());
413 }
414
425 static vtkAbstractArray* CreateArray(int dataType);
426
431 virtual int IsNumeric() const = 0;
432
436 virtual bool IsIntegral() const;
437
444
451 virtual vtkIdType GetDataSize() const
452 {
453 return this->GetNumberOfComponents() * this->GetNumberOfTuples();
454 }
455
457
464 virtual vtkIdType LookupValue(vtkVariant value) = 0;
465 virtual void LookupValue(vtkVariant value, vtkIdList* valueIds) = 0;
467
472 VTK_EXPECTS(0 <= valueIdx && valueIdx < GetNumberOfValues());
473
478 virtual void InsertVariantValue(vtkIdType valueIdx, vtkVariant value)
479 VTK_EXPECTS(0 <= valueIdx) = 0;
480
485 virtual void SetVariantValue(vtkIdType valueIdx, vtkVariant value)
486 VTK_EXPECTS(0 <= valueIdx && valueIdx < GetNumberOfValues()) = 0;
487
496 virtual void DataChanged() = 0;
497
503 virtual void ClearLookup() = 0;
504
557 virtual void GetProminentComponentValues(int comp, vtkVariantArray* values,
558 double uncertainty = 1.e-6, double minimumProminence = 1.e-3);
559
560 // TODO: Implement these lookup functions also.
561 // virtual void LookupRange(vtkVariant min, vtkVariant max, vtkIdList* ids,
562 // bool includeMin = true, bool includeMax = true) = 0;
563 // virtual void LookupGreaterThan(vtkVariant min, vtkIdList* ids, bool includeMin = false) = 0;
564 // virtual void LookupLessThan(vtkVariant max, vtkIdList* ids, bool includeMax = false) = 0;
565
576 bool HasInformation() const { return this->Information != nullptr; }
577
589 virtual int CopyInformation(vtkInformation* infoFrom, vtkTypeBool deep = 1);
590
596
610
624
628 void Modified() override;
629
636
645
646 // Deprecated. Use vtkAbstractArray::MaxDiscreteValues instead.
647 enum
648 {
649 MAX_DISCRETE_VALUES = 32
650 };
651
653
657 vtkGetMacro(MaxDiscreteValues, unsigned int);
658 vtkSetMacro(MaxDiscreteValues, unsigned int);
660
661 enum
662 {
663 AbstractArray = 0,
671
672 DataArrayTemplate = AoSDataArrayTemplate
673 };
674
679 virtual int GetArrayType() const { return AbstractArray; }
680
684 const char* GetArrayTypeAsString() const;
685
686protected:
687 // Construct object with default tuple dimension (number of components) of 1.
690
697
709 virtual void UpdateDiscreteValueSet(double uncertainty, double minProminence);
710
711 vtkIdType Size; // allocated size of data
712 vtkIdType MaxId; // maximum index inserted thus far
713 int NumberOfComponents; // the number of components per tuple
714
715 // maximum number of prominent values before array is considered continuous.
716 unsigned int MaxDiscreteValues;
717
718 char* Name;
719
720 bool RebuildArray; // whether to rebuild the fast lookup data structure.
721
723
724 class vtkInternalComponentNames;
725 vtkInternalComponentNames* ComponentNames; // names for each component
726
727private:
728 vtkAbstractArray(const vtkAbstractArray&) = delete;
729 void operator=(const vtkAbstractArray&) = delete;
730};
731
733
738template <typename ArrayT>
740{
741 inline ArrayT* operator()(vtkAbstractArray* array) { return ArrayT::SafeDownCast(array); }
742};
744
762template <typename ArrayT>
764{
765 // The default vtkArrayDownCast_impl struct uses SafeDownCast, but is
766 // specialized for arrays that support FastDownCast.
767 return vtkArrayDownCast_impl<ArrayT>()(array);
768}
769
770VTK_ABI_NAMESPACE_END
771
773
777#define vtkArrayDownCast_FastCastMacro(ArrayT) \
778 template <> \
779 struct vtkArrayDownCast_impl<ArrayT> \
780 { \
781 inline ArrayT* operator()(vtkAbstractArray* array) \
782 { \
783 return ArrayT::FastDownCast(array); \
784 } \
785 }
787
789
795#define vtkArrayDownCast_TemplateFastCastMacro(ArrayT) \
796 template <typename ValueT> \
797 struct vtkArrayDownCast_impl<ArrayT<ValueT>> \
798 { \
799 inline ArrayT<ValueT>* operator()(vtkAbstractArray* array) \
800 { \
801 return ArrayT<ValueT>::FastDownCast(array); \
802 } \
803 }
805#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.
static vtkInformationInformationVectorKey * PER_FINITE_COMPONENT()
This key is used to hold a vector of COMPONENT_VALUES (and, for vtkDataArray subclasses,...
virtual void Initialize()=0
Release storage and reset array to initial state.
void PrintValues(ostream &os)
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.
virtual void SetInformation(vtkInformation *)
Set an information object that can be used to annotate 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 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
Return the size of the data.
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.
virtual void SetVoidArray(void *vtkNotUsed(array), vtkIdType vtkNotUsed(size), int vtkNotUsed(save))=0
This method lets the user specify data to be held by the array.
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.
nlohmann::json SerializeValues()
static vtkAbstractArray * CreateArray(int dataType)
Creates an array for dataType where dataType is one of VTK_BIT, VTK_CHAR, VTK_UNSIGNED_CHAR,...
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.
static vtkInformationInformationVectorKey * PER_COMPONENT()
This key is used to hold a vector of COMPONENT_VALUES (and, for vtkDataArray subclasses,...
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.
static vtkInformationVariantVectorKey * DISCRETE_VALUES()
A key used to hold discrete values taken on either by the tuples of the array (when present in this->...
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.
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.
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...
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).
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...
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.
virtual int GetDataType() const =0
Return the underlying data type.
~vtkAbstractArray() override
virtual void SetVoidArray(void *array, vtkIdType size, int save, int vtkNotUsed(deleteMethod))
This method lets the user specify data to be held by the array.
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 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
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 *)
int vtkIdType
Definition vtkType.h:315
#define VTK_INT_MAX
Definition vtkType.h:144
void save(Archiver &ar, const std::string &str, const unsigned int vtkNotUsed(version))
#define VTK_MARSHAL_EXCLUDE_REASON_IS_INTERNAL
#define VTK_EXPECTS(x)
#define VTK_MARSHALAUTO
#define VTK_MARSHALEXCLUDE(reason)
#define VTK_NEWINSTANCE