VTK
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 //
60 #ifndef vtkAbstractArray_h
61 #define vtkAbstractArray_h
62 
63 #include "vtkCommonCoreModule.h" // For export macro
64 #include "vtkObject.h"
65 #include "vtkVariant.h" // for variant arguments
66 
67 class vtkArrayIterator;
68 class vtkDataArray;
69 class vtkIdList;
70 class vtkIdTypeArray;
71 class vtkInformation;
76 class vtkVariantArray;
77 
78 class VTKCOMMONCORE_EXPORT vtkAbstractArray : public vtkObject
79 {
80 public:
81  vtkTypeMacro(vtkAbstractArray,vtkObject);
82  void PrintSelf(ostream& os, vtkIndent indent) override;
83 
92  virtual vtkTypeBool Allocate(vtkIdType numValues, vtkIdType ext=1000) = 0;
93 
97  virtual void Initialize() = 0;
98 
103  virtual int GetDataType() = 0;
104 
106 
111  virtual int GetDataTypeSize() = 0;
112  static int GetDataTypeSize(int type);
114 
122  virtual int GetElementComponentSize() = 0;
123 
125 
129  vtkSetClampMacro(NumberOfComponents, int, 1, VTK_INT_MAX);
130  int GetNumberOfComponents() { return this->NumberOfComponents; }
132 
136  void SetComponentName( vtkIdType component, const char *name );
137 
142  const char* GetComponentName( vtkIdType component );
143 
147  bool HasAComponentName();
148 
153  int CopyComponentNames( vtkAbstractArray *da );
154 
162  virtual void SetNumberOfTuples(vtkIdType numTuples) = 0;
163 
169  virtual void SetNumberOfValues(vtkIdType numValues);
170 
175  {return (this->MaxId + 1)/this->NumberOfComponents;}
176 
184  {
185  return (this->MaxId + 1);
186  }
187 
194  virtual void SetTuple(vtkIdType dstTupleIdx, vtkIdType srcTupleIdx,
195  vtkAbstractArray *source) = 0;
196 
202  virtual void InsertTuple(vtkIdType dstTupleIdx, vtkIdType srcTupleIdx,
203  vtkAbstractArray* source) = 0;
204 
210  virtual void InsertTuples(vtkIdList *dstIds, vtkIdList *srcIds,
211  vtkAbstractArray* source) = 0;
212 
218  virtual void InsertTuples(vtkIdType dstStart, vtkIdType n, vtkIdType srcStart,
219  vtkAbstractArray* source) = 0;
220 
226  virtual vtkIdType InsertNextTuple(vtkIdType srcTupleIdx,
227  vtkAbstractArray* source) = 0;
228 
234  virtual void GetTuples(vtkIdList *tupleIds, vtkAbstractArray* output);
235 
241  virtual void GetTuples(vtkIdType p1, vtkIdType p2, vtkAbstractArray *output);
242 
249  virtual bool HasStandardMemoryLayout();
250 
258  virtual void *GetVoidPointer(vtkIdType valueIdx) = 0;
259 
268  virtual void DeepCopy(vtkAbstractArray* da);
269 
277  virtual void InterpolateTuple(vtkIdType dstTupleIdx, vtkIdList *ptIndices,
278  vtkAbstractArray* source, double* weights) = 0;
279 
288  virtual void InterpolateTuple(vtkIdType dstTupleIdx,
289  vtkIdType srcTupleIdx1, vtkAbstractArray* source1,
290  vtkIdType srcTupleIdx2, vtkAbstractArray* source2, double t) =0;
291 
297  virtual void Squeeze() = 0;
298 
308  virtual vtkTypeBool Resize(vtkIdType numTuples) = 0;
309 
311 
314  void Reset()
315  {
316  this->MaxId = -1;
317  this->DataChanged();
318  }
320 
325  {return this->Size;}
326 
331  {return this->MaxId;}
332 
334  {
338  VTK_DATA_ARRAY_USER_DEFINED
339  };
340 
342 
359  virtual void SetVoidArray(void *vtkNotUsed(array),
360  vtkIdType vtkNotUsed(size),
361  int vtkNotUsed(save)) =0;
362  virtual void SetVoidArray(void *array, vtkIdType size, int save,
363  int vtkNotUsed(deleteMethod))
364  {this->SetVoidArray(array,size,save);};
366 
373  virtual void SetArrayFreeFunction(void (*callback)(void *)) = 0;
374 
380  virtual void ExportToVoidPointer(void *out_ptr);
381 
390  virtual unsigned long GetActualMemorySize() = 0;
391 
393 
396  vtkSetStringMacro(Name);
397  vtkGetStringMacro(Name);
399 
403  virtual const char *GetDataTypeAsString( void )
404  { return vtkImageScalarTypeNameMacro( this->GetDataType() ); }
405 
416  static vtkAbstractArray* CreateArray(int dataType);
417 
422  virtual int IsNumeric() = 0;
423 
429  virtual vtkArrayIterator* NewIterator() = 0;
430 
438  {
439  return this->GetNumberOfComponents() * this->GetNumberOfTuples();
440  }
441 
443 
446  virtual vtkIdType LookupValue(vtkVariant value) = 0;
447  virtual void LookupValue(vtkVariant value, vtkIdList* valueIds) = 0;
449 
453  virtual vtkVariant GetVariantValue(vtkIdType valueIdx)
454  VTK_EXPECTS(0 <= valueIdx && valueIdx < GetNumberOfValues());
455 
460  virtual void InsertVariantValue(vtkIdType valueIdx, vtkVariant value)
461  VTK_EXPECTS(0 <= valueIdx) = 0;
462 
467  virtual void SetVariantValue(vtkIdType valueIdx, vtkVariant value)
468  VTK_EXPECTS(0 <= valueIdx && valueIdx < GetNumberOfValues()) = 0;
469 
478  virtual void DataChanged() = 0;
479 
485  virtual void ClearLookup() = 0;
486 
539  virtual void GetProminentComponentValues(int comp, vtkVariantArray* values,
540  double uncertainty = 1.e-6, double minimumProminence = 1.e-3);
541 
542  // TODO: Implement these lookup functions also.
543  //virtual void LookupRange(vtkVariant min, vtkVariant max, vtkIdList* ids,
544  // bool includeMin = true, bool includeMax = true) = 0;
545  //virtual void LookupGreaterThan(vtkVariant min, vtkIdList* ids, bool includeMin = false) = 0;
546  //virtual void LookupLessThan(vtkVariant max, vtkIdList* ids, bool includeMax = false) = 0;
547 
553  vtkInformation* GetInformation();
558  bool HasInformation(){ return this->Information!=nullptr; }
559 
571  virtual int CopyInformation(vtkInformation *infoFrom, int deep=1);
572 
577  static vtkInformationIntegerKey* GUI_HIDE();
578 
591  static vtkInformationInformationVectorKey* PER_COMPONENT();
592 
605  static vtkInformationInformationVectorKey* PER_FINITE_COMPONENT();
606 
610  void Modified() override;
611 
617  static vtkInformationVariantVectorKey* DISCRETE_VALUES();
618 
626  static vtkInformationDoubleVectorKey* DISCRETE_VALUE_SAMPLE_PARAMETERS();
627 
628  // Deprecated. Use vtkAbstractArray::MaxDiscreteValues instead.
629  enum {
630  MAX_DISCRETE_VALUES = 32
631  };
632 
634 
638  vtkGetMacro(MaxDiscreteValues, unsigned int);
639  vtkSetMacro(MaxDiscreteValues, unsigned int);
641 
642  enum {
643  AbstractArray = 0,
649 
650  DataArrayTemplate = AoSDataArrayTemplate
651  };
652 
657  virtual int GetArrayType()
658  {
659  return AbstractArray;
660  }
661 
662 protected:
663  // Construct object with default tuple dimension (number of components) of 1.
665  ~vtkAbstractArray() override;
666 
672  virtual void SetInformation( vtkInformation* );
673 
685  virtual void UpdateDiscreteValueSet(double uncertainty, double minProminence);
686 
687  vtkIdType Size; // allocated size of data
688  vtkIdType MaxId; // maximum index inserted thus far
689  int NumberOfComponents; // the number of components per tuple
690 
691  // maximum number of prominent values before array is considered continuous.
692  unsigned int MaxDiscreteValues;
693 
694  char* Name;
695 
696  bool RebuildArray; // whether to rebuild the fast lookup data structure.
697 
699 
700  class vtkInternalComponentNames;
701  vtkInternalComponentNames* ComponentNames; //names for each component
702 
703 private:
704  vtkAbstractArray(const vtkAbstractArray&) = delete;
705  void operator=(const vtkAbstractArray&) = delete;
706 };
707 
709 
714 template <typename ArrayT>
716 {
717  inline ArrayT* operator()(vtkAbstractArray* array)
718  {
719  return ArrayT::SafeDownCast(array);
720  }
721 };
723 
741 template <typename ArrayT>
743 {
744  // The default vtkArrayDownCast_impl struct uses SafeDownCast, but is
745  // specialized for arrays that support FastDownCast.
746  return vtkArrayDownCast_impl<ArrayT>()(array);
747 }
748 
750 
754 #define vtkArrayDownCast_FastCastMacro(ArrayT) \
755  template <> struct vtkArrayDownCast_impl<ArrayT> \
756  { \
757  inline ArrayT* operator()(vtkAbstractArray *array) \
758  { \
759  return ArrayT::FastDownCast(array); \
760  } \
761  };
762 
763 
765 
771 #define vtkArrayDownCast_TemplateFastCastMacro(ArrayT) \
772  template <typename ValueT> struct vtkArrayDownCast_impl<ArrayT<ValueT> > \
773  { \
774  inline ArrayT<ValueT>* operator()(vtkAbstractArray *array) \
775  { \
776  return ArrayT<ValueT>::FastDownCast(array); \
777  } \
778  };
779 
780 
781 #endif
vtkIdType GetMaxId()
What is the maximum id currently in the array.
abstract base class for most VTK objects
Definition: vtkObject.h:59
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.
vtkIdType GetNumberOfTuples()
Get the number of complete tuples (a component group) in the array.
Abstract superclass for all arrays.
Implementation of vtkArrayDownCast.
#define VTK_INT_MAX
Definition: vtkType.h:159
virtual int GetArrayType()
Method for type-checking in FastDownCast implementations.
dynamic, self-adjusting array of vtkIdType
int vtkIdType
Definition: vtkType.h:347
int GetNumberOfComponents()
Set/Get the dimension (n) of the components.
A atomic type representing the union of many types.
Definition: vtkVariant.h:71
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.
virtual vtkIdType GetDataSize()
Returns the size of the data in DataTypeSize units.
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.
a simple class to control print indentation
Definition: vtkIndent.h:39
list of point or cell ids
Definition: vtkIdList.h:36
Key for integer values in vtkInformation.
virtual const char * GetDataTypeAsString(void)
Get the name of a data type as a string.
ArrayT * operator()(vtkAbstractArray *array)
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:54
bool HasInformation()
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.
void Reset()
Reset to an empty state, without freeing any memory.
#define VTK_NEWINSTANCE
void save(Archiver &ar, const vtkUnicodeString &str, const unsigned int vtkNotUsed(version))
boost::graph_traits< vtkGraph * >::vertex_descriptor source(boost::graph_traits< vtkGraph * >::edge_descriptor e, vtkGraph *)
vtkIdType GetSize()
Return the size of the data.
vtkInternalComponentNames * ComponentNames
ArrayT * vtkArrayDownCast(vtkAbstractArray *array)
vtkArrayDownCast is to be used by generic (e.g.
unsigned int MaxDiscreteValues
#define VTK_EXPECTS(x)