VTK  9.3.20241003
vtkTypedDataArray.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2// SPDX-License-Identifier: BSD-3-Clause
27#ifndef vtkTypedDataArray_h
28#define vtkTypedDataArray_h
29
30#include "vtkGenericDataArray.h"
31
32#include "vtkCommonCoreModule.h" // For export macro
33#include "vtkTypeTraits.h" // For type metadata
34
35VTK_ABI_NAMESPACE_BEGIN
36template <class Scalar>
38
39template <class Scalar>
40class vtkTypedDataArray : public vtkGenericDataArray<vtkTypedDataArray<Scalar>, Scalar>
41{
43
44public:
46 typedef typename Superclass::ValueType ValueType;
47
52
57
61 Iterator End();
62
66 enum
67 {
69 };
70
80
84 int GetDataType() const override;
85
89 int GetDataTypeSize() const override;
90
94 virtual void SetTypedTuple(vtkIdType i, const ValueType* t) = 0;
95
100 virtual void InsertTypedTuple(vtkIdType i, const ValueType* t) = 0;
101
106
110 virtual ValueType GetValue(vtkIdType idx) const = 0;
111
116
121 virtual void SetValue(vtkIdType idx, ValueType value) = 0;
122
126 virtual void GetTypedTuple(vtkIdType idx, ValueType* t) const = 0;
127
132
136 virtual void InsertValue(vtkIdType idx, ValueType v) = 0;
137
138 virtual ValueType GetTypedComponent(vtkIdType tupleIdx, int comp) const;
139 virtual void SetTypedComponent(vtkIdType tupleIdx, int comp, ValueType v);
140
144 int GetArrayType() const override { return vtkAbstractArray::TypedDataArray; }
145
146 // Reintroduced as pure virtual since the base vtkGenericDataArray method
147 // requires new allocation/resize APIs, though existing MappedDataArrays
148 // would just use the vtkDataArray-level virtuals.
149 vtkTypeBool Allocate(vtkIdType size, vtkIdType ext = 1000) override = 0;
150 vtkTypeBool Resize(vtkIdType numTuples) override = 0;
151
152protected:
155
160 virtual bool AllocateTuples(vtkIdType numTuples);
161
166 virtual bool ReallocateTuples(vtkIdType numTuples);
167
168private:
169 vtkTypedDataArray(const vtkTypedDataArray&) = delete;
170 void operator=(const vtkTypedDataArray&) = delete;
171
172 friend class vtkGenericDataArray<vtkTypedDataArray<Scalar>, Scalar>;
173};
174
175// Declare vtkArrayDownCast implementations for typed containers:
177
178// Included here to resolve chicken/egg issue with container/iterator:
179VTK_ABI_NAMESPACE_END
180#include "vtkTypedDataArrayIterator.h" // For iterator
181
182VTK_ABI_NAMESPACE_BEGIN
183template <class Scalar>
185{
186 return Iterator(this, 0);
187}
188
189template <class Scalar>
191{
192 return Iterator(this, this->MaxId + 1);
193}
194
195VTK_ABI_NAMESPACE_END
196#include "vtkTypedDataArray.txx"
197
198#endif // vtkTypedDataArray_h
199
200#ifdef VTK_TYPED_VALUERANGE_INSTANTIATING
201
202// Needed to export for this module and not CommonCore
203#define VTK_INSTANTIATE_VALUERANGE_ARRAYTYPE(ArrayType, ValueType) \
204 template VTKCOMMONCORE_EXPORT bool DoComputeScalarRange( \
205 ArrayType*, ValueType*, vtkDataArrayPrivate::AllValues, const unsigned char*, unsigned char); \
206 template VTKCOMMONCORE_EXPORT bool DoComputeScalarRange(ArrayType*, ValueType*, \
207 vtkDataArrayPrivate::FiniteValues, const unsigned char*, unsigned char); \
208 template VTKCOMMONCORE_EXPORT bool DoComputeVectorRange(ArrayType*, ValueType[2], \
209 vtkDataArrayPrivate::AllValues, const unsigned char*, unsigned char); \
210 template VTKCOMMONCORE_EXPORT bool DoComputeVectorRange(ArrayType*, ValueType[2], \
211 vtkDataArrayPrivate::FiniteValues, const unsigned char*, unsigned char);
212
213#define VTK_INSTANTIATE_VALUERANGE_VALUETYPE(ValueType) \
214 VTK_INSTANTIATE_VALUERANGE_ARRAYTYPE(vtkTypedDataArray<ValueType>, double)
215
216#elif defined(VTK_USE_EXTERN_TEMPLATE) // VTK_IMPLICIT_VALUERANGE_INSTANTIATING
217
218#ifndef VTK_IMPLICIT_TEMPLATE_EXTERN
219#define VTK_IMPLICIT_TEMPLATE_EXTERN
220#ifdef _MSC_VER
221#pragma warning(push)
222// The following is needed when the following is declared
223// dllexport and is used from another class in vtkCommonCore
224#pragma warning(disable : 4910) // extern and dllexport incompatible
225#endif
226
227namespace vtkDataArrayPrivate
228{
229VTK_ABI_NAMESPACE_BEGIN
230template <typename A, typename R, typename T>
231VTKCOMMONCORE_EXPORT bool DoComputeScalarRange(
232 A*, R*, T, const unsigned char* ghosts, unsigned char ghostsToSkip);
233template <typename A, typename R>
234VTKCOMMONCORE_EXPORT bool DoComputeVectorRange(
235 A*, R[2], AllValues, const unsigned char* ghosts, unsigned char ghostsToSkip);
236template <typename A, typename R>
237VTKCOMMONCORE_EXPORT bool DoComputeVectorRange(
238 A*, R[2], FiniteValues, const unsigned char* ghosts, unsigned char ghostsToSkip);
239VTK_ABI_NAMESPACE_END
240} // namespace vtkDataArrayPrivate
241
242#define VTK_DECLARE_VALUERANGE_ARRAYTYPE(ArrayType, ValueType) \
243 extern template VTKCOMMONCORE_EXPORT bool DoComputeScalarRange( \
244 ArrayType*, ValueType*, vtkDataArrayPrivate::AllValues, const unsigned char*, unsigned char); \
245 extern template VTKCOMMONCORE_EXPORT bool DoComputeScalarRange(ArrayType*, ValueType*, \
246 vtkDataArrayPrivate::FiniteValues, const unsigned char*, unsigned char); \
247 extern template VTKCOMMONCORE_EXPORT bool DoComputeVectorRange(ArrayType*, ValueType[2], \
248 vtkDataArrayPrivate::AllValues, const unsigned char*, unsigned char); \
249 extern template VTKCOMMONCORE_EXPORT bool DoComputeVectorRange(ArrayType*, ValueType[2], \
250 vtkDataArrayPrivate::FiniteValues, const unsigned char*, unsigned char);
251
252#define VTK_DECLARE_VALUERANGE_VALUETYPE(ValueType) \
253 VTK_DECLARE_VALUERANGE_ARRAYTYPE(vtkTypedDataArray<ValueType>, double)
254
255namespace vtkDataArrayPrivate
256{
257VTK_ABI_NAMESPACE_BEGIN
268VTK_DECLARE_VALUERANGE_VALUETYPE(unsigned long long)
271VTK_ABI_NAMESPACE_END
272}
273
274#undef VTK_DECLARE_VALUERANGE_VALUETYPE
275#undef VTK_DECLARE_VALUERANGE_ARRAYTYPE
276
277#ifdef _MSC_VER
278#pragma warning(pop)
279#endif
280#endif // VTK_IMPLICIT_TEMPLATE_EXTERN
281
282#endif // VTK_TYPED_VALUERANGE_INSTANTIATING
283
284// 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.
static vtkTypedDataArray< Scalar > * FastDownCast(vtkAbstractArray *source)
Perform a fast, safe cast from a vtkAbstractArray to a vtkTypedDataArray.
int GetDataTypeSize() const override
Return the size of the element type in bytes.
virtual bool AllocateTuples(vtkIdType numTuples)
Needed for vtkGenericDataArray API, but just aborts.
virtual ValueType & GetValueReference(vtkIdType idx)=0
Get a reference to the scalar value at a particular index.
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 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.
VTKCOMMONCORE_EXPORT bool DoComputeScalarRange(A *, R *, T, const unsigned char *ghosts, unsigned char ghostsToSkip)
VTKCOMMONCORE_EXPORT bool DoComputeVectorRange(A *, R[2], AllValues, const unsigned char *ghosts, unsigned char ghostsToSkip)
Template defining traits of native types used by VTK.
int vtkTypeBool
Definition vtkABI.h:64
#define vtkArrayDownCast_TemplateFastCastMacro(ArrayT)
Same as vtkArrayDownCast_FastCastMacro, but treats ArrayT as a single-parameter template (the paramet...
boost::graph_traits< vtkGraph * >::vertex_descriptor source(boost::graph_traits< vtkGraph * >::edge_descriptor e, vtkGraph *)
#define VTK_DECLARE_VALUERANGE_VALUETYPE(ValueType)
int vtkIdType
Definition vtkType.h:315