VTK  9.3.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 //
55 #ifndef vtkAbstractArray_h
56 #define vtkAbstractArray_h
57 
58 #include "vtkCommonCoreModule.h" // For export macro
59 #include "vtkIdList.h" // For InsertTuples
60 #include "vtkObject.h"
61 #include "vtkVariant.h" // for variant arguments
62 
63 VTK_ABI_NAMESPACE_BEGIN
64 class vtkArrayIterator;
65 class vtkDataArray;
66 class vtkIdList;
67 class vtkIdTypeArray;
68 class vtkInformation;
73 class vtkVariantArray;
74 
75 class VTKCOMMONCORE_EXPORT vtkAbstractArray : public vtkObject
76 {
77 public:
78  vtkTypeMacro(vtkAbstractArray, vtkObject);
79  void PrintSelf(ostream& os, vtkIndent indent) override;
80 
89  virtual vtkTypeBool Allocate(vtkIdType numValues, vtkIdType ext = 1000) = 0;
90 
94  virtual void Initialize() = 0;
95 
100  virtual int GetDataType() const = 0;
101 
103 
108  virtual int GetDataTypeSize() const = 0;
109  static int GetDataTypeSize(int type);
111 
119  virtual int GetElementComponentSize() const = 0;
120 
122 
126  vtkSetClampMacro(NumberOfComponents, int, 1, VTK_INT_MAX);
127  int GetNumberOfComponents() const { return this->NumberOfComponents; }
129 
133  void SetComponentName(vtkIdType component, const char* name);
134 
139  const char* GetComponentName(vtkIdType component) const;
140 
144  bool HasAComponentName() const;
145 
150  int CopyComponentNames(vtkAbstractArray* da);
151 
159  virtual void SetNumberOfTuples(vtkIdType numTuples) = 0;
160 
167  virtual bool SetNumberOfValues(vtkIdType numValues);
168 
172  vtkIdType GetNumberOfTuples() const { return (this->MaxId + 1) / this->NumberOfComponents; }
173 
180  inline vtkIdType GetNumberOfValues() const { return (this->MaxId + 1); }
181 
188  virtual void SetTuple(vtkIdType dstTupleIdx, vtkIdType srcTupleIdx, vtkAbstractArray* source) = 0;
189 
195  virtual void InsertTuple(
196  vtkIdType dstTupleIdx, vtkIdType srcTupleIdx, vtkAbstractArray* source) = 0;
197 
203  virtual void InsertTuples(vtkIdList* dstIds, vtkIdList* srcIds, vtkAbstractArray* source) = 0;
204 
210  virtual void InsertTuplesStartingAt(
211  vtkIdType dstStart, vtkIdList* srcIds, vtkAbstractArray* source) = 0;
212 
218  virtual void InsertTuples(
219  vtkIdType dstStart, vtkIdType n, vtkIdType srcStart, vtkAbstractArray* source) = 0;
220 
226  virtual vtkIdType InsertNextTuple(vtkIdType srcTupleIdx, vtkAbstractArray* source) = 0;
227 
233  virtual void GetTuples(vtkIdList* tupleIds, vtkAbstractArray* output);
234 
240  virtual void GetTuples(vtkIdType p1, vtkIdType p2, vtkAbstractArray* output);
241 
248  virtual bool HasStandardMemoryLayout() const;
249 
257  virtual void* GetVoidPointer(vtkIdType valueIdx) = 0;
258 
267  virtual void DeepCopy(vtkAbstractArray* da);
268 
276  virtual void InterpolateTuple(
277  vtkIdType dstTupleIdx, vtkIdList* ptIndices, vtkAbstractArray* source, double* weights) = 0;
278 
287  virtual void InterpolateTuple(vtkIdType dstTupleIdx, vtkIdType srcTupleIdx1,
288  vtkAbstractArray* source1, vtkIdType srcTupleIdx2, vtkAbstractArray* source2, double t) = 0;
289 
295  virtual void Squeeze() = 0;
296 
306  virtual vtkTypeBool Resize(vtkIdType numTuples) = 0;
307 
309 
312  void Reset()
313  {
314  this->MaxId = -1;
315  this->DataChanged();
316  }
318 
322  vtkIdType GetSize() const { return this->Size; }
323 
327  vtkIdType GetMaxId() const { return this->MaxId; }
328 
330  {
334  VTK_DATA_ARRAY_USER_DEFINED
335  };
336 
338 
355  virtual void SetVoidArray(
356  void* vtkNotUsed(array), vtkIdType vtkNotUsed(size), int vtkNotUsed(save)) = 0;
357  virtual void SetVoidArray(void* array, vtkIdType size, int save, int vtkNotUsed(deleteMethod))
358  {
359  this->SetVoidArray(array, size, save);
360  }
362 
369  virtual void SetArrayFreeFunction(void (*callback)(void*)) = 0;
370 
376  virtual void ExportToVoidPointer(void* out_ptr);
377 
386  virtual unsigned long GetActualMemorySize() const = 0;
387 
389 
392  vtkSetStringMacro(Name);
393  vtkGetStringMacro(Name);
395 
399  virtual const char* GetDataTypeAsString() const
400  {
401  return vtkImageScalarTypeNameMacro(this->GetDataType());
402  }
403 
414  static vtkAbstractArray* CreateArray(int dataType);
415 
420  virtual int IsNumeric() const = 0;
421 
427  virtual vtkArrayIterator* NewIterator() = 0;
428 
435  virtual vtkIdType GetDataSize() const
436  {
437  return this->GetNumberOfComponents() * this->GetNumberOfTuples();
438  }
439 
441 
448  virtual vtkIdType LookupValue(vtkVariant value) = 0;
449  virtual void LookupValue(vtkVariant value, vtkIdList* valueIds) = 0;
451 
455  virtual vtkVariant GetVariantValue(vtkIdType valueIdx)
456  VTK_EXPECTS(0 <= valueIdx && valueIdx < GetNumberOfValues());
457 
462  virtual void InsertVariantValue(vtkIdType valueIdx, vtkVariant value)
463  VTK_EXPECTS(0 <= valueIdx) = 0;
464 
469  virtual void SetVariantValue(vtkIdType valueIdx, vtkVariant value)
470  VTK_EXPECTS(0 <= valueIdx && valueIdx < GetNumberOfValues()) = 0;
471 
480  virtual void DataChanged() = 0;
481 
487  virtual void ClearLookup() = 0;
488 
541  virtual void GetProminentComponentValues(int comp, vtkVariantArray* values,
542  double uncertainty = 1.e-6, double minimumProminence = 1.e-3);
543 
544  // TODO: Implement these lookup functions also.
545  // virtual void LookupRange(vtkVariant min, vtkVariant max, vtkIdList* ids,
546  // bool includeMin = true, bool includeMax = true) = 0;
547  // virtual void LookupGreaterThan(vtkVariant min, vtkIdList* ids, bool includeMin = false) = 0;
548  // virtual void LookupLessThan(vtkVariant max, vtkIdList* ids, bool includeMax = false) = 0;
549 
555  vtkInformation* GetInformation();
560  bool HasInformation() const { return this->Information != nullptr; }
561 
573  virtual int CopyInformation(vtkInformation* infoFrom, vtkTypeBool deep = 1);
574 
579  static vtkInformationIntegerKey* GUI_HIDE();
580 
593  static vtkInformationInformationVectorKey* PER_COMPONENT();
594 
607  static vtkInformationInformationVectorKey* PER_FINITE_COMPONENT();
608 
612  void Modified() override;
613 
619  static vtkInformationVariantVectorKey* DISCRETE_VALUES();
620 
628  static vtkInformationDoubleVectorKey* DISCRETE_VALUE_SAMPLE_PARAMETERS();
629 
630  // Deprecated. Use vtkAbstractArray::MaxDiscreteValues instead.
631  enum
632  {
633  MAX_DISCRETE_VALUES = 32
634  };
635 
637 
641  vtkGetMacro(MaxDiscreteValues, unsigned int);
642  vtkSetMacro(MaxDiscreteValues, unsigned int);
644 
645  enum
646  {
647  AbstractArray = 0,
655 
656  DataArrayTemplate = AoSDataArrayTemplate
657  };
658 
663  virtual int GetArrayType() const { return AbstractArray; }
664 
668  const char* GetArrayTypeAsString() const;
669 
670 protected:
671  // Construct object with default tuple dimension (number of components) of 1.
673  ~vtkAbstractArray() override;
674 
680  virtual void SetInformation(vtkInformation*);
681 
693  virtual void UpdateDiscreteValueSet(double uncertainty, double minProminence);
694 
695  vtkIdType Size; // allocated size of data
696  vtkIdType MaxId; // maximum index inserted thus far
697  int NumberOfComponents; // the number of components per tuple
698 
699  // maximum number of prominent values before array is considered continuous.
700  unsigned int MaxDiscreteValues;
701 
702  char* Name;
703 
704  bool RebuildArray; // whether to rebuild the fast lookup data structure.
705 
707 
708  class vtkInternalComponentNames;
709  vtkInternalComponentNames* ComponentNames; // names for each component
710 
711 private:
712  vtkAbstractArray(const vtkAbstractArray&) = delete;
713  void operator=(const vtkAbstractArray&) = delete;
714 };
715 
717 
722 template <typename ArrayT>
724 {
725  inline ArrayT* operator()(vtkAbstractArray* array) { return ArrayT::SafeDownCast(array); }
726 };
728 
746 template <typename ArrayT>
748 {
749  // The default vtkArrayDownCast_impl struct uses SafeDownCast, but is
750  // specialized for arrays that support FastDownCast.
751  return vtkArrayDownCast_impl<ArrayT>()(array);
752 }
753 
754 VTK_ABI_NAMESPACE_END
755 
757 
761 #define vtkArrayDownCast_FastCastMacro(ArrayT) \
762  template <> \
763  struct vtkArrayDownCast_impl<ArrayT> \
764  { \
765  inline ArrayT* operator()(vtkAbstractArray* array) { return ArrayT::FastDownCast(array); } \
766  }
767 
770 
776 #define vtkArrayDownCast_TemplateFastCastMacro(ArrayT) \
777  template <typename ValueT> \
778  struct vtkArrayDownCast_impl<ArrayT<ValueT>> \
779  { \
780  inline ArrayT<ValueT>* operator()(vtkAbstractArray* array) \
781  { \
782  return ArrayT<ValueT>::FastDownCast(array); \
783  } \
784  }
785 #endif
virtual const char * GetDataTypeAsString() const
Get the name of a data type as a string.
abstract base class for most VTK objects
Definition: vtkObject.h:51
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:144
dynamic, self-adjusting array of vtkIdType
int vtkIdType
Definition: vtkType.h:315
A type representing the union of many types.
Definition: vtkVariant.h:52
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.
vtkInformation * Information
int vtkTypeBool
Definition: vtkABI.h:64
vtkIdType GetNumberOfValues() const
Get the total number of values in the array.
Key for double vector values.
virtual vtkIdType GetDataSize() const
Returns the size of the data in DataTypeSize units.
a simple class to control print indentation
Definition: vtkIndent.h:28
list of point or cell ids
Definition: vtkIdList.h:22
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.
void save(Archiver &ar, const std::string &str, const unsigned int vtkNotUsed(version))
virtual void Modified()
Update the modification time for this object.
Abstract superclass to iterate over elements in an vtkAbstractArray.
vtkIdType GetNumberOfTuples() const
Get the number of complete tuples (a component group) in the array.
void Reset()
Reset to an empty state, without freeing any memory.
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
vtkInternalComponentNames * ComponentNames
vtkIdType GetSize() const
Return the size of the data.
ArrayT * vtkArrayDownCast(vtkAbstractArray *array)
vtkArrayDownCast is to be used by generic (e.g.
unsigned int MaxDiscreteValues
#define VTK_EXPECTS(x)
vtkSmartPointer< vtkDataArray > CreateArray(const Ioss::Field &field)
Create an array for the given field.
vtkIdType GetMaxId() const
What is the maximum id currently in the array.