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) 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  VTK_EXPECTS(0 <= valueIdx && valueIdx < GetNumberOfValues());
440 
445  virtual void InsertVariantValue(vtkIdType valueIdx, vtkVariant value)
446  VTK_EXPECTS(0 <= valueIdx) = 0;
447 
452  virtual void SetVariantValue(vtkIdType valueIdx, vtkVariant value)
453  VTK_EXPECTS(0 <= valueIdx && valueIdx < GetNumberOfValues()) = 0;
454 
463  virtual void DataChanged() = 0;
464 
470  virtual void ClearLookup() = 0;
471 
524  virtual void GetProminentComponentValues(int comp, vtkVariantArray* values,
525  double uncertainty = 1.e-6, double minimumProminence = 1.e-3);
526 
527  // TODO: Implement these lookup functions also.
528  //virtual void LookupRange(vtkVariant min, vtkVariant max, vtkIdList* ids,
529  // bool includeMin = true, bool includeMax = true) = 0;
530  //virtual void LookupGreaterThan(vtkVariant min, vtkIdList* ids, bool includeMin = false) = 0;
531  //virtual void LookupLessThan(vtkVariant max, vtkIdList* ids, bool includeMax = false) = 0;
532 
538  vtkInformation* GetInformation();
543  bool HasInformation(){ return this->Information!=nullptr; }
544 
556  virtual int CopyInformation(vtkInformation *infoFrom, int deep=1);
557 
562  static vtkInformationIntegerKey* GUI_HIDE();
563 
576  static vtkInformationInformationVectorKey* PER_COMPONENT();
577 
590  static vtkInformationInformationVectorKey* PER_FINITE_COMPONENT();
591 
595  void Modified() override;
596 
602  static vtkInformationVariantVectorKey* DISCRETE_VALUES();
603 
611  static vtkInformationDoubleVectorKey* DISCRETE_VALUE_SAMPLE_PARAMETERS();
612 
613  // Deprecated. Use vtkAbstractArray::MaxDiscreteValues instead.
614  enum {
615  MAX_DISCRETE_VALUES = 32
616  };
617 
619 
623  vtkGetMacro(MaxDiscreteValues, unsigned int);
624  vtkSetMacro(MaxDiscreteValues, unsigned int);
626 
627  enum {
628  AbstractArray = 0,
634 
635  DataArrayTemplate = AoSDataArrayTemplate
636  };
637 
642  virtual int GetArrayType()
643  {
644  return AbstractArray;
645  }
646 
647 protected:
648  // Construct object with default tuple dimension (number of components) of 1.
650  ~vtkAbstractArray() override;
651 
657  virtual void SetInformation( vtkInformation* );
658 
670  virtual void UpdateDiscreteValueSet(double uncertainty, double minProminence);
671 
672  vtkIdType Size; // allocated size of data
673  vtkIdType MaxId; // maximum index inserted thus far
674  int NumberOfComponents; // the number of components per tuple
675 
676  // maximum number of prominent values before array is considered continuous.
677  unsigned int MaxDiscreteValues;
678 
679  char* Name;
680 
681  bool RebuildArray; // whether to rebuild the fast lookup data structure.
682 
684 
685  class vtkInternalComponentNames;
686  vtkInternalComponentNames* ComponentNames; //names for each component
687 
688 private:
689  vtkAbstractArray(const vtkAbstractArray&) = delete;
690  void operator=(const vtkAbstractArray&) = delete;
691 };
692 
694 
699 template <typename ArrayT>
701 {
702  inline ArrayT* operator()(vtkAbstractArray* array)
703  {
704  return ArrayT::SafeDownCast(array);
705  }
706 };
708 
726 template <typename ArrayT>
728 {
729  // The default vtkArrayDownCast_impl struct uses SafeDownCast, but is
730  // specialized for arrays that support FastDownCast.
731  return vtkArrayDownCast_impl<ArrayT>()(array);
732 }
733 
735 
739 #define vtkArrayDownCast_FastCastMacro(ArrayT) \
740  template <> struct vtkArrayDownCast_impl<ArrayT> \
741  { \
742  inline ArrayT* operator()(vtkAbstractArray *array) \
743  { \
744  return ArrayT::FastDownCast(array); \
745  } \
746  };
747 
748 
750 
756 #define vtkArrayDownCast_TemplateFastCastMacro(ArrayT) \
757  template <typename ValueT> struct vtkArrayDownCast_impl<ArrayT<ValueT> > \
758  { \
759  inline ArrayT<ValueT>* operator()(vtkAbstractArray *array) \
760  { \
761  return ArrayT<ValueT>::FastDownCast(array); \
762  } \
763  };
764 
765 
766 #endif
vtkIdType GetMaxId()
What is the maximum id currently in the array.
abstract base class for most VTK objects
Definition: vtkObject.h:53
vtkIdType GetNumberOfValues() const
Get the total number of values in the array.
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:65
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
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.
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)