Mercurial > hg > orthanc-stone
annotate OrthancStone/Sources/Toolbox/CoordinateSystem3D.cpp @ 1640:52b8b96cb55f
cleaning namespaces
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 10 Nov 2020 16:55:22 +0100 |
parents | 78509230f0d7 |
children | 4a43106bc122 |
rev | line source |
---|---|
0 | 1 /** |
2 * Stone of Orthanc | |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
4 * Department, University Hospital of Liege, Belgium | |
1270
2d8ab34c8c91
upgrade to year 2020
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1020
diff
changeset
|
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium |
0 | 6 * |
7 * 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
|
8 * modify it under the terms of the GNU Lesser General Public License |
47 | 9 * as published by the Free Software Foundation, either version 3 of |
10 * the License, or (at your option) any later version. | |
0 | 11 * |
12 * This program is distributed in the hope that it will be useful, but | |
13 * 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
|
14 * 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
|
15 * Lesser General Public License for more details. |
1596
4fb8fdf03314
removed annoying whitespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1571
diff
changeset
|
16 * |
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
|
17 * 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
|
18 * 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
|
19 * <http://www.gnu.org/licenses/>. |
0 | 20 **/ |
21 | |
22 | |
110
53025eecbc95
renamed SliceGeometry as CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
89
diff
changeset
|
23 #include "CoordinateSystem3D.h" |
0 | 24 |
158
a053ca7fa5c6
LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
157
diff
changeset
|
25 #include "LinearAlgebra.h" |
0 | 26 #include "GeometryToolbox.h" |
27 | |
1455
30deba7bc8e2
simplifying include_directories
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1279
diff
changeset
|
28 #include <Logging.h> |
30deba7bc8e2
simplifying include_directories
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1279
diff
changeset
|
29 #include <Toolbox.h> |
30deba7bc8e2
simplifying include_directories
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1279
diff
changeset
|
30 #include <OrthancException.h> |
0 | 31 |
32 namespace OrthancStone | |
33 { | |
110
53025eecbc95
renamed SliceGeometry as CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
89
diff
changeset
|
34 void CoordinateSystem3D::CheckAndComputeNormal() |
0 | 35 { |
36 // DICOM expects normal vectors to define the axes: "The row and | |
37 // column direction cosine vectors shall be normal, i.e., the dot | |
38 // product of each direction cosine vector with itself shall be | |
39 // unity." | |
40 // http://dicom.nema.org/medical/dicom/current/output/chtml/part03/sect_C.7.6.2.html | |
158
a053ca7fa5c6
LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
157
diff
changeset
|
41 if (!LinearAlgebra::IsNear(boost::numeric::ublas::norm_2(axisX_), 1.0) || |
a053ca7fa5c6
LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
157
diff
changeset
|
42 !LinearAlgebra::IsNear(boost::numeric::ublas::norm_2(axisY_), 1.0)) |
0 | 43 { |
1630
78509230f0d7
SortedFrames sharing code with CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1598
diff
changeset
|
44 LOG(WARNING) << "Invalid 3D geometry: Axes are not normal vectors"; |
78509230f0d7
SortedFrames sharing code with CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1598
diff
changeset
|
45 SetupCanonical(); |
0 | 46 } |
47 | |
48 // The vectors within "Image Orientation Patient" must be | |
49 // orthogonal, according to the DICOM specification: "The row and | |
50 // column direction cosine vectors shall be orthogonal, i.e., | |
51 // their dot product shall be zero." | |
52 // http://dicom.nema.org/medical/dicom/current/output/chtml/part03/sect_C.7.6.2.html | |
1630
78509230f0d7
SortedFrames sharing code with CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1598
diff
changeset
|
53 else if (!LinearAlgebra::IsCloseToZero(boost::numeric::ublas::inner_prod(axisX_, axisY_))) |
0 | 54 { |
1630
78509230f0d7
SortedFrames sharing code with CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1598
diff
changeset
|
55 LOG(WARNING) << "Invalid 3D geometry: Image orientation patient is not orthogonal"; |
78509230f0d7
SortedFrames sharing code with CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1598
diff
changeset
|
56 SetupCanonical(); |
0 | 57 } |
1630
78509230f0d7
SortedFrames sharing code with CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1598
diff
changeset
|
58 else |
78509230f0d7
SortedFrames sharing code with CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1598
diff
changeset
|
59 { |
78509230f0d7
SortedFrames sharing code with CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1598
diff
changeset
|
60 LinearAlgebra::CrossProduct(normal_, axisX_, axisY_); |
0 | 61 |
1630
78509230f0d7
SortedFrames sharing code with CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1598
diff
changeset
|
62 d_ = -(normal_[0] * origin_[0] + normal_[1] * origin_[1] + normal_[2] * origin_[2]); |
0 | 63 |
1630
78509230f0d7
SortedFrames sharing code with CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1598
diff
changeset
|
64 // Just a sanity check, it should be useless by construction |
78509230f0d7
SortedFrames sharing code with CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1598
diff
changeset
|
65 assert(LinearAlgebra::IsNear(boost::numeric::ublas::norm_2(normal_), 1.0)); |
78509230f0d7
SortedFrames sharing code with CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1598
diff
changeset
|
66 } |
0 | 67 } |
68 | |
69 | |
110
53025eecbc95
renamed SliceGeometry as CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
89
diff
changeset
|
70 void CoordinateSystem3D::SetupCanonical() |
0 | 71 { |
1630
78509230f0d7
SortedFrames sharing code with CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1598
diff
changeset
|
72 valid_ = false; |
78509230f0d7
SortedFrames sharing code with CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1598
diff
changeset
|
73 |
158
a053ca7fa5c6
LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
157
diff
changeset
|
74 LinearAlgebra::AssignVector(origin_, 0, 0, 0); |
a053ca7fa5c6
LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
157
diff
changeset
|
75 LinearAlgebra::AssignVector(axisX_, 1, 0, 0); |
a053ca7fa5c6
LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
157
diff
changeset
|
76 LinearAlgebra::AssignVector(axisY_, 0, 1, 0); |
1630
78509230f0d7
SortedFrames sharing code with CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1598
diff
changeset
|
77 LinearAlgebra::AssignVector(normal_, 0, 0, 1); |
78509230f0d7
SortedFrames sharing code with CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1598
diff
changeset
|
78 d_ = 0; |
0 | 79 } |
80 | |
81 | |
110
53025eecbc95
renamed SliceGeometry as CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
89
diff
changeset
|
82 CoordinateSystem3D::CoordinateSystem3D(const Vector& origin, |
53025eecbc95
renamed SliceGeometry as CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
89
diff
changeset
|
83 const Vector& axisX, |
53025eecbc95
renamed SliceGeometry as CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
89
diff
changeset
|
84 const Vector& axisY) : |
1630
78509230f0d7
SortedFrames sharing code with CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1598
diff
changeset
|
85 valid_(true), |
0 | 86 origin_(origin), |
87 axisX_(axisX), | |
88 axisY_(axisY) | |
89 { | |
90 CheckAndComputeNormal(); | |
91 } | |
92 | |
93 | |
110
53025eecbc95
renamed SliceGeometry as CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
89
diff
changeset
|
94 void CoordinateSystem3D::Setup(const std::string& imagePositionPatient, |
53025eecbc95
renamed SliceGeometry as CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
89
diff
changeset
|
95 const std::string& imageOrientationPatient) |
0 | 96 { |
1630
78509230f0d7
SortedFrames sharing code with CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1598
diff
changeset
|
97 valid_ = true; |
78509230f0d7
SortedFrames sharing code with CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1598
diff
changeset
|
98 |
0 | 99 std::string tmpPosition = Orthanc::Toolbox::StripSpaces(imagePositionPatient); |
100 std::string tmpOrientation = Orthanc::Toolbox::StripSpaces(imageOrientationPatient); | |
101 | |
102 Vector orientation; | |
158
a053ca7fa5c6
LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
157
diff
changeset
|
103 if (!LinearAlgebra::ParseVector(origin_, tmpPosition) || |
a053ca7fa5c6
LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
157
diff
changeset
|
104 !LinearAlgebra::ParseVector(orientation, tmpOrientation) || |
0 | 105 origin_.size() != 3 || |
106 orientation.size() != 6) | |
107 { | |
1630
78509230f0d7
SortedFrames sharing code with CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1598
diff
changeset
|
108 LOG(WARNING) << "Bad 3D geometry: image position/orientation patient: \"" |
78509230f0d7
SortedFrames sharing code with CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1598
diff
changeset
|
109 << tmpPosition << "\" / \"" << tmpOrientation << "\""; |
78509230f0d7
SortedFrames sharing code with CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1598
diff
changeset
|
110 SetupCanonical(); |
0 | 111 } |
1630
78509230f0d7
SortedFrames sharing code with CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1598
diff
changeset
|
112 else |
78509230f0d7
SortedFrames sharing code with CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1598
diff
changeset
|
113 { |
78509230f0d7
SortedFrames sharing code with CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1598
diff
changeset
|
114 axisX_.resize(3); |
78509230f0d7
SortedFrames sharing code with CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1598
diff
changeset
|
115 axisX_[0] = orientation[0]; |
78509230f0d7
SortedFrames sharing code with CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1598
diff
changeset
|
116 axisX_[1] = orientation[1]; |
78509230f0d7
SortedFrames sharing code with CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1598
diff
changeset
|
117 axisX_[2] = orientation[2]; |
0 | 118 |
1630
78509230f0d7
SortedFrames sharing code with CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1598
diff
changeset
|
119 axisY_.resize(3); |
78509230f0d7
SortedFrames sharing code with CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1598
diff
changeset
|
120 axisY_[0] = orientation[3]; |
78509230f0d7
SortedFrames sharing code with CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1598
diff
changeset
|
121 axisY_[1] = orientation[4]; |
78509230f0d7
SortedFrames sharing code with CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1598
diff
changeset
|
122 axisY_[2] = orientation[5]; |
0 | 123 |
1630
78509230f0d7
SortedFrames sharing code with CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1598
diff
changeset
|
124 CheckAndComputeNormal(); |
78509230f0d7
SortedFrames sharing code with CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1598
diff
changeset
|
125 } |
0 | 126 } |
127 | |
128 | |
1504 | 129 CoordinateSystem3D::CoordinateSystem3D(const IDicomDataset& dicom) |
0 | 130 { |
32 | 131 std::string a, b; |
132 | |
1571 | 133 if (dicom.GetStringValue(a, DicomPath(Orthanc::DICOM_TAG_IMAGE_POSITION_PATIENT)) && |
134 dicom.GetStringValue(b, DicomPath(Orthanc::DICOM_TAG_IMAGE_ORIENTATION_PATIENT))) | |
0 | 135 { |
32 | 136 Setup(a, b); |
0 | 137 } |
138 else | |
139 { | |
140 SetupCanonical(); | |
141 } | |
122
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
142 } |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
143 |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
144 |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
145 CoordinateSystem3D::CoordinateSystem3D(const Orthanc::DicomMap& dicom) |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
146 { |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
147 std::string a, b; |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
148 |
994
1f74bc3459ba
fix build due to rename in Orthanc::DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
986
diff
changeset
|
149 if (dicom.LookupStringValue(a, Orthanc::DICOM_TAG_IMAGE_POSITION_PATIENT, false) && |
1f74bc3459ba
fix build due to rename in Orthanc::DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
986
diff
changeset
|
150 dicom.LookupStringValue(b, Orthanc::DICOM_TAG_IMAGE_ORIENTATION_PATIENT, false)) |
122
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
151 { |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
152 Setup(a, b); |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
153 } |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
154 else |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
155 { |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
156 SetupCanonical(); |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
157 } |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
158 } |
0 | 159 |
160 | |
760
1181e1ad98ec
progressive loading working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
757
diff
changeset
|
161 void CoordinateSystem3D::SetOrigin(const Vector& origin) |
1181e1ad98ec
progressive loading working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
757
diff
changeset
|
162 { |
1181e1ad98ec
progressive loading working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
757
diff
changeset
|
163 if (origin.size() != 3) |
1181e1ad98ec
progressive loading working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
757
diff
changeset
|
164 { |
1181e1ad98ec
progressive loading working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
757
diff
changeset
|
165 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); |
1181e1ad98ec
progressive loading working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
757
diff
changeset
|
166 } |
1181e1ad98ec
progressive loading working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
757
diff
changeset
|
167 else |
1181e1ad98ec
progressive loading working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
757
diff
changeset
|
168 { |
1181e1ad98ec
progressive loading working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
757
diff
changeset
|
169 origin_ = origin; |
1181e1ad98ec
progressive loading working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
757
diff
changeset
|
170 } |
1181e1ad98ec
progressive loading working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
757
diff
changeset
|
171 } |
1181e1ad98ec
progressive loading working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
757
diff
changeset
|
172 |
1181e1ad98ec
progressive loading working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
757
diff
changeset
|
173 |
110
53025eecbc95
renamed SliceGeometry as CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
89
diff
changeset
|
174 Vector CoordinateSystem3D::MapSliceToWorldCoordinates(double x, |
53025eecbc95
renamed SliceGeometry as CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
89
diff
changeset
|
175 double y) const |
0 | 176 { |
177 return origin_ + x * axisX_ + y * axisY_; | |
178 } | |
179 | |
180 | |
110
53025eecbc95
renamed SliceGeometry as CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
89
diff
changeset
|
181 double CoordinateSystem3D::ProjectAlongNormal(const Vector& point) const |
0 | 182 { |
183 return boost::numeric::ublas::inner_prod(point, normal_); | |
184 } | |
185 | |
1013
53cc787bd7bc
- Added an optimized ProjectPoint2 to CoordinateSystem3D. It has *not* replaced
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
186 void CoordinateSystem3D::ProjectPoint2(double& offsetX, double& offsetY, const Vector& point) const |
53cc787bd7bc
- Added an optimized ProjectPoint2 to CoordinateSystem3D. It has *not* replaced
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
187 { |
53cc787bd7bc
- Added an optimized ProjectPoint2 to CoordinateSystem3D. It has *not* replaced
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
188 // Project the point onto the slice |
53cc787bd7bc
- Added an optimized ProjectPoint2 to CoordinateSystem3D. It has *not* replaced
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
189 double projectionX,projectionY,projectionZ; |
53cc787bd7bc
- Added an optimized ProjectPoint2 to CoordinateSystem3D. It has *not* replaced
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
190 GeometryToolbox::ProjectPointOntoPlane2(projectionX, projectionY, projectionZ, point, normal_, origin_); |
53cc787bd7bc
- Added an optimized ProjectPoint2 to CoordinateSystem3D. It has *not* replaced
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
191 |
53cc787bd7bc
- Added an optimized ProjectPoint2 to CoordinateSystem3D. It has *not* replaced
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
192 // As the axes are orthonormal vectors thanks to |
53cc787bd7bc
- Added an optimized ProjectPoint2 to CoordinateSystem3D. It has *not* replaced
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
193 // CheckAndComputeNormal(), the following dot products give the |
53cc787bd7bc
- Added an optimized ProjectPoint2 to CoordinateSystem3D. It has *not* replaced
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
194 // offset of the origin of the slice wrt. the origin of the |
53cc787bd7bc
- Added an optimized ProjectPoint2 to CoordinateSystem3D. It has *not* replaced
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
195 // reference plane https://en.wikipedia.org/wiki/Vector_projection |
53cc787bd7bc
- Added an optimized ProjectPoint2 to CoordinateSystem3D. It has *not* replaced
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
196 offsetX = axisX_[0] * (projectionX - origin_[0]) + axisX_[1] * (projectionY - origin_[1]) + axisX_[2] * (projectionZ - origin_[2]); |
53cc787bd7bc
- Added an optimized ProjectPoint2 to CoordinateSystem3D. It has *not* replaced
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
197 offsetY = axisY_[0] * (projectionX - origin_[0]) + axisY_[1] * (projectionY - origin_[1]) + axisY_[2] * (projectionZ - origin_[2]); |
53cc787bd7bc
- Added an optimized ProjectPoint2 to CoordinateSystem3D. It has *not* replaced
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
198 } |
0 | 199 |
110
53025eecbc95
renamed SliceGeometry as CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
89
diff
changeset
|
200 void CoordinateSystem3D::ProjectPoint(double& offsetX, |
53025eecbc95
renamed SliceGeometry as CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
89
diff
changeset
|
201 double& offsetY, |
53025eecbc95
renamed SliceGeometry as CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
89
diff
changeset
|
202 const Vector& point) const |
0 | 203 { |
204 // Project the point onto the slice | |
205 Vector projection; | |
206 GeometryToolbox::ProjectPointOntoPlane(projection, point, normal_, origin_); | |
207 | |
208 // As the axes are orthonormal vectors thanks to | |
209 // CheckAndComputeNormal(), the following dot products give the | |
210 // offset of the origin of the slice wrt. the origin of the | |
211 // reference plane https://en.wikipedia.org/wiki/Vector_projection | |
212 offsetX = boost::numeric::ublas::inner_prod(axisX_, projection - origin_); | |
213 offsetY = boost::numeric::ublas::inner_prod(axisY_, projection - origin_); | |
214 } | |
151
c5044bbfc303
CoordinateSystem3D::IntersectSegment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
135
diff
changeset
|
215 |
152 | 216 bool CoordinateSystem3D::IntersectSegment(Vector& p, |
151
c5044bbfc303
CoordinateSystem3D::IntersectSegment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
135
diff
changeset
|
217 const Vector& edgeFrom, |
c5044bbfc303
CoordinateSystem3D::IntersectSegment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
135
diff
changeset
|
218 const Vector& edgeTo) const |
c5044bbfc303
CoordinateSystem3D::IntersectSegment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
135
diff
changeset
|
219 { |
157
2309e8d86efe
IntersectPlaneAndLine
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
152
diff
changeset
|
220 return GeometryToolbox::IntersectPlaneAndSegment(p, normal_, d_, edgeFrom, edgeTo); |
2309e8d86efe
IntersectPlaneAndLine
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
152
diff
changeset
|
221 } |
2309e8d86efe
IntersectPlaneAndLine
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
152
diff
changeset
|
222 |
2309e8d86efe
IntersectPlaneAndLine
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
152
diff
changeset
|
223 |
2309e8d86efe
IntersectPlaneAndLine
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
152
diff
changeset
|
224 bool CoordinateSystem3D::IntersectLine(Vector& p, |
2309e8d86efe
IntersectPlaneAndLine
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
152
diff
changeset
|
225 const Vector& origin, |
2309e8d86efe
IntersectPlaneAndLine
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
152
diff
changeset
|
226 const Vector& direction) const |
2309e8d86efe
IntersectPlaneAndLine
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
152
diff
changeset
|
227 { |
2309e8d86efe
IntersectPlaneAndLine
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
152
diff
changeset
|
228 return GeometryToolbox::IntersectPlaneAndLine(p, normal_, d_, origin, direction); |
151
c5044bbfc303
CoordinateSystem3D::IntersectSegment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
135
diff
changeset
|
229 } |
647
6af3099ed8da
uncoupling OrthancStone::SlicesSorter from OrthancStone::Slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
230 |
6af3099ed8da
uncoupling OrthancStone::SlicesSorter from OrthancStone::Slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
231 |
757 | 232 bool CoordinateSystem3D::ComputeDistance(double& distance, |
233 const CoordinateSystem3D& a, | |
234 const CoordinateSystem3D& b) | |
647
6af3099ed8da
uncoupling OrthancStone::SlicesSorter from OrthancStone::Slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
235 { |
986 | 236 bool opposite = false; // Ignored |
647
6af3099ed8da
uncoupling OrthancStone::SlicesSorter from OrthancStone::Slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
237 |
1640
52b8b96cb55f
cleaning namespaces
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1630
diff
changeset
|
238 if (GeometryToolbox::IsParallelOrOpposite(opposite, a.GetNormal(), b.GetNormal())) |
647
6af3099ed8da
uncoupling OrthancStone::SlicesSorter from OrthancStone::Slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
239 { |
6af3099ed8da
uncoupling OrthancStone::SlicesSorter from OrthancStone::Slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
240 distance = std::abs(a.ProjectAlongNormal(a.GetOrigin()) - |
6af3099ed8da
uncoupling OrthancStone::SlicesSorter from OrthancStone::Slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
241 a.ProjectAlongNormal(b.GetOrigin())); |
6af3099ed8da
uncoupling OrthancStone::SlicesSorter from OrthancStone::Slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
242 return true; |
6af3099ed8da
uncoupling OrthancStone::SlicesSorter from OrthancStone::Slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
243 } |
6af3099ed8da
uncoupling OrthancStone::SlicesSorter from OrthancStone::Slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
244 else |
6af3099ed8da
uncoupling OrthancStone::SlicesSorter from OrthancStone::Slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
245 { |
6af3099ed8da
uncoupling OrthancStone::SlicesSorter from OrthancStone::Slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
246 return false; |
6af3099ed8da
uncoupling OrthancStone::SlicesSorter from OrthancStone::Slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
247 } |
6af3099ed8da
uncoupling OrthancStone::SlicesSorter from OrthancStone::Slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
248 } |
949
32eaf4929b08
OrthancMultiframeVolumeLoader and OrthancSeriesVolumeProgressiveLoader now implement IGeometryProvider so that the geometry reference can be switched (CT or DOSE, for instance) + VolumeImageGeometry::SetSize renamed to VolumeImageGeometry::SetSizeInVoxels + prevent text layer update if text or properties do not change + a few stream operator<< for debug (Vector, Matrix,...) + fixed memory access aligment issues in ImageBuffer3D::ExtractSagittalSlice + fix for wrong screen Y offset of mpr slices in DicomVolumeImageMPRSlicer.
Benjamin Golinvaux <bgo@osimis.io>
parents:
760
diff
changeset
|
249 |
32eaf4929b08
OrthancMultiframeVolumeLoader and OrthancSeriesVolumeProgressiveLoader now implement IGeometryProvider so that the geometry reference can be switched (CT or DOSE, for instance) + VolumeImageGeometry::SetSize renamed to VolumeImageGeometry::SetSizeInVoxels + prevent text layer update if text or properties do not change + a few stream operator<< for debug (Vector, Matrix,...) + fixed memory access aligment issues in ImageBuffer3D::ExtractSagittalSlice + fix for wrong screen Y offset of mpr slices in DicomVolumeImageMPRSlicer.
Benjamin Golinvaux <bgo@osimis.io>
parents:
760
diff
changeset
|
250 std::ostream& operator<< (std::ostream& s, const CoordinateSystem3D& that) |
32eaf4929b08
OrthancMultiframeVolumeLoader and OrthancSeriesVolumeProgressiveLoader now implement IGeometryProvider so that the geometry reference can be switched (CT or DOSE, for instance) + VolumeImageGeometry::SetSize renamed to VolumeImageGeometry::SetSizeInVoxels + prevent text layer update if text or properties do not change + a few stream operator<< for debug (Vector, Matrix,...) + fixed memory access aligment issues in ImageBuffer3D::ExtractSagittalSlice + fix for wrong screen Y offset of mpr slices in DicomVolumeImageMPRSlicer.
Benjamin Golinvaux <bgo@osimis.io>
parents:
760
diff
changeset
|
251 { |
32eaf4929b08
OrthancMultiframeVolumeLoader and OrthancSeriesVolumeProgressiveLoader now implement IGeometryProvider so that the geometry reference can be switched (CT or DOSE, for instance) + VolumeImageGeometry::SetSize renamed to VolumeImageGeometry::SetSizeInVoxels + prevent text layer update if text or properties do not change + a few stream operator<< for debug (Vector, Matrix,...) + fixed memory access aligment issues in ImageBuffer3D::ExtractSagittalSlice + fix for wrong screen Y offset of mpr slices in DicomVolumeImageMPRSlicer.
Benjamin Golinvaux <bgo@osimis.io>
parents:
760
diff
changeset
|
252 s << "origin: " << that.origin_ << " normal: " << that.normal_ |
32eaf4929b08
OrthancMultiframeVolumeLoader and OrthancSeriesVolumeProgressiveLoader now implement IGeometryProvider so that the geometry reference can be switched (CT or DOSE, for instance) + VolumeImageGeometry::SetSize renamed to VolumeImageGeometry::SetSizeInVoxels + prevent text layer update if text or properties do not change + a few stream operator<< for debug (Vector, Matrix,...) + fixed memory access aligment issues in ImageBuffer3D::ExtractSagittalSlice + fix for wrong screen Y offset of mpr slices in DicomVolumeImageMPRSlicer.
Benjamin Golinvaux <bgo@osimis.io>
parents:
760
diff
changeset
|
253 << " axisX: " << that.axisX_ << " axisY: " << that.axisY_ |
32eaf4929b08
OrthancMultiframeVolumeLoader and OrthancSeriesVolumeProgressiveLoader now implement IGeometryProvider so that the geometry reference can be switched (CT or DOSE, for instance) + VolumeImageGeometry::SetSize renamed to VolumeImageGeometry::SetSizeInVoxels + prevent text layer update if text or properties do not change + a few stream operator<< for debug (Vector, Matrix,...) + fixed memory access aligment issues in ImageBuffer3D::ExtractSagittalSlice + fix for wrong screen Y offset of mpr slices in DicomVolumeImageMPRSlicer.
Benjamin Golinvaux <bgo@osimis.io>
parents:
760
diff
changeset
|
254 << " D: " << that.d_; |
32eaf4929b08
OrthancMultiframeVolumeLoader and OrthancSeriesVolumeProgressiveLoader now implement IGeometryProvider so that the geometry reference can be switched (CT or DOSE, for instance) + VolumeImageGeometry::SetSize renamed to VolumeImageGeometry::SetSizeInVoxels + prevent text layer update if text or properties do not change + a few stream operator<< for debug (Vector, Matrix,...) + fixed memory access aligment issues in ImageBuffer3D::ExtractSagittalSlice + fix for wrong screen Y offset of mpr slices in DicomVolumeImageMPRSlicer.
Benjamin Golinvaux <bgo@osimis.io>
parents:
760
diff
changeset
|
255 return s; |
32eaf4929b08
OrthancMultiframeVolumeLoader and OrthancSeriesVolumeProgressiveLoader now implement IGeometryProvider so that the geometry reference can be switched (CT or DOSE, for instance) + VolumeImageGeometry::SetSize renamed to VolumeImageGeometry::SetSizeInVoxels + prevent text layer update if text or properties do not change + a few stream operator<< for debug (Vector, Matrix,...) + fixed memory access aligment issues in ImageBuffer3D::ExtractSagittalSlice + fix for wrong screen Y offset of mpr slices in DicomVolumeImageMPRSlicer.
Benjamin Golinvaux <bgo@osimis.io>
parents:
760
diff
changeset
|
256 } |
32eaf4929b08
OrthancMultiframeVolumeLoader and OrthancSeriesVolumeProgressiveLoader now implement IGeometryProvider so that the geometry reference can be switched (CT or DOSE, for instance) + VolumeImageGeometry::SetSize renamed to VolumeImageGeometry::SetSizeInVoxels + prevent text layer update if text or properties do not change + a few stream operator<< for debug (Vector, Matrix,...) + fixed memory access aligment issues in ImageBuffer3D::ExtractSagittalSlice + fix for wrong screen Y offset of mpr slices in DicomVolumeImageMPRSlicer.
Benjamin Golinvaux <bgo@osimis.io>
parents:
760
diff
changeset
|
257 |
1161
19b1c8caade4
fix sagittal geometry
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1020
diff
changeset
|
258 |
19b1c8caade4
fix sagittal geometry
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1020
diff
changeset
|
259 CoordinateSystem3D CoordinateSystem3D::NormalizeCuttingPlane(const CoordinateSystem3D& plane) |
19b1c8caade4
fix sagittal geometry
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1020
diff
changeset
|
260 { |
19b1c8caade4
fix sagittal geometry
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1020
diff
changeset
|
261 double ox, oy; |
19b1c8caade4
fix sagittal geometry
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1020
diff
changeset
|
262 plane.ProjectPoint(ox, oy, LinearAlgebra::CreateVector(0, 0, 0)); |
19b1c8caade4
fix sagittal geometry
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1020
diff
changeset
|
263 |
19b1c8caade4
fix sagittal geometry
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1020
diff
changeset
|
264 CoordinateSystem3D normalized(plane); |
19b1c8caade4
fix sagittal geometry
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1020
diff
changeset
|
265 normalized.SetOrigin(plane.MapSliceToWorldCoordinates(ox, oy)); |
19b1c8caade4
fix sagittal geometry
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1020
diff
changeset
|
266 return normalized; |
19b1c8caade4
fix sagittal geometry
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1020
diff
changeset
|
267 } |
0 | 268 } |