VTK  9.2.6
vtkAbstractArray.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkAbstractArray.h
5 
6  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7  All rights reserved.
8  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10  This software is distributed WITHOUT ANY WARRANTY; without even
11  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12  PURPOSE. See the above copyright notice for more information.
13 
14 =========================================================================*/
15 //
67 #ifndef vtkAbstractArray_h
68 #define vtkAbstractArray_h
69 
70 #include "vtkCommonCoreModule.h" // For export macro
71 #include "vtkIdList.h" // For InsertTuples
72 #include "vtkObject.h"
73 #include "vtkVariant.h" // for variant arguments
74 
75 class vtkArrayIterator;
76 class vtkDataArray;
77 class vtkIdList;
78 class vtkIdTypeArray;
79 class vtkInformation;
84 class vtkVariantArray;
85 
86 class VTKCOMMONCORE_EXPORT vtkAbstractArray : public vtkObject
87 {
88 public:
89  vtkTypeMacro(vtkAbstractArray, vtkObject);
90  void PrintSelf(ostream& os, vtkIndent indent) override;
91 
100  virtual vtkTypeBool Allocate(vtkIdType numValues, vtkIdType ext = 1000) = 0;
101 
105  virtual void Initialize() = 0;
106 
111  virtual int GetDataType() const = 0;
112 
114 
119  virtual int GetDataTypeSize() const = 0;
120  static int GetDataTypeSize(int type);
122 
130  virtual int GetElementComponentSize() const = 0;
131 
133 
137  vtkSetClampMacro(NumberOfComponents, int, 1, VTK_INT_MAX);
138  int GetNumberOfComponents() const { return this->NumberOfComponents; }
140 
144  void SetComponentName(vtkIdType component, const char* name);
145 
150  const char* GetComponentName(vtkIdType component) const;
151 
155  bool HasAComponentName() const;
156 
161  int CopyComponentNames(vtkAbstractArray* da);
162 
170  virtual void SetNumberOfTuples(vtkIdType numTuples) = 0;
171 
178  virtual bool SetNumberOfValues(vtkIdType numValues);
179 
183  vtkIdType GetNumberOfTuples() const { return (this->MaxId + 1) / this->NumberOfComponents; }
184 
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 
221  virtual void InsertTuplesStartingAt(
222  vtkIdType dstStart, vtkIdList* srcIds, vtkAbstractArray* source) = 0;
223 
229  virtual void InsertTuples(
230  vtkIdType dstStart, vtkIdType n, vtkIdType srcStart, vtkAbstractArray* source) = 0;
231 
237  virtual vtkIdType InsertNextTuple(vtkIdType srcTupleIdx, vtkAbstractArray* source) = 0;
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(void) const
411  {
412  return vtkImageScalarTypeNameMacro(this->GetDataType());
413  }
414 
425  static vtkAbstractArray* CreateArray(int dataType);
426 
431  virtual int IsNumeric() const = 0;
432 
438  virtual vtkArrayIterator* NewIterator() = 0;
439 
446  virtual vtkIdType GetDataSize() const
447  {
448  return this->GetNumberOfComponents() * this->GetNumberOfTuples();
449  }
450 
452 
459  virtual vtkIdType LookupValue(vtkVariant value) = 0;
460  virtual void LookupValue(vtkVariant value, vtkIdList* valueIds) = 0;
462 
466  virtual vtkVariant GetVariantValue(vtkIdType valueIdx)
467  VTK_EXPECTS(0 <= valueIdx && valueIdx < GetNumberOfValues());
468 
473  virtual void InsertVariantValue(vtkIdType valueIdx, vtkVariant value)
474  VTK_EXPECTS(0 <= valueIdx) = 0;
475 
480  virtual void SetVariantValue(vtkIdType valueIdx, vtkVariant value)
481  VTK_EXPECTS(0 <= valueIdx && valueIdx < GetNumberOfValues()) = 0;
482 
491  virtual void DataChanged() = 0;
492 
498  virtual void ClearLookup() = 0;
499 
552  virtual void GetProminentComponentValues(int comp, vtkVariantArray* values,
553  double uncertainty = 1.e-6, double minimumProminence = 1.e-3);
554 
555  // TODO: Implement these lookup functions also.
556  // virtual void LookupRange(vtkVariant min, vtkVariant max, vtkIdList* ids,
557  // bool includeMin = true, bool includeMax = true) = 0;
558  // virtual void LookupGreaterThan(vtkVariant min, vtkIdList* ids, bool includeMin = false) = 0;
559  // virtual void LookupLessThan(vtkVariant max, vtkIdList* ids, bool includeMax = false) = 0;
560 
566  vtkInformation* GetInformation();
571  bool HasInformation() const { return this->Information != nullptr; }
572 
584  virtual int CopyInformation(vtkInformation* infoFrom, int deep = 1);
585 
590  static vtkInformationIntegerKey* GUI_HIDE();
591 
604  static vtkInformationInformationVectorKey* PER_COMPONENT();
605 
618  static vtkInformationInformationVectorKey* PER_FINITE_COMPONENT();
619 
623  void Modified() override;
624 
630  static vtkInformationVariantVectorKey* DISCRETE_VALUES();
631 
639  static vtkInformationDoubleVectorKey* DISCRETE_VALUE_SAMPLE_PARAMETERS();
640 
641  // Deprecated. Use vtkAbstractArray::MaxDiscreteValues instead.
642  enum
643  {
644  MAX_DISCRETE_VALUES = 32
645  };
646 
648 
652  vtkGetMacro(MaxDiscreteValues, unsigned int);
653  vtkSetMacro(MaxDiscreteValues, unsigned int);
655 
656  enum
657  {
658  AbstractArray = 0,
665 
666  DataArrayTemplate = AoSDataArrayTemplate
667  };
668 
673  virtual int GetArrayType() const { return AbstractArray; }
674 
678  const char* GetArrayTypeAsString() const;
679 
680 protected:
681  // Construct object with default tuple dimension (number of components) of 1.
683  ~vtkAbstractArray() override;
684 
690  virtual void SetInformation(vtkInformation*);
691 
703  virtual void UpdateDiscreteValueSet(double uncertainty, double minProminence);
704 
705  vtkIdType Size; // allocated size of data
706  vtkIdType MaxId; // maximum index inserted thus far
707  int NumberOfComponents; // the number of components per tuple
708 
709  // maximum number of prominent values before array is considered continuous.
710  unsigned int MaxDiscreteValues;
711 
712  char* Name;
713 
714  bool RebuildArray; // whether to rebuild the fast lookup data structure.
715 
717 
718  class vtkInternalComponentNames;
719  vtkInternalComponentNames* ComponentNames; // names for each component
720 
721 private:
722  vtkAbstractArray(const vtkAbstractArray&) = delete;
723  void operator=(const vtkAbstractArray&) = delete;
724 };
725 
727 
732 template <typename ArrayT>
734 {
735  inline ArrayT* operator()(vtkAbstractArray* array) { return ArrayT::SafeDownCast(array); }
736 };
738 
756 template <typename ArrayT>
758 {
759  // The default vtkArrayDownCast_impl struct uses SafeDownCast, but is
760  // specialized for arrays that support FastDownCast.
761  return vtkArrayDownCast_impl<ArrayT>()(array);
762 }
763 
765 
769 #define vtkArrayDownCast_FastCastMacro(ArrayT) \
770  template <> \
771  struct vtkArrayDownCast_impl<ArrayT> \
772  { \
773  inline ArrayT* operator()(vtkAbstractArray* array) { return ArrayT::FastDownCast(array); } \
774  }
775 
778 
784 #define vtkArrayDownCast_TemplateFastCastMacro(ArrayT) \
785  template <typename ValueT> \
786  struct vtkArrayDownCast_impl<ArrayT<ValueT>> \
787  { \
788  inline ArrayT<ValueT>* operator()(vtkAbstractArray* array) \
789  { \
790  return ArrayT<ValueT>::FastDownCast(array); \
791  } \
792  }
793 
795 #endif
abstract base class for most VTK objects
Definition: vtkObject.h:62
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:155
dynamic, self-adjusting array of vtkIdType
int vtkIdType
Definition: vtkType.h:332
virtual const char * GetDataTypeAsString(void) const
Get the name of a data type as a string.
A atomic type representing the union of many types.
Definition: vtkVariant.h:69
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:69
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:39
list of point or cell ids
Definition: vtkIdList.h:33
Key for integer values in vtkInformation.
ArrayT * operator()(vtkAbstractArray *array)
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:55
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.