VTK  9.2.6
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 =========================================================================*/
39 #ifndef vtkTypedDataArray_h
40 #define vtkTypedDataArray_h
41 
42 #include "vtkGenericDataArray.h"
43 
44 #include "vtkCommonCoreModule.h" // For export macro
45 #include "vtkTypeTraits.h" // For type metadata
46 
47 template <class Scalar>
49 
50 template <class Scalar>
51 class vtkTypedDataArray : public vtkGenericDataArray<vtkTypedDataArray<Scalar>, Scalar>
52 {
54 
55 public:
56  vtkTemplateTypeMacro(vtkTypedDataArray<Scalar>, GenericDataArrayType);
57  typedef typename Superclass::ValueType ValueType;
58 
63 
67  Iterator Begin();
68 
72  Iterator End();
73 
77  enum
78  {
80  };
81 
91 
95  int GetDataType() const override;
96 
100  int GetDataTypeSize() const override;
101 
105  virtual void SetTypedTuple(vtkIdType i, const ValueType* t) = 0;
106 
111  virtual void InsertTypedTuple(vtkIdType i, const ValueType* t) = 0;
112 
116  virtual vtkIdType InsertNextTypedTuple(const ValueType* t) = 0;
117 
121  virtual ValueType GetValue(vtkIdType idx) const = 0;
122 
126  virtual ValueType& GetValueReference(vtkIdType idx) = 0;
127 
132  virtual void SetValue(vtkIdType idx, ValueType value) = 0;
133 
137  virtual void GetTypedTuple(vtkIdType idx, ValueType* t) const = 0;
138 
142  virtual vtkIdType InsertNextValue(ValueType v) = 0;
143 
147  virtual void InsertValue(vtkIdType idx, ValueType v) = 0;
148 
149  virtual ValueType GetTypedComponent(vtkIdType tupleIdx, int comp) const;
150  virtual void SetTypedComponent(vtkIdType tupleIdx, int comp, ValueType v);
151 
155  int GetArrayType() const override { return vtkAbstractArray::TypedDataArray; }
156 
157  // Reintroduced as pure virtual since the base vtkGenericDataArray method
158  // requires new allocation/resize APIs, though existing MappedDataArrays
159  // would just use the vtkDataArray-level virtuals.
160  vtkTypeBool Allocate(vtkIdType size, vtkIdType ext = 1000) override = 0;
161  vtkTypeBool Resize(vtkIdType numTuples) override = 0;
162 
163 protected:
165  ~vtkTypedDataArray() override;
166 
171  virtual bool AllocateTuples(vtkIdType numTuples);
172 
177  virtual bool ReallocateTuples(vtkIdType numTuples);
178 
179 private:
180  vtkTypedDataArray(const vtkTypedDataArray&) = delete;
181  void operator=(const vtkTypedDataArray&) = delete;
182 
183  friend class vtkGenericDataArray<vtkTypedDataArray<Scalar>, Scalar>;
184 };
185 
186 // Declare vtkArrayDownCast implementations for typed containers:
188 
189 // Included here to resolve chicken/egg issue with container/iterator:
190 #include "vtkTypedDataArrayIterator.h" // For iterator
191 
192 template <class Scalar>
194 {
195  return Iterator(this, 0);
196 }
197 
198 template <class Scalar>
200 {
201  return Iterator(this, this->MaxId + 1);
202 }
203 
204 #include "vtkTypedDataArray.txx"
205 
206 #endif // vtkTypedDataArray_h
207 
208 // VTK-HeaderTest-Exclude: vtkTypedDataArray.h
virtual ValueType GetValue(vtkIdType idx) const =0
Get the data at a particular index.
virtual ValueType GetTypedComponent(vtkIdType tupleIdx, int comp) const
virtual vtkIdType InsertNextTypedTuple(const ValueType *t)=0
Insert (memory allocation performed) the tuple onto the end of the array.
int GetDataType() const override
Return the VTK data type held by this array.
Abstract superclass for all arrays.
virtual vtkIdType InsertNextValue(ValueType v)=0
Insert data at the end of the array.
virtual bool ReallocateTuples(vtkIdType numTuples)
Needed for vtkGenericDataArray API, but just aborts.
static vtkTypedDataArray< Scalar > * FastDownCast(vtkAbstractArray *source)
Perform a fast, safe cast from a vtkAbstractArray to a vtkTypedDataArray.
~vtkTypedDataArray() override
int vtkIdType
Definition: vtkType.h:332
Base interface for all typed vtkDataArray subclasses.
int vtkTypeBool
Definition: vtkABI.h:69
int GetDataTypeSize() const override
Return the size of the element type in bytes.
vtkTypeBool Resize(vtkIdType numTuples) override=0
Resize the array to the requested number of tuples and preserve data.
virtual void InsertValue(vtkIdType idx, ValueType v)=0
Insert data at a specified position in the array.
Iterator End()
Return an iterator initialized to first element past the end of the data.
virtual void SetTypedComponent(vtkIdType tupleIdx, int comp, ValueType v)
virtual void GetTypedTuple(vtkIdType idx, ValueType *t) const =0
Copy the tuple value into a user-provided array.
virtual void InsertTypedTuple(vtkIdType i, const ValueType *t)=0
Insert (memory allocation performed) the tuple into the ith location in the array.
Iterator Begin()
Return an iterator initialized to the first element of the data.
virtual bool AllocateTuples(vtkIdType numTuples)
Needed for vtkGenericDataArray API, but just aborts.
int GetArrayType() const override
Method for type-checking in FastDownCast implementations.
boost::graph_traits< vtkGraph * >::vertex_descriptor source(boost::graph_traits< vtkGraph * >::edge_descriptor e, vtkGraph *)
virtual ValueType & GetValueReference(vtkIdType idx)=0
Get a reference to the scalar value at a particular index.
Extend vtkDataArray with abstract type-specific API.
virtual void SetTypedTuple(vtkIdType i, const ValueType *t)=0
Set the tuple value at the ith location in the array.
vtkArrayDownCast_TemplateFastCastMacro(vtkTypedDataArray)
Superclass::ValueType ValueType
vtkTemplateTypeMacro(vtkTypedDataArray< Scalar >, GenericDataArrayType)
virtual void SetValue(vtkIdType idx, ValueType value)=0
Set the data at a particular index.
vtkTypeBool Allocate(vtkIdType size, vtkIdType ext=1000) override=0
Allocate memory for this array.
STL-style random access iterator for vtkTypedDataArrays.
Template defining traits of native types used by VTK.
Definition: vtkTypeTraits.h:33
vtkTypedDataArrayIterator< ValueType > Iterator
Typedef to a suitable iterator class.