VTK
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 "vtkCommonCoreModule.h" // For export macro
35 #include "vtkAbstractArray.h"
36 #include "vtkVariant.h" // For variant type
37 
38 class vtkVariantArrayLookup;
39 
41 namespace boost { namespace serialization { class access; } }
42 
43 class VTKCOMMONCORE_EXPORT vtkVariantArray : public vtkAbstractArray
44 {
45 
47  friend class boost::serialization::access;
48 
49 public:
51  {
54  VTK_DATA_ARRAY_ALIGNED_FREE=vtkAbstractArray::VTK_DATA_ARRAY_ALIGNED_FREE,
56  };
57 
58  static vtkVariantArray* New();
60  void PrintSelf(ostream& os, vtkIndent indent) override;
61 
62  //
63  // Functions required by vtkAbstractArray
64  //
65 
70  int Allocate(vtkIdType sz, vtkIdType ext=1000) override;
71 
75  void Initialize() override;
76 
81  int GetDataType() override;
82 
88  int GetDataTypeSize() override;
89 
97  int GetElementComponentSize() override;
98 
103  void SetNumberOfTuples(vtkIdType number) override;
104 
111  void SetTuple(vtkIdType i, vtkIdType j,
112  vtkAbstractArray* source) override;
113 
118  void InsertTuple(vtkIdType i, vtkIdType j,
119  vtkAbstractArray* source) override;
120 
126  void InsertTuples(vtkIdList *dstIds, vtkIdList *srcIds,
127  vtkAbstractArray *source) override;
128 
134  void InsertTuples(vtkIdType dstStart, vtkIdType n, vtkIdType srcStart,
135  vtkAbstractArray* source) override;
136 
143 
148  void *GetVoidPointer(vtkIdType id) override;
149 
155  void DeepCopy(vtkAbstractArray *da) override;
156 
164  void InterpolateTuple(vtkIdType i, vtkIdList *ptIndices,
165  vtkAbstractArray* source, double* weights) override;
166 
176  vtkIdType id1, vtkAbstractArray* source1,
177  vtkIdType id2, vtkAbstractArray* source2, double t) override;
178 
184  void Squeeze() override;
185 
190  int Resize(vtkIdType numTuples) override;
191 
193 
201  void SetVoidArray(void *arr, vtkIdType size, int save) override;
202  void SetVoidArray(void *arr, vtkIdType size, int save,
203  int deleteM) override;
205 
214  unsigned long GetActualMemorySize() override;
215 
219  int IsNumeric() override;
220 
226 
227  //
228  // Additional functions
229  //
230 
234  vtkVariant & GetValue(vtkIdType id) const;
235 
240  void SetValue(vtkIdType id, vtkVariant value)
241  VTK_EXPECTS(0 <= id && id < this->GetNumberOfValues());
242 
248  void InsertValue(vtkIdType id, vtkVariant value)
249  VTK_EXPECTS(0 <= id);
250 
254  void SetVariantValue(vtkIdType idx, vtkVariant value) override;
255 
259  void InsertVariantValue(vtkIdType idx, vtkVariant value) override;
260 
265  vtkIdType InsertNextValue(vtkVariant value);
266 
270  vtkVariant* GetPointer(vtkIdType id);
271 
275  void SetArray(vtkVariant* arr, vtkIdType size, int save, int deleteMethod=VTK_DATA_ARRAY_DELETE);
276 
283  void SetArrayFreeFunction(void (*callback)(void *)) override;
284 
290  void SetNumberOfValues(vtkIdType number) override;
291 
295  vtkIdType GetNumberOfValues() { return this->MaxId + 1; }
296 
298 
302  void LookupValue(vtkVariant value, vtkIdList* ids) override;
304 
313  void DataChanged() override;
314 
320  virtual void DataElementChanged(vtkIdType id);
321 
327  void ClearLookup() override;
328 
333  ~vtkVariantArray() override;
334 
335 protected:
336  // Construct object with default tuple dimension (number of components) of 1.
337  vtkVariantArray();
338 
339  // Pointer to data
340 
342 
343  // Function to resize data
344  vtkVariant* ResizeAndExtend(vtkIdType sz);
345 
346  void (*DeleteFunction)(void*);
347 
348 private:
349  vtkVariantArray(const vtkVariantArray&) = delete;
350  void operator=(const vtkVariantArray&) = delete;
351 
352  vtkVariantArrayLookup* Lookup;
353  void UpdateLookup();
354 };
355 
356 #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:330
vtkAbstractArray::VTK_DATA_ARRAY_ALIGNED_FREE
Definition: vtkAbstractArray.h:334
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::Resize
virtual int Resize(vtkIdType numTuples)=0
Resize the array to the requested number of tuples and preserve data.
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:41
vtkX3D::value
Definition: vtkX3D.h:220
vtkAbstractArray::VTK_DATA_ARRAY_DELETE
Definition: vtkAbstractArray.h:333
vtkIdType
int vtkIdType
Definition: vtkType.h:347
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:65
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:332
boost
Forward declaration required for Boost serialization.
Definition: vtkVariantArray.h:41
vtkVariantArray
An array holding vtkVariants.
Definition: vtkVariantArray.h:43
vtkVariantArray::GetNumberOfValues
vtkIdType GetNumberOfValues()
Return the number of values in the array.
Definition: vtkVariantArray.h:295
vtkAbstractArray.h
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.
source
boost::graph_traits< vtkGraph * >::vertex_descriptor source(boost::graph_traits< vtkGraph * >::edge_descriptor e, vtkGraph *)
Definition: vtkBoostGraphAdapter.h:825
vtkAbstractArray::GetNumberOfValues
vtkIdType GetNumberOfValues() const
Get the total number of values in the array.
Definition: vtkAbstractArray.h:180
vtkAbstractArray::GetElementComponentSize
virtual int GetElementComponentSize()=0
Return the size, in bytes, of the lowest-level element of an array.
vtkAbstractArray::GetActualMemorySize
virtual unsigned long GetActualMemorySize()=0
Return the memory in kibibytes (1024 bytes) consumed by this data array.
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:335
vtkAbstractArray::IsNumeric
virtual int IsNumeric()=0
This method is here to make backward compatibility easier.
vtkAbstractArray::GetDataTypeSize
virtual int GetDataTypeSize()=0
Return the size of the underlying data type.
vtkIndent
a simple class to control print indentation
Definition: vtkIndent.h:33
vtkAbstractArray::GetDataType
virtual int GetDataType()=0
Return the underlying data type.
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:253
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:341
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::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:39
vtkAbstractArray::Allocate
virtual int Allocate(vtkIdType numValues, vtkIdType ext=1000)=0
Allocate memory for this array.
vtkAbstractArray::DataChanged
virtual void DataChanged()=0
Tell the array explicitly that the data has changed.
vtkAbstractArray::SetNumberOfValues
virtual void SetNumberOfValues(vtkIdType numValues)
Specify the number of values (tuples * components) for this object to hold.