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) VTK_OVERRIDE;
83 
92  virtual int 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 
143 
148 
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 int 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  {
336  VTK_DATA_ARRAY_DELETE
337  };
338 
340 
351  virtual void SetVoidArray(void *vtkNotUsed(array),
352  vtkIdType vtkNotUsed(size),
353  int vtkNotUsed(save)) =0;
354  virtual void SetVoidArray(void *array, vtkIdType size, int save,
355  int vtkNotUsed(deleteMethod))
356  {this->SetVoidArray(array,size,save);};
358 
364  virtual void ExportToVoidPointer(void *out_ptr);
365 
374  virtual unsigned long GetActualMemorySize() = 0;
375 
377 
380  vtkSetStringMacro(Name);
383 
387  virtual const char *GetDataTypeAsString( void )
388  { return vtkImageScalarTypeNameMacro( this->GetDataType() ); }
389 
400  static vtkAbstractArray* CreateArray(int dataType);
401 
406  virtual int IsNumeric() = 0;
407 
414 
422  {
423  return this->GetNumberOfComponents() * this->GetNumberOfTuples();
424  }
425 
427 
431  virtual void LookupValue(vtkVariant value, vtkIdList* valueIds) = 0;
433 
438 
443  virtual void InsertVariantValue(vtkIdType valueIdx, vtkVariant value) = 0;
444 
449  virtual void SetVariantValue(vtkIdType valueIdx, vtkVariant value) = 0;
450 
459  virtual void DataChanged() = 0;
460 
466  virtual void ClearLookup() = 0;
467 
520  virtual void GetProminentComponentValues(int comp, vtkVariantArray* values,
521  double uncertainty = 1.e-6, double minimumProminence = 1.e-3);
522 
523  // TODO: Implement these lookup functions also.
524  //virtual void LookupRange(vtkVariant min, vtkVariant max, vtkIdList* ids,
525  // bool includeMin = true, bool includeMax = true) = 0;
526  //virtual void LookupGreaterThan(vtkVariant min, vtkIdList* ids, bool includeMin = false) = 0;
527  //virtual void LookupLessThan(vtkVariant max, vtkIdList* ids, bool includeMax = false) = 0;
528 
539  bool HasInformation(){ return this->Information!=0; }
540 
552  virtual int CopyInformation(vtkInformation *infoFrom, int deep=1);
553 
559 
575 
582 
591 
592  // Deprecated. Use vtkAbstractArray::MaxDiscreteValues instead.
593  enum {
594  MAX_DISCRETE_VALUES = 32
595  };
596 
598 
602  vtkGetMacro(MaxDiscreteValues, unsigned int);
603  vtkSetMacro(MaxDiscreteValues, unsigned int);
605 
606  enum {
607  AbstractArray = 0,
613 
614  DataArrayTemplate = AoSDataArrayTemplate
615  };
616 
621  virtual int GetArrayType()
622  {
623  return AbstractArray;
624  }
625 
626 protected:
627  // Construct object with default tuple dimension (number of components) of 1.
629  ~vtkAbstractArray() VTK_OVERRIDE;
630 
636  virtual void SetInformation( vtkInformation* );
637 
649  virtual void UpdateDiscreteValueSet(double uncertainty, double minProminence);
650 
651  vtkIdType Size; // allocated size of data
652  vtkIdType MaxId; // maximum index inserted thus far
653  int NumberOfComponents; // the number of components per tuple
654 
655  // maximum number of prominent values before array is considered continuous.
656  unsigned int MaxDiscreteValues;
657 
658  char* Name;
659 
660  bool RebuildArray; // whether to rebuild the fast lookup data structure.
661 
662  vtkInformation* Information;
663 
664  class vtkInternalComponentNames;
665  vtkInternalComponentNames* ComponentNames; //names for each component
666 
667 private:
668  vtkAbstractArray(const vtkAbstractArray&) VTK_DELETE_FUNCTION;
669  void operator=(const vtkAbstractArray&) VTK_DELETE_FUNCTION;
670 };
671 
673 
678 template <typename ArrayT>
680 {
681  inline ArrayT* operator()(vtkAbstractArray* array)
682  {
683  return ArrayT::SafeDownCast(array);
684  }
685 };
687 
705 template <typename ArrayT>
707 {
708  // The default vtkArrayDownCast_impl struct uses SafeDownCast, but is
709  // specialized for arrays that support FastDownCast.
710  return vtkArrayDownCast_impl<ArrayT>()(array);
711 }
712 
714 
718 #define vtkArrayDownCast_FastCastMacro(ArrayT) \
719  template <> struct vtkArrayDownCast_impl<ArrayT> \
720  { \
721  inline ArrayT* operator()(vtkAbstractArray *array) \
722  { \
723  return ArrayT::FastDownCast(array); \
724  } \
725  };
727 
729 
735 #define vtkArrayDownCast_TemplateFastCastMacro(ArrayT) \
736  template <typename ValueT> struct vtkArrayDownCast_impl<ArrayT<ValueT> > \
737  { \
738  inline ArrayT<ValueT>* operator()(vtkAbstractArray *array) \
739  { \
740  return ArrayT<ValueT>::FastDownCast(array); \
741  } \
742  };
744 
745 #endif
Abstract superclass for all arrays.
static vtkInformationInformationVectorKey * PER_COMPONENT()
This key is used to hold a vector of COMPONENT_VALUES (and, for vtkDataArray subclasses,...
virtual void GetTuples(vtkIdList *tupleIds, vtkAbstractArray *output)
Given a list of tuple ids, return an array of tuples.
virtual void Initialize()=0
Release storage and reset array to initial state.
bool HasInformation()
Inquire if this array has an instance of vtkInformation already associated with it.
virtual void DeepCopy(vtkAbstractArray *da)
Deep copy of data.
virtual void InterpolateTuple(vtkIdType dstTupleIdx, vtkIdType srcTupleIdx1, vtkAbstractArray *source1, vtkIdType srcTupleIdx2, vtkAbstractArray *source2, double t)=0
Insert the tuple at dstTupleIdx in this array to the tuple interpolated from the two tuple indices,...
static vtkInformationDoubleVectorKey * DISCRETE_VALUE_SAMPLE_PARAMETERS()
A key used to hold conditions under which cached discrete values were generated; the value is a 2-vec...
virtual int Resize(vtkIdType numTuples)=0
Resize the array to the requested number of tuples and preserve data.
virtual void SetNumberOfValues(vtkIdType numValues)
Specify the number of values (tuples * components) for this object to hold.
static int GetDataTypeSize(int type)
virtual void SetVoidArray(void *vtkNotUsed(array), vtkIdType vtkNotUsed(size), int vtkNotUsed(save))=0
This method lets the user specify data to be held by the array.
void SetComponentName(vtkIdType component, const char *name)
Set the name for a component.
virtual bool HasStandardMemoryLayout()
Returns true if this array uses the standard memory layout defined in the VTK user guide,...
virtual vtkVariant GetVariantValue(vtkIdType valueIdx)
Retrieve value from the array as a variant.
virtual const char * GetDataTypeAsString(void)
Get the name of a data type as a string.
virtual void SetNumberOfTuples(vtkIdType numTuples)=0
Set the number of tuples (a component group) in the array.
virtual vtkIdType GetDataSize()
Returns the size of the data in DataTypeSize units.
virtual void SetTuple(vtkIdType dstTupleIdx, vtkIdType srcTupleIdx, vtkAbstractArray *source)=0
Set the tuple at dstTupleIdx in this array to the tuple at srcTupleIdx in the source array.
virtual void ClearLookup()=0
Delete the associated fast lookup data structure on this array, if it exists.
virtual VTK_NEWINSTANCE vtkArrayIterator * NewIterator()=0
Subclasses must override this method and provide the right kind of templated vtkArrayIteratorTemplate...
virtual void InsertTuples(vtkIdList *dstIds, vtkIdList *srcIds, vtkAbstractArray *source)=0
Copy the tuples indexed in srcIds from the source array to the tuple locations indexed by dstIds in t...
virtual int CopyInformation(vtkInformation *infoFrom, int deep=1)
Copy information instance.
const char * GetComponentName(vtkIdType component)
Get the component name for a given component.
virtual void InterpolateTuple(vtkIdType dstTupleIdx, vtkIdList *ptIndices, vtkAbstractArray *source, double *weights)=0
Set the tuple at dstTupleIdx in this array to the interpolated tuple value, given the ptIndices in th...
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
virtual int IsNumeric()=0
This method is here to make backward compatibility easier.
virtual int Allocate(vtkIdType numValues, vtkIdType ext=1000)=0
Allocate memory for this array.
vtkIdType GetNumberOfTuples()
Get the number of complete tuples (a component group) in the array.
void Reset()
Reset to an empty state, without freeing any memory.
vtkInformation * GetInformation()
Get an information object that can be used to annotate the array.
int CopyComponentNames(vtkAbstractArray *da)
Copies the component names from the inputed array to the current array make sure that the current arr...
virtual void ExportToVoidPointer(void *out_ptr)
This method copies the array data to the void pointer specified by the user.
virtual void InsertTuples(vtkIdType dstStart, vtkIdType n, vtkIdType srcStart, vtkAbstractArray *source)=0
Copy n consecutive tuples starting at srcStart from the source array to this array,...
virtual void SetVariantValue(vtkIdType valueIdx, vtkVariant value)=0
Set a value in the array from a variant.
virtual void InsertTuple(vtkIdType dstTupleIdx, vtkIdType srcTupleIdx, vtkAbstractArray *source)=0
Insert the tuple at srcTupleIdx in the source array into this array at dstTupleIdx.
vtkIdType GetNumberOfValues() const
Get the total number of values in the array.
virtual int GetDataTypeSize()=0
Return the size of the underlying data type.
vtkIdType GetSize()
Return the size of the data.
static vtkInformationVariantVectorKey * DISCRETE_VALUES()
A key used to hold discrete values taken on either by the tuples of the array (when present in this->...
virtual int GetArrayType()
Method for type-checking in FastDownCast implementations.
virtual void GetTuples(vtkIdType p1, vtkIdType p2, vtkAbstractArray *output)
Get the tuples for the range of tuple ids specified (i.e., p1->p2 inclusive).
virtual int GetDataType()=0
Return the underlying data type.
static vtkInformationIntegerKey * GUI_HIDE()
This key is a hint to end user interface that this array is internal and should not be shown to the e...
vtkIdType GetMaxId()
What is the maximum id currently in the array.
virtual vtkIdType LookupValue(vtkVariant value)=0
Return the value indices where a specific value appears.
virtual unsigned long GetActualMemorySize()=0
Return the memory in kibibytes (1024 bytes) consumed by this data array.
~vtkAbstractArray() override
virtual void SetVoidArray(void *array, vtkIdType size, int save, int vtkNotUsed(deleteMethod))
virtual void LookupValue(vtkVariant value, vtkIdList *valueIds)=0
virtual void InsertVariantValue(vtkIdType valueIdx, vtkVariant value)=0
Insert a value into the array from a variant.
virtual vtkIdType InsertNextTuple(vtkIdType srcTupleIdx, vtkAbstractArray *source)=0
Insert the tuple from srcTupleIdx in the source array at the end of this array.
virtual void Squeeze()=0
Free any unnecessary memory.
virtual int GetElementComponentSize()=0
Return the size, in bytes, of the lowest-level element of an array.
bool HasAComponentName()
Returns if any component has had a name assigned.
virtual void GetProminentComponentValues(int comp, vtkVariantArray *values, double uncertainty=1.e-6, double minimumProminence=1.e-3)
Populate the given vtkVariantArray with a set of distinct values taken on by the requested component ...
virtual void DataChanged()=0
Tell the array explicitly that the data has changed.
static VTK_NEWINSTANCE vtkAbstractArray * CreateArray(int dataType)
Creates an array for dataType where dataType is one of VTK_BIT, VTK_CHAR, VTK_UNSIGNED_CHAR,...
virtual void * GetVoidPointer(vtkIdType valueIdx)=0
Return a void pointer.
Abstract superclass to iterate over elements in an vtkAbstractArray.
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:55
list of point or cell ids
Definition: vtkIdList.h:37
dynamic, self-adjusting array of vtkIdType
a simple class to control print indentation
Definition: vtkIndent.h:40
Key for integer values in vtkInformation.
Store vtkAlgorithm input/output information.
abstract base class for most VTK objects
Definition: vtkObject.h:60
An array holding vtkVariants.
A atomic type representing the union of many types.
Definition: vtkVariant.h:76
@ component
Definition: vtkX3D.h:175
@ value
Definition: vtkX3D.h:220
@ type
Definition: vtkX3D.h:516
@ name
Definition: vtkX3D.h:219
@ size
Definition: vtkX3D.h:253
Implementation of vtkArrayDownCast.
ArrayT * operator()(vtkAbstractArray *array)
ArrayT * vtkArrayDownCast(vtkAbstractArray *array)
vtkArrayDownCast is to be used by generic (e.g.
boost::graph_traits< vtkGraph * >::vertex_descriptor source(boost::graph_traits< vtkGraph * >::edge_descriptor e, vtkGraph *)
vtkSetMacro(IgnoreDriverBugs, bool)
Updates the extensions string.
vtkGetStringMacro(ExtensionsString)
Returns a string listing all available extensions.
int vtkIdType
Definition: vtkType.h:287
#define VTK_INT_MAX
Definition: vtkType.h:153
void save(Archiver &ar, const vtkUnicodeString &str, const unsigned int vtkNotUsed(version))
#define VTK_NEWINSTANCE