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 //
57 #ifndef vtkAbstractArray_h
58 #define vtkAbstractArray_h
59 
60 #include "vtkCommonCoreModule.h" // For export macro
61 #include "vtkObject.h"
62 #include "vtkVariant.h" // for variant arguments
63 
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) VTK_OVERRIDE;
80 
89  virtual int Allocate(vtkIdType numValues, vtkIdType ext=1000) = 0;
90 
94  virtual void Initialize() = 0;
95 
100  virtual int GetDataType() =0;
101 
103 
108  virtual int GetDataTypeSize() = 0;
109  static int GetDataTypeSize(int type);
111 
119  virtual int GetElementComponentSize() = 0;
120 
122 
126  vtkSetClampMacro(NumberOfComponents, int, 1, VTK_INT_MAX);
127  int GetNumberOfComponents() { return this->NumberOfComponents; }
129 
133  void SetComponentName( vtkIdType component, const char *name );
134 
139  const char* GetComponentName( vtkIdType component );
140 
144  bool HasAComponentName();
145 
150  int CopyComponentNames( vtkAbstractArray *da );
151 
159  virtual void SetNumberOfTuples(vtkIdType numTuples) = 0;
160 
166  virtual void SetNumberOfValues(vtkIdType numValues);
167 
172  {return (this->MaxId + 1)/this->NumberOfComponents;}
173 
181  {
182  return (this->MaxId + 1);
183  }
184 
191  virtual void SetTuple(vtkIdType dstTupleIdx, vtkIdType srcTupleIdx,
192  vtkAbstractArray *source) = 0;
193 
199  virtual void InsertTuple(vtkIdType dstTupleIdx, vtkIdType srcTupleIdx,
200  vtkAbstractArray* source) = 0;
201 
207  virtual void InsertTuples(vtkIdList *dstIds, vtkIdList *srcIds,
208  vtkAbstractArray* source) = 0;
209 
215  virtual void InsertTuples(vtkIdType dstStart, vtkIdType n, vtkIdType srcStart,
216  vtkAbstractArray* source) = 0;
217 
223  virtual vtkIdType InsertNextTuple(vtkIdType srcTupleIdx,
224  vtkAbstractArray* source) = 0;
225 
231  virtual void GetTuples(vtkIdList *tupleIds, vtkAbstractArray* output);
232 
238  virtual void GetTuples(vtkIdType p1, vtkIdType p2, vtkAbstractArray *output);
239 
246  virtual bool HasStandardMemoryLayout();
247 
255  virtual void *GetVoidPointer(vtkIdType valueIdx) = 0;
256 
265  virtual void DeepCopy(vtkAbstractArray* da);
266 
274  virtual void InterpolateTuple(vtkIdType dstTupleIdx, vtkIdList *ptIndices,
275  vtkAbstractArray* source, double* weights) = 0;
276 
285  virtual void InterpolateTuple(vtkIdType dstTupleIdx,
286  vtkIdType srcTupleIdx1, vtkAbstractArray* source1,
287  vtkIdType srcTupleIdx2, vtkAbstractArray* source2, double t) =0;
288 
294  virtual void Squeeze() = 0;
295 
305  virtual int Resize(vtkIdType numTuples) = 0;
306 
308 
311  void Reset()
312  {
313  this->MaxId = -1;
314  this->DataChanged();
315  }
317 
322  {return this->Size;}
323 
328  {return this->MaxId;}
329 
331  {
334  VTK_DATA_ARRAY_ALIGNED_FREE
335  };
336 
338 
352  virtual void SetVoidArray(void *vtkNotUsed(array),
353  vtkIdType vtkNotUsed(size),
354  int vtkNotUsed(save)) =0;
355  virtual void SetVoidArray(void *array, vtkIdType size, int save,
356  int vtkNotUsed(deleteMethod))
357  {this->SetVoidArray(array,size,save);};
359 
365  virtual void ExportToVoidPointer(void *out_ptr);
366 
375  virtual unsigned long GetActualMemorySize() = 0;
376 
378 
381  vtkSetStringMacro(Name);
382  vtkGetStringMacro(Name);
384 
388  virtual const char *GetDataTypeAsString( void )
389  { return vtkImageScalarTypeNameMacro( this->GetDataType() ); }
390 
401  static vtkAbstractArray* CreateArray(int dataType);
402 
407  virtual int IsNumeric() = 0;
408 
414  virtual vtkArrayIterator* NewIterator() = 0;
415 
423  {
424  return this->GetNumberOfComponents() * this->GetNumberOfTuples();
425  }
426 
428 
431  virtual vtkIdType LookupValue(vtkVariant value) = 0;
432  virtual void LookupValue(vtkVariant value, vtkIdList* valueIds) = 0;
434 
438  virtual vtkVariant GetVariantValue(vtkIdType valueIdx);
439 
444  virtual void InsertVariantValue(vtkIdType valueIdx, vtkVariant value) = 0;
445 
450  virtual void SetVariantValue(vtkIdType valueIdx, vtkVariant value) = 0;
451 
460  virtual void DataChanged() = 0;
461 
467  virtual void ClearLookup() = 0;
468 
521  virtual void GetProminentComponentValues(int comp, vtkVariantArray* values,
522  double uncertainty = 1.e-6, double minimumProminence = 1.e-3);
523 
524  // TODO: Implement these lookup functions also.
525  //virtual void LookupRange(vtkVariant min, vtkVariant max, vtkIdList* ids,
526  // bool includeMin = true, bool includeMax = true) = 0;
527  //virtual void LookupGreaterThan(vtkVariant min, vtkIdList* ids, bool includeMin = false) = 0;
528  //virtual void LookupLessThan(vtkVariant max, vtkIdList* ids, bool includeMax = false) = 0;
529 
535  vtkInformation* GetInformation();
540  bool HasInformation(){ return this->Information!=0; }
541 
553  virtual int CopyInformation(vtkInformation *infoFrom, int deep=1);
554 
559  static vtkInformationIntegerKey* GUI_HIDE();
560 
575  static vtkInformationInformationVectorKey* PER_COMPONENT();
576 
582  static vtkInformationVariantVectorKey* DISCRETE_VALUES();
583 
591  static vtkInformationDoubleVectorKey* DISCRETE_VALUE_SAMPLE_PARAMETERS();
592 
593  // Deprecated. Use vtkAbstractArray::MaxDiscreteValues instead.
594  enum {
595  MAX_DISCRETE_VALUES = 32
596  };
597 
599 
603  vtkGetMacro(MaxDiscreteValues, unsigned int);
604  vtkSetMacro(MaxDiscreteValues, unsigned int);
606 
607  enum {
608  AbstractArray = 0,
614 
615  DataArrayTemplate = AoSDataArrayTemplate
616  };
617 
622  virtual int GetArrayType()
623  {
624  return AbstractArray;
625  }
626 
627 protected:
628  // Construct object with default tuple dimension (number of components) of 1.
630  ~vtkAbstractArray() VTK_OVERRIDE;
631 
637  virtual void SetInformation( vtkInformation* );
638 
650  virtual void UpdateDiscreteValueSet(double uncertainty, double minProminence);
651 
652  vtkIdType Size; // allocated size of data
653  vtkIdType MaxId; // maximum index inserted thus far
654  int NumberOfComponents; // the number of components per tuple
655 
656  // maximum number of prominent values before array is considered continuous.
657  unsigned int MaxDiscreteValues;
658 
659  char* Name;
660 
661  bool RebuildArray; // whether to rebuild the fast lookup data structure.
662 
663  vtkInformation* Information;
664 
665  class vtkInternalComponentNames;
666  vtkInternalComponentNames* ComponentNames; //names for each component
667 
668 private:
669  vtkAbstractArray(const vtkAbstractArray&) VTK_DELETE_FUNCTION;
670  void operator=(const vtkAbstractArray&) VTK_DELETE_FUNCTION;
671 };
672 
674 
679 template <typename ArrayT>
681 {
682  inline ArrayT* operator()(vtkAbstractArray* array)
683  {
684  return ArrayT::SafeDownCast(array);
685  }
686 };
688 
706 template <typename ArrayT>
708 {
709  // The default vtkArrayDownCast_impl struct uses SafeDownCast, but is
710  // specialized for arrays that support FastDownCast.
711  return vtkArrayDownCast_impl<ArrayT>()(array);
712 }
713 
715 
719 #define vtkArrayDownCast_FastCastMacro(ArrayT) \
720  template <> struct vtkArrayDownCast_impl<ArrayT> \
721  { \
722  inline ArrayT* operator()(vtkAbstractArray *array) \
723  { \
724  return ArrayT::FastDownCast(array); \
725  } \
726  };
727 
728 
730 
736 #define vtkArrayDownCast_TemplateFastCastMacro(ArrayT) \
737  template <typename ValueT> struct vtkArrayDownCast_impl<ArrayT<ValueT> > \
738  { \
739  inline ArrayT<ValueT>* operator()(vtkAbstractArray *array) \
740  { \
741  return ArrayT<ValueT>::FastDownCast(array); \
742  } \
743  };
744 
745 
746 #endif
vtkIdType GetMaxId()
What is the maximum id currently in the array.
abstract base class for most VTK objects
Definition: vtkObject.h:53
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:157
virtual int GetArrayType()
Method for type-checking in FastDownCast implementations.
dynamic, self-adjusting array of vtkIdType
int vtkIdType
Definition: vtkType.h:345
int GetNumberOfComponents()
Set/Get the dimension (n) of the components.
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.
virtual vtkIdType GetDataSize()
Returns the size of the data in DataTypeSize units.
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:33
list of point or cell ids
Definition: vtkIdList.h:30
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:48
bool HasInformation()
Inquire if this array has an instance of vtkInformation already associated with it.
vtkGetStringMacro(ExtensionsString)
Returns a string listing all available extensions.
Abstract superclass to iterate over elements in an vtkAbstractArray.
void Reset()
Reset to an empty state, without freeing any memory.
#define VTK_NEWINSTANCE
vtkSetMacro(IgnoreDriverBugs, bool)
When set known driver bugs are ignored during driver feature detection.
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.
ArrayT * vtkArrayDownCast(vtkAbstractArray *array)
vtkArrayDownCast is to be used by generic (e.g.