forked from Kitware/VTK
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vtkTypedDataArray.h
209 lines (168 loc) · 6.35 KB
/
vtkTypedDataArray.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
/*=========================================================================
Program: Visualization Toolkit
Module: vtkTypedDataArray.h
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
/**
* @class vtkTypedDataArray
* @brief Extend vtkDataArray with abstract type-specific API
*
*
* This templated class decorates vtkDataArray with additional type-specific
* methods that can be used to interact with the data.
*
* NOTE: This class has been made obsolete by the newer vtkGenericDataArray.
*
* @warning
* This class uses vtkTypeTraits to implement GetDataType(). Since vtkIdType
* is a typedef for either a 32- or 64-bit integer, subclasses that are designed
* to hold vtkIdTypes will, by default, return an incorrect value from
* GetDataType(). To fix this, such subclasses should override GetDataType() to
* return VTK_ID_TYPE.
*
* @sa
* vtkGenericDataArray
*/
#ifndef vtkTypedDataArray_h
#define vtkTypedDataArray_h
#include "vtkGenericDataArray.h"
#include "vtkCommonCoreModule.h" // For export macro
#include "vtkTypeTraits.h" // For type metadata
template <class Scalar> class vtkTypedDataArrayIterator;
template <class Scalar>
class vtkTypedDataArray :
public vtkGenericDataArray<vtkTypedDataArray<Scalar>, Scalar>
{
typedef vtkGenericDataArray<vtkTypedDataArray<Scalar>, Scalar>
GenericDataArrayType;
public:
vtkTemplateTypeMacro(vtkTypedDataArray<Scalar>, GenericDataArrayType)
typedef typename Superclass::ValueType ValueType;
/**
* Typedef to a suitable iterator class.
*/
typedef vtkTypedDataArrayIterator<ValueType> Iterator;
/**
* Return an iterator initialized to the first element of the data.
*/
Iterator Begin();
/**
* Return an iterator initialized to first element past the end of the data.
*/
Iterator End();
/**
* Compile time access to the VTK type identifier.
*/
enum { VTK_DATA_TYPE = vtkTypeTraits<ValueType>::VTK_TYPE_ID };
/**
* Perform a fast, safe cast from a vtkAbstractArray to a vtkTypedDataArray.
* This method checks if:
* - source->GetArrayType() is appropriate, and
* - source->GetDataType() matches the Scalar template argument
* if these conditions are met, the method performs a static_cast to return
* source as a vtkTypedDataArray pointer. Otherwise, NULL is returned.
*/
static vtkTypedDataArray<Scalar>* FastDownCast(vtkAbstractArray *source);
/**
* Return the VTK data type held by this array.
*/
int GetDataType() VTK_OVERRIDE;
/**
* Return the size of the element type in bytes.
*/
int GetDataTypeSize() VTK_OVERRIDE;
/**
* Specify the number of values for this object to hold. Does an
* allocation as well as setting the MaxId ivar. Used in conjunction with
* SetValue() method for fast insertion.
*/
void SetNumberOfValues(vtkIdType num) VTK_OVERRIDE;
/**
* Set the tuple value at the ith location in the array.
*/
virtual void SetTypedTuple(vtkIdType i, const ValueType *t) = 0;
/**
* Insert (memory allocation performed) the tuple into the ith location
* in the array.
*/
virtual void InsertTypedTuple(vtkIdType i, const ValueType *t) = 0;
/**
* Insert (memory allocation performed) the tuple onto the end of the array.
*/
virtual vtkIdType InsertNextTypedTuple(const ValueType *t) = 0;
/**
* Get the data at a particular index.
*/
virtual ValueType GetValue(vtkIdType idx) const = 0;
/**
* Get a reference to the scalar value at a particular index.
*/
virtual ValueType& GetValueReference(vtkIdType idx) = 0;
/**
* Set the data at a particular index. Does not do range checking. Make sure
* you use the method SetNumberOfValues() before inserting data.
*/
virtual void SetValue(vtkIdType idx, ValueType value) = 0;
/**
* Copy the tuple value into a user-provided array.
*/
virtual void GetTypedTuple(vtkIdType idx, ValueType *t) const = 0;
/**
* Insert data at the end of the array. Return its location in the array.
*/
virtual vtkIdType InsertNextValue(ValueType v) = 0;
/**
* Insert data at a specified position in the array.
*/
virtual void InsertValue(vtkIdType idx, ValueType v) = 0;
virtual ValueType GetTypedComponent(vtkIdType tupleIdx, int comp) const;
virtual void SetTypedComponent(vtkIdType tupleIdx, int comp, ValueType v);
/**
* Method for type-checking in FastDownCast implementations.
*/
int GetArrayType() VTK_OVERRIDE { return vtkAbstractArray::TypedDataArray; }
// Reintroduced as pure virtual since the base vtkGenericDataArray method
// requires new allocation/resize APIs, though existing MappedDataArrays
// would just use the vtkDataArray-level virtuals.
int Allocate(vtkIdType size, vtkIdType ext = 1000) VTK_OVERRIDE = 0;
int Resize(vtkIdType numTuples) VTK_OVERRIDE = 0;
protected:
vtkTypedDataArray();
~vtkTypedDataArray() VTK_OVERRIDE;
/**
* Needed for vtkGenericDataArray API, but just aborts. Override Allocate
* instead.
*/
virtual bool AllocateTuples(vtkIdType numTuples);
/**
* Needed for vtkGenericDataArray API, but just aborts. Override Resize
* instead.
*/
virtual bool ReallocateTuples(vtkIdType numTuples);
private:
vtkTypedDataArray(const vtkTypedDataArray &) VTK_DELETE_FUNCTION;
void operator=(const vtkTypedDataArray &) VTK_DELETE_FUNCTION;
friend class vtkGenericDataArray<vtkTypedDataArray<Scalar>, Scalar>;
};
// Declare vtkArrayDownCast implementations for typed containers:
vtkArrayDownCast_TemplateFastCastMacro(vtkTypedDataArray)
// Included here to resolve chicken/egg issue with container/iterator:
#include "vtkTypedDataArrayIterator.h" // For iterator
template <class Scalar> inline
typename vtkTypedDataArray<Scalar>::Iterator vtkTypedDataArray<Scalar>::Begin()
{
return Iterator(this, 0);
}
template <class Scalar> inline
typename vtkTypedDataArray<Scalar>::Iterator vtkTypedDataArray<Scalar>::End()
{
return Iterator(this, this->MaxId + 1);
}
#include "vtkTypedDataArray.txx"
#endif //vtkTypedDataArray_h
// VTK-HeaderTest-Exclude: vtkTypedDataArray.h