Mercurial > hg > orthanc-stone
annotate OrthancStone/Sources/Toolbox/GeometryToolbox.h @ 2034:4b24b7533346 deep-learning
cont
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 27 Jan 2023 15:43:24 +0100 |
parents | 7053b8a0aaec |
children | 07964689cb0b |
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 | |
1871
7053b8a0aaec
upgrade to year 2022
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1870
diff
changeset
|
5 * Copyright (C) 2017-2022 Osimis S.A., Belgium |
7053b8a0aaec
upgrade to year 2022
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1870
diff
changeset
|
6 * Copyright (C) 2021-2022 Sebastien Jodogne, ICTEAM UCLouvain, Belgium |
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:
1512
diff
changeset
|
17 * |
1598
8563ea5d8ae4
relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
18 * You should have received a copy of the GNU Lesser General Public |
8563ea5d8ae4
relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
19 * License along with this program. If not, see |
8563ea5d8ae4
relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
20 * <http://www.gnu.org/licenses/>. |
0 | 21 **/ |
22 | |
23 | |
24 #pragma once | |
25 | |
158
a053ca7fa5c6
LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
157
diff
changeset
|
26 #include "LinearAlgebra.h" |
0 | 27 |
28 namespace OrthancStone | |
29 { | |
30 namespace GeometryToolbox | |
31 { | |
32 void ProjectPointOntoPlane(Vector& result, | |
33 const Vector& point, | |
34 const Vector& planeNormal, | |
35 const Vector& planeOrigin); | |
36 | |
1013
53cc787bd7bc
- Added an optimized ProjectPoint2 to CoordinateSystem3D. It has *not* replaced
Benjamin Golinvaux <bgo@osimis.io>
parents:
439
diff
changeset
|
37 /* |
53cc787bd7bc
- Added an optimized ProjectPoint2 to CoordinateSystem3D. It has *not* replaced
Benjamin Golinvaux <bgo@osimis.io>
parents:
439
diff
changeset
|
38 Alternated faster implementation (untested yet) |
53cc787bd7bc
- Added an optimized ProjectPoint2 to CoordinateSystem3D. It has *not* replaced
Benjamin Golinvaux <bgo@osimis.io>
parents:
439
diff
changeset
|
39 */ |
53cc787bd7bc
- Added an optimized ProjectPoint2 to CoordinateSystem3D. It has *not* replaced
Benjamin Golinvaux <bgo@osimis.io>
parents:
439
diff
changeset
|
40 void ProjectPointOntoPlane2(double& resultX, |
53cc787bd7bc
- Added an optimized ProjectPoint2 to CoordinateSystem3D. It has *not* replaced
Benjamin Golinvaux <bgo@osimis.io>
parents:
439
diff
changeset
|
41 double& resultY, |
53cc787bd7bc
- Added an optimized ProjectPoint2 to CoordinateSystem3D. It has *not* replaced
Benjamin Golinvaux <bgo@osimis.io>
parents:
439
diff
changeset
|
42 double& resultZ, |
53cc787bd7bc
- Added an optimized ProjectPoint2 to CoordinateSystem3D. It has *not* replaced
Benjamin Golinvaux <bgo@osimis.io>
parents:
439
diff
changeset
|
43 const Vector& point, |
53cc787bd7bc
- Added an optimized ProjectPoint2 to CoordinateSystem3D. It has *not* replaced
Benjamin Golinvaux <bgo@osimis.io>
parents:
439
diff
changeset
|
44 const Vector& planeNormal, |
53cc787bd7bc
- Added an optimized ProjectPoint2 to CoordinateSystem3D. It has *not* replaced
Benjamin Golinvaux <bgo@osimis.io>
parents:
439
diff
changeset
|
45 const Vector& planeOrigin); |
53cc787bd7bc
- Added an optimized ProjectPoint2 to CoordinateSystem3D. It has *not* replaced
Benjamin Golinvaux <bgo@osimis.io>
parents:
439
diff
changeset
|
46 |
0 | 47 bool IsParallel(const Vector& u, |
48 const Vector& v); | |
49 | |
50 bool IsParallelOrOpposite(bool& isOpposite, | |
51 const Vector& u, | |
52 const Vector& v); | |
53 | |
54 bool IntersectTwoPlanes(Vector& p, | |
55 Vector& direction, | |
56 const Vector& origin1, | |
57 const Vector& normal1, | |
58 const Vector& origin2, | |
59 const Vector& normal2); | |
60 | |
61 bool ClipLineToRectangle(double& x1, // Coordinates of the clipped line (out) | |
62 double& y1, | |
63 double& x2, | |
64 double& y2, | |
65 const double ax, // Two points defining the line (in) | |
66 const double ay, | |
67 const double bx, | |
68 const double by, | |
69 const double& xmin, // Coordinates of the rectangle (in) | |
70 const double& ymin, | |
71 const double& xmax, | |
72 const double& ymax); | |
32 | 73 |
1821
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
74 bool GetPixelSpacing(double& spacingX, |
32 | 75 double& spacingY, |
118
a4d0b6c82b29
using Orthanc::DicomMap instead of OrthancPlugins::DicomDatasetReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
76 const Orthanc::DicomMap& dicom); |
122
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
77 |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
78 inline double ProjectAlongNormal(const Vector& point, |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
79 const Vector& normal) |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
80 { |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
81 return boost::numeric::ublas::inner_prod(point, normal); |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
82 } |
140
2115530d3703
OrientedBoundingBox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
135
diff
changeset
|
83 |
2115530d3703
OrientedBoundingBox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
135
diff
changeset
|
84 Matrix CreateRotationMatrixAlongX(double a); |
2115530d3703
OrientedBoundingBox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
135
diff
changeset
|
85 |
2115530d3703
OrientedBoundingBox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
135
diff
changeset
|
86 Matrix CreateRotationMatrixAlongY(double a); |
2115530d3703
OrientedBoundingBox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
135
diff
changeset
|
87 |
144
9b83f30fc1c0
bilinear and trilinear interpolation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
88 Matrix CreateRotationMatrixAlongZ(double a); |
9b83f30fc1c0
bilinear and trilinear interpolation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
89 |
165
8d50e6be565d
LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
158
diff
changeset
|
90 Matrix CreateTranslationMatrix(double dx, |
8d50e6be565d
LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
158
diff
changeset
|
91 double dy, |
8d50e6be565d
LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
158
diff
changeset
|
92 double dz); |
8d50e6be565d
LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
158
diff
changeset
|
93 |
8d50e6be565d
LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
158
diff
changeset
|
94 Matrix CreateScalingMatrix(double sx, |
8d50e6be565d
LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
158
diff
changeset
|
95 double sy, |
8d50e6be565d
LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
158
diff
changeset
|
96 double sz); |
8d50e6be565d
LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
158
diff
changeset
|
97 |
151
c5044bbfc303
CoordinateSystem3D::IntersectSegment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
150
diff
changeset
|
98 bool IntersectPlaneAndSegment(Vector& p, |
c5044bbfc303
CoordinateSystem3D::IntersectSegment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
150
diff
changeset
|
99 const Vector& normal, |
c5044bbfc303
CoordinateSystem3D::IntersectSegment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
150
diff
changeset
|
100 double d, |
c5044bbfc303
CoordinateSystem3D::IntersectSegment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
150
diff
changeset
|
101 const Vector& edgeFrom, |
c5044bbfc303
CoordinateSystem3D::IntersectSegment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
150
diff
changeset
|
102 const Vector& edgeTo); |
c5044bbfc303
CoordinateSystem3D::IntersectSegment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
150
diff
changeset
|
103 |
157
2309e8d86efe
IntersectPlaneAndLine
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
156
diff
changeset
|
104 bool IntersectPlaneAndLine(Vector& p, |
2309e8d86efe
IntersectPlaneAndLine
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
156
diff
changeset
|
105 const Vector& normal, |
2309e8d86efe
IntersectPlaneAndLine
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
156
diff
changeset
|
106 double d, |
2309e8d86efe
IntersectPlaneAndLine
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
156
diff
changeset
|
107 const Vector& origin, |
2309e8d86efe
IntersectPlaneAndLine
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
156
diff
changeset
|
108 const Vector& direction); |
2309e8d86efe
IntersectPlaneAndLine
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
156
diff
changeset
|
109 |
189
964118e7e6de
unit test for AlignVectorsWithRotation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
177
diff
changeset
|
110 void AlignVectorsWithRotation(Matrix& r, |
964118e7e6de
unit test for AlignVectorsWithRotation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
177
diff
changeset
|
111 const Vector& a, |
964118e7e6de
unit test for AlignVectorsWithRotation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
177
diff
changeset
|
112 const Vector& b); |
964118e7e6de
unit test for AlignVectorsWithRotation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
177
diff
changeset
|
113 |
1477
5732edec7cbd
sorting frames in 3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1270
diff
changeset
|
114 void ComputeNormalFromCosines(Vector& normal, |
5732edec7cbd
sorting frames in 3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1270
diff
changeset
|
115 const Vector& cosines); |
5732edec7cbd
sorting frames in 3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1270
diff
changeset
|
116 |
5732edec7cbd
sorting frames in 3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1270
diff
changeset
|
117 bool ComputeNormal(Vector& normal, |
5732edec7cbd
sorting frames in 3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1270
diff
changeset
|
118 const Orthanc::DicomMap& dicom); |
5732edec7cbd
sorting frames in 3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1270
diff
changeset
|
119 |
177 | 120 inline float ComputeBilinearInterpolationUnitSquare(float x, |
121 float y, | |
122 float f00, // source(0, 0) | |
123 float f01, // source(1, 0) | |
124 float f10, // source(0, 1) | |
125 float f11); // source(1, 1) | |
144
9b83f30fc1c0
bilinear and trilinear interpolation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
126 |
177 | 127 inline float ComputeTrilinearInterpolationUnitSquare(float x, |
128 float y, | |
129 float z, | |
130 float f000, // source(0, 0, 0) | |
131 float f001, // source(1, 0, 0) | |
132 float f010, // source(0, 1, 0) | |
133 float f011, // source(1, 1, 0) | |
134 float f100, // source(0, 0, 1) | |
135 float f101, // source(1, 0, 1) | |
136 float f110, // source(0, 1, 1) | |
137 float f111); // source(1, 1, 1) | |
0 | 138 }; |
139 } | |
144
9b83f30fc1c0
bilinear and trilinear interpolation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
140 |
9b83f30fc1c0
bilinear and trilinear interpolation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
141 |
177 | 142 float OrthancStone::GeometryToolbox::ComputeBilinearInterpolationUnitSquare(float x, |
143 float y, | |
144 float f00, | |
145 float f01, | |
146 float f10, | |
147 float f11) | |
144
9b83f30fc1c0
bilinear and trilinear interpolation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
148 { |
177 | 149 // This function only works within the unit square |
150 assert(x >= 0 && y >= 0 && x <= 1 && y <= 1); | |
144
9b83f30fc1c0
bilinear and trilinear interpolation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
151 |
9b83f30fc1c0
bilinear and trilinear interpolation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
152 // https://en.wikipedia.org/wiki/Bilinear_interpolation#Unit_square |
175
15d92d93738b
fix interpolation with negative coordinates
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
172
diff
changeset
|
153 return (f00 * (1.0f - x) * (1.0f - y) + |
15d92d93738b
fix interpolation with negative coordinates
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
172
diff
changeset
|
154 f01 * x * (1.0f - y) + |
15d92d93738b
fix interpolation with negative coordinates
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
172
diff
changeset
|
155 f10 * (1.0f - x) * y + |
15d92d93738b
fix interpolation with negative coordinates
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
172
diff
changeset
|
156 f11 * x * y); |
144
9b83f30fc1c0
bilinear and trilinear interpolation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
157 } |
9b83f30fc1c0
bilinear and trilinear interpolation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
158 |
9b83f30fc1c0
bilinear and trilinear interpolation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
159 |
177 | 160 float OrthancStone::GeometryToolbox::ComputeTrilinearInterpolationUnitSquare(float x, |
161 float y, | |
162 float z, | |
163 float f000, | |
164 float f001, | |
165 float f010, | |
166 float f011, | |
167 float f100, | |
168 float f101, | |
169 float f110, | |
170 float f111) | |
144
9b83f30fc1c0
bilinear and trilinear interpolation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
171 { |
9b83f30fc1c0
bilinear and trilinear interpolation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
172 // "In practice, a trilinear interpolation is identical to two |
9b83f30fc1c0
bilinear and trilinear interpolation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
173 // bilinear interpolation combined with a linear interpolation" |
9b83f30fc1c0
bilinear and trilinear interpolation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
174 // https://en.wikipedia.org/wiki/Trilinear_interpolation#Method |
177 | 175 float a = ComputeBilinearInterpolationUnitSquare(x, y, f000, f001, f010, f011); |
176 float b = ComputeBilinearInterpolationUnitSquare(x, y, f100, f101, f110, f111); | |
144
9b83f30fc1c0
bilinear and trilinear interpolation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
177 |
177 | 178 return (1.0f - z) * a + z * b; |
144
9b83f30fc1c0
bilinear and trilinear interpolation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
179 } |