VTK  9.4.20250102
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_EMPTY*/), ValueType>::type VTK_ALWAYS_INLINE
138
139 //------------------------------------------------------------------------------
140 template <int Description = DataDescription>
141 typename std::enable_if<(Description != 9 /*VTK_EMPTY*/), ValueType>::type VTK_ALWAYS_INLINE
143
144 //------------------------------------------------------------------------------
145 ValueType mapStructuredXComponent(int i) const override;
146
147 //------------------------------------------------------------------------------
148 template <int Description = DataDescription>
149 typename std::enable_if<(Description == 9 /*VTK_EMPTY*/), ValueType>::type VTK_ALWAYS_INLINE
151
152 //------------------------------------------------------------------------------
153 template <int Description = DataDescription>
154 typename std::enable_if<(Description != 9 /*VTK_EMPTY*/), ValueType>::type VTK_ALWAYS_INLINE
156
157 //------------------------------------------------------------------------------
158 ValueType mapStructuredYComponent(int j) const override;
159
160 //------------------------------------------------------------------------------
161 template <int Description = DataDescription>
162 typename std::enable_if<(Description == 9 /*VTK_EMPTY*/), ValueType>::type VTK_ALWAYS_INLINE
164
165 //------------------------------------------------------------------------------
166 template <int Description = DataDescription>
167 typename std::enable_if<(Description != 9 /*VTK_EMPTY*/), ValueType>::type VTK_ALWAYS_INLINE
169
170 //------------------------------------------------------------------------------
171 ValueType mapStructuredZComponent(int k) const override;
172
173 //------------------------------------------------------------------------------
174 template <int Description = DataDescription>
175 typename std::enable_if<(Description == 9 /*VTK_EMPTY*/), void>::type VTK_ALWAYS_INLINE
176 mapStructuredTupleImpl(int ijk[3], ValueType tuple[3]) const;
177
178 //------------------------------------------------------------------------------
179 template <int Description = DataDescription>
180 typename std::enable_if<(Description != 9 /*VTK_EMPTY*/), void>::type VTK_ALWAYS_INLINE
181 mapStructuredTupleImpl(int ijk[3], ValueType tuple[3]) const;
182
183 //------------------------------------------------------------------------------
184 void mapStructuredTuple(int ijk[3], ValueType tuple[3]) const override;
185
186 //------------------------------------------------------------------------------
187 template <int Description = DataDescription>
188 typename std::enable_if<(Description == 9 /*VTK_EMPTY*/), void>::type VTK_ALWAYS_INLINE
189 ComputePointStructuredCoords(vtkIdType pointId, int ijk[3]) const;
190
191 //------------------------------------------------------------------------------
192 template <int Description = DataDescription>
193 typename std::enable_if<(Description == 1 /*VTK_SINGLE_POINT*/), void>::type VTK_ALWAYS_INLINE
194 ComputePointStructuredCoords(vtkIdType pointId, int ijk[3]) const;
195
196 //------------------------------------------------------------------------------
197 template <int Description = DataDescription>
198 typename std::enable_if<(Description == 2 /*VTK_X_LINE*/), void>::type VTK_ALWAYS_INLINE
199 ComputePointStructuredCoords(vtkIdType pointId, int ijk[3]) const;
200
201 //------------------------------------------------------------------------------
202 template <int Description = DataDescription>
203 typename std::enable_if<(Description == 3 /*VTK_Y_LINE*/), void>::type VTK_ALWAYS_INLINE
204 ComputePointStructuredCoords(vtkIdType pointId, int ijk[3]) const;
205
206 //------------------------------------------------------------------------------
207 template <int Description = DataDescription>
208 typename std::enable_if<(Description == 4 /*VTK_Z_LINE*/), 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 == 5 /*VTK_XY_PLANE*/), void>::type VTK_ALWAYS_INLINE
214 ComputePointStructuredCoords(vtkIdType pointId, int ijk[3]) const;
215
216 //------------------------------------------------------------------------------
217 template <int Description = DataDescription>
218 typename std::enable_if<(Description == 6 /*VTK_YZ_PLANE*/), void>::type VTK_ALWAYS_INLINE
219 ComputePointStructuredCoords(vtkIdType pointId, int ijk[3]) const;
220
221 //------------------------------------------------------------------------------
222 template <int Description = DataDescription>
223 typename std::enable_if<(Description == 7 /*VTK_XZ_PLANE*/), void>::type VTK_ALWAYS_INLINE
224 ComputePointStructuredCoords(vtkIdType pointId, int ijk[3]) const;
225
226 //------------------------------------------------------------------------------
227 template <int Description = DataDescription>
228 typename std::enable_if<(Description == 8 /*VTK_XYZ_GRID*/), void>::type VTK_ALWAYS_INLINE
229 ComputePointStructuredCoords(vtkIdType pointId, int ijk[3]) const;
230
231 //------------------------------------------------------------------------------
232 void mapTuple(vtkIdType tupleId, ValueType tuple[3]) const override;
233
234 //------------------------------------------------------------------------------
235 template <int Description = DataDescription>
236 typename std::enable_if<(Description == 9 /*VTK_EMPTY*/), ValueType>::type VTK_ALWAYS_INLINE
237 mapComponentImpl(vtkIdType tupleId, int comp) const;
238
239 //------------------------------------------------------------------------------
240 template <int Description = DataDescription>
241 typename std::enable_if<(Description == 1 /*VTK_SINGLE_POINT*/), ValueType>::type
242 VTK_ALWAYS_INLINE
243 mapComponentImpl(vtkIdType tupleId, int comp) const;
244
245 //------------------------------------------------------------------------------
246 template <int Description = DataDescription>
247 typename std::enable_if<(Description == 2 /*VTK_X_LINE*/), ValueType>::type VTK_ALWAYS_INLINE
248 mapComponentImpl(vtkIdType tupleId, int comp) const;
249
250 //------------------------------------------------------------------------------
251 template <int Description = DataDescription>
252 typename std::enable_if<(Description == 3 /*VTK_Y_LINE*/), ValueType>::type VTK_ALWAYS_INLINE
253 mapComponentImpl(vtkIdType tupleId, int comp) const;
254
255 //------------------------------------------------------------------------------
256 template <int Description = DataDescription>
257 typename std::enable_if<(Description == 4 /*VTK_Z_LINE*/), ValueType>::type VTK_ALWAYS_INLINE
258 mapComponentImpl(vtkIdType tupleId, int comp) const;
259
260 //------------------------------------------------------------------------------
261 template <int Description = DataDescription>
262 typename std::enable_if<(Description == 5 /*VTK_XY_PLANE*/), ValueType>::type VTK_ALWAYS_INLINE
263 mapComponentImpl(vtkIdType tupleId, int comp) const;
264
265 //------------------------------------------------------------------------------
266 template <int Description = DataDescription>
267 typename std::enable_if<(Description == 6 /*VTK_YZ_PLANE*/), ValueType>::type VTK_ALWAYS_INLINE
268 mapComponentImpl(vtkIdType tupleId, int comp) const;
269
270 //------------------------------------------------------------------------------
271 template <int Description = DataDescription>
272 typename std::enable_if<(Description == 7 /*VTK_XZ_PLANE*/), ValueType>::type VTK_ALWAYS_INLINE
273 mapComponentImpl(vtkIdType tupleId, int comp) const;
274
275 //------------------------------------------------------------------------------
276 template <int Description = DataDescription>
277 typename std::enable_if<(Description == 8 /*VTK_XYZ_GRID*/), ValueType>::type VTK_ALWAYS_INLINE
278 mapComponentImpl(vtkIdType tupleId, int comp) const;
279
280 //------------------------------------------------------------------------------
281 ValueType mapComponent(vtkIdType tupleId, int comp) const override;
282
283 //------------------------------------------------------------------------------
284 ValueType map(vtkIdType valueId) const override;
285};
286VTK_ABI_NAMESPACE_END
287
288#endif // vtkStructuredPointBackend_h
289/* VTK-HeaderTest-Exclude: vtkStructuredPointBackend.h */
290
291#if defined(VTK_STRUCTURED_POINT_BACKEND_INSTANTIATING)
292
293#define VTK_INSTANTIATE_STRUCTURED_POINT_BACKEND(ValueType) \
294 VTK_ABI_NAMESPACE_BEGIN \
295 template class VTKCOMMONCORE_EXPORT vtkStructuredPointBackend<ValueType>; \
296 VTK_ABI_NAMESPACE_END
297#elif defined(VTK_USE_EXTERN_TEMPLATE)
298
299#ifndef VTK_STRUCTURED_POINT_BACKEND_TEMPLATE_EXTERN
300#define VTK_STRUCTURED_POINT_BACKEND_TEMPLATE_EXTERN
301#ifdef _MSC_VER
302#pragma warning(push)
303#pragma warning(disable : 4910) // extern and dllexport incompatible
304#endif
305VTK_ABI_NAMESPACE_BEGIN
306vtkExternTemplateMacro(extern template class VTKCOMMONCORE_EXPORT vtkStructuredPointBackend);
307VTK_ABI_NAMESPACE_END
308#ifdef _MSC_VER
309#pragma warning(pop)
310#endif
311#endif // VTK_STRUCTURED_POINT_BACKEND_TEMPLATE_EXTERN
312
313#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:410
int vtkIdType
Definition vtkType.h:315