VTK  9.6.20260325
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
12
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
62
65 virtual vtkDataArray* GetXCoordinates() const = 0;
66 virtual vtkDataArray* GetYCoordinates() const = 0;
67 virtual vtkDataArray* GetZCoordinates() const = 0;
69
73 virtual bool GetUsesDirectionMatrix() const = 0;
74};
75
76//------------------------------------------------------------------------------
77template <typename ValueType, typename ArrayTypeX, typename ArrayTypeY, typename ArrayTypeZ,
78 int DataDescription, bool UseDirMatrix>
80{
87 const std::array<int, 6> Extent;
88 const std::array<vtkIdType, 3> Dimensions;
89 const vtkIdType Dimension_0_BY_1;
90
91 // these are used only by vtkImageData and when direction matrix is not identity.
92 std::array<double, 16> IndexToPhysicalMatrix;
93 // this is a copy of vtkImageData::TransformCoordinates
94 void TransformIndexToPhysicalPoint(int i, int j, int k, ValueType* out) const;
95
96public:
97 //------------------------------------------------------------------------------
99
100 //------------------------------------------------------------------------------
102 ArrayTypeX* arrayX, ArrayTypeY* arrayY, ArrayTypeZ* arrayZ, int extent[6], double dirMatrix[9])
103 : ArrayX(arrayX)
104 , X(vtk::DataArrayValueRange<1>(ArrayX))
105 , ArrayY(arrayY)
106 , Y(vtk::DataArrayValueRange<1>(ArrayY))
107 , ArrayZ(arrayZ)
108 , Z(vtk::DataArrayValueRange<1>(ArrayZ))
109 , Extent({ { extent[0], extent[1], extent[2], extent[3], extent[4], extent[5] } })
110 , Dimensions(
111 { { extent[1] - extent[0] + 1, extent[3] - extent[2] + 1, extent[5] - extent[4] + 1 } })
112 , Dimension_0_BY_1(this->Dimensions[0] * this->Dimensions[1])
113 , IndexToPhysicalMatrix({ {} })
114 {
115 if (UseDirMatrix)
116 {
117 assert(this->ArrayX->GetNumberOfTuples() == 2);
118 assert(this->ArrayY->GetNumberOfTuples() == 2);
119 assert(this->ArrayZ->GetNumberOfTuples() == 2);
120 // compute origin
121 std::array<double, 3> origin = { { this->X[0], this->Y[0], this->Z[0] } };
122 // compute spacing
123 std::array<double, 3> spacing = { { this->X[1] - this->X[0], this->Y[1] - this->Y[0],
124 this->Z[1] - this->Z[0] } };
125 // compute index to physical matrix
126 this->IndexToPhysicalMatrix[0] = dirMatrix[0] * spacing[0];
127 this->IndexToPhysicalMatrix[1] = dirMatrix[1] * spacing[1];
128 this->IndexToPhysicalMatrix[2] = dirMatrix[2] * spacing[2];
129 this->IndexToPhysicalMatrix[3] = origin[0];
130 this->IndexToPhysicalMatrix[4] = dirMatrix[3] * spacing[0];
131 this->IndexToPhysicalMatrix[5] = dirMatrix[4] * spacing[1];
132 this->IndexToPhysicalMatrix[6] = dirMatrix[5] * spacing[2];
133 this->IndexToPhysicalMatrix[7] = origin[1];
134 this->IndexToPhysicalMatrix[8] = dirMatrix[6] * spacing[0];
135 this->IndexToPhysicalMatrix[9] = dirMatrix[7] * spacing[1];
136 this->IndexToPhysicalMatrix[10] = dirMatrix[8] * spacing[2];
137 this->IndexToPhysicalMatrix[11] = origin[2];
138 this->IndexToPhysicalMatrix[12] = 0.0;
139 this->IndexToPhysicalMatrix[13] = 0.0;
140 this->IndexToPhysicalMatrix[14] = 0.0;
141 this->IndexToPhysicalMatrix[15] = 1.0;
142 }
143 }
144
145 //------------------------------------------------------------------------------
147
148 //------------------------------------------------------------------------------
149 template <int Description = DataDescription>
150 typename std::enable_if<(Description == 9 /*VTK_STRUCTURED_EMPTY*/), ValueType>::type
151 VTK_ALWAYS_INLINE
153
154 //------------------------------------------------------------------------------
155 template <int Description = DataDescription>
156 typename std::enable_if<(Description != 9 /*VTK_STRUCTURED_EMPTY*/), ValueType>::type
157 VTK_ALWAYS_INLINE
159
160 //------------------------------------------------------------------------------
161 ValueType mapStructuredXComponent(int i) const override;
162
163 //------------------------------------------------------------------------------
164 template <int Description = DataDescription>
165 typename std::enable_if<(Description == 9 /*VTK_STRUCTURED_EMPTY*/), ValueType>::type
166 VTK_ALWAYS_INLINE
168
169 //------------------------------------------------------------------------------
170 template <int Description = DataDescription>
171 typename std::enable_if<(Description != 9 /*VTK_STRUCTURED_EMPTY*/), ValueType>::type
172 VTK_ALWAYS_INLINE
174
175 //------------------------------------------------------------------------------
176 ValueType mapStructuredYComponent(int j) const override;
177
178 //------------------------------------------------------------------------------
179 template <int Description = DataDescription>
180 typename std::enable_if<(Description == 9 /*VTK_STRUCTURED_EMPTY*/), ValueType>::type
181 VTK_ALWAYS_INLINE
183
184 //------------------------------------------------------------------------------
185 template <int Description = DataDescription>
186 typename std::enable_if<(Description != 9 /*VTK_STRUCTURED_EMPTY*/), ValueType>::type
187 VTK_ALWAYS_INLINE
189
190 //------------------------------------------------------------------------------
191 ValueType mapStructuredZComponent(int k) const override;
192
193 //------------------------------------------------------------------------------
194 template <int Description = DataDescription>
195 typename std::enable_if<(Description == 9 /*VTK_STRUCTURED_EMPTY*/), void>::type VTK_ALWAYS_INLINE
196 mapStructuredTupleImpl(int ijk[3], ValueType tuple[3]) const;
197
198 //------------------------------------------------------------------------------
199 template <int Description = DataDescription>
200 typename std::enable_if<(Description != 9 /*VTK_STRUCTURED_EMPTY*/), void>::type VTK_ALWAYS_INLINE
201 mapStructuredTupleImpl(int ijk[3], ValueType tuple[3]) const;
202
203 //------------------------------------------------------------------------------
204 void mapStructuredTuple(int ijk[3], ValueType tuple[3]) const override;
205
206 //------------------------------------------------------------------------------
207 template <int Description = DataDescription>
208 typename std::enable_if<(Description == 9 /*VTK_STRUCTURED_EMPTY*/), void>::type VTK_ALWAYS_INLINE
209 ComputePointStructuredCoords(vtkIdType pointId, int ijk[3]) const;
210
211 //------------------------------------------------------------------------------
212 template <int Description = DataDescription>
213 typename std::enable_if<(Description == 1 /*VTK_STRUCTURED_SINGLE_POINT*/), void>::type
214 VTK_ALWAYS_INLINE
215 ComputePointStructuredCoords(vtkIdType pointId, int ijk[3]) const;
216
217 //------------------------------------------------------------------------------
218 template <int Description = DataDescription>
219 typename std::enable_if<(Description == 2 /*VTK_STRUCTURED_X_LINE*/), void>::type
220 VTK_ALWAYS_INLINE
221 ComputePointStructuredCoords(vtkIdType pointId, int ijk[3]) const;
222
223 //------------------------------------------------------------------------------
224 template <int Description = DataDescription>
225 typename std::enable_if<(Description == 3 /*VTK_STRUCTURED_Y_LINE*/), void>::type
226 VTK_ALWAYS_INLINE
227 ComputePointStructuredCoords(vtkIdType pointId, int ijk[3]) const;
228
229 //------------------------------------------------------------------------------
230 template <int Description = DataDescription>
231 typename std::enable_if<(Description == 4 /*VTK_STRUCTURED_Z_LINE*/), void>::type
232 VTK_ALWAYS_INLINE
233 ComputePointStructuredCoords(vtkIdType pointId, int ijk[3]) const;
234
235 //------------------------------------------------------------------------------
236 template <int Description = DataDescription>
237 typename std::enable_if<(Description == 5 /*VTK_STRUCTURED_XY_PLANE*/), void>::type
238 VTK_ALWAYS_INLINE
239 ComputePointStructuredCoords(vtkIdType pointId, int ijk[3]) const;
240
241 //------------------------------------------------------------------------------
242 template <int Description = DataDescription>
243 typename std::enable_if<(Description == 6 /*VTK_STRUCTURED_YZ_PLANE*/), void>::type
244 VTK_ALWAYS_INLINE
245 ComputePointStructuredCoords(vtkIdType pointId, int ijk[3]) const;
246
247 //------------------------------------------------------------------------------
248 template <int Description = DataDescription>
249 typename std::enable_if<(Description == 7 /*VTK_STRUCTURED_XZ_PLANE*/), void>::type
250 VTK_ALWAYS_INLINE
251 ComputePointStructuredCoords(vtkIdType pointId, int ijk[3]) const;
252
253 //------------------------------------------------------------------------------
254 template <int Description = DataDescription>
255 typename std::enable_if<(Description == 8 /*VTK_STRUCTURED_XYZ_GRID*/), void>::type
256 VTK_ALWAYS_INLINE
257 ComputePointStructuredCoords(vtkIdType pointId, int ijk[3]) const;
258
259 //------------------------------------------------------------------------------
260 void mapTuple(vtkIdType tupleId, ValueType tuple[3]) const override;
261
262 //------------------------------------------------------------------------------
263 template <int Description = DataDescription>
264 typename std::enable_if<(Description == 9 /*VTK_STRUCTURED_EMPTY*/), ValueType>::type
265 VTK_ALWAYS_INLINE
266 mapComponentImpl(vtkIdType tupleId, int comp) const;
267
268 //------------------------------------------------------------------------------
269 template <int Description = DataDescription>
270 typename std::enable_if<(Description == 1 /*VTK_STRUCTURED_SINGLE_POINT*/), ValueType>::type
271 VTK_ALWAYS_INLINE
272 mapComponentImpl(vtkIdType tupleId, int comp) const;
273
274 //------------------------------------------------------------------------------
275 template <int Description = DataDescription>
276 typename std::enable_if<(Description == 2 /*VTK_STRUCTURED_X_LINE*/), ValueType>::type
277 VTK_ALWAYS_INLINE
278 mapComponentImpl(vtkIdType tupleId, int comp) const;
279
280 //------------------------------------------------------------------------------
281 template <int Description = DataDescription>
282 typename std::enable_if<(Description == 3 /*VTK_STRUCTURED_Y_LINE*/), ValueType>::type
283 VTK_ALWAYS_INLINE
284 mapComponentImpl(vtkIdType tupleId, int comp) const;
285
286 //------------------------------------------------------------------------------
287 template <int Description = DataDescription>
288 typename std::enable_if<(Description == 4 /*VTK_STRUCTURED_Z_LINE*/), ValueType>::type
289 VTK_ALWAYS_INLINE
290 mapComponentImpl(vtkIdType tupleId, int comp) const;
291
292 //------------------------------------------------------------------------------
293 template <int Description = DataDescription>
294 typename std::enable_if<(Description == 5 /*VTK_STRUCTURED_XY_PLANE*/), ValueType>::type
295 VTK_ALWAYS_INLINE
296 mapComponentImpl(vtkIdType tupleId, int comp) const;
297
298 //------------------------------------------------------------------------------
299 template <int Description = DataDescription>
300 typename std::enable_if<(Description == 6 /*VTK_STRUCTURED_YZ_PLANE*/), ValueType>::type
301 VTK_ALWAYS_INLINE
302 mapComponentImpl(vtkIdType tupleId, int comp) const;
303
304 //------------------------------------------------------------------------------
305 template <int Description = DataDescription>
306 typename std::enable_if<(Description == 7 /*VTK_STRUCTURED_XZ_PLANE*/), ValueType>::type
307 VTK_ALWAYS_INLINE
308 mapComponentImpl(vtkIdType tupleId, int comp) const;
309
310 //------------------------------------------------------------------------------
311 template <int Description = DataDescription>
312 typename std::enable_if<(Description == 8 /*VTK_STRUCTURED_XYZ_GRID*/), ValueType>::type
313 VTK_ALWAYS_INLINE
314 mapComponentImpl(vtkIdType tupleId, int comp) const;
315
316 //------------------------------------------------------------------------------
317 ValueType mapComponent(vtkIdType tupleId, int comp) const override;
318
319 //------------------------------------------------------------------------------
320 ValueType map(vtkIdType valueId) const override;
321
322 //------------------------------------------------------------------------------
323 vtkDataArray* GetXCoordinates() const override { return this->ArrayX; }
324
325 //------------------------------------------------------------------------------
326 vtkDataArray* GetYCoordinates() const override { return this->ArrayY; }
327
328 //------------------------------------------------------------------------------
329 vtkDataArray* GetZCoordinates() const override { return this->ArrayZ; }
330
331 //------------------------------------------------------------------------------
332 bool GetUsesDirectionMatrix() const override { return UseDirMatrix; }
333};
334VTK_ABI_NAMESPACE_END
335
336#endif // vtkStructuredPointBackend_h
337/* VTK-HeaderTest-Exclude: vtkStructuredPointBackend.h */
338
339#if defined(VTK_STRUCTURED_POINT_BACKEND_INSTANTIATING)
340
341#define VTK_INSTANTIATE_STRUCTURED_POINT_BACKEND(ValueType) \
342 VTK_ABI_NAMESPACE_BEGIN \
343 template class VTKCOMMONCORE_EXPORT vtkStructuredPointBackend<ValueType>; \
344 VTK_ABI_NAMESPACE_END
345#elif defined(VTK_USE_EXTERN_TEMPLATE)
346
347#ifndef VTK_STRUCTURED_POINT_BACKEND_TEMPLATE_EXTERN
348#define VTK_STRUCTURED_POINT_BACKEND_TEMPLATE_EXTERN
349#ifdef _MSC_VER
350#pragma warning(push)
351#pragma warning(disable : 4910) // extern and dllexport incompatible
352#endif
353VTK_ABI_NAMESPACE_BEGIN
354vtkExternTemplateMacro(extern template class VTKCOMMONCORE_EXPORT vtkStructuredPointBackend);
355VTK_ABI_NAMESPACE_END
356#ifdef _MSC_VER
357#pragma warning(pop)
358#endif
359#endif // VTK_STRUCTURED_POINT_BACKEND_TEMPLATE_EXTERN
360
361#endif
Hold a reference to a vtkObjectBase instance.
A backend for the vtkImplicitArray to query structured points efficiently.
virtual vtkDataArray * GetZCoordinates() const =0
Get the coordinate arrays used to construct this backend.
virtual ~vtkStructuredPointBackend()
virtual ValueType mapStructuredXComponent(int i) const =0
These function should only be used when direction matrix is NOT identity.
virtual vtkDataArray * GetYCoordinates() const =0
Get the coordinate arrays used to construct this backend.
virtual bool GetUsesDirectionMatrix() const =0
Return true if a non-identity direction matrix is being used.
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 vtkDataArray * GetXCoordinates() const =0
Get the coordinate arrays used to construct this backend.
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
vtkDataArray * GetZCoordinates() const override
Get the coordinate arrays used to construct this backend.
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
vtkDataArray * GetYCoordinates() const override
Get the coordinate arrays used to construct this backend.
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
bool GetUsesDirectionMatrix() const override
Return true if a non-identity direction matrix is being used.
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
vtkDataArray * GetXCoordinates() const override
Get the coordinate arrays used to construct this backend.
@ spacing
Definition vtkX3D.h:482
Specialization of tuple ranges and iterators for vtkAOSDataArrayTemplate.
#define vtkDataArray
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:458
int vtkIdType
Definition vtkType.h:363