VTK  9.1.20211028
vtkTypedDataArray.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkTypedDataArray.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 =========================================================================*/
36 #ifndef vtkTypedDataArray_h
37 #define vtkTypedDataArray_h
38 
39 #include "vtkGenericDataArray.h"
40 
41 #include "vtkCommonCoreModule.h" // For export macro
42 #include "vtkTypeTraits.h" // For type metadata
43 
44 template <class Scalar>
46 
47 template <class Scalar>
48 class vtkTypedDataArray : public vtkGenericDataArray<vtkTypedDataArray<Scalar>, Scalar>
49 {
51 
52 public:
54  typedef typename Superclass::ValueType ValueType;
55 
60 
64  Iterator Begin();
65 
69  Iterator End();
70 
74  enum
75  {
77  };
78 
88 
92  int GetDataType() const override;
93 
97  int GetDataTypeSize() const override;
98 
102  virtual void SetTypedTuple(vtkIdType i, const ValueType* t) = 0;
103 
108  virtual void InsertTypedTuple(vtkIdType i, const ValueType* t) = 0;
109 
113  virtual vtkIdType InsertNextTypedTuple(const ValueType* t) = 0;
114 
118  virtual ValueType GetValue(vtkIdType idx) const = 0;
119 
124 
129  virtual void SetValue(vtkIdType idx, ValueType value) = 0;
130 
134  virtual void GetTypedTuple(vtkIdType idx, ValueType* t) const = 0;
135 
140 
144  virtual void InsertValue(vtkIdType idx, ValueType v) = 0;
145 
146  virtual ValueType GetTypedComponent(vtkIdType tupleIdx, int comp) const;
147  virtual void SetTypedComponent(vtkIdType tupleIdx, int comp, ValueType v);
148 
152  int GetArrayType() const override { return vtkAbstractArray::TypedDataArray; }
153 
154  // Reintroduced as pure virtual since the base vtkGenericDataArray method
155  // requires new allocation/resize APIs, though existing MappedDataArrays
156  // would just use the vtkDataArray-level virtuals.
157  vtkTypeBool Allocate(vtkIdType size, vtkIdType ext = 1000) override = 0;
158  vtkTypeBool Resize(vtkIdType numTuples) override = 0;
159 
160 protected:
162  ~vtkTypedDataArray() override;
163 
168  virtual bool AllocateTuples(vtkIdType numTuples);
169 
174  virtual bool ReallocateTuples(vtkIdType numTuples);
175 
176 private:
177  vtkTypedDataArray(const vtkTypedDataArray&) = delete;
178  void operator=(const vtkTypedDataArray&) = delete;
179 
180  friend class vtkGenericDataArray<vtkTypedDataArray<Scalar>, Scalar>;
181 };
182 
183 // Declare vtkArrayDownCast implementations for typed containers:
185 
186 // Included here to resolve chicken/egg issue with container/iterator:
187 #include "vtkTypedDataArrayIterator.h" // For iterator
188 
189 template <class Scalar>
191 {
192  return Iterator(this, 0);
193 }
194 
195 template <class Scalar>
197 {
198  return Iterator(this, this->MaxId + 1);
199 }
200 
201 #include "vtkTypedDataArray.txx"
202 
203 #endif // vtkTypedDataArray_h
204 
205 // VTK-HeaderTest-Exclude: vtkTypedDataArray.h
Abstract superclass for all arrays.
Base interface for all typed vtkDataArray subclasses.
STL-style random access iterator for vtkTypedDataArrays.
Extend vtkDataArray with abstract type-specific API.
vtkTypeBool Allocate(vtkIdType size, vtkIdType ext=1000) override=0
Allocate memory for this array.
Iterator Begin()
Return an iterator initialized to the first element of the data.
virtual void SetTypedComponent(vtkIdType tupleIdx, int comp, ValueType v)
virtual bool ReallocateTuples(vtkIdType numTuples)
Needed for vtkGenericDataArray API, but just aborts.
int GetDataTypeSize() const override
Return the size of the element type in bytes.
static vtkTypedDataArray< Scalar > * FastDownCast(vtkAbstractArray *source)
Perform a fast, safe cast from a vtkAbstractArray to a vtkTypedDataArray.
virtual bool AllocateTuples(vtkIdType numTuples)
Needed for vtkGenericDataArray API, but just aborts.
virtual ValueType GetTypedComponent(vtkIdType tupleIdx, int comp) const
Superclass::ValueType ValueType
int GetArrayType() const override
Method for type-checking in FastDownCast implementations.
virtual vtkIdType InsertNextTypedTuple(const ValueType *t)=0
Insert (memory allocation performed) the tuple onto the end of the array.
Iterator End()
Return an iterator initialized to first element past the end of the data.
vtkTypedDataArrayIterator< ValueType > Iterator
Typedef to a suitable iterator class.
virtual vtkIdType InsertNextValue(ValueType v)=0
Insert data at the end of the array.
virtual ValueType & GetValueReference(vtkIdType idx)=0
Get a reference to the scalar value at a particular index.
virtual void InsertTypedTuple(vtkIdType i, const ValueType *t)=0
Insert (memory allocation performed) the tuple into the ith location in the array.
vtkTemplateTypeMacro(vtkTypedDataArray< Scalar >, GenericDataArrayType)
virtual ValueType GetValue(vtkIdType idx) const =0
Get the data at a particular index.
~vtkTypedDataArray() override
virtual void SetValue(vtkIdType idx, ValueType value)=0
Set the data at a particular index.
vtkTypeBool Resize(vtkIdType numTuples) override=0
Resize the array to the requested number of tuples and preserve data.
virtual void SetTypedTuple(vtkIdType i, const ValueType *t)=0
Set the tuple value at the ith location in the array.
virtual void GetTypedTuple(vtkIdType idx, ValueType *t) const =0
Copy the tuple value into a user-provided array.
virtual void InsertValue(vtkIdType idx, ValueType v)=0
Insert data at a specified position in the array.
int GetDataType() const override
Return the VTK data type held by this array.
@ value
Definition: vtkX3D.h:226
@ size
Definition: vtkX3D.h:259
Template defining traits of native types used by VTK.
Definition: vtkTypeTraits.h:30
int vtkTypeBool
Definition: vtkABI.h:69
boost::graph_traits< vtkGraph * >::vertex_descriptor source(boost::graph_traits< vtkGraph * >::edge_descriptor e, vtkGraph *)
int vtkIdType
Definition: vtkType.h:332
vtkArrayDownCast_TemplateFastCastMacro(vtkTypedDataArray)