annotate OrthancStone/Sources/Toolbox/ShearWarpProjectiveTransform.cpp @ 1974:446e0d3e9019

fix unit test GeometryToolbox.OrientationMarkers
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 28 Oct 2022 17:58:59 +0200
parents 7053b8a0aaec
children 07964689cb0b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
191
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Stone of Orthanc
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 * Department, University Hospital of Liege, Belgium
1871
7053b8a0aaec upgrade to year 2022
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1870
diff changeset
5 * Copyright (C) 2017-2022 Osimis S.A., Belgium
7053b8a0aaec upgrade to year 2022
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1870
diff changeset
6 * Copyright (C) 2021-2022 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
191
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 *
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * This program is free software: you can redistribute it and/or
1598
8563ea5d8ae4 relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1596
diff changeset
9 * modify it under the terms of the GNU Lesser General Public License
191
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * as published by the Free Software Foundation, either version 3 of
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 * the License, or (at your option) any later version.
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 *
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * This program is distributed in the hope that it will be useful, but
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
1598
8563ea5d8ae4 relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1596
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
8563ea5d8ae4 relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1596
diff changeset
16 * Lesser General Public License for more details.
1596
4fb8fdf03314 removed annoying whitespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1512
diff changeset
17 *
1598
8563ea5d8ae4 relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1596
diff changeset
18 * You should have received a copy of the GNU Lesser General Public
8563ea5d8ae4 relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1596
diff changeset
19 * License along with this program. If not, see
8563ea5d8ae4 relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1596
diff changeset
20 * <http://www.gnu.org/licenses/>.
191
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21 **/
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 #include "ShearWarpProjectiveTransform.h"
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 #include "ImageGeometry.h"
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 #include "Extent2D.h"
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 #include "FiniteProjectiveCamera.h"
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 #include "GeometryToolbox.h"
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30
1455
30deba7bc8e2 simplifying include_directories
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1298
diff changeset
31 #include <Images/PixelTraits.h>
30deba7bc8e2 simplifying include_directories
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1298
diff changeset
32 #include <Images/ImageProcessing.h>
30deba7bc8e2 simplifying include_directories
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1298
diff changeset
33 #include <OrthancException.h>
30deba7bc8e2 simplifying include_directories
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1298
diff changeset
34 #include <Logging.h>
191
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36 #include <boost/numeric/ublas/matrix_proxy.hpp>
193
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
37 #include <boost/math/special_functions/round.hpp>
191
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 #include <cassert>
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 namespace OrthancStone
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 {
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 static bool IsValidShear(const Matrix& M_shear)
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 {
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 return (LinearAlgebra::IsCloseToZero(M_shear(0, 1)) &&
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 LinearAlgebra::IsCloseToZero(M_shear(1, 0)) &&
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 LinearAlgebra::IsCloseToZero(M_shear(2, 0)) &&
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 LinearAlgebra::IsCloseToZero(M_shear(2, 1)) &&
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 LinearAlgebra::IsNear(1.0, M_shear(2, 2)) &&
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 LinearAlgebra::IsCloseToZero(M_shear(2, 3)) &&
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 LinearAlgebra::IsCloseToZero(M_shear(3, 0)) &&
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52 LinearAlgebra::IsCloseToZero(M_shear(3, 1)) &&
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 LinearAlgebra::IsNear(1.0, M_shear(3, 3)));
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 }
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 static void ComputeShearParameters(double& scaling,
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 double& offsetX,
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 double& offsetY,
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 const Matrix& shear,
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 double z)
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 {
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 // Check out: ../../Resources/Computations/ComputeShearParameters.py
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65 if (!LinearAlgebra::IsShearMatrix(shear))
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66 {
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67 LOG(ERROR) << "Not a valid shear matrix";
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69 }
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71 scaling = 1.0 / (shear(3,2) * z + 1.0);
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72 offsetX = shear(0,2) * z * scaling;
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73 offsetY = shear(1,2) * z * scaling;
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74 }
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77 ShearWarpProjectiveTransform::
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78 ShearWarpProjectiveTransform(const Matrix& M_view,
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79 //const Matrix& P, // Permutation applied to the volume
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80 unsigned int volumeWidth,
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81 unsigned int volumeHeight,
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82 unsigned int volumeDepth,
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83 double pixelSpacingX,
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84 double pixelSpacingY,
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85 unsigned int imageWidth,
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86 unsigned int imageHeight)
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87 {
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88 eye_o.resize(4);
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90 {
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91 // Find back the camera center given the "M_view" matrix
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92 const double m11 = M_view(0, 0);
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93 const double m12 = M_view(0, 1);
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94 const double m13 = M_view(0, 2);
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95 const double m14 = M_view(0, 3);
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96 const double m21 = M_view(1, 0);
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97 const double m22 = M_view(1, 1);
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98 const double m23 = M_view(1, 2);
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99 const double m24 = M_view(1, 3);
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100 const double m41 = M_view(3, 0);
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101 const double m42 = M_view(3, 1);
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102 const double m43 = M_view(3, 2);
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103 const double m44 = M_view(3, 3);
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105 // Equations (A.8) to (A.11) on page 203. Also check out
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106 // "Finding the camera center" in "Multiple View Geometry in
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107 // Computer Vision - 2nd edition", page 163.
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108 const double vx[9] = { m12, m13, m14, m22, m23, m24, m42, m43, m44 };
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109 const double vy[9] = { m11, m13, m14, m21, m23, m24, m41, m43, m44 };
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110 const double vz[9] = { m11, m12, m14, m21, m22, m24, m41, m42, m44 };
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111 const double vw[9] = { m11, m12, m13, m21, m22, m23, m41, m42, m43 };
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113 Matrix m;
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
115 LinearAlgebra::FillMatrix(m, 3, 3, vx);
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
116 eye_o[0] = -LinearAlgebra::ComputeDeterminant(m);
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
117
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
118 LinearAlgebra::FillMatrix(m, 3, 3, vy);
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
119 eye_o[1] = LinearAlgebra::ComputeDeterminant(m);
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121 LinearAlgebra::FillMatrix(m, 3, 3, vz);
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122 eye_o[2] = -LinearAlgebra::ComputeDeterminant(m);
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
123
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124 LinearAlgebra::FillMatrix(m, 3, 3, vw);
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
125 eye_o[3] = LinearAlgebra::ComputeDeterminant(m);
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
126
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
127 if (LinearAlgebra::IsCloseToZero(eye_o[3]))
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
128 {
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
129 LOG(ERROR) << "The shear-warp projective transform is not applicable to affine cameras";
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
130 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
131 }
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
132 }
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
133
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
134 #if 0
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
135 // Assume "T_shift = I" (the eye does not lie on plane k = 0)
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
136 const Matrix T_shift = LinearAlgebra::IdentityMatrix(4);
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
137
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
138 // Equation (A.13) on page 204, given that the inverse of a
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
139 // permutation matrix is its transpose (TODO CHECK). If no T_shift
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
140 // or permutation P is applied, M'_view == M_view
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
141 const Matrix MM_view = LinearAlgebra::Product(
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
142 M_view,
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
143 LinearAlgebra::Transpose(P),
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
144 LinearAlgebra::InvertScalingTranslationMatrix(T_shift));
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
145 #else
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
146 // This is a shortcut, as we take "T_shift = I" and "P = I"
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
147 const Matrix MM_view = M_view;
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
148 #endif
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
149
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
150 // Equation (A.14) on page 207
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
151 Matrix MM_shear = LinearAlgebra::IdentityMatrix(4);
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
152 MM_shear(0, 2) = -eye_o[0] / eye_o[2];
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
153 MM_shear(1, 2) = -eye_o[1] / eye_o[2];
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
154 MM_shear(3, 2) = -eye_o[3] / eye_o[2];
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
155
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
156
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
157 // Compute the extent of the intermediate image
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
158 Extent2D extent;
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
159 double maxScaling = 1;
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
160
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
161 {
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
162 // Compute the shearing factors of the two extreme planes of the
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
163 // volume (z=0 and z=volumeDepth)
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
164 double scaling, offsetX, offsetY;
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
165 ComputeShearParameters(scaling, offsetX, offsetY, MM_shear, 0);
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
166
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
167 if (scaling > 0)
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
168 {
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
169 extent.AddPoint(offsetX, offsetY);
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
170 extent.AddPoint(offsetX + static_cast<double>(volumeWidth) * scaling,
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
171 offsetY + static_cast<double>(volumeHeight) * scaling);
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
172
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
173 if (scaling > maxScaling)
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
174 {
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
175 maxScaling = scaling;
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
176 }
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
177 }
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
178
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
179 ComputeShearParameters(scaling, offsetX, offsetY, MM_shear, volumeDepth);
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
180
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
181 if (scaling > 0)
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
182 {
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
183 extent.AddPoint(offsetX, offsetY);
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
184 extent.AddPoint(offsetX + static_cast<double>(volumeWidth) * scaling,
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
185 offsetY + static_cast<double>(volumeHeight) * scaling);
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
186
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
187 if (scaling > maxScaling)
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
188 {
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
189 maxScaling = scaling;
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
190 }
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
191 }
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
192 }
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
193
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
194 if (LinearAlgebra::IsCloseToZero(extent.GetWidth()) ||
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
195 LinearAlgebra::IsCloseToZero(extent.GetHeight()))
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
196 {
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
197 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
198 }
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
199
693
9a474e90e832 Fixed a bunch of truncation warnings in various parts of the library
Benjamin Golinvaux <bgo@osimis.io>
parents: 684
diff changeset
200 intermediateWidth_ =
9a474e90e832 Fixed a bunch of truncation warnings in various parts of the library
Benjamin Golinvaux <bgo@osimis.io>
parents: 684
diff changeset
201 static_cast<unsigned int>(std::ceil(extent.GetWidth() / maxScaling));
9a474e90e832 Fixed a bunch of truncation warnings in various parts of the library
Benjamin Golinvaux <bgo@osimis.io>
parents: 684
diff changeset
202 intermediateHeight_ =
9a474e90e832 Fixed a bunch of truncation warnings in various parts of the library
Benjamin Golinvaux <bgo@osimis.io>
parents: 684
diff changeset
203 static_cast<unsigned int>(std::ceil(extent.GetHeight() / maxScaling));
191
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
204
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
205 // This is the product "T * S" in Equation (A.16) on page 209
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
206 Matrix TS = LinearAlgebra::Product(
693
9a474e90e832 Fixed a bunch of truncation warnings in various parts of the library
Benjamin Golinvaux <bgo@osimis.io>
parents: 684
diff changeset
207 GeometryToolbox::CreateTranslationMatrix(
9a474e90e832 Fixed a bunch of truncation warnings in various parts of the library
Benjamin Golinvaux <bgo@osimis.io>
parents: 684
diff changeset
208 static_cast<double>(intermediateWidth_) / 2.0,
9a474e90e832 Fixed a bunch of truncation warnings in various parts of the library
Benjamin Golinvaux <bgo@osimis.io>
parents: 684
diff changeset
209 static_cast<double>(intermediateHeight_) / 2.0, 0),
9a474e90e832 Fixed a bunch of truncation warnings in various parts of the library
Benjamin Golinvaux <bgo@osimis.io>
parents: 684
diff changeset
210 GeometryToolbox::CreateScalingMatrix(
9a474e90e832 Fixed a bunch of truncation warnings in various parts of the library
Benjamin Golinvaux <bgo@osimis.io>
parents: 684
diff changeset
211 1.0 / maxScaling, 1.0 / maxScaling, 1),
9a474e90e832 Fixed a bunch of truncation warnings in various parts of the library
Benjamin Golinvaux <bgo@osimis.io>
parents: 684
diff changeset
212 GeometryToolbox::CreateTranslationMatrix(
9a474e90e832 Fixed a bunch of truncation warnings in various parts of the library
Benjamin Golinvaux <bgo@osimis.io>
parents: 684
diff changeset
213 -extent.GetCenterX(), -extent.GetCenterY(), 0));
191
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
214
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
215 // This is Equation (A.16) on page 209. WARNING: There is an
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
216 // error in Lacroute's thesis: "inv(MM_shear)" is used instead
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
217 // of "MM_shear".
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
218 M_shear = LinearAlgebra::Product(TS, MM_shear);
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
219
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
220 if (!IsValidShear(M_shear))
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
221 {
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
222 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
223 }
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
224
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
225 // This is Equation (A.17) on page 209
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
226 Matrix tmp;
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
227 LinearAlgebra::InvertMatrix(tmp, M_shear);
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
228 M_warp = LinearAlgebra::Product(MM_view, tmp);
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
229
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
230 // Intrinsic parameters of the camera
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
231 k_ = LinearAlgebra::ZeroMatrix(3, 4);
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
232 k_(0, 0) = 1.0 / pixelSpacingX;
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
233 k_(0, 3) = static_cast<double>(imageWidth) / 2.0;
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
234 k_(1, 1) = 1.0 / pixelSpacingY;
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
235 k_(1, 3) = static_cast<double>(imageHeight) / 2.0;
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
236 k_(2, 3) = 1.0;
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
237 }
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
238
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
239
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
240 FiniteProjectiveCamera *ShearWarpProjectiveTransform::CreateCamera() const
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
241 {
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
242 Matrix p = LinearAlgebra::Product(k_, M_warp, M_shear);
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
243 return new FiniteProjectiveCamera(p);
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
244 }
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
245
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
246
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
247 void ShearWarpProjectiveTransform::ComputeShearOnSlice(double& a11,
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
248 double& b1,
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
249 double& a22,
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
250 double& b2,
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
251 double& shearedZ,
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
252 const double sourceZ)
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
253 {
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
254 // Check out: ../../Resources/Computations/ComputeShearOnSlice.py
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
255 assert(IsValidShear(M_shear));
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
256
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
257 const double s11 = M_shear(0, 0);
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
258 const double s13 = M_shear(0, 2);
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
259 const double s14 = M_shear(0, 3);
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
260 const double s22 = M_shear(1, 1);
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
261 const double s23 = M_shear(1, 2);
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
262 const double s24 = M_shear(1, 3);
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
263 const double s43 = M_shear(3, 2);
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
264
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
265 double scaling = 1.0 / (s43 * sourceZ + 1.0);
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
266 shearedZ = sourceZ * scaling;
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
267
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
268 a11 = s11 * scaling;
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
269 a22 = s22 * scaling;
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
270
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
271 b1 = (s13 * sourceZ + s14) * scaling;
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
272 b2 = (s23 * sourceZ + s24) * scaling;
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
273 }
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
274
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
275
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
276 Matrix ShearWarpProjectiveTransform::CalibrateView(const Vector& camera,
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
277 const Vector& principalPoint,
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
278 double angle)
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
279 {
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
280 if (camera.size() != 3 ||
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
281 principalPoint.size() != 3)
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
282 {
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
283 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
284 }
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
285
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
286 const double sid = boost::numeric::ublas::norm_2(camera - principalPoint);
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
287
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
288 Matrix a;
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
289 GeometryToolbox::AlignVectorsWithRotation(a, camera - principalPoint,
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
290 LinearAlgebra::CreateVector(0, 0, -1));
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
291
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
292 Matrix r = LinearAlgebra::Product(GeometryToolbox::CreateRotationMatrixAlongZ(angle), a);
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
293
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
294 a = LinearAlgebra::ZeroMatrix(4, 4);
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
295 boost::numeric::ublas::subrange(a, 0, 3, 0, 3) = r;
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
296
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
297 const Vector v = LinearAlgebra::Product(r, -camera);
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
298 a(0, 3) = v[0];
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
299 a(1, 3) = v[1];
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
300 a(2, 3) = v[2];
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
301 a(3, 3) = 1;
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
302
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
303 Matrix perspective = LinearAlgebra::ZeroMatrix(4, 4);
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
304 // https://stackoverflow.com/questions/5267866/calculation-of-a-perspective-transformation-matrix
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
305 perspective(0, 0) = sid;
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
306 perspective(1, 1) = sid;
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
307 perspective(2, 2) = sid;
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
308 perspective(3, 2) = 1;
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
309
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
310 Matrix M_view = LinearAlgebra::Product(perspective, a);
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
311 assert(M_view.size1() == 4 &&
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
312 M_view.size2() == 4);
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
313
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
314 {
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
315 // Sanity checks
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
316 Vector p1 = LinearAlgebra::CreateVector(camera[0], camera[1], camera[2], 1.0);
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
317 Vector p2 = LinearAlgebra::CreateVector(principalPoint[0], principalPoint[1], principalPoint[2], 1.0);
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
318
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
319 Vector v1 = LinearAlgebra::Product(M_view, p1);
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
320 Vector v2 = LinearAlgebra::Product(M_view, p2);
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
321
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
322 if (!LinearAlgebra::IsCloseToZero(v1[3]) || // Must be mapped to singularity (w=0)
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
323 LinearAlgebra::IsCloseToZero(v2[3]))
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
324 {
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
325 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
326 }
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
327
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
328 // The principal point must be mapped to (0,0,z,1)
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
329 v2 /= v2[3];
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
330 if (!LinearAlgebra::IsCloseToZero(v2[0]) ||
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
331 !LinearAlgebra::IsCloseToZero(v2[1]))
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
332 {
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
333 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
334 }
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
335 }
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
336
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
337 return M_view;
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
338 }
193
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
339
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
340
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
341 template <Orthanc::PixelFormat SourceFormat,
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
342 Orthanc::PixelFormat TargetFormat,
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
343 bool MIP>
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
344 static void ApplyAxialInternal(Orthanc::ImageAccessor& target,
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
345 float& maxValue,
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
346 const Matrix& M_view,
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
347 const ImageBuffer3D& source,
735
c3bbb130abc4 removing dependencies in ImageBuffer3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 705
diff changeset
348 const VolumeImageGeometry& geometry,
193
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
349 double pixelSpacing,
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
350 unsigned int countSlices,
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
351 ImageInterpolation shearInterpolation,
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
352 ImageInterpolation warpInterpolation)
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
353 {
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
354 typedef Orthanc::PixelTraits<SourceFormat> SourceTraits;
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
355 typedef Orthanc::PixelTraits<TargetFormat> TargetTraits;
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
356
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
357 /**
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
358 * Step 1: Precompute some information.
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
359 **/
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
360
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
361 if (target.GetFormat() != TargetFormat ||
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
362 source.GetFormat() != SourceFormat ||
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
363 !std::numeric_limits<float>::is_iec559 ||
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
364 sizeof(float) != 4)
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
365 {
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
366 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
367 }
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
368
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
369 if (countSlices > source.GetDepth())
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
370 {
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
371 countSlices = source.GetDepth();
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
372 }
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
373
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
374 if (countSlices == 0)
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
375 {
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
376 maxValue = 0;
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
377 Orthanc::ImageProcessing::Set(target, 0);
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
378 return;
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
379 }
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
380
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
381 LOG(INFO) << "Number of rendered slices: " << countSlices;
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
382
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
383
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
384 /**
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
385 * Step 2: Extract the shear-warp transform corresponding to
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
386 * M_view.
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
387 **/
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
388
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
389 // Compute the "world" matrix that maps the source volume to the
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
390 // (0,0,0)->(1,1,1) unit cube
735
c3bbb130abc4 removing dependencies in ImageBuffer3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 705
diff changeset
391 Vector origin = geometry.GetCoordinates(0, 0, 0);
c3bbb130abc4 removing dependencies in ImageBuffer3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 705
diff changeset
392 Vector ps = geometry.GetVoxelDimensions(VolumeProjection_Axial);
193
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
393 Matrix world = LinearAlgebra::Product(
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
394 GeometryToolbox::CreateScalingMatrix(1.0 / ps[0], 1.0 / ps[1], 1.0 / ps[2]),
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
395 GeometryToolbox::CreateTranslationMatrix(-origin[0], -origin[1], -origin[2]));
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
396
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
397 Matrix worldInv;
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
398 LinearAlgebra::InvertMatrix(worldInv, world);
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
399
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
400 ShearWarpProjectiveTransform shearWarp(LinearAlgebra::Product(M_view, worldInv),
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
401 /*LinearAlgebra::IdentityMatrix(4),*/
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
402 source.GetWidth(),
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
403 source.GetHeight(),
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
404 source.GetDepth(),
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
405 pixelSpacing, pixelSpacing,
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
406 target.GetWidth(), target.GetHeight());
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
407
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
408 const unsigned int intermediateWidth = shearWarp.GetIntermediateWidth();
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
409 const unsigned int intermediateHeight = shearWarp.GetIntermediateHeight();
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
410
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
411
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
412 /**
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
413 * Step 3: Apply the "shear" part of the transform to form the
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
414 * intermediate image. The sheared images are accumulated into the
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
415 * Float32 image "accumulator". The number of samples available
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
416 * for each pixel is stored in the "counter" image.
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
417 **/
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
418
1298
8a0a62189f46 replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1270
diff changeset
419 std::unique_ptr<Orthanc::ImageAccessor> accumulator, counter, intermediate;
193
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
420
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
421 accumulator.reset(new Orthanc::Image(Orthanc::PixelFormat_Float32,
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
422 intermediateWidth, intermediateHeight, false));
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
423 counter.reset(new Orthanc::Image(Orthanc::PixelFormat_Grayscale16,
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
424 intermediateWidth, intermediateHeight, false));
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
425 intermediate.reset(new Orthanc::Image(SourceFormat, intermediateWidth, intermediateHeight, false));
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
426
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
427 Orthanc::ImageProcessing::Set(*accumulator, 0);
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
428 Orthanc::ImageProcessing::Set(*counter, 0);
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
429
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
430 // Loop around the slices of the volume
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
431 for (unsigned int i = 0; i <= countSlices; i++)
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
432 {
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
433 // (3.a) Compute the shear for this specific slice
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
434 unsigned int z = static_cast<unsigned int>(
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
435 boost::math::iround(static_cast<double>(i) /
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
436 static_cast<double>(countSlices) *
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
437 static_cast<double>(source.GetDepth() - 1)));
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
438
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
439 double a11, b1, a22, b2, vz;
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
440 shearWarp.ComputeShearOnSlice(a11, b1, a22, b2, vz, static_cast<double>(z) + 0.5);
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
441
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
442
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
443 {
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
444 // (3.b) Detect the "useful" portion of the intermediate image
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
445 // for this slice (i.e. the bounding box where the source
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
446 // slice is mapped to by the shear), so as to update "counter"
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
447 Matrix a = LinearAlgebra::ZeroMatrix(3, 3);
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
448 a(0,0) = a11;
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
449 a(0,2) = b1;
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
450 a(1,1) = a22;
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
451 a(1,2) = b2;
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
452 a(2,2) = 1;
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
453
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
454 unsigned int x1, y1, x2, y2;
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
455 if (GetProjectiveTransformExtent(x1, y1, x2, y2, a,
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
456 source.GetWidth(), source.GetHeight(),
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
457 intermediateWidth, intermediateHeight))
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
458 {
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
459 for (unsigned int y = y1; y <= y2; y++)
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
460 {
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
461 uint16_t* p = reinterpret_cast<uint16_t*>(counter->GetRow(y)) + x1;
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
462 for (unsigned int x = x1; x <= x2; x++, p++)
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
463 {
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
464 if (MIP)
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
465 {
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
466 // TODO - In the case of MIP, "counter" could be
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
467 // reduced to "PixelFormat_Grayscale8" to reduce
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
468 // memory usage
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
469 *p = 1;
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
470 }
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
471 else
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
472 {
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
473 *p += 1;
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
474 }
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
475 }
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
476 }
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
477 }
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
478 }
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
479
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
480
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
481 {
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
482 // (3.c) Shear the source slice into a temporary image
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
483 ImageBuffer3D::SliceReader reader(source, VolumeProjection_Axial, z);
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
484 ApplyAffineTransform(*intermediate, reader.GetAccessor(),
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
485 a11, 0, b1,
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
486 0, a22, b2,
340
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 212
diff changeset
487 shearInterpolation, true);
193
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
488 }
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
489
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
490
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
491 for (unsigned int y = 0; y < intermediateHeight; y++)
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
492 {
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
493 // (3.d) Accumulate the pixels of the sheared image into "accumulator"
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
494 const typename SourceTraits::PixelType* p =
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
495 reinterpret_cast<const typename SourceTraits::PixelType*>(intermediate->GetConstRow(y));
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
496
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
497 float* q = reinterpret_cast<float*>(accumulator->GetRow(y));
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
498
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
499 for (unsigned int x = 0; x < intermediateWidth; x++)
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
500 {
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
501 float pixel = SourceTraits::PixelToFloat(*p);
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
502
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
503 if (MIP)
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
504 {
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
505 // Get maximum for MIP
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
506 if (*q < pixel)
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
507 {
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
508 *q = pixel;
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
509 }
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
510 }
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
511 else
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
512 {
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
513 *q += pixel;
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
514 }
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
515
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
516 p++;
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
517 q++;
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
518 }
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
519 }
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
520 }
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
521
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
522
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
523 /**
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
524 * Step 4: The intermediate image (that will be transformed by the
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
525 * "warp") is now available as an accumulator image together with
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
526 * a counter image. "Flatten" these two images into one.
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
527 **/
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
528
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
529 intermediate.reset(new Orthanc::Image
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
530 (TargetFormat, intermediateWidth, intermediateHeight, false));
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
531
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
532 maxValue = 0;
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
533
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
534 for (unsigned int y = 0; y < intermediateHeight; y++)
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
535 {
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
536 const float *qacc = reinterpret_cast<const float*>(accumulator->GetConstRow(y));
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
537 const uint16_t *qcount = reinterpret_cast<const uint16_t*>(counter->GetConstRow(y));
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
538 typename TargetTraits::PixelType *p =
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
539 reinterpret_cast<typename TargetTraits::PixelType*>(intermediate->GetRow(y));
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
540
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
541 for (unsigned int x = 0; x < intermediateWidth; x++)
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
542 {
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
543 if (*qcount == 0)
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
544 {
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
545 TargetTraits::SetZero(*p);
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
546 }
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
547 else
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
548 {
705
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 700
diff changeset
549 *p = static_cast<typename TargetTraits::PixelType>
700
059e1fd05fd6 Introduced the ViewportController that sits between the application and the
Benjamin Golinvaux <bgo@osimis.io>
parents: 693
diff changeset
550 (*qacc / static_cast<float>(*qcount));
193
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
551
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
552 if (*p > maxValue)
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
553 {
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
554 maxValue = *p;
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
555 }
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
556 }
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
557
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
558 p++;
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
559 qacc++;
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
560 qcount++;
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
561 }
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
562 }
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
563
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
564 // We don't need the accumulator images anymore
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
565 accumulator.reset(NULL);
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
566 counter.reset(NULL);
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
567
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
568
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
569 /**
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
570 * Step 6: Apply the "warp" part of the transform to map the
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
571 * intermediate image to the final image.
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
572 **/
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
573
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
574 Matrix warp;
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
575
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
576 {
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
577 // (5.a) Compute the "warp" matrix by removing the 3rd row and
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
578 // 3rd column from the GetWarp() matrix
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
579 // Check out: ../../Resources/Computations/ComputeWarp.py
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
580
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
581 Matrix fullWarp = LinearAlgebra::Product
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
582 (shearWarp.GetIntrinsicParameters(), shearWarp.GetWarp());
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
583
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
584 const double v[] = {
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
585 fullWarp(0,0), fullWarp(0,1), fullWarp(0,3),
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
586 fullWarp(1,0), fullWarp(1,1), fullWarp(1,3),
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
587 fullWarp(2,0), fullWarp(2,1), fullWarp(2,3)
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
588 };
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
589
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
590 LinearAlgebra::FillMatrix(warp, 3, 3, v);
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
591 }
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
592
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
593 // (5.b) Apply the projective transform to the image
340
f5d5814a41a0 rendering BitmapStack
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 212
diff changeset
594 ApplyProjectiveTransform(target, *intermediate, warp, warpInterpolation, true);
193
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
595 }
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
596
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
597
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
598 template <Orthanc::PixelFormat SourceFormat,
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
599 Orthanc::PixelFormat TargetFormat>
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
600 static void ApplyAxialInternal2(Orthanc::ImageAccessor& target,
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
601 float& maxValue,
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
602 const Matrix& M_view,
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
603 const ImageBuffer3D& source,
735
c3bbb130abc4 removing dependencies in ImageBuffer3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 705
diff changeset
604 const VolumeImageGeometry& geometry,
193
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
605 bool mip,
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
606 double pixelSpacing,
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
607 unsigned int countSlices,
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
608 ImageInterpolation shearInterpolation,
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
609 ImageInterpolation warpInterpolation)
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
610 {
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
611 if (mip)
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
612 {
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
613 ApplyAxialInternal<SourceFormat, TargetFormat, true>
735
c3bbb130abc4 removing dependencies in ImageBuffer3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 705
diff changeset
614 (target, maxValue, M_view, source, geometry, pixelSpacing,
193
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
615 countSlices, shearInterpolation, warpInterpolation);
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
616 }
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
617 else
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
618 {
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
619 ApplyAxialInternal<SourceFormat, TargetFormat, false>
735
c3bbb130abc4 removing dependencies in ImageBuffer3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 705
diff changeset
620 (target, maxValue, M_view, source, geometry, pixelSpacing,
193
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
621 countSlices, shearInterpolation, warpInterpolation);
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
622 }
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
623 }
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
624
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
625
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
626 Orthanc::ImageAccessor*
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
627 ShearWarpProjectiveTransform::ApplyAxial(float& maxValue,
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
628 const Matrix& M_view,
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
629 const ImageBuffer3D& source,
735
c3bbb130abc4 removing dependencies in ImageBuffer3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 705
diff changeset
630 const VolumeImageGeometry& geometry,
193
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
631 Orthanc::PixelFormat targetFormat,
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
632 unsigned int targetWidth,
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
633 unsigned int targetHeight,
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
634 bool mip,
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
635 double pixelSpacing,
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
636 unsigned int countSlices,
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
637 ImageInterpolation shearInterpolation,
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
638 ImageInterpolation warpInterpolation)
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
639 {
1298
8a0a62189f46 replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1270
diff changeset
640 std::unique_ptr<Orthanc::ImageAccessor> target
193
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
641 (new Orthanc::Image(targetFormat, targetWidth, targetHeight, false));
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
642
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
643 if (source.GetFormat() == Orthanc::PixelFormat_Grayscale16 &&
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
644 targetFormat == Orthanc::PixelFormat_Grayscale16)
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
645 {
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
646 ApplyAxialInternal2<Orthanc::PixelFormat_Grayscale16,
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
647 Orthanc::PixelFormat_Grayscale16>
735
c3bbb130abc4 removing dependencies in ImageBuffer3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 705
diff changeset
648 (*target, maxValue, M_view, source, geometry, mip, pixelSpacing,
193
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
649 countSlices, shearInterpolation, warpInterpolation);
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
650 }
199
dabe9982fca3 shear-warp on int16_t
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 193
diff changeset
651 else if (source.GetFormat() == Orthanc::PixelFormat_SignedGrayscale16 &&
dabe9982fca3 shear-warp on int16_t
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 193
diff changeset
652 targetFormat == Orthanc::PixelFormat_SignedGrayscale16)
dabe9982fca3 shear-warp on int16_t
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 193
diff changeset
653 {
dabe9982fca3 shear-warp on int16_t
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 193
diff changeset
654 ApplyAxialInternal2<Orthanc::PixelFormat_SignedGrayscale16,
dabe9982fca3 shear-warp on int16_t
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 193
diff changeset
655 Orthanc::PixelFormat_SignedGrayscale16>
735
c3bbb130abc4 removing dependencies in ImageBuffer3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 705
diff changeset
656 (*target, maxValue, M_view, source, geometry, mip, pixelSpacing,
199
dabe9982fca3 shear-warp on int16_t
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 193
diff changeset
657 countSlices, shearInterpolation, warpInterpolation);
dabe9982fca3 shear-warp on int16_t
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 193
diff changeset
658 }
193
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
659 else
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
660 {
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
661 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented);
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
662 }
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
663
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
664 return target.release();
4abddd083374 ShearWarpProjectiveTransform::ApplyAxial()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 191
diff changeset
665 }
191
46cb2eedc2e0 ShearWarpProjectiveTransform
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
666 }