VTK  9.0.20200605
vtkVariantArray.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkVariantArray.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 /*-------------------------------------------------------------------------
16  Copyright 2008 Sandia Corporation.
17  Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
18  the U.S. Government retains certain rights in this software.
19 -------------------------------------------------------------------------*/
31 #ifndef vtkVariantArray_h
32 #define vtkVariantArray_h
33 
34 #include "vtkAbstractArray.h"
35 #include "vtkCommonCoreModule.h" // For export macro
36 #include "vtkVariant.h" // For variant type
37 
38 class vtkVariantArrayLookup;
39 
41 namespace boost
42 {
43 namespace serialization
44 {
45 class access;
46 }
47 }
48 
49 class VTKCOMMONCORE_EXPORT vtkVariantArray : public vtkAbstractArray
50 {
51 
53  friend class boost::serialization::access;
54 
55 public:
57  {
59  VTK_DATA_ARRAY_DELETE = vtkAbstractArray::VTK_DATA_ARRAY_DELETE,
60  VTK_DATA_ARRAY_ALIGNED_FREE = vtkAbstractArray::VTK_DATA_ARRAY_ALIGNED_FREE,
61  VTK_DATA_ARRAY_USER_DEFINED = vtkAbstractArray::VTK_DATA_ARRAY_USER_DEFINED
62  };
63 
64  static vtkVariantArray* New();
65  static vtkVariantArray* ExtendedNew();
67  void PrintSelf(ostream& os, vtkIndent indent) override;
68 
69  //
70  // Functions required by vtkAbstractArray
71  //
72 
77  vtkTypeBool Allocate(vtkIdType sz, vtkIdType ext = 1000) override;
78 
82  void Initialize() override;
83 
88  int GetDataType() const override;
89 
95  int GetDataTypeSize() const override;
96 
104  int GetElementComponentSize() const override;
105 
110  void SetNumberOfTuples(vtkIdType number) override;
111 
118  void SetTuple(vtkIdType i, vtkIdType j, vtkAbstractArray* source) override;
119 
124  void InsertTuple(vtkIdType i, vtkIdType j, vtkAbstractArray* source) override;
125 
131  void InsertTuples(vtkIdList* dstIds, vtkIdList* srcIds, vtkAbstractArray* source) override;
132 
138  void InsertTuples(
139  vtkIdType dstStart, vtkIdType n, vtkIdType srcStart, vtkAbstractArray* source) override;
140 
147 
152  void* GetVoidPointer(vtkIdType id) override;
153 
159  void DeepCopy(vtkAbstractArray* da) override;
160 
168  void InterpolateTuple(
169  vtkIdType i, vtkIdList* ptIndices, vtkAbstractArray* source, double* weights) override;
170 
180  vtkAbstractArray* source2, double t) override;
181 
187  void Squeeze() override;
188 
193  vtkTypeBool Resize(vtkIdType numTuples) override;
194 
196 
204  void SetVoidArray(void* arr, vtkIdType size, int save) override;
205  void SetVoidArray(void* arr, vtkIdType size, int save, int deleteM) override;
207 
216  unsigned long GetActualMemorySize() const override;
217 
221  int IsNumeric() const override;
222 
228 
229  //
230  // Additional functions
231  //
232 
236  vtkVariant& GetValue(vtkIdType id) const;
237 
242  void SetValue(vtkIdType id, vtkVariant value)
243  VTK_EXPECTS(0 <= id && id < this->GetNumberOfValues());
244 
250  void InsertValue(vtkIdType id, vtkVariant value) VTK_EXPECTS(0 <= id);
251 
255  void SetVariantValue(vtkIdType idx, vtkVariant value) override;
256 
260  void InsertVariantValue(vtkIdType idx, vtkVariant value) override;
261 
266  vtkIdType InsertNextValue(vtkVariant value);
267 
271  vtkVariant* GetPointer(vtkIdType id);
272 
276  void SetArray(
277  vtkVariant* arr, vtkIdType size, int save, int deleteMethod = VTK_DATA_ARRAY_DELETE);
278 
285  void SetArrayFreeFunction(void (*callback)(void*)) override;
286 
290  vtkIdType GetNumberOfValues() { return this->MaxId + 1; }
291 
293 
297  void LookupValue(vtkVariant value, vtkIdList* ids) override;
299 
308  void DataChanged() override;
309 
315  virtual void DataElementChanged(vtkIdType id);
316 
322  void ClearLookup() override;
323 
328  ~vtkVariantArray() override;
329 
330 protected:
331  // Construct object with default tuple dimension (number of components) of 1.
332  vtkVariantArray();
333 
334  // Pointer to data
335 
337 
338  // Function to resize data
339  vtkVariant* ResizeAndExtend(vtkIdType sz);
340 
341  void (*DeleteFunction)(void*);
342 
343 private:
344  vtkVariantArray(const vtkVariantArray&) = delete;
345  void operator=(const vtkVariantArray&) = delete;
346 
347  vtkVariantArrayLookup* Lookup;
348  void UpdateLookup();
349 };
350 
351 #endif
vtkAbstractArray::SetArrayFreeFunction
virtual void SetArrayFreeFunction(void(*callback)(void *))=0
This method allows the user to specify a custom free function to be called when the array is dealloca...
vtkAbstractArray::Initialize
virtual void Initialize()=0
Release storage and reset array to initial state.
vtkAbstractArray::LookupValue
virtual vtkIdType LookupValue(vtkVariant value)=0
Return the value indices where a specific value appears.
vtkAbstractArray::Squeeze
virtual void Squeeze()=0
Free any unnecessary memory.
vtkAbstractArray::InterpolateTuple
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...
vtkAbstractArray::DeleteMethod
DeleteMethod
Definition: vtkAbstractArray.h:321
vtkAbstractArray::VTK_DATA_ARRAY_ALIGNED_FREE
Definition: vtkAbstractArray.h:325
vtkVariant.h
vtkAbstractArray::SetVoidArray
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.
vtkAbstractArray::NewIterator
virtual vtkArrayIterator * NewIterator()=0
Subclasses must override this method and provide the right kind of templated vtkArrayIteratorTemplate...
vtkAbstractArray::InsertTuple
virtual void InsertTuple(vtkIdType dstTupleIdx, vtkIdType srcTupleIdx, vtkAbstractArray *source)=0
Insert the tuple at srcTupleIdx in the source array into this array at dstTupleIdx.
VTK_EXPECTS
#define VTK_EXPECTS(x)
Definition: vtkWrappingHints.h:44
vtkX3D::value
Definition: vtkX3D.h:226
vtkAbstractArray::VTK_DATA_ARRAY_DELETE
Definition: vtkAbstractArray.h:324
vtkAbstractArray::GetElementComponentSize
virtual int GetElementComponentSize() const =0
Return the size, in bytes, of the lowest-level element of an array.
vtkIdType
int vtkIdType
Definition: vtkType.h:330
vtkAbstractArray::PrintSelf
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
vtkAbstractArray::InsertNextTuple
virtual vtkIdType InsertNextTuple(vtkIdType srcTupleIdx, vtkAbstractArray *source)=0
Insert the tuple from srcTupleIdx in the source array at the end of this array.
vtkObject::New
static vtkObject * New()
Create an object with Debug turned off, modified time initialized to zero, and reference counting on.
vtkAbstractArray::SetNumberOfTuples
virtual void SetNumberOfTuples(vtkIdType numTuples)=0
Set the number of tuples (a component group) in the array.
save
void save(Archiver &ar, const vtkUnicodeString &str, const unsigned int vtkNotUsed(version))
Definition: vtkVariantBoostSerialization.h:64
vtkAbstractArray::InsertTuples
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...
vtkAbstractArray::VTK_DATA_ARRAY_FREE
Definition: vtkAbstractArray.h:323
vtkAbstractArray::GetDataType
virtual int GetDataType() const =0
Return the underlying data type.
vtkAbstractArray::IsNumeric
virtual int IsNumeric() const =0
This method is here to make backward compatibility easier.
boost
Forward declaration required for Boost serialization.
Definition: vtkVariantArray.h:41
vtkVariantArray
An array holding vtkVariants.
Definition: vtkVariantArray.h:49
vtkVariantArray::GetNumberOfValues
vtkIdType GetNumberOfValues()
Return the number of values in the array.
Definition: vtkVariantArray.h:290
vtkAbstractArray.h
vtkAbstractArray::Allocate
virtual vtkTypeBool Allocate(vtkIdType numValues, vtkIdType ext=1000)=0
Allocate memory for this array.
vtkAbstractArray::InsertVariantValue
virtual void InsertVariantValue(vtkIdType valueIdx, vtkVariant value)=0
Insert a value into the array from a variant.
vtkAbstractArray::GetVoidPointer
virtual void * GetVoidPointer(vtkIdType valueIdx)=0
Return a void pointer.
vtkAbstractArray::GetNumberOfValues
vtkIdType GetNumberOfValues() const
Get the total number of values in the array.
Definition: vtkAbstractArray.h:180
vtkAbstractArray::SetTuple
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.
vtkAbstractArray::VTK_DATA_ARRAY_USER_DEFINED
Definition: vtkAbstractArray.h:326
vtkIndent
a simple class to control print indentation
Definition: vtkIndent.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
vtkX3D::size
Definition: vtkX3D.h:259
vtkAbstractArray::SetVariantValue
virtual void SetVariantValue(vtkIdType valueIdx, vtkVariant value)=0
Set a value in the array from a variant.
vtkAbstractArray
Abstract superclass for all arrays.
Definition: vtkAbstractArray.h:75
vtkVariantArray::Array
vtkVariant * Array
Definition: vtkVariantArray.h:336
vtkAbstractArray::GetActualMemorySize
virtual unsigned long GetActualMemorySize() const =0
Return the memory in kibibytes (1024 bytes) consumed by this data array.
vtkAbstractArray::DeepCopy
virtual void DeepCopy(vtkAbstractArray *da)
Deep copy of data.
vtkArrayIterator
Abstract superclass to iterate over elements in an vtkAbstractArray.
Definition: vtkArrayIterator.h:49
vtkAbstractArray::GetDataTypeSize
virtual int GetDataTypeSize() const =0
Return the size of the underlying data type.
source
boost::graph_traits< vtkGraph * >::vertex_descriptor source(boost::graph_traits< vtkGraph * >::edge_descriptor e, vtkGraph *)
Definition: vtkBoostGraphAdapter.h:959
vtkAbstractArray::ClearLookup
virtual void ClearLookup()=0
Delete the associated fast lookup data structure on this array, if it exists.
VTK_NEWINSTANCE
#define VTK_NEWINSTANCE
Definition: vtkWrappingHints.h:42
vtkAbstractArray::DataChanged
virtual void DataChanged()=0
Tell the array explicitly that the data has changed.
vtkTypeBool
int vtkTypeBool
Definition: vtkABI.h:69
vtkAbstractArray::Resize
virtual vtkTypeBool Resize(vtkIdType numTuples)=0
Resize the array to the requested number of tuples and preserve data.