ITK 6.0.0
Insight Toolkit
 
Loading...
Searching...
No Matches
itkMINCTransformAdapter.h
Go to the documentation of this file.
1/*=========================================================================
2 *
3 * Copyright NumFOCUS
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * https://www.apache.org/licenses/LICENSE-2.0.txt
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 *=========================================================================*/
18#ifndef itkMINCTransformAdapter_h
19#define itkMINCTransformAdapter_h
20
21#include "itkObject.h"
22#include "itkPoint.h"
23#include "itkVector.h"
24#include "itkCovariantVector.h"
25#include "vnl/vnl_matrix_fixed.h"
26#include "vnl/vnl_vector_fixed.h"
27#include "vnl/vnl_vector_fixed_ref.h"
28#include "vnl/vnl_vector.h"
29#include "itkTransform.h"
30#include "itkObjectFactory.h"
31
32// minc header
33#include "itk_minc2.h"
34
35namespace itk
36{
37
47template <typename TParametersValueType = double, unsigned int VInputDimension = 3, unsigned int VOutputDimension = 3>
48class ITK_TEMPLATE_EXPORT MINCTransformAdapter
49 : public Transform<TParametersValueType, VInputDimension, VOutputDimension>
50{
51public:
52 ITK_DISALLOW_COPY_AND_MOVE(MINCTransformAdapter);
53
56
58
61
63
65 itkNewMacro(Self);
66
68 itkOverrideGetNameOfClassMacro(MINCTransformAdapter);
69
71 static constexpr unsigned int InputSpaceDimension = VInputDimension;
72 static constexpr unsigned int OutputSpaceDimension = VOutputDimension;
73
75 using ScalarType = double;
76
78 using typename Superclass::ParametersType;
80
82 using typename Superclass::JacobianType;
83
87
92
95
97
101
103 using InputVnlVectorType = vnl_vector_fixed<TParametersValueType, VInputDimension>;
104 using OutputVnlVectorType = vnl_vector_fixed<TParametersValueType, VOutputDimension>;
105
108 TransformPoint(const InputPointType & point) const override
109 {
110 if (!m_Initialized)
111 {
112 return point;
113 }
114
116 {
117 return point;
118 }
119
120 OutputPointType pnt;
121 // works only for 3D->3D transforms
122 general_transform_point((m_Invert ? &m_Xfm_inv : &m_Xfm), point[0], point[1], point[2], &pnt[0], &pnt[1], &pnt[2]);
123
124 return pnt;
125 }
126
128 void
129 estimate_local_jacobian(const InputPointType & orig, vnl_matrix_fixed<double, 3, 3> & m)
130 {
131 double u1, v1, w1;
132 double u2, v2, w2;
133 constexpr double delta{ 1e-4 };
134
135 general_transform_point((m_Invert ? &m_Xfm_inv : &m_Xfm), orig[0] - delta, orig[1], orig[2], &u1, &v1, &w1);
136 general_transform_point((m_Invert ? &m_Xfm_inv : &m_Xfm), orig[0] + delta, orig[1], orig[2], &u2, &v2, &w2);
137 m(0, 0) = (u2 - u1) / (2 * delta);
138 m(0, 1) = (v2 - v1) / (2 * delta);
139 m(0, 2) = (w2 - w1) / (2 * delta);
140
141 general_transform_point((m_Invert ? &m_Xfm_inv : &m_Xfm), orig[0], orig[1] - delta, orig[2], &u1, &v1, &w1);
142 general_transform_point((m_Invert ? &m_Xfm_inv : &m_Xfm), orig[0], orig[1] + delta, orig[2], &u2, &v2, &w2);
143 m(1, 0) = (u2 - u1) / (2 * delta);
144 m(1, 1) = (v2 - v1) / (2 * delta);
145 m(1, 2) = (w2 - w1) / (2 * delta);
146
147 general_transform_point((m_Invert ? &m_Xfm_inv : &m_Xfm), orig[0], orig[1], orig[2] - delta, &u1, &v1, &w1);
148 general_transform_point((m_Invert ? &m_Xfm_inv : &m_Xfm), orig[0], orig[1], orig[2] + delta, &u2, &v2, &w2);
149 m(2, 0) = (u2 - u1) / (2 * delta);
150 m(2, 1) = (v2 - v1) / (2 * delta);
151 m(2, 2) = (w2 - w1) / (2 * delta);
152 }
153
155 OutputVectorType
156 TransformVector(const InputVectorType &, const InputPointType &) const override
157 {
158 itkExceptionStringMacro("Not Implemented");
159 }
160
162 OutputVnlVectorType
163 TransformVector(const InputVnlVectorType &, const InputPointType &) const override
164 {
165 itkExceptionStringMacro("Not Implemented");
166 }
167
169 OutputVectorType
170 TransformVector(const InputVectorType & vector) const override
171 {
172 return Superclass::TransformVector(vector);
173 }
174
176 OutputVnlVectorType
177 TransformVector(const InputVnlVectorType & vector) const override
178 {
179 return Superclass::TransformVector(vector);
180 }
181
183 OutputVectorPixelType
184 TransformVector(const InputVectorPixelType & vector) const override
185 {
186 return Superclass::TransformVector(vector);
187 }
188
190 OutputVectorPixelType
191 TransformVector(const InputVectorPixelType &, const InputPointType &) const override
192 {
193 itkExceptionStringMacro("Not Implemented");
194 }
195
197 OutputCovariantVectorType
199 {
200 itkExceptionStringMacro("Not Implemented");
201 }
202
204 OutputCovariantVectorType
206 {
208 }
209
211 OutputVectorPixelType
212 TransformCovariantVector(const InputVectorPixelType & vector) const override
213 {
215 }
216
218 OutputVectorPixelType
220 {
221 itkExceptionStringMacro("Not Implemented");
222 }
223
226 virtual void
228 {
229 cleanup();
230 }
231
232 void
234 {
235 itkExceptionStringMacro("Not Implemented");
236 }
237
238 void
240 {
241 itkExceptionStringMacro("Not Implemented");
242 }
243
244 NumberOfParametersType
245 GetNumberOfParameters() const override
246 {
247 // this transform is defined by XFM file
248 itkExceptionStringMacro("Not Defined");
249 }
250
253 void
255 {
256 itkExceptionStringMacro("Not Implemented");
257 }
258
259 const ParametersType &
260 GetParameters() const override
261 {
262 itkExceptionStringMacro("Not Implemented");
263 }
264
265 void
266 OpenXfm(const char * xfm)
267 {
268 cleanup();
269 if (input_transform_file(xfm, &m_Xfm) != VIO_OK)
270 {
271 itkExceptionMacro("Error reading XFM:" << xfm);
272 }
273 m_Initialized = true;
274 }
275
276 void
278 {
279 if (!m_Initialized)
280 {
281 itkExceptionStringMacro("XFM not initialized");
282 }
284 {
285 create_inverse_general_transform(&m_Xfm, &m_Xfm_inv);
287 }
289 }
290
291protected:
293 {
294 if constexpr (VInputDimension != 3 || VOutputDimension != 3)
295 {
296 itkExceptionStringMacro("MINC transform is currently implemented only for 3D to 3D.");
297 }
298 }
299
301
302 void
304 {
305 if (m_Initialized)
306 {
307 delete_general_transform(&m_Xfm);
308 }
310 {
311 delete_general_transform(&m_Xfm_inv);
312 }
313 m_Initialized = false;
314 m_Initialized_invert = false;
315 }
316
318
319 mutable VIO_General_transform m_Xfm{};
320 mutable VIO_General_transform m_Xfm_inv{};
321
322 bool m_Invert{ false };
323 bool m_Initialized{ false };
324 bool m_Initialized_invert{ false };
325};
326
327} // namespace itk
328#endif // itkMINCTransformAdapter_h
A templated class holding a n-Dimensional covariant vector.
static constexpr unsigned int InputSpaceDimension
OutputVectorPixelType TransformCovariantVector(const InputVectorPixelType &, const InputPointType &) const override
VariableLengthVector< TParametersValueType > OutputVectorPixelType
CovariantVector< TParametersValueType, Self::InputSpaceDimension > InputCovariantVectorType
static constexpr unsigned int OutputSpaceDimension
OutputVectorType TransformVector(const InputVectorType &vector) const override
OutputVnlVectorType TransformVector(const InputVnlVectorType &vector) const override
Array2D< ParametersValueType > JacobianType
OutputVectorPixelType TransformVector(const InputVectorPixelType &, const InputPointType &) const override
Point< TParametersValueType, VInputDimension > InputPointType
void ComputeJacobianWithRespectToParameters(const InputPointType &, JacobianType &) const override
void SetParameters(const ParametersType &) override
OutputVectorPixelType TransformCovariantVector(const InputVectorPixelType &vector) const override
const ParametersType & GetParameters() const override
OptimizerParameters< FixedParametersValueType > FixedParametersType
OutputVnlVectorType TransformVector(const InputVnlVectorType &, const InputPointType &) const override
vnl_vector_fixed< TParametersValueType, VInputDimension > InputVnlVectorType
OutputPointType TransformPoint(const InputPointType &point) const override
void estimate_local_jacobian(const InputPointType &orig, vnl_matrix_fixed< double, 3, 3 > &m)
use finite element difference to estimate local jacobian
void SetFixedParameters(const FixedParametersType &) override
NumberOfParametersType GetNumberOfParameters() const override
OutputVectorPixelType TransformVector(const InputVectorPixelType &vector) const override
OutputCovariantVectorType TransformCovariantVector(const InputCovariantVectorType &vector) const override
vnl_vector_fixed< TParametersValueType, VOutputDimension > OutputVnlVectorType
Vector< TParametersValueType, Self::OutputSpaceDimension > OutputVectorType
Point< TParametersValueType, VInputDimension > OutputPointType
SmartPointer< const Self > ConstPointer
Transform< TParametersValueType, VInputDimension, VOutputDimension > Superclass
Vector< TParametersValueType, Self::InputSpaceDimension > InputVectorType
CovariantVector< TParametersValueType, Self::OutputSpaceDimension > OutputCovariantVectorType
VariableLengthVector< TParametersValueType > InputVectorPixelType
OptimizerParameters< ParametersValueType > ParametersType
OutputCovariantVectorType TransformCovariantVector(const InputCovariantVectorType &, const InputPointType &) const override
OutputVectorType TransformVector(const InputVectorType &, const InputPointType &) const override
A templated class holding a geometric point in n-Dimensional space.
Definition itkPoint.h:54
Implements transparent reference counting.
OptimizerParameters< FixedParametersValueType > FixedParametersType
virtual OutputVectorType TransformVector(const InputVectorType &) const
virtual OutputCovariantVectorType TransformCovariantVector(const InputCovariantVectorType &) const
A templated class holding a n-Dimensional vector.
Definition itkVector.h:63
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....