annotate OrthancStone/Sources/Toolbox/CoordinateSystem3D.cpp @ 1717:391c798e4dae

fix for KNIX sample dataset
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 01 Dec 2020 10:08:26 +0100
parents af312e145980
children 9ac2a65d4172
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Stone of Orthanc
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 *
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
28956ed68280 agpl license
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 40
diff changeset
9 * as published by the Free Software Foundation, either version 3 of
28956ed68280 agpl license
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 40
diff changeset
10 * the License, or (at your option) any later version.
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 *
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * This program is distributed in the hope that it will be useful, but
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 **/
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22
110
53025eecbc95 renamed SliceGeometry as CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 89
diff changeset
23 #include "CoordinateSystem3D.h"
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24
158
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 157
diff changeset
25 #include "LinearAlgebra.h"
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 #include "GeometryToolbox.h"
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32 namespace OrthancStone
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33 {
110
53025eecbc95 renamed SliceGeometry as CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 89
diff changeset
34 void CoordinateSystem3D::CheckAndComputeNormal()
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 {
1717
391c798e4dae fix for KNIX sample dataset
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1650
diff changeset
36 /**
391c798e4dae fix for KNIX sample dataset
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1650
diff changeset
37 * 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
38 * 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
39 * 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
40 * unity."
391c798e4dae fix for KNIX sample dataset
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1650
diff changeset
41 * 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
42 **/
158
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 157
diff changeset
43 if (!LinearAlgebra::IsNear(boost::numeric::ublas::norm_2(axisX_), 1.0) ||
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 157
diff changeset
44 !LinearAlgebra::IsNear(boost::numeric::ublas::norm_2(axisY_), 1.0))
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 {
1630
78509230f0d7 SortedFrames sharing code with CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1598
diff changeset
46 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
47 SetupCanonical();
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 }
1717
391c798e4dae fix for KNIX sample dataset
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1650
diff changeset
49
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 * The vectors within "Image Orientation Patient" must be
391c798e4dae fix for KNIX sample dataset
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1650
diff changeset
52 * 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
53 * 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
54 * their dot product shall be zero."
391c798e4dae fix for KNIX sample dataset
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1650
diff changeset
55 * 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
56 *
391c798e4dae fix for KNIX sample dataset
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1650
diff changeset
57 * 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
58 * 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
59 * by "LinearAlgebra::IsCloseToZero()").
391c798e4dae fix for KNIX sample dataset
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1650
diff changeset
60 **/
391c798e4dae fix for KNIX sample dataset
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1650
diff changeset
61 else if (!LinearAlgebra::IsNear(0, boost::numeric::ublas::inner_prod(axisX_, axisY_), 0.00001))
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 {
1630
78509230f0d7 SortedFrames sharing code with CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1598
diff changeset
63 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
64 SetupCanonical();
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65 }
1630
78509230f0d7 SortedFrames sharing code with CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1598
diff changeset
66 else
78509230f0d7 SortedFrames sharing code with CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1598
diff changeset
67 {
78509230f0d7 SortedFrames sharing code with CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1598
diff changeset
68 LinearAlgebra::CrossProduct(normal_, axisX_, axisY_);
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69
1630
78509230f0d7 SortedFrames sharing code with CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1598
diff changeset
70 d_ = -(normal_[0] * origin_[0] + normal_[1] * origin_[1] + normal_[2] * origin_[2]);
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71
1648
4a43106bc122 cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1640
diff changeset
72 // 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
73 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
74 }
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75 }
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77
110
53025eecbc95 renamed SliceGeometry as CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 89
diff changeset
78 void CoordinateSystem3D::SetupCanonical()
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79 {
1630
78509230f0d7 SortedFrames sharing code with CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1598
diff changeset
80 valid_ = false;
78509230f0d7 SortedFrames sharing code with CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1598
diff changeset
81
158
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 157
diff changeset
82 LinearAlgebra::AssignVector(origin_, 0, 0, 0);
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 157
diff changeset
83 LinearAlgebra::AssignVector(axisX_, 1, 0, 0);
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 157
diff changeset
84 LinearAlgebra::AssignVector(axisY_, 0, 1, 0);
1630
78509230f0d7 SortedFrames sharing code with CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1598
diff changeset
85 LinearAlgebra::AssignVector(normal_, 0, 0, 1);
78509230f0d7 SortedFrames sharing code with CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1598
diff changeset
86 d_ = 0;
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87 }
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89
110
53025eecbc95 renamed SliceGeometry as CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 89
diff changeset
90 CoordinateSystem3D::CoordinateSystem3D(const Vector& origin,
53025eecbc95 renamed SliceGeometry as CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 89
diff changeset
91 const Vector& axisX,
53025eecbc95 renamed SliceGeometry as CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 89
diff changeset
92 const Vector& axisY) :
1630
78509230f0d7 SortedFrames sharing code with CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1598
diff changeset
93 valid_(true),
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94 origin_(origin),
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95 axisX_(axisX),
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96 axisY_(axisY)
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97 {
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98 CheckAndComputeNormal();
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99 }
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101
110
53025eecbc95 renamed SliceGeometry as CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 89
diff changeset
102 void CoordinateSystem3D::Setup(const std::string& imagePositionPatient,
53025eecbc95 renamed SliceGeometry as CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 89
diff changeset
103 const std::string& imageOrientationPatient)
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104 {
1630
78509230f0d7 SortedFrames sharing code with CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1598
diff changeset
105 valid_ = true;
78509230f0d7 SortedFrames sharing code with CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1598
diff changeset
106
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107 std::string tmpPosition = Orthanc::Toolbox::StripSpaces(imagePositionPatient);
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108 std::string tmpOrientation = Orthanc::Toolbox::StripSpaces(imageOrientationPatient);
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110 Vector orientation;
158
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 157
diff changeset
111 if (!LinearAlgebra::ParseVector(origin_, tmpPosition) ||
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 157
diff changeset
112 !LinearAlgebra::ParseVector(orientation, tmpOrientation) ||
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113 origin_.size() != 3 ||
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114 orientation.size() != 6)
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
115 {
1630
78509230f0d7 SortedFrames sharing code with CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1598
diff changeset
116 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
117 << tmpPosition << "\" / \"" << tmpOrientation << "\"";
78509230f0d7 SortedFrames sharing code with CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1598
diff changeset
118 SetupCanonical();
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
119 }
1630
78509230f0d7 SortedFrames sharing code with CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1598
diff changeset
120 else
78509230f0d7 SortedFrames sharing code with CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1598
diff changeset
121 {
78509230f0d7 SortedFrames sharing code with CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1598
diff changeset
122 axisX_.resize(3);
78509230f0d7 SortedFrames sharing code with CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1598
diff changeset
123 axisX_[0] = orientation[0];
78509230f0d7 SortedFrames sharing code with CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1598
diff changeset
124 axisX_[1] = orientation[1];
78509230f0d7 SortedFrames sharing code with CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1598
diff changeset
125 axisX_[2] = orientation[2];
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
126
1630
78509230f0d7 SortedFrames sharing code with CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1598
diff changeset
127 axisY_.resize(3);
78509230f0d7 SortedFrames sharing code with CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1598
diff changeset
128 axisY_[0] = orientation[3];
78509230f0d7 SortedFrames sharing code with CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1598
diff changeset
129 axisY_[1] = orientation[4];
78509230f0d7 SortedFrames sharing code with CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1598
diff changeset
130 axisY_[2] = orientation[5];
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
131
1630
78509230f0d7 SortedFrames sharing code with CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1598
diff changeset
132 CheckAndComputeNormal();
78509230f0d7 SortedFrames sharing code with CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1598
diff changeset
133 }
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
134 }
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
135
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
136
1504
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1455
diff changeset
137 CoordinateSystem3D::CoordinateSystem3D(const IDicomDataset& dicom)
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
138 {
32
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 16
diff changeset
139 std::string a, b;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 16
diff changeset
140
1571
85e117739eca cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1512
diff changeset
141 if (dicom.GetStringValue(a, DicomPath(Orthanc::DICOM_TAG_IMAGE_POSITION_PATIENT)) &&
85e117739eca cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1512
diff changeset
142 dicom.GetStringValue(b, DicomPath(Orthanc::DICOM_TAG_IMAGE_ORIENTATION_PATIENT)))
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
143 {
32
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 16
diff changeset
144 Setup(a, b);
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
145 }
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
146 else
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
147 {
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
148 SetupCanonical();
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
149 }
122
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
150 }
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 CoordinateSystem3D::CoordinateSystem3D(const Orthanc::DicomMap& dicom)
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
154 {
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
155 std::string a, b;
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
156
994
1f74bc3459ba fix build due to rename in Orthanc::DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 986
diff changeset
157 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
158 dicom.LookupStringValue(b, Orthanc::DICOM_TAG_IMAGE_ORIENTATION_PATIENT, false))
122
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
159 {
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
160 Setup(a, b);
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
161 }
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
162 else
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
163 {
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
164 SetupCanonical();
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
165 }
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
166 }
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
167
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
168
760
1181e1ad98ec progressive loading working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 757
diff changeset
169 void CoordinateSystem3D::SetOrigin(const Vector& 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 if (origin.size() != 3)
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 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
1181e1ad98ec progressive loading working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 757
diff changeset
174 }
1181e1ad98ec progressive loading working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 757
diff changeset
175 else
1181e1ad98ec progressive loading working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 757
diff changeset
176 {
1181e1ad98ec progressive loading working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 757
diff changeset
177 origin_ = origin;
1181e1ad98ec progressive loading working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 757
diff changeset
178 }
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
110
53025eecbc95 renamed SliceGeometry as CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 89
diff changeset
182 Vector CoordinateSystem3D::MapSliceToWorldCoordinates(double x,
53025eecbc95 renamed SliceGeometry as CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 89
diff changeset
183 double y) const
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
184 {
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
185 return origin_ + x * axisX_ + y * axisY_;
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
186 }
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
187
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
188
110
53025eecbc95 renamed SliceGeometry as CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 89
diff changeset
189 double CoordinateSystem3D::ProjectAlongNormal(const Vector& point) const
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
190 {
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
191 return boost::numeric::ublas::inner_prod(point, normal_);
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
192 }
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
193
1013
53cc787bd7bc - Added an optimized ProjectPoint2 to CoordinateSystem3D. It has *not* replaced
Benjamin Golinvaux <bgo@osimis.io>
parents: 994
diff changeset
194 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
195 {
53cc787bd7bc - Added an optimized ProjectPoint2 to CoordinateSystem3D. It has *not* replaced
Benjamin Golinvaux <bgo@osimis.io>
parents: 994
diff changeset
196 // 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
197 double projectionX,projectionY,projectionZ;
53cc787bd7bc - Added an optimized ProjectPoint2 to CoordinateSystem3D. It has *not* replaced
Benjamin Golinvaux <bgo@osimis.io>
parents: 994
diff changeset
198 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
199
53cc787bd7bc - Added an optimized ProjectPoint2 to CoordinateSystem3D. It has *not* replaced
Benjamin Golinvaux <bgo@osimis.io>
parents: 994
diff changeset
200 // 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
201 // 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
202 // 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
203 // 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
204 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
205 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
206 }
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
207
110
53025eecbc95 renamed SliceGeometry as CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 89
diff changeset
208 void CoordinateSystem3D::ProjectPoint(double& offsetX,
53025eecbc95 renamed SliceGeometry as CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 89
diff changeset
209 double& offsetY,
53025eecbc95 renamed SliceGeometry as CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 89
diff changeset
210 const Vector& point) const
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
211 {
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
212 // Project the point onto the slice
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
213 Vector projection;
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
214 GeometryToolbox::ProjectPointOntoPlane(projection, point, normal_, origin_);
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
215
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
216 // As the axes are orthonormal vectors thanks to
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
217 // CheckAndComputeNormal(), the following dot products give the
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
218 // offset of the origin of the slice wrt. the origin of the
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
219 // reference plane https://en.wikipedia.org/wiki/Vector_projection
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
220 offsetX = boost::numeric::ublas::inner_prod(axisX_, projection - origin_);
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
221 offsetY = boost::numeric::ublas::inner_prod(axisY_, projection - origin_);
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
222 }
151
c5044bbfc303 CoordinateSystem3D::IntersectSegment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 135
diff changeset
223
152
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 151
diff changeset
224 bool CoordinateSystem3D::IntersectSegment(Vector& p,
151
c5044bbfc303 CoordinateSystem3D::IntersectSegment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 135
diff changeset
225 const Vector& edgeFrom,
c5044bbfc303 CoordinateSystem3D::IntersectSegment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 135
diff changeset
226 const Vector& edgeTo) const
c5044bbfc303 CoordinateSystem3D::IntersectSegment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 135
diff changeset
227 {
157
2309e8d86efe IntersectPlaneAndLine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 152
diff changeset
228 return GeometryToolbox::IntersectPlaneAndSegment(p, normal_, d_, edgeFrom, edgeTo);
2309e8d86efe IntersectPlaneAndLine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 152
diff changeset
229 }
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 bool CoordinateSystem3D::IntersectLine(Vector& p,
2309e8d86efe IntersectPlaneAndLine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 152
diff changeset
233 const Vector& origin,
2309e8d86efe IntersectPlaneAndLine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 152
diff changeset
234 const Vector& direction) const
2309e8d86efe IntersectPlaneAndLine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 152
diff changeset
235 {
2309e8d86efe IntersectPlaneAndLine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 152
diff changeset
236 return GeometryToolbox::IntersectPlaneAndLine(p, normal_, d_, origin, direction);
151
c5044bbfc303 CoordinateSystem3D::IntersectSegment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 135
diff changeset
237 }
647
6af3099ed8da uncoupling OrthancStone::SlicesSorter from OrthancStone::Slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 439
diff changeset
238
6af3099ed8da uncoupling OrthancStone::SlicesSorter from OrthancStone::Slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 439
diff changeset
239
1648
4a43106bc122 cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1640
diff changeset
240 double CoordinateSystem3D::ComputeDistance(const Vector& p) const
4a43106bc122 cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1640
diff changeset
241 {
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 * "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
244 * and the denominator equals 1 by construction.
4a43106bc122 cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1640
diff changeset
245 * 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
246 **/
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 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
249 }
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
757
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 647
diff changeset
252 bool CoordinateSystem3D::ComputeDistance(double& distance,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 647
diff changeset
253 const CoordinateSystem3D& a,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 647
diff changeset
254 const CoordinateSystem3D& b)
647
6af3099ed8da uncoupling OrthancStone::SlicesSorter from OrthancStone::Slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 439
diff changeset
255 {
986
4e2de6b8a70b Uninit. var.
Benjamin Golinvaux <bgo@osimis.io>
parents: 949
diff changeset
256 bool opposite = false; // Ignored
647
6af3099ed8da uncoupling OrthancStone::SlicesSorter from OrthancStone::Slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 439
diff changeset
257
1640
52b8b96cb55f cleaning namespaces
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1630
diff changeset
258 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
259 {
6af3099ed8da uncoupling OrthancStone::SlicesSorter from OrthancStone::Slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 439
diff changeset
260 distance = std::abs(a.ProjectAlongNormal(a.GetOrigin()) -
6af3099ed8da uncoupling OrthancStone::SlicesSorter from OrthancStone::Slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 439
diff changeset
261 a.ProjectAlongNormal(b.GetOrigin()));
6af3099ed8da uncoupling OrthancStone::SlicesSorter from OrthancStone::Slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 439
diff changeset
262 return true;
6af3099ed8da uncoupling OrthancStone::SlicesSorter from OrthancStone::Slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 439
diff changeset
263 }
6af3099ed8da uncoupling OrthancStone::SlicesSorter from OrthancStone::Slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 439
diff changeset
264 else
6af3099ed8da uncoupling OrthancStone::SlicesSorter from OrthancStone::Slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 439
diff changeset
265 {
6af3099ed8da uncoupling OrthancStone::SlicesSorter from OrthancStone::Slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 439
diff changeset
266 return false;
6af3099ed8da uncoupling OrthancStone::SlicesSorter from OrthancStone::Slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 439
diff changeset
267 }
6af3099ed8da uncoupling OrthancStone::SlicesSorter from OrthancStone::Slice
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 439
diff changeset
268 }
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
269
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 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
271 {
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 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
273 << " 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
274 << " 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
275 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
276 }
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
1161
19b1c8caade4 fix sagittal geometry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1020
diff changeset
278
19b1c8caade4 fix sagittal geometry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1020
diff changeset
279 CoordinateSystem3D CoordinateSystem3D::NormalizeCuttingPlane(const CoordinateSystem3D& plane)
19b1c8caade4 fix sagittal geometry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1020
diff changeset
280 {
19b1c8caade4 fix sagittal geometry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1020
diff changeset
281 double ox, oy;
19b1c8caade4 fix sagittal geometry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1020
diff changeset
282 plane.ProjectPoint(ox, oy, LinearAlgebra::CreateVector(0, 0, 0));
19b1c8caade4 fix sagittal geometry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1020
diff changeset
283
19b1c8caade4 fix sagittal geometry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1020
diff changeset
284 CoordinateSystem3D normalized(plane);
19b1c8caade4 fix sagittal geometry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1020
diff changeset
285 normalized.SetOrigin(plane.MapSliceToWorldCoordinates(ox, oy));
19b1c8caade4 fix sagittal geometry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1020
diff changeset
286 return normalized;
19b1c8caade4 fix sagittal geometry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1020
diff changeset
287 }
1648
4a43106bc122 cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1640
diff changeset
288
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 CoordinateSystem3D CoordinateSystem3D::CreateFromPlaneGeneralForm(double a,
4a43106bc122 cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1640
diff changeset
291 double b,
4a43106bc122 cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1640
diff changeset
292 double c,
4a43106bc122 cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1640
diff changeset
293 double d)
4a43106bc122 cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1640
diff changeset
294 {
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 * "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
297 * (a,b,c).
4a43106bc122 cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1640
diff changeset
298 **/
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 Vector normal;
4a43106bc122 cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1640
diff changeset
301 LinearAlgebra::AssignVector(normal, a, b, c);
4a43106bc122 cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1640
diff changeset
302
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 * 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
306 * origin of the axes (0,0,0).
4a43106bc122 cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1640
diff changeset
307 * 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
308 **/
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 double squaredNorm = a * a + b * b + c * c;
4a43106bc122 cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1640
diff changeset
311 if (LinearAlgebra::IsCloseToZero(squaredNorm))
4a43106bc122 cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1640
diff changeset
312 {
4a43106bc122 cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1640
diff changeset
313 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadGeometry, "Singular matrix");
4a43106bc122 cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1640
diff changeset
314 }
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 Vector origin = -d * normal / squaredNorm;
4a43106bc122 cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1640
diff changeset
317
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 * 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
321 * to the normal.
4a43106bc122 cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1640
diff changeset
322 *
4a43106bc122 cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1640
diff changeset
323 * "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
324 * 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
325 * subsequent dimensions and not greater than all previous
4a43106bc122 cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1640
diff changeset
326 * 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
327 * 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
328 * 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
329 * 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
330 * 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
331 * 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
332 * 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
333 * dimension corresponds to the dimension where "normal" was
4a43106bc122 cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1640
diff changeset
334 * 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
335 * "normal" before taking the cross product, with least
4a43106bc122 cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1640
diff changeset
336 * 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
337 * 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
338 * 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
339 * 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
340 * 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
341 * vectors." https://stackoverflow.com/a/43454629/881731
4a43106bc122 cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1640
diff changeset
342 **/
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 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
345 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
346 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
347 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
348
4a43106bc122 cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1640
diff changeset
349 Vector axisX;
4a43106bc122 cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1640
diff changeset
350 LinearAlgebra::CrossProduct(axisX, normal, swap);
4a43106bc122 cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1640
diff changeset
351 LinearAlgebra::NormalizeVector(axisX);
4a43106bc122 cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1640
diff changeset
352
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 * 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
356 * axis.
4a43106bc122 cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1640
diff changeset
357 **/
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 Vector axisY;
4a43106bc122 cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1640
diff changeset
360 LinearAlgebra::CrossProduct(axisY, axisX, normal);
4a43106bc122 cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1640
diff changeset
361 LinearAlgebra::NormalizeVector(axisY);
4a43106bc122 cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1640
diff changeset
362
4a43106bc122 cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1640
diff changeset
363 return CoordinateSystem3D(origin, axisX, axisY);
4a43106bc122 cross-hair starts to work
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1640
diff changeset
364 }
1650
af312e145980 more tests for CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1648
diff changeset
365
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 CoordinateSystem3D CoordinateSystem3D::CreateFromThreePoints(const Vector& a,
af312e145980 more tests for CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1648
diff changeset
368 const Vector& b,
af312e145980 more tests for CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1648
diff changeset
369 const Vector& c)
af312e145980 more tests for CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1648
diff changeset
370 {
af312e145980 more tests for CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1648
diff changeset
371 Vector axisX = b - a;
af312e145980 more tests for CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1648
diff changeset
372 LinearAlgebra::NormalizeVector(axisX);
af312e145980 more tests for CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1648
diff changeset
373
af312e145980 more tests for CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1648
diff changeset
374 Vector normal;
af312e145980 more tests for CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1648
diff changeset
375 LinearAlgebra::CrossProduct(normal, axisX, c - a);
af312e145980 more tests for CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1648
diff changeset
376
af312e145980 more tests for CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1648
diff changeset
377 Vector axisY;
af312e145980 more tests for CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1648
diff changeset
378 LinearAlgebra::CrossProduct(axisY, axisX, normal);
af312e145980 more tests for CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1648
diff changeset
379 LinearAlgebra::NormalizeVector(axisY);
af312e145980 more tests for CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1648
diff changeset
380
af312e145980 more tests for CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1648
diff changeset
381 return CoordinateSystem3D(a, axisX, axisY);
af312e145980 more tests for CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1648
diff changeset
382 }
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
383 }