VTK  9.5.20250806
vtkStructuredPointBackend.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
13#ifndef vtkStructuredPointBackend_h
14#define vtkStructuredPointBackend_h
15
16#include "vtkCommonCoreModule.h" // For export macro
17#include "vtkDataArrayRange.h" // For vtkDataArrayRange
18#include "vtkSmartPointer.h" // For vtkSmartPointer
19
20#include <array> // For std::array
21
22VTK_ABI_NAMESPACE_BEGIN
23//------------------------------------------------------------------------------
24template <typename ValueType>
25class VTKCOMMONCORE_EXPORT vtkStructuredPointBackend
26{
27public:
28 //------------------------------------------------------------------------------
30
31 //------------------------------------------------------------------------------
33
37 virtual ValueType mapStructuredXComponent(int i) const = 0;
38
42 virtual ValueType mapStructuredYComponent(int j) const = 0;
43
47 virtual ValueType mapStructuredZComponent(int k) const = 0;
48
49 //------------------------------------------------------------------------------
50 virtual void mapStructuredTuple(int ijk[3], ValueType tuple[3]) const = 0;
51
52 //------------------------------------------------------------------------------
53 virtual void mapTuple(vtkIdType tupleId, ValueType tuple[3]) const = 0;
54
55 //------------------------------------------------------------------------------
56 virtual ValueType mapComponent(vtkIdType tupleId, int comp) const = 0;
57
58 //------------------------------------------------------------------------------
59 virtual ValueType map(vtkIdType valueId) const = 0;
60};
61
62//------------------------------------------------------------------------------
63template <typename ValueType, typename ArrayTypeX, typename ArrayTypeY, typename ArrayTypeZ,
64 int DataDescription, bool UseDirMatrix>
66{
73 const std::array<int, 6> Extent;
74 const std::array<vtkIdType, 3> Dimensions;
75 const vtkIdType Dimension_0_BY_1;
76
77 // these are used only by vtkImageData and when direction matrix is not identity.
78 std::array<double, 16> IndexToPhysicalMatrix;
79 // this is a copy of vtkImageData::TransformCoordinates
80 void TransformIndexToPhysicalPoint(int i, int j, int k, ValueType* out) const;
81
82public:
83 //------------------------------------------------------------------------------
85
86 //------------------------------------------------------------------------------
88 ArrayTypeX* arrayX, ArrayTypeY* arrayY, ArrayTypeZ* arrayZ, int extent[6], double dirMatrix[9])
89 : ArrayX(arrayX)
90 , X(vtk::DataArrayValueRange<1>(ArrayX))
91 , ArrayY(arrayY)
92 , Y(vtk::DataArrayValueRange<1>(ArrayY))
93 , ArrayZ(arrayZ)
94 , Z(vtk::DataArrayValueRange<1>(ArrayZ))
95 , Extent({ { extent[0], extent[1], extent[2], extent[3], extent[4], extent[5] } })
96 , Dimensions(
97 { { extent[1] - extent[0] + 1, extent[3] - extent[2] + 1, extent[5] - extent[4] + 1 } })
98 , Dimension_0_BY_1(this->Dimensions[0] * this->Dimensions[1])
99 , IndexToPhysicalMatrix({ {} })
100 {
101 if (UseDirMatrix)
102 {
103 assert(this->ArrayX->GetNumberOfTuples() == 2);
104 assert(this->ArrayY->GetNumberOfTuples() == 2);
105 assert(this->ArrayZ->GetNumberOfTuples() == 2);
106 // compute origin
107 std::array<double, 3> origin = { { this->X[0], this->Y[0], this->Z[0] } };
108 // compute spacing
109 std::array<double, 3> spacing = { { this->X[1] - this->X[0], this->Y[1] - this->Y[0],
110 this->Z[1] - this->Z[0] } };
111 // compute index to physical matrix
112 this->IndexToPhysicalMatrix[0] = dirMatrix[0] * spacing[0];
113 this->IndexToPhysicalMatrix[1] = dirMatrix[1] * spacing[1];
114 this->IndexToPhysicalMatrix[2] = dirMatrix[2] * spacing[2];
115 this->IndexToPhysicalMatrix[3] = origin[0];
116 this->IndexToPhysicalMatrix[4] = dirMatrix[3] * spacing[0];
117 this->IndexToPhysicalMatrix[5] = dirMatrix[4] * spacing[1];
118 this->IndexToPhysicalMatrix[6] = dirMatrix[5] * spacing[2];
119 this->IndexToPhysicalMatrix[7] = origin[1];
120 this->IndexToPhysicalMatrix[8] = dirMatrix[6] * spacing[0];
121 this->IndexToPhysicalMatrix[9] = dirMatrix[7] * spacing[1];
122 this->IndexToPhysicalMatrix[10] = dirMatrix[8] * spacing[2];
123 this->IndexToPhysicalMatrix[11] = origin[2];
124 this->IndexToPhysicalMatrix[12] = 0.0;
125 this->IndexToPhysicalMatrix[13] = 0.0;
126 this->IndexToPhysicalMatrix[14] = 0.0;
127 this->IndexToPhysicalMatrix[15] = 1.0;
128 }
129 }
130
131 //------------------------------------------------------------------------------
133
134 //------------------------------------------------------------------------------
135 template <int Description = DataDescription>
136 typename std::enable_if<(Description == 9 /*VTK_STRUCTURED_EMPTY*/), ValueType>::type
137 VTK_ALWAYS_INLINE
139
140 //------------------------------------------------------------------------------
141 template <int Description = DataDescription>
142 typename std::enable_if<(Description != 9 /*VTK_STRUCTURED_EMPTY*/), ValueType>::type
143 VTK_ALWAYS_INLINE
145
146 //------------------------------------------------------------------------------
147 ValueType mapStructuredXComponent(int i) const override;
148
149 //------------------------------------------------------------------------------
150 template <int Description = DataDescription>
151 typename std::enable_if<(Description == 9 /*VTK_STRUCTURED_EMPTY*/), ValueType>::type
152 VTK_ALWAYS_INLINE
154
155 //------------------------------------------------------------------------------
156 template <int Description = DataDescription>
157 typename std::enable_if<(Description != 9 /*VTK_STRUCTURED_EMPTY*/), ValueType>::type
158 VTK_ALWAYS_INLINE
160
161 //------------------------------------------------------------------------------
162 ValueType mapStructuredYComponent(int j) const override;
163
164 //------------------------------------------------------------------------------
165 template <int Description = DataDescription>
166 typename std::enable_if<(Description == 9 /*VTK_STRUCTURED_EMPTY*/), ValueType>::type
167 VTK_ALWAYS_INLINE
169
170 //------------------------------------------------------------------------------
171 template <int Description = DataDescription>
172 typename std::enable_if<(Description != 9 /*VTK_STRUCTURED_EMPTY*/), ValueType>::type
173 VTK_ALWAYS_INLINE
175
176 //------------------------------------------------------------------------------
177 ValueType mapStructuredZComponent(int k) const override;
178
179 //------------------------------------------------------------------------------
180 template <int Description = DataDescription>
181 typename std::enable_if<(Description == 9 /*VTK_STRUCTURED_EMPTY*/), void>::type VTK_ALWAYS_INLINE
182 mapStructuredTupleImpl(int ijk[3], ValueType tuple[3]) const;
183
184 //------------------------------------------------------------------------------
185 template <int Description = DataDescription>
186 typename std::enable_if<(Description != 9 /*VTK_STRUCTURED_EMPTY*/), void>::type VTK_ALWAYS_INLINE
187 mapStructuredTupleImpl(int ijk[3], ValueType tuple[3]) const;
188
189 //------------------------------------------------------------------------------
190 void mapStructuredTuple(int ijk[3], ValueType tuple[3]) const override;
191
192 //------------------------------------------------------------------------------
193 template <int Description = DataDescription>
194 typename std::enable_if<(Description == 9 /*VTK_STRUCTURED_EMPTY*/), void>::type VTK_ALWAYS_INLINE
195 ComputePointStructuredCoords(vtkIdType pointId, int ijk[3]) const;
196
197 //------------------------------------------------------------------------------
198 template <int Description = DataDescription>
199 typename std::enable_if<(Description == 1 /*VTK_STRUCTURED_SINGLE_POINT*/), void>::type
200 VTK_ALWAYS_INLINE
201 ComputePointStructuredCoords(vtkIdType pointId, int ijk[3]) const;
202
203 //------------------------------------------------------------------------------
204 template <int Description = DataDescription>
205 typename std::enable_if<(Description == 2 /*VTK_STRUCTURED_X_LINE*/), void>::type
206 VTK_ALWAYS_INLINE
207 ComputePointStructuredCoords(vtkIdType pointId, int ijk[3]) const;
208
209 //------------------------------------------------------------------------------
210 template <int Description = DataDescription>
211 typename std::enable_if<(Description == 3 /*VTK_STRUCTURED_Y_LINE*/), void>::type
212 VTK_ALWAYS_INLINE
213 ComputePointStructuredCoords(vtkIdType pointId, int ijk[3]) const;
214
215 //------------------------------------------------------------------------------
216 template <int Description = DataDescription>
217 typename std::enable_if<(Description == 4 /*VTK_STRUCTURED_Z_LINE*/), void>::type
218 VTK_ALWAYS_INLINE
219 ComputePointStructuredCoords(vtkIdType pointId, int ijk[3]) const;
220
221 //------------------------------------------------------------------------------
222 template <int Description = DataDescription>
223 typename std::enable_if<(Description == 5 /*VTK_STRUCTURED_XY_PLANE*/), void>::type
224 VTK_ALWAYS_INLINE
225 ComputePointStructuredCoords(vtkIdType pointId, int ijk[3]) const;
226
227 //------------------------------------------------------------------------------
228 template <int Description = DataDescription>
229 typename std::enable_if<(Description == 6 /*VTK_STRUCTURED_YZ_PLANE*/), void>::type
230 VTK_ALWAYS_INLINE
231 ComputePointStructuredCoords(vtkIdType pointId, int ijk[3]) const;
232
233 //------------------------------------------------------------------------------
234 template <int Description = DataDescription>
235 typename std::enable_if<(Description == 7 /*VTK_STRUCTURED_XZ_PLANE*/), void>::type
236 VTK_ALWAYS_INLINE
237 ComputePointStructuredCoords(vtkIdType pointId, int ijk[3]) const;
238
239 //------------------------------------------------------------------------------
240 template <int Description = DataDescription>
241 typename std::enable_if<(Description == 8 /*VTK_STRUCTURED_XYZ_GRID*/), void>::type
242 VTK_ALWAYS_INLINE
243 ComputePointStructuredCoords(vtkIdType pointId, int ijk[3]) const;
244
245 //------------------------------------------------------------------------------
246 void mapTuple(vtkIdType tupleId, ValueType tuple[3]) const override;
247
248 //------------------------------------------------------------------------------
249 template <int Description = DataDescription>
250 typename std::enable_if<(Description == 9 /*VTK_STRUCTURED_EMPTY*/), ValueType>::type
251 VTK_ALWAYS_INLINE
252 mapComponentImpl(vtkIdType tupleId, int comp) const;
253
254 //------------------------------------------------------------------------------
255 template <int Description = DataDescription>
256 typename std::enable_if<(Description == 1 /*VTK_STRUCTURED_SINGLE_POINT*/), ValueType>::type
257 VTK_ALWAYS_INLINE
258 mapComponentImpl(vtkIdType tupleId, int comp) const;
259
260 //------------------------------------------------------------------------------
261 template <int Description = DataDescription>
262 typename std::enable_if<(Description == 2 /*VTK_STRUCTURED_X_LINE*/), ValueType>::type
263 VTK_ALWAYS_INLINE
264 mapComponentImpl(vtkIdType tupleId, int comp) const;
265
266 //------------------------------------------------------------------------------
267 template <int Description = DataDescription>
268 typename std::enable_if<(Description == 3 /*VTK_STRUCTURED_Y_LINE*/), ValueType>::type
269 VTK_ALWAYS_INLINE
270 mapComponentImpl(vtkIdType tupleId, int comp) const;
271
272 //------------------------------------------------------------------------------
273 template <int Description = DataDescription>
274 typename std::enable_if<(Description == 4 /*VTK_STRUCTURED_Z_LINE*/), ValueType>::type
275 VTK_ALWAYS_INLINE
276 mapComponentImpl(vtkIdType tupleId, int comp) const;
277
278 //------------------------------------------------------------------------------
279 template <int Description = DataDescription>
280 typename std::enable_if<(Description == 5 /*VTK_STRUCTURED_XY_PLANE*/), ValueType>::type
281 VTK_ALWAYS_INLINE
282 mapComponentImpl(vtkIdType tupleId, int comp) const;
283
284 //------------------------------------------------------------------------------
285 template <int Description = DataDescription>
286 typename std::enable_if<(Description == 6 /*VTK_STRUCTURED_YZ_PLANE*/), ValueType>::type
287 VTK_ALWAYS_INLINE
288 mapComponentImpl(vtkIdType tupleId, int comp) const;
289
290 //------------------------------------------------------------------------------
291 template <int Description = DataDescription>
292 typename std::enable_if<(Description == 7 /*VTK_STRUCTURED_XZ_PLANE*/), ValueType>::type
293 VTK_ALWAYS_INLINE
294 mapComponentImpl(vtkIdType tupleId, int comp) const;
295
296 //------------------------------------------------------------------------------
297 template <int Description = DataDescription>
298 typename std::enable_if<(Description == 8 /*VTK_STRUCTURED_XYZ_GRID*/), ValueType>::type
299 VTK_ALWAYS_INLINE
300 mapComponentImpl(vtkIdType tupleId, int comp) const;
301
302 //------------------------------------------------------------------------------
303 ValueType mapComponent(vtkIdType tupleId, int comp) const override;
304
305 //------------------------------------------------------------------------------
306 ValueType map(vtkIdType valueId) const override;
307};
308VTK_ABI_NAMESPACE_END
309
310#endif // vtkStructuredPointBackend_h
311/* VTK-HeaderTest-Exclude: vtkStructuredPointBackend.h */
312
313#if defined(VTK_STRUCTURED_POINT_BACKEND_INSTANTIATING)
314
315#define VTK_INSTANTIATE_STRUCTURED_POINT_BACKEND(ValueType) \
316 VTK_ABI_NAMESPACE_BEGIN \
317 template class VTKCOMMONCORE_EXPORT vtkStructuredPointBackend<ValueType>; \
318 VTK_ABI_NAMESPACE_END
319#elif defined(VTK_USE_EXTERN_TEMPLATE)
320
321#ifndef VTK_STRUCTURED_POINT_BACKEND_TEMPLATE_EXTERN
322#define VTK_STRUCTURED_POINT_BACKEND_TEMPLATE_EXTERN
323#ifdef _MSC_VER
324#pragma warning(push)
325#pragma warning(disable : 4910) // extern and dllexport incompatible
326#endif
327VTK_ABI_NAMESPACE_BEGIN
328vtkExternTemplateMacro(extern template class VTKCOMMONCORE_EXPORT vtkStructuredPointBackend);
329VTK_ABI_NAMESPACE_END
330#ifdef _MSC_VER
331#pragma warning(pop)
332#endif
333#endif // VTK_STRUCTURED_POINT_BACKEND_TEMPLATE_EXTERN
334
335#endif
Hold a reference to a vtkObjectBase instance.
A backend for the vtkImplicitArray to query structured points efficiently.
virtual ~vtkStructuredPointBackend()
virtual ValueType mapStructuredXComponent(int i) const =0
These function should only be used when direction matrix is NOT identity.
virtual ValueType mapComponent(vtkIdType tupleId, int comp) const =0
virtual void mapStructuredTuple(int ijk[3], ValueType tuple[3]) const =0
virtual ValueType mapStructuredYComponent(int j) const =0
These function should only be used when direction matrix is NOT identity.
virtual ValueType mapStructuredZComponent(int k) const =0
These function should only be used when direction matrix is NOT identity.
virtual void mapTuple(vtkIdType tupleId, ValueType tuple[3]) const =0
virtual ValueType map(vtkIdType valueId) const =0
std::enable_if<(Description==2), ValueType >::type VTK_ALWAYS_INLINE mapComponentImpl(vtkIdType tupleId, int comp) const
std::enable_if<(Description==4), ValueType >::type VTK_ALWAYS_INLINE mapComponentImpl(vtkIdType tupleId, int comp) const
std::enable_if<(Description==1), void >::type VTK_ALWAYS_INLINE ComputePointStructuredCoords(vtkIdType pointId, int ijk[3]) const
std::enable_if<(Description!=9), ValueType >::type VTK_ALWAYS_INLINE mapStructuredZComponentImpl(int k) const
std::enable_if<(Description==1), ValueType >::type VTK_ALWAYS_INLINE mapComponentImpl(vtkIdType tupleId, int comp) const
std::enable_if<(Description==7), void >::type VTK_ALWAYS_INLINE ComputePointStructuredCoords(vtkIdType pointId, int ijk[3]) const
std::enable_if<(Description==5), void >::type VTK_ALWAYS_INLINE ComputePointStructuredCoords(vtkIdType pointId, int ijk[3]) const
std::enable_if<(Description!=9), ValueType >::type VTK_ALWAYS_INLINE mapStructuredXComponentImpl(int i) const
ValueType mapComponent(vtkIdType tupleId, int comp) const override
std::enable_if<(Description==9), ValueType >::type VTK_ALWAYS_INLINE mapStructuredZComponentImpl(int k) const
vtkStructuredTPointBackend(ArrayTypeX *arrayX, ArrayTypeY *arrayY, ArrayTypeZ *arrayZ, int extent[6], double dirMatrix[9])
void mapStructuredTuple(int ijk[3], ValueType tuple[3]) const override
std::enable_if<(Description==3), void >::type VTK_ALWAYS_INLINE ComputePointStructuredCoords(vtkIdType pointId, int ijk[3]) const
~vtkStructuredTPointBackend() override
std::enable_if<(Description==8), void >::type VTK_ALWAYS_INLINE ComputePointStructuredCoords(vtkIdType pointId, int ijk[3]) const
ValueType mapStructuredZComponent(int k) const override
These function should only be used when direction matrix is NOT identity.
std::enable_if<(Description!=9), void >::type VTK_ALWAYS_INLINE mapStructuredTupleImpl(int ijk[3], ValueType tuple[3]) const
std::enable_if<(Description==5), ValueType >::type VTK_ALWAYS_INLINE mapComponentImpl(vtkIdType tupleId, int comp) const
std::enable_if<(Description!=9), ValueType >::type VTK_ALWAYS_INLINE mapStructuredYComponentImpl(int j) const
std::enable_if<(Description==2), void >::type VTK_ALWAYS_INLINE ComputePointStructuredCoords(vtkIdType pointId, int ijk[3]) const
ValueType mapStructuredYComponent(int j) const override
These function should only be used when direction matrix is NOT identity.
std::enable_if<(Description==9), void >::type VTK_ALWAYS_INLINE mapStructuredTupleImpl(int ijk[3], ValueType tuple[3]) const
std::enable_if<(Description==9), ValueType >::type VTK_ALWAYS_INLINE mapComponentImpl(vtkIdType tupleId, int comp) const
ValueType mapStructuredXComponent(int i) const override
These function should only be used when direction matrix is NOT identity.
void mapTuple(vtkIdType tupleId, ValueType tuple[3]) const override
std::enable_if<(Description==7), ValueType >::type VTK_ALWAYS_INLINE mapComponentImpl(vtkIdType tupleId, int comp) const
std::enable_if<(Description==9), ValueType >::type VTK_ALWAYS_INLINE mapStructuredYComponentImpl(int j) const
ValueType map(vtkIdType valueId) const override
std::enable_if<(Description==9), ValueType >::type VTK_ALWAYS_INLINE mapStructuredXComponentImpl(int i) const
std::enable_if<(Description==3), ValueType >::type VTK_ALWAYS_INLINE mapComponentImpl(vtkIdType tupleId, int comp) const
std::enable_if<(Description==6), ValueType >::type VTK_ALWAYS_INLINE mapComponentImpl(vtkIdType tupleId, int comp) const
std::enable_if<(Description==6), void >::type VTK_ALWAYS_INLINE ComputePointStructuredCoords(vtkIdType pointId, int ijk[3]) const
std::enable_if<(Description==8), ValueType >::type VTK_ALWAYS_INLINE mapComponentImpl(vtkIdType tupleId, int comp) const
std::enable_if<(Description==4), void >::type VTK_ALWAYS_INLINE ComputePointStructuredCoords(vtkIdType pointId, int ijk[3]) const
std::enable_if<(Description==9), void >::type VTK_ALWAYS_INLINE ComputePointStructuredCoords(vtkIdType pointId, int ijk[3]) const
@ spacing
Definition vtkX3D.h:481
Specialization of tuple ranges and iterators for vtkAOSDataArrayTemplate.
STL-compatible iterable ranges that provide access to vtkDataArray elements.
#define vtkExternTemplateMacro(decl)
A macro to declare extern templates for all numerical types.
Definition vtkType.h:427
int vtkIdType
Definition vtkType.h:332