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  {
335  VTK_DATA_ARRAY_USER_DEFINED
336  };
337 
339 
356  virtual void SetVoidArray(void *vtkNotUsed(array),
357  vtkIdType vtkNotUsed(size),
358  int vtkNotUsed(save)) =0;
359  virtual void SetVoidArray(void *array, vtkIdType size, int save,
360  int vtkNotUsed(deleteMethod))
361  {this->SetVoidArray(array,size,save);};
363 
370  virtual void SetArrayFreeFunction(void (*callback)(void *)) = 0;
371 
377  virtual void ExportToVoidPointer(void *out_ptr);
378 
387  virtual unsigned long GetActualMemorySize() = 0;
388 
390 
393  vtkSetStringMacro(Name);
394  vtkGetStringMacro(Name);
396 
400  virtual const char *GetDataTypeAsString( void )
401  { return vtkImageScalarTypeNameMacro( this->GetDataType() ); }
402 
413  static vtkAbstractArray* CreateArray(int dataType);
414 
419  virtual int IsNumeric() = 0;
420 
426  virtual vtkArrayIterator* NewIterator() = 0;
427 
435  {
436  return this->GetNumberOfComponents() * this->GetNumberOfTuples();
437  }
438 
440 
443  virtual vtkIdType LookupValue(vtkVariant value) = 0;
444  virtual void LookupValue(vtkVariant value, vtkIdList* valueIds) = 0;
446 
450  virtual vtkVariant GetVariantValue(vtkIdType valueIdx)
451  VTK_EXPECTS(0 <= valueIdx && valueIdx < GetNumberOfValues());
452 
457  virtual void InsertVariantValue(vtkIdType valueIdx, vtkVariant value)
458  VTK_EXPECTS(0 <= valueIdx) = 0;
459 
464  virtual void SetVariantValue(vtkIdType valueIdx, vtkVariant value)
465  VTK_EXPECTS(0 <= valueIdx && valueIdx < GetNumberOfValues()) = 0;
466 
475  virtual void DataChanged() = 0;
476 
482  virtual void ClearLookup() = 0;
483 
536  virtual void GetProminentComponentValues(int comp, vtkVariantArray* values,
537  double uncertainty = 1.e-6, double minimumProminence = 1.e-3);
538 
539  // TODO: Implement these lookup functions also.
540  //virtual void LookupRange(vtkVariant min, vtkVariant max, vtkIdList* ids,
541  // bool includeMin = true, bool includeMax = true) = 0;
542  //virtual void LookupGreaterThan(vtkVariant min, vtkIdList* ids, bool includeMin = false) = 0;
543  //virtual void LookupLessThan(vtkVariant max, vtkIdList* ids, bool includeMax = false) = 0;
544 
550  vtkInformation* GetInformation();
555  bool HasInformation(){ return this->Information!=nullptr; }
556 
568  virtual int CopyInformation(vtkInformation *infoFrom, int deep=1);
569 
574  static vtkInformationIntegerKey* GUI_HIDE();
575 
588  static vtkInformationInformationVectorKey* PER_COMPONENT();
589 
602  static vtkInformationInformationVectorKey* PER_FINITE_COMPONENT();
603 
607  void Modified() override;
608 
614  static vtkInformationVariantVectorKey* DISCRETE_VALUES();
615 
623  static vtkInformationDoubleVectorKey* DISCRETE_VALUE_SAMPLE_PARAMETERS();
624 
625  // Deprecated. Use vtkAbstractArray::MaxDiscreteValues instead.
626  enum {
627  MAX_DISCRETE_VALUES = 32
628  };
629 
631 
635  vtkGetMacro(MaxDiscreteValues, unsigned int);
636  vtkSetMacro(MaxDiscreteValues, unsigned int);
638 
639  enum {
640  AbstractArray = 0,
646 
647  DataArrayTemplate = AoSDataArrayTemplate
648  };
649 
654  virtual int GetArrayType()
655  {
656  return AbstractArray;
657  }
658 
659 protected:
660  // Construct object with default tuple dimension (number of components) of 1.
662  ~vtkAbstractArray() override;
663 
669  virtual void SetInformation( vtkInformation* );
670 
682  virtual void UpdateDiscreteValueSet(double uncertainty, double minProminence);
683 
684  vtkIdType Size; // allocated size of data
685  vtkIdType MaxId; // maximum index inserted thus far
686  int NumberOfComponents; // the number of components per tuple
687 
688  // maximum number of prominent values before array is considered continuous.
689  unsigned int MaxDiscreteValues;
690 
691  char* Name;
692 
693  bool RebuildArray; // whether to rebuild the fast lookup data structure.
694 
696 
697  class vtkInternalComponentNames;
698  vtkInternalComponentNames* ComponentNames; //names for each component
699 
700 private:
701  vtkAbstractArray(const vtkAbstractArray&) = delete;
702  void operator=(const vtkAbstractArray&) = delete;
703 };
704 
706 
711 template <typename ArrayT>
713 {
714  inline ArrayT* operator()(vtkAbstractArray* array)
715  {
716  return ArrayT::SafeDownCast(array);
717  }
718 };
720 
738 template <typename ArrayT>
740 {
741  // The default vtkArrayDownCast_impl struct uses SafeDownCast, but is
742  // specialized for arrays that support FastDownCast.
743  return vtkArrayDownCast_impl<ArrayT>()(array);
744 }
745 
747 
751 #define vtkArrayDownCast_FastCastMacro(ArrayT) \
752  template <> struct vtkArrayDownCast_impl<ArrayT> \
753  { \
754  inline ArrayT* operator()(vtkAbstractArray *array) \
755  { \
756  return ArrayT::FastDownCast(array); \
757  } \
758  };
759 
760 
762 
768 #define vtkArrayDownCast_TemplateFastCastMacro(ArrayT) \
769  template <typename ValueT> struct vtkArrayDownCast_impl<ArrayT<ValueT> > \
770  { \
771  inline ArrayT<ValueT>* operator()(vtkAbstractArray *array) \
772  { \
773  return ArrayT<ValueT>::FastDownCast(array); \
774  } \
775  };
776 
777 
778 #endif
vtkAbstractArray::Name
char * Name
Definition: vtkAbstractArray.h:691
vtkAbstractArray::DeleteMethod
DeleteMethod
Definition: vtkAbstractArray.h:330
VTK_INT_MAX
#define VTK_INT_MAX
Definition: vtkType.h:159
vtkAbstractArray::VTK_DATA_ARRAY_ALIGNED_FREE
Definition: vtkAbstractArray.h:334
vtkAbstractArray::GetDataSize
virtual vtkIdType GetDataSize()
Returns the size of the data in DataTypeSize units.
Definition: vtkAbstractArray.h:434
vtkAbstractArray::GetNumberOfComponents
int GetNumberOfComponents()
Definition: vtkAbstractArray.h:127
vtkVariant.h
vtkX3D::component
Definition: vtkX3D.h:175
VTK_EXPECTS
#define VTK_EXPECTS(x)
Definition: vtkWrappingHints.h:41
vtkX3D::value
Definition: vtkX3D.h:220
vtkAbstractArray::VTK_DATA_ARRAY_DELETE
Definition: vtkAbstractArray.h:333
vtkX3D::type
Definition: vtkX3D.h:516
vtkIdType
int vtkIdType
Definition: vtkType.h:347
save
void save(Archiver &ar, const vtkUnicodeString &str, const unsigned int vtkNotUsed(version))
Definition: vtkVariantBoostSerialization.h:65
vtkAbstractArray::Size
vtkIdType Size
Definition: vtkAbstractArray.h:684
vtkAbstractArray::VTK_DATA_ARRAY_FREE
Definition: vtkAbstractArray.h:332
vtkObject::Modified
virtual void Modified()
Update the modification time for this object.
vtkAbstractArray::Information
vtkInformation * Information
Definition: vtkAbstractArray.h:695
vtkAbstractArray::SetVoidArray
virtual void SetVoidArray(void *array, vtkIdType size, int save, int vtkNotUsed(deleteMethod))
Definition: vtkAbstractArray.h:359
vtkObject
abstract base class for most VTK objects
Definition: vtkObject.h:53
vtkVariantArray
An array holding vtkVariants.
Definition: vtkVariantArray.h:43
vtkDataArray
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:48
vtkAbstractArray::ComponentNames
vtkInternalComponentNames * ComponentNames
Definition: vtkAbstractArray.h:697
vtkAbstractArray::HasInformation
bool HasInformation()
Inquire if this array has an instance of vtkInformation already associated with it.
Definition: vtkAbstractArray.h:555
vtkAbstractArray::SoADataArrayTemplate
Definition: vtkAbstractArray.h:643
vtkAbstractArray::GetSize
vtkIdType GetSize()
Return the size of the data.
Definition: vtkAbstractArray.h:321
source
boost::graph_traits< vtkGraph * >::vertex_descriptor source(boost::graph_traits< vtkGraph * >::edge_descriptor e, vtkGraph *)
Definition: vtkBoostGraphAdapter.h:825
vtkAbstractArray::GetNumberOfTuples
vtkIdType GetNumberOfTuples()
Get the number of complete tuples (a component group) in the array.
Definition: vtkAbstractArray.h:171
vtkAbstractArray::AoSDataArrayTemplate
Definition: vtkAbstractArray.h:642
vtkAbstractArray::GetNumberOfValues
vtkIdType GetNumberOfValues() const
Get the total number of values in the array.
Definition: vtkAbstractArray.h:180
vtkAbstractArray::RebuildArray
bool RebuildArray
Definition: vtkAbstractArray.h:693
vtkAbstractArray::GetMaxId
vtkIdType GetMaxId()
What is the maximum id currently in the array.
Definition: vtkAbstractArray.h:327
vtkAbstractArray::Reset
void Reset()
Reset to an empty state, without freeing any memory.
Definition: vtkAbstractArray.h:311
vtkInformationIntegerKey
Key for integer values in vtkInformation.
Definition: vtkInformationIntegerKey.h:31
vtkIndent
a simple class to control print indentation
Definition: vtkIndent.h:33
vtkInformationVariantVectorKey
Key for variant vector values.
Definition: vtkInformationVariantVectorKey.h:33
vtkVariant
A atomic type representing the union of many types.
Definition: vtkVariant.h:65
vtkIdList
list of point or cell ids
Definition: vtkIdList.h:30
vtkArrayDownCast_impl::operator()
ArrayT * operator()(vtkAbstractArray *array)
Definition: vtkAbstractArray.h:714
vtkArrayDownCast_impl
Implementation of vtkArrayDownCast.
Definition: vtkAbstractArray.h:712
vtkX3D::size
Definition: vtkX3D.h:253
vtkObject::PrintSelf
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
vtkAbstractArray::GetArrayType
virtual int GetArrayType()
Method for type-checking in FastDownCast implementations.
Definition: vtkAbstractArray.h:654
vtkX3D::name
Definition: vtkX3D.h:219
vtkObject.h
vtkArrayDownCast
ArrayT * vtkArrayDownCast(vtkAbstractArray *array)
vtkArrayDownCast is to be used by generic (e.g.
Definition: vtkAbstractArray.h:739
vtkAbstractArray
Abstract superclass for all arrays.
Definition: vtkAbstractArray.h:75
vtkAbstractArray::DataArray
Definition: vtkAbstractArray.h:641
vtkInformation
Store vtkAlgorithm input/output information.
Definition: vtkInformation.h:80
vtkAbstractArray::MaxDiscreteValues
unsigned int MaxDiscreteValues
Definition: vtkAbstractArray.h:689
vtkIdTypeArray
dynamic, self-adjusting array of vtkIdType
Definition: vtkIdTypeArray.h:35
vtkInformationDoubleVectorKey
Key for double vector values.
Definition: vtkInformationDoubleVectorKey.h:31
vtkAbstractArray::TypedDataArray
Definition: vtkAbstractArray.h:644
vtkArrayIterator
Abstract superclass to iterate over elements in an vtkAbstractArray.
Definition: vtkArrayIterator.h:49
vtkInformationInformationVectorKey
Key for vtkInformation vectors.
Definition: vtkInformationInformationVectorKey.h:33
VTK_NEWINSTANCE
#define VTK_NEWINSTANCE
Definition: vtkWrappingHints.h:39
vtkAbstractArray::MaxId
vtkIdType MaxId
Definition: vtkAbstractArray.h:685
vtkAbstractArray::MappedDataArray
Definition: vtkAbstractArray.h:645
vtkAbstractArray::GetDataTypeAsString
virtual const char * GetDataTypeAsString(void)
Get the name of a data type as a string.
Definition: vtkAbstractArray.h:400
vtkAbstractArray::NumberOfComponents
int NumberOfComponents
Definition: vtkAbstractArray.h:686