Site: GHA-SIMPLEITK-Linux-X64
Build Name: itk-coverage 9362331059
Coverage File: ./Modules/Core/Transform/include/itkMatrixOffsetTransformBase.hxx

    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 itkMatrixOffsetTransformBase_hxx
19 | #define itkMatrixOffsetTransformBase_hxx
20 |
21 | #include "itkNumericTraits.h"
22 | #include "vnl/algo/vnl_matrix_inverse.h"
23 | #include "itkMath.h"
24 | #include "itkCrossHelper.h"
25 |
26 | namespace itk
27 | {
28 |
29 | template <typename TParametersValueType, unsigned int VInputDimension, unsigned int VOutputDimension>
30 7764 | MatrixOffsetTransformBase<TParametersValueType, VInputDimension, VOutputDimension>::MatrixOffsetTransformBase(
31 | unsigned int paramDims)
3242702 | : Superclass(paramDims)
33 | {
34 7764 | m_MatrixMTime.Modified();
35 7764 | m_InverseMatrixMTime = m_MatrixMTime;
36 7764 | this->m_FixedParameters.SetSize(VInputDimension);
37 7764 | this->m_FixedParameters.Fill(0.0);
38 7764 | }
39 |
40 |
41 | template <typename TParametersValueType, unsigned int VInputDimension, unsigned int VOutputDimension>
42 | MatrixOffsetTransformBase<TParametersValueType, VInputDimension, VOutputDimension>::MatrixOffsetTransformBase(
43 | const MatrixType & matrix,
44 | const OutputVectorType & offset)
45 | : m_Matrix(matrix)
46 | , m_Offset(offset)
47 | {
48 | m_MatrixMTime.Modified();
49 | std::copy_n(offset.begin(), VOutputDimension, m_Translation.begin());
50 | this->ComputeMatrixParameters();
51 | }
52 |
53 | template <typename TParametersValueType, unsigned int VInputDimension, unsigned int VOutputDimension>
54 | void
55 530 | MatrixOffsetTransformBase<TParametersValueType, VInputDimension, VOutputDimension>::PrintSelf(std::ostream & os,
56 | Indent indent) const
57 | {
58 530 | Superclass::PrintSelf(os, indent);
59 |
60 | unsigned int i, j;
61 |
62 530 | os << indent << "Matrix: " << std::endl;
63 1981 | for (i = 0; i < VInputDimension; ++i)
64 | {
65 1451 | os << indent.GetNextIndent();
66 5614 | for (j = 0; j < VOutputDimension; ++j)
67 | {
68 4163 | os << m_Matrix[i][j] << ' ';
69 | }
70 1451 | os << std::endl;
71 | }
72 |
73 530 | os << indent << "Offset: " << m_Offset << std::endl;
74 530 | os << indent << "Center: " << m_Center << std::endl;
75 530 | os << indent << "Translation: " << m_Translation << std::endl;
76 |
77 530 | os << indent << "Inverse: " << std::endl;
78 |
79 530 | const auto & inverseMatrix = this->GetInverseMatrix();
80 |
81 1981 | for (i = 0; i < VInputDimension; ++i)
82 | {
83 1451 | os << indent.GetNextIndent();
84 5614 | for (j = 0; j < VOutputDimension; ++j)
85 | {
86 4163 | os << inverseMatrix[i][j] << ' ';
87 | }
88 1451 | os << std::endl;
89 | }
90 530 | os << indent << "Singular: " << m_Singular << std::endl;
91 530 | }
92 |
93 |
94 | template <typename TParametersValueType, unsigned int VInputDimension, unsigned int VOutputDimension>
95 | void
96 1682 | MatrixOffsetTransformBase<TParametersValueType, VInputDimension, VOutputDimension>::SetIdentity()
97 | {
98 1682 | m_Matrix.SetIdentity();
99 1682 | m_MatrixMTime.Modified();
100 1682 | m_Offset.Fill(OutputVectorValueType{});
101 1682 | m_Translation.Fill(OutputVectorValueType{});
102 | // Fixed parameters must be preserved when setting the transform to identity
103 | // the center is part of the stationary fixed parameters
104 | // and should not be modified by SetIdentity. m_Center.Fill(InputPointValueType{});
105 1682 | m_Singular = false;
106 1682 | m_InverseMatrix.SetIdentity();
107 1682 | m_InverseMatrixMTime = m_MatrixMTime;
108 1682 | this->Modified();
109 1682 | }
110 |
111 |
112 | template <typename TParametersValueType, unsigned int VInputDimension, unsigned int VOutputDimension>
113 | void
114 1017 | MatrixOffsetTransformBase<TParametersValueType, VInputDimension, VOutputDimension>::Compose(const Self * other,
115 | bool pre)
116 | {
117 1017 | if (pre)
118 | {
119 309 | m_Offset = m_Matrix * other->m_Offset + m_Offset;
120 309 | m_Matrix = m_Matrix * other->m_Matrix;
121 | }
122 | else
123 | {
124 708 | m_Offset = other->m_Matrix * m_Offset + other->m_Offset;
125 708 | m_Matrix = other->m_Matrix * m_Matrix;
126 | }
127 |
128 1017 | this->ComputeTranslation();
129 1017 | this->ComputeMatrixParameters();
130 |
131 1017 | m_MatrixMTime.Modified();
132 1017 | this->Modified();
133 1017 | }
134 |
135 |
136 | template <typename TParametersValueType, unsigned int VInputDimension, unsigned int VOutputDimension>
137 | auto
138368493226 | MatrixOffsetTransformBase<TParametersValueType, VInputDimension, VOutputDimension>::TransformPoint(
139 | const InputPointType & point) const -> OutputPointType
140 | {
141369394289 | return m_Matrix * point + m_Offset;
142 | }
143 |
144 |
145 | template <typename TParametersValueType, unsigned int VInputDimension, unsigned int VOutputDimension>
146 | auto
147 126 | MatrixOffsetTransformBase<TParametersValueType, VInputDimension, VOutputDimension>::TransformVector(
148 | const InputVectorType & vect) const -> OutputVectorType
149 | {
150 126 | return m_Matrix * vect;
151 | }
152 |
153 |
154 | template <typename TParametersValueType, unsigned int VInputDimension, unsigned int VOutputDimension>
155 | auto
156 26 | MatrixOffsetTransformBase<TParametersValueType, VInputDimension, VOutputDimension>::TransformVector(
157 | const InputVnlVectorType & vect) const -> OutputVnlVectorType
158 | {
159 26 | return m_Matrix.GetVnlMatrix() * vect;
160 | }
161 |
162 |
163 | template <typename TParametersValueType, unsigned int VInputDimension, unsigned int VOutputDimension>
164 | auto
165 2 | MatrixOffsetTransformBase<TParametersValueType, VInputDimension, VOutputDimension>::TransformVector(
166 | const InputVectorPixelType & vect) const -> OutputVectorPixelType
167 | {
168 2 | const unsigned int vectorDim = vect.Size();
169 |
170 4 | vnl_vector<TParametersValueType> vnl_vect(vectorDim);
171 4 | vnl_matrix<TParametersValueType> vnl_mat(vectorDim, vect.Size(), 0.0);
172 6 | for (unsigned int i = 0; i < vectorDim; ++i)
173 | {
174 4 | vnl_vect[i] = vect[i];
175 12 | for (unsigned int j = 0; j < vectorDim; ++j)
176 | {
177 8 | if ((i < VInputDimension) && (j < VInputDimension))
178 | {
179 8 | vnl_mat(i, j) = m_Matrix(i, j);
180 | }
181 0 | else if (i == j)
182 | {
183 0 | vnl_mat(i, j) = 1.0;
184 | }
185 | }
186 | }
187 |
188 4 | vnl_vector<TParametersValueType> tvect = vnl_mat * vnl_vect;
189 2 | OutputVectorPixelType outVect;
190 2 | outVect.SetSize(vectorDim);
191 6 | for (unsigned int i = 0; i < vectorDim; ++i)
192 | {
193 4 | outVect[i] = tvect(i);
194 | }
195 |
196 4 | return outVect;
197 | }
198 |
199 |
200 | template <typename TParametersValueType, unsigned int VInputDimension, unsigned int VOutputDimension>
201 | auto
202 74 | MatrixOffsetTransformBase<TParametersValueType, VInputDimension, VOutputDimension>::TransformCovariantVector(
203 | const InputCovariantVectorType & vec) const -> OutputCovariantVectorType
204 | {
205 | OutputCovariantVectorType result; // Converted vector
206 |
207 74 | const auto & inverseMatrix = this->GetInverseMatrix();
208 |
209 288 | for (unsigned int i = 0; i < VOutputDimension; ++i)
210 | {
211 214 | result[i] = ScalarType{};
212 840 | for (unsigned int j = 0; j < VInputDimension; ++j)
213 | {
214 626 | result[i] += inverseMatrix[j][i] * vec[j]; // Inverse transposed
215 | }
216 | }
217 74 | return result;
218 | }
219 |
220 |
221 | template <typename TParametersValueType, unsigned int VInputDimension, unsigned int VOutputDimension>
222 | auto
223 2 | MatrixOffsetTransformBase<TParametersValueType, VInputDimension, VOutputDimension>::TransformCovariantVector(
224 | const InputVectorPixelType & vect) const -> OutputVectorPixelType
225 | {
226 |
227 2 | const unsigned int vectorDim = vect.Size();
228 |
229 4 | vnl_vector<TParametersValueType> vnl_vect(vectorDim);
230 4 | vnl_matrix<TParametersValueType> vnl_mat(vectorDim, vect.Size(), 0.0);
231 |
232 2 | const auto & inverseMatrix = this->GetInverseMatrix();
233 |
234 6 | for (unsigned int i = 0; i < vectorDim; ++i)
235 | {
236 4 | vnl_vect[i] = vect[i];
237 12 | for (unsigned int j = 0; j < vectorDim; ++j)
238 | {
239 8 | if ((i < VInputDimension) && (j < VInputDimension))
240 | {
241 8 | vnl_mat(i, j) = inverseMatrix(j, i);
242 | }
243 0 | else if (i == j)
244 | {
245 0 | vnl_mat(i, j) = 1.0;
246 | }
247 | }
248 | }
249 |
250 4 | vnl_vector<TParametersValueType> tvect = vnl_mat * vnl_vect;
251 2 | OutputVectorPixelType outVect;
252 2 | outVect.SetSize(vectorDim);
253 6 | for (unsigned int i = 0; i < vectorDim; ++i)
254 | {
255 4 | outVect[i] = tvect(i);
256 | }
257 |
258 4 | return outVect;
259 | }
260 |
261 |
262 | template <typename TParametersValueType, unsigned int VInputDimension, unsigned int VOutputDimension>
263 | auto
264 5 | MatrixOffsetTransformBase<TParametersValueType, VInputDimension, VOutputDimension>::TransformDiffusionTensor3D(
265 | const InputDiffusionTensor3DType & tensor) const -> OutputDiffusionTensor3DType
266 | {
267 |
268 10 | JacobianType jacobian;
269 5 | jacobian.SetSize(InverseMatrixType::RowDimensions, InverseMatrixType::ColumnDimensions);
270 |
271 5 | const auto & inverseMatrix = this->GetInverseMatrix();
272 |
273 15 | for (unsigned int i = 0; i < InverseMatrixType::RowDimensions; ++i)
274 | {
275 30 | for (unsigned int j = 0; j < InverseMatrixType::ColumnDimensions; ++j)
276 | {
277 20 | jacobian(i, j) = inverseMatrix(i, j);
278 | }
279 | }
280 |
281 5 | OutputDiffusionTensor3DType result =
282 | this->PreservationOfPrincipalDirectionDiffusionTensor3DReorientation(tensor, jacobian);
283 |
284 10 | return result;
285 | }
286 |
287 |
288 | template <typename TParametersValueType, unsigned int VInputDimension, unsigned int VOutputDimension>
289 | auto
290 0 | MatrixOffsetTransformBase<TParametersValueType, VInputDimension, VOutputDimension>::TransformDiffusionTensor3D(
291 | const InputVectorPixelType & tensor) const -> OutputVectorPixelType
292 | {
293 0 | OutputVectorPixelType result(InputDiffusionTensor3DType::InternalDimension); // Converted tensor
294 |
295 0 | result.Fill(0.0);
296 |
297 0 | InputDiffusionTensor3DType dt(0.0);
298 0 | const unsigned int tDim = tensor.Size();
299 0 | for (unsigned int i = 0; i < tDim; ++i)
300 | {
301 0 | dt[i] = tensor[i];
302 | }
303 |
304 0 | OutputDiffusionTensor3DType outDT = this->TransformDiffusionTensor3D(dt);
305 0 | for (unsigned int i = 0; i < InputDiffusionTensor3DType::InternalDimension; ++i)
306 | {
307 0 | result[i] = outDT[i];
308 | }
309 |
310 0 | return result;
311 | }
312 |
313 |
314 | template <typename TParametersValueType, unsigned int VInputDimension, unsigned int VOutputDimension>
315 | typename MatrixOffsetTransformBase<TParametersValueType,
316 | VInputDimension,
317 | VOutputDimension>::OutputSymmetricSecondRankTensorType
318 4 | MatrixOffsetTransformBase<TParametersValueType, VInputDimension, VOutputDimension>::TransformSymmetricSecondRankTensor(
319 | const InputSymmetricSecondRankTensorType & inputTensor) const
320 | {
321 8 | JacobianType jacobian;
322 4 | jacobian.SetSize(VOutputDimension, VInputDimension);
323 8 | JacobianType invJacobian;
324 4 | invJacobian.SetSize(VInputDimension, VOutputDimension);
325 8 | JacobianType tensor;
326 4 | tensor.SetSize(VInputDimension, VInputDimension);
327 |
328 12 | for (unsigned int i = 0; i < VInputDimension; ++i)
329 | {
330 24 | for (unsigned int j = 0; j < VInputDimension; ++j)
331 | {
332 16 | tensor(i, j) = inputTensor(i, j);
333 | }
334 | }
335 |
336 |
337 4 | const auto & inverseMatrix = this->GetInverseMatrix();
338 |
339 12 | for (unsigned int i = 0; i < VInputDimension; ++i)
340 | {
341 24 | for (unsigned int j = 0; j < VOutputDimension; ++j)
342 | {
343 16 | jacobian(j, i) = this->GetMatrix()(j, i);
344 16 | invJacobian(i, j) = inverseMatrix(i, j);
345 | }
346 | }
347 |
348 12 | JacobianType outTensor = jacobian * tensor * invJacobian;
349 4 | OutputSymmetricSecondRankTensorType outputTensor;
350 |
351 12 | for (unsigned int i = 0; i < VOutputDimension; ++i)
352 | {
353 24 | for (unsigned int j = 0; j < VOutputDimension; ++j)
354 | {
355 16 | outputTensor(i, j) = outTensor(i, j);
356 | }
357 | }
358 |
359 8 | return outputTensor;
360 | }
361 |
362 |
363 | template <typename TParametersValueType, unsigned int VInputDimension, unsigned int VOutputDimension>
364 | auto
365 0 | MatrixOffsetTransformBase<TParametersValueType, VInputDimension, VOutputDimension>::TransformSymmetricSecondRankTensor(
366 | const InputVectorPixelType & inputTensor) const -> OutputVectorPixelType
367 | {
368 0 | JacobianType jacobian;
369 0 | jacobian.SetSize(VOutputDimension, VInputDimension);
370 0 | JacobianType invJacobian;
371 0 | invJacobian.SetSize(VInputDimension, VOutputDimension);
372 0 | JacobianType tensor;
373 0 | tensor.SetSize(VInputDimension, VInputDimension);
374 |
375 0 | for (unsigned int i = 0; i < VInputDimension; ++i)
376 | {
377 0 | for (unsigned int j = 0; j < VInputDimension; ++j)
378 | {
379 0 | tensor(i, j) = inputTensor[j + VInputDimension * i];
380 | }
381 | }
382 |
383 0 | const auto & inverseMatrix = this->GetInverseMatrix();
384 |
385 0 | for (unsigned int i = 0; i < VInputDimension; ++i)
386 | {
387 0 | for (unsigned int j = 0; j < VOutputDimension; ++j)
388 | {
389 0 | jacobian(j, i) = this->GetMatrix()(j, i);
390 0 | invJacobian(i, j) = inverseMatrix(i, j);
391 | }
392 | }
393 |
394 0 | JacobianType outTensor = jacobian * tensor * invJacobian;
395 |
396 0 | OutputVectorPixelType outputTensor;
397 |
398 0 | for (unsigned int i = 0; i < VOutputDimension; ++i)
399 | {
400 0 | for (unsigned int j = 0; j < VOutputDimension; ++j)
401 | {
402 0 | outputTensor[j + VOutputDimension * i] = outTensor(i, j);
403 | }
404 | }
405 |
406 0 | return outputTensor;
407 | }
408 |
409 |
410 | template <typename TParametersValueType, unsigned int VInputDimension, unsigned int VOutputDimension>
411 | auto
41222811706 | MatrixOffsetTransformBase<TParametersValueType, VInputDimension, VOutputDimension>::GetInverseMatrix() const
413 | -> const InverseMatrixType &
414 | {
415 | // If the transform has been modified we recompute the inverse
41622811706 | if (m_InverseMatrixMTime != m_MatrixMTime)
417 | {
418 3141 | m_Singular = false;
419 | try
420 | {
421 3141 | m_InverseMatrix = m_Matrix.GetInverse();
422 | }
423 34 | catch (...)
424 | {
425 34 | m_Singular = true;
426 | }
427 3141 | m_InverseMatrixMTime = m_MatrixMTime;
428 | }
429 |
43022799846 | return m_InverseMatrix;
431 | }
432 |
433 |
434 | template <typename TParametersValueType, unsigned int VInputDimension, unsigned int VOutputDimension>
435 | bool
43618785209 | MatrixOffsetTransformBase<TParametersValueType, VInputDimension, VOutputDimension>::GetInverse(
437 | InverseTransformType * inverse) const
438 | {
43918785209 | if (!inverse)
440 | {
441 0 | return false;
442 | }
443 |
44418785209 | inverse->SetFixedParameters(this->GetFixedParameters());
44518882201 | const auto & inverseMatrix = this->GetInverseMatrix();
44618854541 | if (m_Singular)
447 | {
448 2 | return false;
449 | }
450 |
45118854539 | inverse->m_Matrix = inverseMatrix;
45218854539 | inverse->m_InverseMatrix = m_Matrix;
45318854539 | inverse->m_Offset = -(inverseMatrix * m_Offset);
45418636733 | inverse->ComputeTranslation();
45518669101 | inverse->ComputeMatrixParameters();
456 |
45718791223 | return true;
458 | }
459 |
460 |
461 | template <typename TParametersValueType, unsigned int VInputDimension, unsigned int VOutputDimension>
462 | auto
463 14 | MatrixOffsetTransformBase<TParametersValueType, VInputDimension, VOutputDimension>::GetInverseTransform() const
464 | -> InverseTransformBasePointer
465 | {
466 14 | return Superclass::InvertTransform(*this);
467 | }
468 |
469 |
470 | template <typename TParametersValueType, unsigned int VInputDimension, unsigned int VOutputDimension>
471 | void
47221128355 | MatrixOffsetTransformBase<TParametersValueType, VInputDimension, VOutputDimension>::SetFixedParameters(
473 | const FixedParametersType & fp)
474 | {
47521128355 | if (fp.size() < VInputDimension)
476 | {
477 15 | itkExceptionMacro("Error setting fixed parameters: parameters array size ("
478 | << fp.size() << ") is less than expected (VInputDimension = " << VInputDimension << ')');
479 | }
48021120650 | this->m_FixedParameters = fp;
481 | InputPointType c;
48282338646 | for (unsigned int i = 0; i < VInputDimension; ++i)
483 | {
48461107275 | c[i] = this->m_FixedParameters[i];
485 | }
48621231371 | this->SetCenter(c);
48721420046 | }
488 |
489 |
490 | template <typename TParametersValueType, unsigned int VInputDimension, unsigned int VOutputDimension>
491 | const typename MatrixOffsetTransformBase<TParametersValueType, VInputDimension, VOutputDimension>::FixedParametersType &
49224390193 | MatrixOffsetTransformBase<TParametersValueType, VInputDimension, VOutputDimension>::GetFixedParameters() const
493 | {
49494539371 | for (unsigned int i = 0; i < VInputDimension; ++i)
495 | {
49670244376 | this->m_FixedParameters[i] = this->m_Center[i];
497 | }
49824294995 | return this->m_FixedParameters;
499 | }
500 |
501 |
502 | template <typename TParametersValueType, unsigned int VInputDimension, unsigned int VOutputDimension>
503 | auto
50444672 | MatrixOffsetTransformBase<TParametersValueType, VInputDimension, VOutputDimension>::GetParameters() const
505 | -> const ParametersType &
506 | {
507 | // Transfer the linear part
50844672 | unsigned int par = 0;
509137934 | for (unsigned int row = 0; row < VOutputDimension; ++row)
510 | {
511293496 | for (unsigned int col = 0; col < VInputDimension; ++col)
512 | {
513200234 | this->m_Parameters[par] = m_Matrix[row][col];
514200234 | ++par;
515 | }
516 | }
517 | // Transfer the constant part
518137934 | for (unsigned int i = 0; i < VOutputDimension; ++i)
519 | {
52093262 | this->m_Parameters[par] = m_Translation[i];
52193262 | ++par;
522 | }
523 |
52444672 | return this->m_Parameters;
525 | }
526 |
527 |
528 | template <typename TParametersValueType, unsigned int VInputDimension, unsigned int VOutputDimension>
529 | void
53053059 | MatrixOffsetTransformBase<TParametersValueType, VInputDimension, VOutputDimension>::SetParameters(
531 | const ParametersType & parameters)
532 | {
53353059 | if (parameters.Size() < (VOutputDimension * VInputDimension + VOutputDimension))
534 | {
535 0 | itkExceptionMacro("Error setting parameters: parameters array size ("
536 | << parameters.Size() << ") is less than expected "
537 | << " (VInputDimension * VOutputDimension + VOutputDimension) "
538 | << " (" << VInputDimension << " * " << VOutputDimension << " + " << VOutputDimension << " = "
539 | << VInputDimension * VOutputDimension + VOutputDimension << ')');
540 | }
541 |
54253059 | unsigned int par = 0;
543 |
544 | // Save parameters. Needed for proper operation of TransformUpdateParameters.
54553059 | if (&parameters != &(this->m_Parameters))
546 | {
54747891 | this->m_Parameters = parameters;
548 | }
549165925 | for (unsigned int row = 0; row < VOutputDimension; ++row)
550 | {
551359902 | for (unsigned int col = 0; col < VInputDimension; ++col)
552 | {
553247036 | m_Matrix[row][col] = this->m_Parameters[par];
554247036 | ++par;
555 | }
556 | }
557 | // Transfer the constant part
558165925 | for (unsigned int i = 0; i < VOutputDimension; ++i)
559 | {
560112866 | m_Translation[i] = this->m_Parameters[par];
561112866 | ++par;
562 | }
563 |
56453059 | m_MatrixMTime.Modified();
565 |
56653059 | this->ComputeMatrix(); // Not necessary since parameters explicitly define
567 | // the matrix
56853059 | this->ComputeOffset();
569 |
570 | // Modified is always called since we just have a pointer to the
571 | // parameters and cannot know if the parameters have changed.
57253059 | this->Modified();
57353059 | }
574 |
575 | template <typename TParametersValueType, unsigned int VInputDimension, unsigned int VOutputDimension>
576 | void
577159366044 | MatrixOffsetTransformBase<TParametersValueType, VInputDimension, VOutputDimension>::
578 | ComputeJacobianWithRespectToParameters(const InputPointType & p, JacobianType & jacobian) const
579 | {
580 | // This will not reallocate memory if the dimensions are equal
581 | // to the matrix's current dimensions.
582159366044 | jacobian.SetSize(VOutputDimension, this->GetNumberOfLocalParameters());
583159397141 | jacobian.Fill(0.0);
584 |
585 | // The Jacobian of the affine transform is composed of
586 | // subblocks of diagonal matrices, each one of them having
587 | // a constant value in the diagonal.
588159662271 | const InputVectorType v = p - this->GetCenter();
589 |
590159552980 | unsigned int blockOffset = 0;
591480140798 | for (unsigned int block = 0; block < VInputDimension; ++block)
592 | {
593966923395 | for (unsigned int dim = 0; dim < VOutputDimension; ++dim)
594 | {
595646335577 | jacobian(block, blockOffset + dim) = v[dim];
596 | }
597 |
598320587818 | blockOffset += VInputDimension;
599 | }
600480186527 | for (unsigned int dim = 0; dim < VOutputDimension; ++dim)
601 | {
602320678032 | jacobian(dim, blockOffset + dim) = 1.0;
603 | }
604159508495 | }
605 |
606 |
607 | template <typename TParametersValueType, unsigned int VInputDimension, unsigned int VOutputDimension>
608 | void
6094019808 | MatrixOffsetTransformBase<TParametersValueType, VInputDimension, VOutputDimension>::
610 | ComputeJacobianWithRespectToPosition(const InputPointType &, JacobianPositionType & jac) const
611 | {
6124019808 | jac = this->GetMatrix().GetVnlMatrix();
6134022947 | }
614 |
615 |
616 | template <typename TParametersValueType, unsigned int VInputDimension, unsigned int VOutputDimension>
617 | void
618 2 | MatrixOffsetTransformBase<TParametersValueType, VInputDimension, VOutputDimension>::
619 | ComputeInverseJacobianWithRespectToPosition(const InputPointType &, InverseJacobianPositionType & jac) const
620 | {
621 2 | jac = this->GetInverseMatrix().GetVnlMatrix();
622 2 | }
623 |
624 |
625 | template <typename TParametersValueType, unsigned int VInputDimension, unsigned int VOutputDimension>
626 | void
62737625425 | MatrixOffsetTransformBase<TParametersValueType, VInputDimension, VOutputDimension>::ComputeOffset()
628 | {
62937625425 | const MatrixType & matrix = this->GetMatrix();
630 |
631 | OffsetType offset;
632 |
633133876775 | for (unsigned int i = 0; i < VOutputDimension; ++i)
634 | {
63596366624 | offset[i] = m_Translation[i] + m_Center[i];
636222452846 | for (unsigned int j = 0; j < VInputDimension; ++j)
637 | {
638255295375 | offset[i] -= matrix[i][j] * m_Center[j];
639 | }
640 | }
641 |
64237510151 | m_Offset = offset;
64337510151 | }
644 |
645 |
646 | template <typename TParametersValueType, unsigned int VInputDimension, unsigned int VOutputDimension>
647 | void
64818663020 | MatrixOffsetTransformBase<TParametersValueType, VInputDimension, VOutputDimension>::ComputeTranslation()
649 | {
65018663020 | const MatrixType & matrix = this->GetMatrix();
651 |
652 | OffsetType translation;
653 |
65474005911 | for (unsigned int i = 0; i < VOutputDimension; ++i)
655 | {
65655365233 | translation[i] = m_Offset[i] - m_Center[i];
657109951018 | for (unsigned int j = 0; j < VInputDimension; ++j)
658 | {
659164527719 | translation[i] += matrix[i][j] * m_Center[j];
660 | }
661 | }
662 |
66318640678 | m_Translation = translation;
66418640678 | }
665 |
666 | template <typename TParametersValueType, unsigned int VInputDimension, unsigned int VOutputDimension>
667 | void
66853060 | MatrixOffsetTransformBase<TParametersValueType, VInputDimension, VOutputDimension>::ComputeMatrix()
669 | {
670 | // Since parameters explicitly define the matrix in this base class, this
671 | // function does nothing. Normally used to compute a matrix when
672 | // its parameterization (e.g., the class' versor) is modified.
67353060 | }
674 |
675 |
676 | template <typename TParametersValueType, unsigned int VInputDimension, unsigned int VOutputDimension>
677 | void
6789282425 | MatrixOffsetTransformBase<TParametersValueType, VInputDimension, VOutputDimension>::ComputeMatrixParameters()
679 | {
680 | // Since parameters explicitly define the matrix in this base class, this
681 | // function does nothing. Normally used to update the parameterization
682 | // of the matrix (e.g., the class' versor) when the matrix is explicitly
683 | // set.
6849282425 | }
685 |
686 | } // end namespace itk
687 |
688 | #endif