VTK  9.7.1
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 
73 VTK_ABI_NAMESPACE_BEGIN
74 class vtkArrayIterator;
75 class vtkDataArray;
76 class vtkIdList;
77 class vtkIdTypeArray;
78 class vtkInformation;
83 class vtkVariantArray;
84 
85 class VTKCOMMONCORE_EXPORT VTK_MARSHALAUTO vtkAbstractArray : public vtkObject
86 {
87 public:
88  vtkTypeMacro(vtkAbstractArray, vtkObject);
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 
131  vtkTypeBool ReserveValues(vtkIdType numValues);
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; }
171 
175  void SetComponentName(vtkIdType component, const char* name);
176 
181  const char* GetComponentName(vtkIdType component) const;
182 
186  bool HasAComponentName() const;
187 
192  int CopyComponentNames(vtkAbstractArray* da);
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 
271  virtual void InsertTuplesStartingAt(
272  vtkIdType dstStart, vtkIdList* srcIds, vtkAbstractArray* source) = 0;
273 
279  virtual void InsertTuples(
280  vtkIdType dstStart, vtkIdType n, vtkIdType srcStart, vtkAbstractArray* source) = 0;
281 
287  virtual vtkIdType InsertNextTuple(vtkIdType srcTupleIdx, vtkAbstractArray* source) = 0;
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  }
387 
392  vtkIdType GetCapacity() const { return this->Capacity; }
393 
397  vtkIdType GetMaxId() const { return this->MaxId; }
398 
400  {
404  VTK_DATA_ARRAY_USER_DEFINED
405  };
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  }
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")
503  VTK_NEWINSTANCE virtual vtkArrayIterator* NewIterator() = 0;
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 
531  virtual vtkVariant GetVariantValue(vtkIdType valueIdx)
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 
631  vtkInformation* GetInformation();
636  bool HasInformation() const { return this->Information != nullptr; }
637 
649  virtual int CopyInformation(vtkInformation* infoFrom, vtkTypeBool deep = 1);
650 
656  static vtkInformationIntegerKey* GUI_HIDE();
657 
671  static vtkInformationInformationVectorKey* PER_COMPONENT();
672 
686  static vtkInformationInformationVectorKey* PER_FINITE_COMPONENT();
687 
691  void Modified() override;
692 
699  static vtkInformationVariantVectorKey* DISCRETE_VALUES();
700 
709  static vtkInformationDoubleVectorKey* DISCRETE_VALUE_SAMPLE_PARAMETERS();
710 
711  enum
712  {
713  MAX_DISCRETE_VALUES = 32
714  };
715 
717 
721  vtkGetMacro(MaxDiscreteValues, unsigned int);
722  vtkSetMacro(MaxDiscreteValues, unsigned int);
724 
725  static constexpr int AbstractArray VTK_DEPRECATED_IN_9_6_0(
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;
729  static constexpr int AoSDataArrayTemplate VTK_DEPRECATED_IN_9_6_0(
730  "Use vtkArrayTypes::VTK_AOS_DATA_ARRAY") = vtkArrayTypes::VTK_AOS_DATA_ARRAY;
731  static constexpr int SoADataArrayTemplate VTK_DEPRECATED_IN_9_6_0(
732  "Use vtkArrayTypes::VTK_SOA_DATA_ARRAY") = vtkArrayTypes::VTK_SOA_DATA_ARRAY;
733  static constexpr int ScaledSoADataArrayTemplate VTK_DEPRECATED_IN_9_6_0(
734  "Use vtkArrayTypes::VTK_SCALED_SOA_DATA_ARRAY") =
735  /*vtkArrayTypes::VTK_SCALED_SOA_DATA_ARRAY*/ 7;
736  static constexpr int ImplicitArray VTK_DEPRECATED_IN_9_6_0(
737  "Use vtkArrayTypes::VTK_IMPLICIT_ARRAY") = vtkArrayTypes::VTK_IMPLICIT_ARRAY;
738  static constexpr int DataArrayTemplate VTK_DEPRECATED_IN_9_6_0(
739  "DataArrayTemplate has been deprecated") = vtkArrayTypes::VTK_AOS_DATA_ARRAY;
740  static constexpr int ScaleSoADataArrayTemplate VTK_DEPRECATED_IN_9_6_0(
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  {
757  return vtkAbstractArray::GetArrayTypeAsString(this->GetArrayType());
758  }
760 
764  VTK_DEPRECATED_IN_9_7_0("Use GetCapacity() instead")
765  vtkIdType GetSize() const { return this->GetCapacity(); }
766 
767 protected:
768  // Construct object with default tuple dimension (number of components) of 1.
770  ~vtkAbstractArray() override;
771 
777  virtual void SetInformation(vtkInformation*);
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 
810 private:
811  vtkAbstractArray(const vtkAbstractArray&) = delete;
812  void operator=(const vtkAbstractArray&) = delete;
813 };
814 
816 
821 template <typename ArrayT>
823 {
824  ArrayT* operator()(vtkAbstractArray* array) { return ArrayT::SafeDownCast(array); }
825 };
827 
845 template <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 
853 VTK_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 
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 
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 #endif
virtual void SetNumberOfTuples(vtkIdType numTuples)
Set the number of tuples (a component group) in the array.
abstract base class for most VTK objects
Definition: vtkObject.h:52
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
An array holding vtkVariants.
Store vtkAlgorithm input/output information.
int GetNumberOfComponents() const
Set/Get the dimension (n) of the components.
Abstract superclass for all arrays.
Implementation of vtkArrayDownCast.
#define VTK_INT_MAX
Definition: vtkType.h:192
dynamic, self-adjusting array of vtkIdType
int vtkIdType
Definition: vtkType.h:363
virtual void SetVoidArray(void *array, vtkIdType size, int save, int deleteMethod)
This method lets the user specify data to be held by the array.
A type representing the union of many types.
Definition: vtkVariant.h:52
vtkInformation * Information
int vtkTypeBool
Definition: vtkABI.h:64
#define VTK_DEPRECATED_IN_9_6_0(reason)
Key for double vector values.
a simple class to control print indentation
Definition: vtkIndent.h:28
void save(Archiver &ar, const std::string &str, const unsigned int version)
list of point or cell ids
Definition: vtkIdList.h:25
Key for integer values in vtkInformation.
ArrayT * operator()(vtkAbstractArray *array)
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:44
bool HasInformation() const
Inquire if this array has an instance of vtkInformation already associated with it.
virtual void Modified()
Update the modification time for this object.
Abstract superclass to iterate over elements in an vtkAbstractArray.
boost::graph_traits< vtkGraph * >::vertex_descriptor source(boost::graph_traits< vtkGraph * >::edge_descriptor e, vtkGraph *)
virtual int GetArrayType() const
Method for type-checking in FastDownCast implementations.
#define VTK_NEWINSTANCE
#define VTK_MARSHALEXCLUDE(reason)
vtkIdType GetCapacity() const
Get the capacity of the array.
std::integral_constant< int, VTK_OPAQUE > DataTypeTag
vtkInternalComponentNames * ComponentNames
ArrayT * vtkArrayDownCast(vtkAbstractArray *array)
vtkArrayDownCast is to be used by generic (e.g.
std::integral_constant< int, vtkArrayTypes::VTK_ABSTRACT_ARRAY > ArrayTypeTag
#define VTK_MARSHALAUTO
unsigned int MaxDiscreteValues
#define VTK_EXPECTS(x)
const char * GetArrayTypeAsString() const
Get the name for the array type as string.
vtkSmartPointer< vtkDataArray > CreateArray(const Ioss::Field &field)
Create an array for the given field.
#define VTK_DEPRECATED_IN_9_7_0(reason)
vtkIdType GetMaxId() const
What is the maximum id currently in the array.
#define VTK_MARSHAL_EXCLUDE_REASON_IS_INTERNAL