Mercurial > hg > orthanc-stone
annotate OrthancStone/Sources/Toolbox/CoordinateSystem3D.cpp @ 2171:8e3c403cc643
Improved support of the (0028,9132) tag for Philips multiframe images
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 22 Oct 2024 15:40:40 +0200 |
parents | 16c01cc201e7 |
children |
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 | |
2124
16c01cc201e7
updated copyright, as Osimis is not active on Orthanc anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2114
diff
changeset
|
5 * Copyright (C) 2017-2023 Osimis S.A., Belgium |
2114
c23eef785569
update year to 2024
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2077
diff
changeset
|
6 * Copyright (C) 2021-2024 Sebastien Jodogne, ICTEAM UCLouvain, Belgium |
0 | 7 * |
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 |
47 | 10 * as published by the Free Software Foundation, either version 3 of |
11 * the License, or (at your option) any later version. | |
0 | 12 * |
13 * This program is distributed in the hope that it will be useful, but | |
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:
1571
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/>. |
0 | 21 **/ |
22 | |
23 | |
110
53025eecbc95
renamed SliceGeometry as CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
89
diff
changeset
|
24 #include "CoordinateSystem3D.h" |
0 | 25 |
158
a053ca7fa5c6
LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
157
diff
changeset
|
26 #include "LinearAlgebra.h" |
0 | 27 #include "GeometryToolbox.h" |
28 | |
1455
30deba7bc8e2
simplifying include_directories
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1279
diff
changeset
|
29 #include <Logging.h> |
30deba7bc8e2
simplifying include_directories
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1279
diff
changeset
|
30 #include <Toolbox.h> |
30deba7bc8e2
simplifying include_directories
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1279
diff
changeset
|
31 #include <OrthancException.h> |
0 | 32 |
33 namespace OrthancStone | |
34 { | |
110
53025eecbc95
renamed SliceGeometry as CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
89
diff
changeset
|
35 void CoordinateSystem3D::CheckAndComputeNormal() |
0 | 36 { |
1717
391c798e4dae
fix for KNIX sample dataset
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1650
diff
changeset
|
37 /** |
391c798e4dae
fix for KNIX sample dataset
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1650
diff
changeset
|
38 * DICOM expects normal vectors to define the axes: "The row and |
391c798e4dae
fix for KNIX sample dataset
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1650
diff
changeset
|
39 * column direction cosine vectors shall be normal, i.e., the dot |
391c798e4dae
fix for KNIX sample dataset
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1650
diff
changeset
|
40 * product of each direction cosine vector with itself shall be |
391c798e4dae
fix for KNIX sample dataset
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1650
diff
changeset
|
41 * unity." |
391c798e4dae
fix for KNIX sample dataset
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1650
diff
changeset
|
42 * http://dicom.nema.org/medical/dicom/current/output/chtml/part03/sect_C.7.6.2.html |
391c798e4dae
fix for KNIX sample dataset
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1650
diff
changeset
|
43 **/ |
158
a053ca7fa5c6
LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
157
diff
changeset
|
44 if (!LinearAlgebra::IsNear(boost::numeric::ublas::norm_2(axisX_), 1.0) || |
a053ca7fa5c6
LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
157
diff
changeset
|
45 !LinearAlgebra::IsNear(boost::numeric::ublas::norm_2(axisY_), 1.0)) |
0 | 46 { |
1630
78509230f0d7
SortedFrames sharing code with CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1598
diff
changeset
|
47 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
|
48 SetupCanonical(); |
0 | 49 } |
1717
391c798e4dae
fix for KNIX sample dataset
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1650
diff
changeset
|
50 |
391c798e4dae
fix for KNIX sample dataset
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1650
diff
changeset
|
51 /** |
391c798e4dae
fix for KNIX sample dataset
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1650
diff
changeset
|
52 * The vectors within "Image Orientation Patient" must be |
391c798e4dae
fix for KNIX sample dataset
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1650
diff
changeset
|
53 * orthogonal, according to the DICOM specification: "The row and |
391c798e4dae
fix for KNIX sample dataset
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1650
diff
changeset
|
54 * column direction cosine vectors shall be orthogonal, i.e., |
391c798e4dae
fix for KNIX sample dataset
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1650
diff
changeset
|
55 * their dot product shall be zero." |
391c798e4dae
fix for KNIX sample dataset
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1650
diff
changeset
|
56 * http://dicom.nema.org/medical/dicom/current/output/chtml/part03/sect_C.7.6.2.html |
391c798e4dae
fix for KNIX sample dataset
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1650
diff
changeset
|
57 * |
391c798e4dae
fix for KNIX sample dataset
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1650
diff
changeset
|
58 * The "0.00001" threshold is needed for KNIX (on this sample |
391c798e4dae
fix for KNIX sample dataset
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1650
diff
changeset
|
59 * image, the inner product equals "0.000003", which is rejected |
391c798e4dae
fix for KNIX sample dataset
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1650
diff
changeset
|
60 * by "LinearAlgebra::IsCloseToZero()"). |
391c798e4dae
fix for KNIX sample dataset
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1650
diff
changeset
|
61 **/ |
391c798e4dae
fix for KNIX sample dataset
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1650
diff
changeset
|
62 else if (!LinearAlgebra::IsNear(0, boost::numeric::ublas::inner_prod(axisX_, axisY_), 0.00001)) |
0 | 63 { |
1630
78509230f0d7
SortedFrames sharing code with CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1598
diff
changeset
|
64 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
|
65 SetupCanonical(); |
0 | 66 } |
1630
78509230f0d7
SortedFrames sharing code with CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1598
diff
changeset
|
67 else |
78509230f0d7
SortedFrames sharing code with CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1598
diff
changeset
|
68 { |
78509230f0d7
SortedFrames sharing code with CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1598
diff
changeset
|
69 LinearAlgebra::CrossProduct(normal_, axisX_, axisY_); |
0 | 70 |
1630
78509230f0d7
SortedFrames sharing code with CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1598
diff
changeset
|
71 d_ = -(normal_[0] * origin_[0] + normal_[1] * origin_[1] + normal_[2] * origin_[2]); |
0 | 72 |
1648
4a43106bc122
cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1640
diff
changeset
|
73 // Just a sanity check, it should be useless by construction (*) |
1630
78509230f0d7
SortedFrames sharing code with CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1598
diff
changeset
|
74 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
|
75 } |
0 | 76 } |
77 | |
78 | |
110
53025eecbc95
renamed SliceGeometry as CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
89
diff
changeset
|
79 void CoordinateSystem3D::SetupCanonical() |
0 | 80 { |
1630
78509230f0d7
SortedFrames sharing code with CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1598
diff
changeset
|
81 valid_ = false; |
78509230f0d7
SortedFrames sharing code with CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1598
diff
changeset
|
82 |
158
a053ca7fa5c6
LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
157
diff
changeset
|
83 LinearAlgebra::AssignVector(origin_, 0, 0, 0); |
a053ca7fa5c6
LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
157
diff
changeset
|
84 LinearAlgebra::AssignVector(axisX_, 1, 0, 0); |
a053ca7fa5c6
LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
157
diff
changeset
|
85 LinearAlgebra::AssignVector(axisY_, 0, 1, 0); |
1630
78509230f0d7
SortedFrames sharing code with CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1598
diff
changeset
|
86 LinearAlgebra::AssignVector(normal_, 0, 0, 1); |
78509230f0d7
SortedFrames sharing code with CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1598
diff
changeset
|
87 d_ = 0; |
0 | 88 } |
89 | |
90 | |
110
53025eecbc95
renamed SliceGeometry as CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
89
diff
changeset
|
91 CoordinateSystem3D::CoordinateSystem3D(const Vector& origin, |
53025eecbc95
renamed SliceGeometry as CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
89
diff
changeset
|
92 const Vector& axisX, |
53025eecbc95
renamed SliceGeometry as CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
89
diff
changeset
|
93 const Vector& axisY) : |
1630
78509230f0d7
SortedFrames sharing code with CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1598
diff
changeset
|
94 valid_(true), |
0 | 95 origin_(origin), |
96 axisX_(axisX), | |
97 axisY_(axisY) | |
98 { | |
99 CheckAndComputeNormal(); | |
100 } | |
101 | |
102 | |
110
53025eecbc95
renamed SliceGeometry as CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
89
diff
changeset
|
103 void CoordinateSystem3D::Setup(const std::string& imagePositionPatient, |
53025eecbc95
renamed SliceGeometry as CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
89
diff
changeset
|
104 const std::string& imageOrientationPatient) |
0 | 105 { |
1630
78509230f0d7
SortedFrames sharing code with CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1598
diff
changeset
|
106 valid_ = true; |
78509230f0d7
SortedFrames sharing code with CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1598
diff
changeset
|
107 |
0 | 108 std::string tmpPosition = Orthanc::Toolbox::StripSpaces(imagePositionPatient); |
109 std::string tmpOrientation = Orthanc::Toolbox::StripSpaces(imageOrientationPatient); | |
110 | |
111 Vector orientation; | |
158
a053ca7fa5c6
LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
157
diff
changeset
|
112 if (!LinearAlgebra::ParseVector(origin_, tmpPosition) || |
a053ca7fa5c6
LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
157
diff
changeset
|
113 !LinearAlgebra::ParseVector(orientation, tmpOrientation) || |
0 | 114 origin_.size() != 3 || |
115 orientation.size() != 6) | |
116 { | |
1630
78509230f0d7
SortedFrames sharing code with CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1598
diff
changeset
|
117 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
|
118 << tmpPosition << "\" / \"" << tmpOrientation << "\""; |
78509230f0d7
SortedFrames sharing code with CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1598
diff
changeset
|
119 SetupCanonical(); |
0 | 120 } |
1630
78509230f0d7
SortedFrames sharing code with CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1598
diff
changeset
|
121 else |
78509230f0d7
SortedFrames sharing code with CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1598
diff
changeset
|
122 { |
78509230f0d7
SortedFrames sharing code with CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1598
diff
changeset
|
123 axisX_.resize(3); |
78509230f0d7
SortedFrames sharing code with CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1598
diff
changeset
|
124 axisX_[0] = orientation[0]; |
78509230f0d7
SortedFrames sharing code with CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1598
diff
changeset
|
125 axisX_[1] = orientation[1]; |
78509230f0d7
SortedFrames sharing code with CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1598
diff
changeset
|
126 axisX_[2] = orientation[2]; |
0 | 127 |
1630
78509230f0d7
SortedFrames sharing code with CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1598
diff
changeset
|
128 axisY_.resize(3); |
78509230f0d7
SortedFrames sharing code with CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1598
diff
changeset
|
129 axisY_[0] = orientation[3]; |
78509230f0d7
SortedFrames sharing code with CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1598
diff
changeset
|
130 axisY_[1] = orientation[4]; |
78509230f0d7
SortedFrames sharing code with CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1598
diff
changeset
|
131 axisY_[2] = orientation[5]; |
0 | 132 |
1630
78509230f0d7
SortedFrames sharing code with CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1598
diff
changeset
|
133 CheckAndComputeNormal(); |
78509230f0d7
SortedFrames sharing code with CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1598
diff
changeset
|
134 } |
0 | 135 } |
136 | |
137 | |
1504 | 138 CoordinateSystem3D::CoordinateSystem3D(const IDicomDataset& dicom) |
0 | 139 { |
32 | 140 std::string a, b; |
141 | |
1834
126522623e20
replaced OrthancStone::DicomPath by new class Orthanc::DicomPath from orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
142 if (dicom.GetStringValue(a, Orthanc::DicomPath(Orthanc::DICOM_TAG_IMAGE_POSITION_PATIENT)) && |
126522623e20
replaced OrthancStone::DicomPath by new class Orthanc::DicomPath from orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
143 dicom.GetStringValue(b, Orthanc::DicomPath(Orthanc::DICOM_TAG_IMAGE_ORIENTATION_PATIENT))) |
0 | 144 { |
32 | 145 Setup(a, b); |
0 | 146 } |
147 else | |
148 { | |
149 SetupCanonical(); | |
150 } | |
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 |
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 CoordinateSystem3D::CoordinateSystem3D(const Orthanc::DicomMap& dicom) |
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 std::string a, b; |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
157 |
994
1f74bc3459ba
fix build due to rename in Orthanc::DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
986
diff
changeset
|
158 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
|
159 dicom.LookupStringValue(b, Orthanc::DICOM_TAG_IMAGE_ORIENTATION_PATIENT, false)) |
122
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
160 { |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
161 Setup(a, b); |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
162 } |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
163 else |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
164 { |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
165 SetupCanonical(); |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
166 } |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
167 } |
0 | 168 |
169 | |
760
1181e1ad98ec
progressive loading working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
757
diff
changeset
|
170 void CoordinateSystem3D::SetOrigin(const Vector& origin) |
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 if (origin.size() != 3) |
1181e1ad98ec
progressive loading working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
757
diff
changeset
|
173 { |
1181e1ad98ec
progressive loading working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
757
diff
changeset
|
174 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); |
1181e1ad98ec
progressive loading working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
757
diff
changeset
|
175 } |
1181e1ad98ec
progressive loading working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
757
diff
changeset
|
176 else |
1181e1ad98ec
progressive loading working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
757
diff
changeset
|
177 { |
1181e1ad98ec
progressive loading working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
757
diff
changeset
|
178 origin_ = origin; |
1181e1ad98ec
progressive loading working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
757
diff
changeset
|
179 } |
1181e1ad98ec
progressive loading working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
757
diff
changeset
|
180 } |
1181e1ad98ec
progressive loading working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
757
diff
changeset
|
181 |
1181e1ad98ec
progressive loading working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
757
diff
changeset
|
182 |
110
53025eecbc95
renamed SliceGeometry as CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
89
diff
changeset
|
183 Vector CoordinateSystem3D::MapSliceToWorldCoordinates(double x, |
53025eecbc95
renamed SliceGeometry as CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
89
diff
changeset
|
184 double y) const |
0 | 185 { |
186 return origin_ + x * axisX_ + y * axisY_; | |
187 } | |
188 | |
189 | |
110
53025eecbc95
renamed SliceGeometry as CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
89
diff
changeset
|
190 double CoordinateSystem3D::ProjectAlongNormal(const Vector& point) const |
0 | 191 { |
192 return boost::numeric::ublas::inner_prod(point, normal_); | |
193 } | |
194 | |
1013
53cc787bd7bc
- Added an optimized ProjectPoint2 to CoordinateSystem3D. It has *not* replaced
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
195 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
|
196 { |
53cc787bd7bc
- Added an optimized ProjectPoint2 to CoordinateSystem3D. It has *not* replaced
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
197 // 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
|
198 double projectionX,projectionY,projectionZ; |
53cc787bd7bc
- Added an optimized ProjectPoint2 to CoordinateSystem3D. It has *not* replaced
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
199 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
|
200 |
53cc787bd7bc
- Added an optimized ProjectPoint2 to CoordinateSystem3D. It has *not* replaced
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
201 // 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
|
202 // 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
|
203 // 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
|
204 // 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
|
205 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
|
206 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
|
207 } |
0 | 208 |
110
53025eecbc95
renamed SliceGeometry as CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
89
diff
changeset
|
209 void CoordinateSystem3D::ProjectPoint(double& offsetX, |
53025eecbc95
renamed SliceGeometry as CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
89
diff
changeset
|
210 double& offsetY, |
53025eecbc95
renamed SliceGeometry as CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
89
diff
changeset
|
211 const Vector& point) const |
0 | 212 { |
213 // Project the point onto the slice | |
214 Vector projection; | |
215 GeometryToolbox::ProjectPointOntoPlane(projection, point, normal_, origin_); | |
216 | |
217 // As the axes are orthonormal vectors thanks to | |
218 // CheckAndComputeNormal(), the following dot products give the | |
219 // offset of the origin of the slice wrt. the origin of the | |
220 // reference plane https://en.wikipedia.org/wiki/Vector_projection | |
221 offsetX = boost::numeric::ublas::inner_prod(axisX_, projection - origin_); | |
222 offsetY = boost::numeric::ublas::inner_prod(axisY_, projection - origin_); | |
223 } | |
151
c5044bbfc303
CoordinateSystem3D::IntersectSegment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
135
diff
changeset
|
224 |
152 | 225 bool CoordinateSystem3D::IntersectSegment(Vector& p, |
151
c5044bbfc303
CoordinateSystem3D::IntersectSegment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
135
diff
changeset
|
226 const Vector& edgeFrom, |
c5044bbfc303
CoordinateSystem3D::IntersectSegment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
135
diff
changeset
|
227 const Vector& edgeTo) const |
c5044bbfc303
CoordinateSystem3D::IntersectSegment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
135
diff
changeset
|
228 { |
157
2309e8d86efe
IntersectPlaneAndLine
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
152
diff
changeset
|
229 return GeometryToolbox::IntersectPlaneAndSegment(p, normal_, d_, edgeFrom, edgeTo); |
2309e8d86efe
IntersectPlaneAndLine
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
152
diff
changeset
|
230 } |
2309e8d86efe
IntersectPlaneAndLine
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
152
diff
changeset
|
231 |
2309e8d86efe
IntersectPlaneAndLine
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
152
diff
changeset
|
232 |
2309e8d86efe
IntersectPlaneAndLine
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
152
diff
changeset
|
233 bool CoordinateSystem3D::IntersectLine(Vector& p, |
2309e8d86efe
IntersectPlaneAndLine
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
152
diff
changeset
|
234 const Vector& origin, |
2309e8d86efe
IntersectPlaneAndLine
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
152
diff
changeset
|
235 const Vector& direction) const |
2309e8d86efe
IntersectPlaneAndLine
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
152
diff
changeset
|
236 { |
2309e8d86efe
IntersectPlaneAndLine
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
152
diff
changeset
|
237 return GeometryToolbox::IntersectPlaneAndLine(p, normal_, d_, origin, direction); |
151
c5044bbfc303
CoordinateSystem3D::IntersectSegment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
135
diff
changeset
|
238 } |
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 |
1648
4a43106bc122
cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1640
diff
changeset
|
241 double CoordinateSystem3D::ComputeDistance(const Vector& p) const |
4a43106bc122
cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1640
diff
changeset
|
242 { |
4a43106bc122
cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1640
diff
changeset
|
243 /** |
4a43106bc122
cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1640
diff
changeset
|
244 * "normal_" is an unit vector (*) => sqrt(a_1^2+a_2^2+a_3^2) = 1, |
4a43106bc122
cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1640
diff
changeset
|
245 * and the denominator equals 1 by construction. |
4a43106bc122
cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1640
diff
changeset
|
246 * https://en.wikipedia.org/wiki/Distance_from_a_point_to_a_plane#Closest_point_and_distance_for_a_hyperplane_and_arbitrary_point |
4a43106bc122
cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1640
diff
changeset
|
247 **/ |
4a43106bc122
cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1640
diff
changeset
|
248 |
4a43106bc122
cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1640
diff
changeset
|
249 return std::abs(boost::numeric::ublas::inner_prod(p, normal_) + d_); |
4a43106bc122
cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1640
diff
changeset
|
250 } |
4a43106bc122
cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1640
diff
changeset
|
251 |
4a43106bc122
cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1640
diff
changeset
|
252 |
757 | 253 bool CoordinateSystem3D::ComputeDistance(double& distance, |
254 const CoordinateSystem3D& a, | |
255 const CoordinateSystem3D& b) | |
647
6af3099ed8da
uncoupling OrthancStone::SlicesSorter from OrthancStone::Slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
256 { |
986 | 257 bool opposite = false; // Ignored |
647
6af3099ed8da
uncoupling OrthancStone::SlicesSorter from OrthancStone::Slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
258 |
1640
52b8b96cb55f
cleaning namespaces
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1630
diff
changeset
|
259 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
|
260 { |
6af3099ed8da
uncoupling OrthancStone::SlicesSorter from OrthancStone::Slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
261 distance = std::abs(a.ProjectAlongNormal(a.GetOrigin()) - |
6af3099ed8da
uncoupling OrthancStone::SlicesSorter from OrthancStone::Slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
262 a.ProjectAlongNormal(b.GetOrigin())); |
6af3099ed8da
uncoupling OrthancStone::SlicesSorter from OrthancStone::Slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
263 return true; |
6af3099ed8da
uncoupling OrthancStone::SlicesSorter from OrthancStone::Slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
264 } |
6af3099ed8da
uncoupling OrthancStone::SlicesSorter from OrthancStone::Slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
265 else |
6af3099ed8da
uncoupling OrthancStone::SlicesSorter from OrthancStone::Slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
266 { |
6af3099ed8da
uncoupling OrthancStone::SlicesSorter from OrthancStone::Slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
267 return false; |
6af3099ed8da
uncoupling OrthancStone::SlicesSorter from OrthancStone::Slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
268 } |
6af3099ed8da
uncoupling OrthancStone::SlicesSorter from OrthancStone::Slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
269 } |
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
|
270 |
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
|
271 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
|
272 { |
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
|
273 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
|
274 << " 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
|
275 << " 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
|
276 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
|
277 } |
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
|
278 |
1161
19b1c8caade4
fix sagittal geometry
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1020
diff
changeset
|
279 |
19b1c8caade4
fix sagittal geometry
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1020
diff
changeset
|
280 CoordinateSystem3D CoordinateSystem3D::NormalizeCuttingPlane(const CoordinateSystem3D& plane) |
19b1c8caade4
fix sagittal geometry
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1020
diff
changeset
|
281 { |
19b1c8caade4
fix sagittal geometry
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1020
diff
changeset
|
282 double ox, oy; |
19b1c8caade4
fix sagittal geometry
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1020
diff
changeset
|
283 plane.ProjectPoint(ox, oy, LinearAlgebra::CreateVector(0, 0, 0)); |
19b1c8caade4
fix sagittal geometry
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1020
diff
changeset
|
284 |
19b1c8caade4
fix sagittal geometry
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1020
diff
changeset
|
285 CoordinateSystem3D normalized(plane); |
19b1c8caade4
fix sagittal geometry
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1020
diff
changeset
|
286 normalized.SetOrigin(plane.MapSliceToWorldCoordinates(ox, oy)); |
19b1c8caade4
fix sagittal geometry
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1020
diff
changeset
|
287 return normalized; |
19b1c8caade4
fix sagittal geometry
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1020
diff
changeset
|
288 } |
1648
4a43106bc122
cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1640
diff
changeset
|
289 |
4a43106bc122
cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1640
diff
changeset
|
290 |
4a43106bc122
cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1640
diff
changeset
|
291 CoordinateSystem3D CoordinateSystem3D::CreateFromPlaneGeneralForm(double a, |
4a43106bc122
cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1640
diff
changeset
|
292 double b, |
4a43106bc122
cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1640
diff
changeset
|
293 double c, |
4a43106bc122
cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1640
diff
changeset
|
294 double d) |
4a43106bc122
cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1640
diff
changeset
|
295 { |
4a43106bc122
cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1640
diff
changeset
|
296 /** |
4a43106bc122
cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1640
diff
changeset
|
297 * "a*x + b*y + c*z + d = 0" => The un-normalized normal is vector |
4a43106bc122
cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1640
diff
changeset
|
298 * (a,b,c). |
4a43106bc122
cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1640
diff
changeset
|
299 **/ |
4a43106bc122
cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1640
diff
changeset
|
300 |
4a43106bc122
cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1640
diff
changeset
|
301 Vector normal; |
4a43106bc122
cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1640
diff
changeset
|
302 LinearAlgebra::AssignVector(normal, a, b, c); |
4a43106bc122
cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1640
diff
changeset
|
303 |
4a43106bc122
cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1640
diff
changeset
|
304 |
4a43106bc122
cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1640
diff
changeset
|
305 /** |
4a43106bc122
cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1640
diff
changeset
|
306 * Choose the origin of plane, as the point that is closest to the |
4a43106bc122
cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1640
diff
changeset
|
307 * origin of the axes (0,0,0). |
4a43106bc122
cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1640
diff
changeset
|
308 * https://en.wikipedia.org/wiki/Distance_from_a_point_to_a_plane#Restatement_using_linear_algebra |
4a43106bc122
cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1640
diff
changeset
|
309 **/ |
4a43106bc122
cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1640
diff
changeset
|
310 |
4a43106bc122
cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1640
diff
changeset
|
311 double squaredNorm = a * a + b * b + c * c; |
4a43106bc122
cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1640
diff
changeset
|
312 if (LinearAlgebra::IsCloseToZero(squaredNorm)) |
4a43106bc122
cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1640
diff
changeset
|
313 { |
4a43106bc122
cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1640
diff
changeset
|
314 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadGeometry, "Singular matrix"); |
4a43106bc122
cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1640
diff
changeset
|
315 } |
4a43106bc122
cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1640
diff
changeset
|
316 |
4a43106bc122
cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1640
diff
changeset
|
317 Vector origin = -d * normal / squaredNorm; |
4a43106bc122
cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1640
diff
changeset
|
318 |
4a43106bc122
cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1640
diff
changeset
|
319 |
4a43106bc122
cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1640
diff
changeset
|
320 /** |
4a43106bc122
cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1640
diff
changeset
|
321 * Select the X axis by computing a vector that is perpendicular |
4a43106bc122
cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1640
diff
changeset
|
322 * to the normal. |
4a43106bc122
cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1640
diff
changeset
|
323 * |
4a43106bc122
cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1640
diff
changeset
|
324 * "Exactly 1 and only 1 of the bools get set; b0/b1/b2 gets set |
4a43106bc122
cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1640
diff
changeset
|
325 * if dimension "i" has magnitude strictly less than all |
4a43106bc122
cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1640
diff
changeset
|
326 * subsequent dimensions and not greater than all previous |
4a43106bc122
cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1640
diff
changeset
|
327 * dimensions. We then have a unit vector with a single non-zero |
4a43106bc122
cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1640
diff
changeset
|
328 * dimension that corresponds to a dimension of minimum magnitude |
4a43106bc122
cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1640
diff
changeset
|
329 * in "normal". The cross product of this with "normal" is |
4a43106bc122
cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1640
diff
changeset
|
330 * orthogonal to "normal" by definition of cross product. Consider |
4a43106bc122
cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1640
diff
changeset
|
331 * now that the cross product is numerically unstable only when |
4a43106bc122
cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1640
diff
changeset
|
332 * the two vectors are very closely aligned. Consider that our |
4a43106bc122
cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1640
diff
changeset
|
333 * unit vector is large in only a single dimension and that that |
4a43106bc122
cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1640
diff
changeset
|
334 * dimension corresponds to the dimension where "normal" was |
4a43106bc122
cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1640
diff
changeset
|
335 * small. It's thus guaranteed to be loosely orthogonal to |
4a43106bc122
cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1640
diff
changeset
|
336 * "normal" before taking the cross product, with least |
4a43106bc122
cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1640
diff
changeset
|
337 * orthogonality in the case where all dimensions of "normal" are |
4a43106bc122
cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1640
diff
changeset
|
338 * equal. In this least-orthogonal case, we're still quite |
4a43106bc122
cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1640
diff
changeset
|
339 * orthogonal given that our unit vector has all but one dimension |
4a43106bc122
cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1640
diff
changeset
|
340 * 0 whereas "normal" has all equal. We thus avoid the unstable |
4a43106bc122
cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1640
diff
changeset
|
341 * case of taking the cross product of two nearly-aligned |
4a43106bc122
cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1640
diff
changeset
|
342 * vectors." https://stackoverflow.com/a/43454629/881731 |
4a43106bc122
cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1640
diff
changeset
|
343 **/ |
4a43106bc122
cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1640
diff
changeset
|
344 |
4a43106bc122
cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1640
diff
changeset
|
345 bool b0 = (normal[0] < normal[1]) && (normal[0] < normal[2]); |
4a43106bc122
cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1640
diff
changeset
|
346 bool b1 = (normal[1] <= normal[0]) && (normal[1] < normal[2]); |
4a43106bc122
cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1640
diff
changeset
|
347 bool b2 = (normal[2] <= normal[0]) && (normal[2] <= normal[1]); |
4a43106bc122
cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1640
diff
changeset
|
348 Vector swap = LinearAlgebra::CreateVector(b0 ? 1 : 0, b1 ? 1 : 0, b2 ? 1 : 0); |
4a43106bc122
cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1640
diff
changeset
|
349 |
4a43106bc122
cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1640
diff
changeset
|
350 Vector axisX; |
4a43106bc122
cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1640
diff
changeset
|
351 LinearAlgebra::CrossProduct(axisX, normal, swap); |
4a43106bc122
cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1640
diff
changeset
|
352 LinearAlgebra::NormalizeVector(axisX); |
4a43106bc122
cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1640
diff
changeset
|
353 |
4a43106bc122
cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1640
diff
changeset
|
354 |
4a43106bc122
cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1640
diff
changeset
|
355 /** |
4a43106bc122
cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1640
diff
changeset
|
356 * The Y axis follows as the cross-product of the normal and the X |
4a43106bc122
cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1640
diff
changeset
|
357 * axis. |
4a43106bc122
cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1640
diff
changeset
|
358 **/ |
4a43106bc122
cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1640
diff
changeset
|
359 |
4a43106bc122
cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1640
diff
changeset
|
360 Vector axisY; |
4a43106bc122
cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1640
diff
changeset
|
361 LinearAlgebra::CrossProduct(axisY, axisX, normal); |
4a43106bc122
cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1640
diff
changeset
|
362 LinearAlgebra::NormalizeVector(axisY); |
4a43106bc122
cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1640
diff
changeset
|
363 |
4a43106bc122
cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1640
diff
changeset
|
364 return CoordinateSystem3D(origin, axisX, axisY); |
4a43106bc122
cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1640
diff
changeset
|
365 } |
1650
af312e145980
more tests for CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1648
diff
changeset
|
366 |
af312e145980
more tests for CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1648
diff
changeset
|
367 |
af312e145980
more tests for CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1648
diff
changeset
|
368 CoordinateSystem3D CoordinateSystem3D::CreateFromThreePoints(const Vector& a, |
af312e145980
more tests for CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1648
diff
changeset
|
369 const Vector& b, |
af312e145980
more tests for CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1648
diff
changeset
|
370 const Vector& c) |
af312e145980
more tests for CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1648
diff
changeset
|
371 { |
af312e145980
more tests for CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1648
diff
changeset
|
372 Vector axisX = b - a; |
af312e145980
more tests for CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1648
diff
changeset
|
373 LinearAlgebra::NormalizeVector(axisX); |
af312e145980
more tests for CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1648
diff
changeset
|
374 |
af312e145980
more tests for CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1648
diff
changeset
|
375 Vector normal; |
af312e145980
more tests for CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1648
diff
changeset
|
376 LinearAlgebra::CrossProduct(normal, axisX, c - a); |
af312e145980
more tests for CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1648
diff
changeset
|
377 |
af312e145980
more tests for CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1648
diff
changeset
|
378 Vector axisY; |
af312e145980
more tests for CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1648
diff
changeset
|
379 LinearAlgebra::CrossProduct(axisY, axisX, normal); |
af312e145980
more tests for CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1648
diff
changeset
|
380 LinearAlgebra::NormalizeVector(axisY); |
af312e145980
more tests for CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1648
diff
changeset
|
381 |
af312e145980
more tests for CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1648
diff
changeset
|
382 return CoordinateSystem3D(a, axisX, axisY); |
af312e145980
more tests for CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1648
diff
changeset
|
383 } |
1961
cbf54cd28d59
added CoordinateSystem3D::GetOrientationMarkers()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1871
diff
changeset
|
384 |
cbf54cd28d59
added CoordinateSystem3D::GetOrientationMarkers()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1871
diff
changeset
|
385 |
cbf54cd28d59
added CoordinateSystem3D::GetOrientationMarkers()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1871
diff
changeset
|
386 static std::string GetOrientationString(const Vector& v) |
cbf54cd28d59
added CoordinateSystem3D::GetOrientationMarkers()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1871
diff
changeset
|
387 { |
cbf54cd28d59
added CoordinateSystem3D::GetOrientationMarkers()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1871
diff
changeset
|
388 /** |
cbf54cd28d59
added CoordinateSystem3D::GetOrientationMarkers()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1871
diff
changeset
|
389 * This function directly comes from David Clunie: |
cbf54cd28d59
added CoordinateSystem3D::GetOrientationMarkers()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1871
diff
changeset
|
390 * https://sites.google.com/site/dicomnotes/ |
cbf54cd28d59
added CoordinateSystem3D::GetOrientationMarkers()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1871
diff
changeset
|
391 * |
cbf54cd28d59
added CoordinateSystem3D::GetOrientationMarkers()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1871
diff
changeset
|
392 * It is also a C++ reimplementation of function |
cbf54cd28d59
added CoordinateSystem3D::GetOrientationMarkers()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1871
diff
changeset
|
393 * "getOrientationString()" from Cornerstone: |
cbf54cd28d59
added CoordinateSystem3D::GetOrientationMarkers()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1871
diff
changeset
|
394 * https://bitbucket.org/osimis/osimis-webviewer-plugin/src/master/frontend/local_dependencies/cornerstoneTools/cornerstoneTools.js |
cbf54cd28d59
added CoordinateSystem3D::GetOrientationMarkers()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1871
diff
changeset
|
395 **/ |
cbf54cd28d59
added CoordinateSystem3D::GetOrientationMarkers()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1871
diff
changeset
|
396 |
cbf54cd28d59
added CoordinateSystem3D::GetOrientationMarkers()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1871
diff
changeset
|
397 const char orientationX = v[0] < 0 ? 'R' : 'L'; |
cbf54cd28d59
added CoordinateSystem3D::GetOrientationMarkers()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1871
diff
changeset
|
398 const char orientationY = v[1] < 0 ? 'A' : 'P'; |
cbf54cd28d59
added CoordinateSystem3D::GetOrientationMarkers()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1871
diff
changeset
|
399 const char orientationZ = v[2] < 0 ? 'F' : 'H'; |
cbf54cd28d59
added CoordinateSystem3D::GetOrientationMarkers()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1871
diff
changeset
|
400 |
1974
446e0d3e9019
fix unit test GeometryToolbox.OrientationMarkers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1961
diff
changeset
|
401 double absX = std::abs(v[0]); |
446e0d3e9019
fix unit test GeometryToolbox.OrientationMarkers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1961
diff
changeset
|
402 double absY = std::abs(v[1]); |
446e0d3e9019
fix unit test GeometryToolbox.OrientationMarkers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1961
diff
changeset
|
403 double absZ = std::abs(v[2]); |
1961
cbf54cd28d59
added CoordinateSystem3D::GetOrientationMarkers()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1871
diff
changeset
|
404 |
cbf54cd28d59
added CoordinateSystem3D::GetOrientationMarkers()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1871
diff
changeset
|
405 std::string result; |
cbf54cd28d59
added CoordinateSystem3D::GetOrientationMarkers()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1871
diff
changeset
|
406 |
cbf54cd28d59
added CoordinateSystem3D::GetOrientationMarkers()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1871
diff
changeset
|
407 static const double THRESHOLD = 0.0001; |
cbf54cd28d59
added CoordinateSystem3D::GetOrientationMarkers()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1871
diff
changeset
|
408 |
cbf54cd28d59
added CoordinateSystem3D::GetOrientationMarkers()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1871
diff
changeset
|
409 for (unsigned int i = 0; i < 3; i++) |
cbf54cd28d59
added CoordinateSystem3D::GetOrientationMarkers()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1871
diff
changeset
|
410 { |
cbf54cd28d59
added CoordinateSystem3D::GetOrientationMarkers()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1871
diff
changeset
|
411 if (absX > THRESHOLD && absX > absY && absX > absZ) |
cbf54cd28d59
added CoordinateSystem3D::GetOrientationMarkers()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1871
diff
changeset
|
412 { |
cbf54cd28d59
added CoordinateSystem3D::GetOrientationMarkers()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1871
diff
changeset
|
413 result.push_back(orientationX); |
cbf54cd28d59
added CoordinateSystem3D::GetOrientationMarkers()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1871
diff
changeset
|
414 absX = 0; |
cbf54cd28d59
added CoordinateSystem3D::GetOrientationMarkers()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1871
diff
changeset
|
415 } |
cbf54cd28d59
added CoordinateSystem3D::GetOrientationMarkers()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1871
diff
changeset
|
416 else if (absY > THRESHOLD && absY > absX && absY > absZ) |
cbf54cd28d59
added CoordinateSystem3D::GetOrientationMarkers()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1871
diff
changeset
|
417 { |
cbf54cd28d59
added CoordinateSystem3D::GetOrientationMarkers()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1871
diff
changeset
|
418 result.push_back(orientationY); |
cbf54cd28d59
added CoordinateSystem3D::GetOrientationMarkers()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1871
diff
changeset
|
419 absY = 0; |
cbf54cd28d59
added CoordinateSystem3D::GetOrientationMarkers()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1871
diff
changeset
|
420 } |
cbf54cd28d59
added CoordinateSystem3D::GetOrientationMarkers()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1871
diff
changeset
|
421 else if (absZ > THRESHOLD && absZ > absX && absZ > absY) |
cbf54cd28d59
added CoordinateSystem3D::GetOrientationMarkers()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1871
diff
changeset
|
422 { |
cbf54cd28d59
added CoordinateSystem3D::GetOrientationMarkers()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1871
diff
changeset
|
423 result.push_back(orientationZ); |
cbf54cd28d59
added CoordinateSystem3D::GetOrientationMarkers()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1871
diff
changeset
|
424 absZ = 0; |
cbf54cd28d59
added CoordinateSystem3D::GetOrientationMarkers()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1871
diff
changeset
|
425 } |
cbf54cd28d59
added CoordinateSystem3D::GetOrientationMarkers()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1871
diff
changeset
|
426 else |
cbf54cd28d59
added CoordinateSystem3D::GetOrientationMarkers()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1871
diff
changeset
|
427 { |
cbf54cd28d59
added CoordinateSystem3D::GetOrientationMarkers()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1871
diff
changeset
|
428 break; |
cbf54cd28d59
added CoordinateSystem3D::GetOrientationMarkers()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1871
diff
changeset
|
429 } |
cbf54cd28d59
added CoordinateSystem3D::GetOrientationMarkers()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1871
diff
changeset
|
430 } |
cbf54cd28d59
added CoordinateSystem3D::GetOrientationMarkers()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1871
diff
changeset
|
431 |
cbf54cd28d59
added CoordinateSystem3D::GetOrientationMarkers()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1871
diff
changeset
|
432 return result; |
cbf54cd28d59
added CoordinateSystem3D::GetOrientationMarkers()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1871
diff
changeset
|
433 } |
cbf54cd28d59
added CoordinateSystem3D::GetOrientationMarkers()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1871
diff
changeset
|
434 |
cbf54cd28d59
added CoordinateSystem3D::GetOrientationMarkers()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1871
diff
changeset
|
435 |
cbf54cd28d59
added CoordinateSystem3D::GetOrientationMarkers()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1871
diff
changeset
|
436 static std::string InvertOrientationString(const std::string& source) |
cbf54cd28d59
added CoordinateSystem3D::GetOrientationMarkers()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1871
diff
changeset
|
437 { |
cbf54cd28d59
added CoordinateSystem3D::GetOrientationMarkers()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1871
diff
changeset
|
438 std::string target; |
cbf54cd28d59
added CoordinateSystem3D::GetOrientationMarkers()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1871
diff
changeset
|
439 target.resize(source.length()); |
cbf54cd28d59
added CoordinateSystem3D::GetOrientationMarkers()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1871
diff
changeset
|
440 |
cbf54cd28d59
added CoordinateSystem3D::GetOrientationMarkers()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1871
diff
changeset
|
441 for (unsigned int i = 0; i < source.length(); i++) |
cbf54cd28d59
added CoordinateSystem3D::GetOrientationMarkers()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1871
diff
changeset
|
442 { |
cbf54cd28d59
added CoordinateSystem3D::GetOrientationMarkers()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1871
diff
changeset
|
443 switch (source[i]) |
cbf54cd28d59
added CoordinateSystem3D::GetOrientationMarkers()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1871
diff
changeset
|
444 { |
cbf54cd28d59
added CoordinateSystem3D::GetOrientationMarkers()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1871
diff
changeset
|
445 case 'H': target[i] = 'F'; break; |
cbf54cd28d59
added CoordinateSystem3D::GetOrientationMarkers()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1871
diff
changeset
|
446 case 'F': target[i] = 'H'; break; |
cbf54cd28d59
added CoordinateSystem3D::GetOrientationMarkers()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1871
diff
changeset
|
447 case 'R': target[i] = 'L'; break; |
cbf54cd28d59
added CoordinateSystem3D::GetOrientationMarkers()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1871
diff
changeset
|
448 case 'L': target[i] = 'R'; break; |
cbf54cd28d59
added CoordinateSystem3D::GetOrientationMarkers()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1871
diff
changeset
|
449 case 'A': target[i] = 'P'; break; |
cbf54cd28d59
added CoordinateSystem3D::GetOrientationMarkers()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1871
diff
changeset
|
450 case 'P': target[i] = 'A'; break; |
cbf54cd28d59
added CoordinateSystem3D::GetOrientationMarkers()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1871
diff
changeset
|
451 default: |
cbf54cd28d59
added CoordinateSystem3D::GetOrientationMarkers()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1871
diff
changeset
|
452 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); |
cbf54cd28d59
added CoordinateSystem3D::GetOrientationMarkers()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1871
diff
changeset
|
453 } |
cbf54cd28d59
added CoordinateSystem3D::GetOrientationMarkers()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1871
diff
changeset
|
454 } |
cbf54cd28d59
added CoordinateSystem3D::GetOrientationMarkers()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1871
diff
changeset
|
455 |
cbf54cd28d59
added CoordinateSystem3D::GetOrientationMarkers()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1871
diff
changeset
|
456 return target; |
cbf54cd28d59
added CoordinateSystem3D::GetOrientationMarkers()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1871
diff
changeset
|
457 } |
cbf54cd28d59
added CoordinateSystem3D::GetOrientationMarkers()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1871
diff
changeset
|
458 |
cbf54cd28d59
added CoordinateSystem3D::GetOrientationMarkers()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1871
diff
changeset
|
459 |
cbf54cd28d59
added CoordinateSystem3D::GetOrientationMarkers()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1871
diff
changeset
|
460 void CoordinateSystem3D::GetOrientationMarkers(std::string& top /* out */, |
cbf54cd28d59
added CoordinateSystem3D::GetOrientationMarkers()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1871
diff
changeset
|
461 std::string& bottom /* out */, |
cbf54cd28d59
added CoordinateSystem3D::GetOrientationMarkers()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1871
diff
changeset
|
462 std::string& left /* out */, |
cbf54cd28d59
added CoordinateSystem3D::GetOrientationMarkers()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1871
diff
changeset
|
463 std::string& right /* out */) const |
cbf54cd28d59
added CoordinateSystem3D::GetOrientationMarkers()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1871
diff
changeset
|
464 { |
cbf54cd28d59
added CoordinateSystem3D::GetOrientationMarkers()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1871
diff
changeset
|
465 if (IsValid()) |
cbf54cd28d59
added CoordinateSystem3D::GetOrientationMarkers()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1871
diff
changeset
|
466 { |
cbf54cd28d59
added CoordinateSystem3D::GetOrientationMarkers()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1871
diff
changeset
|
467 /** |
cbf54cd28d59
added CoordinateSystem3D::GetOrientationMarkers()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1871
diff
changeset
|
468 * This is a C++ reimplementation of function |
cbf54cd28d59
added CoordinateSystem3D::GetOrientationMarkers()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1871
diff
changeset
|
469 * "getOrientationMarkers()" from Cornerstone: |
cbf54cd28d59
added CoordinateSystem3D::GetOrientationMarkers()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1871
diff
changeset
|
470 * https://bitbucket.org/osimis/osimis-webviewer-plugin/src/master/frontend/local_dependencies/cornerstoneTools/cornerstoneTools.js |
cbf54cd28d59
added CoordinateSystem3D::GetOrientationMarkers()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1871
diff
changeset
|
471 * |
cbf54cd28d59
added CoordinateSystem3D::GetOrientationMarkers()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1871
diff
changeset
|
472 * ImageOrientationPatient is row cosines then column cosines |
cbf54cd28d59
added CoordinateSystem3D::GetOrientationMarkers()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1871
diff
changeset
|
473 * (i.e. horizontal then vertical). |
cbf54cd28d59
added CoordinateSystem3D::GetOrientationMarkers()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1871
diff
changeset
|
474 * https://dicom.nema.org/medical/dicom/current/output/html/part03.html#sect_C.7.6.2 |
cbf54cd28d59
added CoordinateSystem3D::GetOrientationMarkers()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1871
diff
changeset
|
475 **/ |
cbf54cd28d59
added CoordinateSystem3D::GetOrientationMarkers()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1871
diff
changeset
|
476 const Vector& rowCosines = axisX_; // horizontal |
cbf54cd28d59
added CoordinateSystem3D::GetOrientationMarkers()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1871
diff
changeset
|
477 const Vector& columnCosines = axisY_; // vertical |
cbf54cd28d59
added CoordinateSystem3D::GetOrientationMarkers()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1871
diff
changeset
|
478 |
cbf54cd28d59
added CoordinateSystem3D::GetOrientationMarkers()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1871
diff
changeset
|
479 bottom = GetOrientationString(columnCosines); |
cbf54cd28d59
added CoordinateSystem3D::GetOrientationMarkers()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1871
diff
changeset
|
480 right = GetOrientationString(rowCosines); |
cbf54cd28d59
added CoordinateSystem3D::GetOrientationMarkers()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1871
diff
changeset
|
481 top = InvertOrientationString(bottom); |
cbf54cd28d59
added CoordinateSystem3D::GetOrientationMarkers()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1871
diff
changeset
|
482 left = InvertOrientationString(right); |
cbf54cd28d59
added CoordinateSystem3D::GetOrientationMarkers()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1871
diff
changeset
|
483 } |
cbf54cd28d59
added CoordinateSystem3D::GetOrientationMarkers()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1871
diff
changeset
|
484 else |
cbf54cd28d59
added CoordinateSystem3D::GetOrientationMarkers()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1871
diff
changeset
|
485 { |
cbf54cd28d59
added CoordinateSystem3D::GetOrientationMarkers()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1871
diff
changeset
|
486 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); |
cbf54cd28d59
added CoordinateSystem3D::GetOrientationMarkers()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1871
diff
changeset
|
487 } |
cbf54cd28d59
added CoordinateSystem3D::GetOrientationMarkers()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1871
diff
changeset
|
488 } |
0 | 489 } |