Mercurial > hg > orthanc-stone
comparison OrthancStone/Sources/Toolbox/GeometryToolbox.h @ 1512:244ad1e4e76a
reorganization of folders
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 07 Jul 2020 16:21:02 +0200 |
parents | Framework/Toolbox/GeometryToolbox.h@5732edec7cbd |
children | 4fb8fdf03314 |
comparison
equal
deleted
inserted
replaced
1511:9dfeee74c1e6 | 1512:244ad1e4e76a |
---|---|
1 /** | |
2 * Stone of Orthanc | |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
4 * Department, University Hospital of Liege, Belgium | |
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium | |
6 * | |
7 * This program is free software: you can redistribute it and/or | |
8 * modify it under the terms of the GNU Affero General Public License | |
9 * as published by the Free Software Foundation, either version 3 of | |
10 * the License, or (at your option) any later version. | |
11 * | |
12 * This program is distributed in the hope that it will be useful, but | |
13 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 * Affero General Public License for more details. | |
16 * | |
17 * You should have received a copy of the GNU Affero General Public License | |
18 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
19 **/ | |
20 | |
21 | |
22 #pragma once | |
23 | |
24 #include "LinearAlgebra.h" | |
25 | |
26 namespace OrthancStone | |
27 { | |
28 namespace GeometryToolbox | |
29 { | |
30 void ProjectPointOntoPlane(Vector& result, | |
31 const Vector& point, | |
32 const Vector& planeNormal, | |
33 const Vector& planeOrigin); | |
34 | |
35 /* | |
36 Alternated faster implementation (untested yet) | |
37 */ | |
38 void ProjectPointOntoPlane2(double& resultX, | |
39 double& resultY, | |
40 double& resultZ, | |
41 const Vector& point, | |
42 const Vector& planeNormal, | |
43 const Vector& planeOrigin); | |
44 | |
45 bool IsParallel(const Vector& u, | |
46 const Vector& v); | |
47 | |
48 bool IsParallelOrOpposite(bool& isOpposite, | |
49 const Vector& u, | |
50 const Vector& v); | |
51 | |
52 bool IntersectTwoPlanes(Vector& p, | |
53 Vector& direction, | |
54 const Vector& origin1, | |
55 const Vector& normal1, | |
56 const Vector& origin2, | |
57 const Vector& normal2); | |
58 | |
59 bool ClipLineToRectangle(double& x1, // Coordinates of the clipped line (out) | |
60 double& y1, | |
61 double& x2, | |
62 double& y2, | |
63 const double ax, // Two points defining the line (in) | |
64 const double ay, | |
65 const double bx, | |
66 const double by, | |
67 const double& xmin, // Coordinates of the rectangle (in) | |
68 const double& ymin, | |
69 const double& xmax, | |
70 const double& ymax); | |
71 | |
72 void GetPixelSpacing(double& spacingX, | |
73 double& spacingY, | |
74 const Orthanc::DicomMap& dicom); | |
75 | |
76 inline double ProjectAlongNormal(const Vector& point, | |
77 const Vector& normal) | |
78 { | |
79 return boost::numeric::ublas::inner_prod(point, normal); | |
80 } | |
81 | |
82 Matrix CreateRotationMatrixAlongX(double a); | |
83 | |
84 Matrix CreateRotationMatrixAlongY(double a); | |
85 | |
86 Matrix CreateRotationMatrixAlongZ(double a); | |
87 | |
88 Matrix CreateTranslationMatrix(double dx, | |
89 double dy, | |
90 double dz); | |
91 | |
92 Matrix CreateScalingMatrix(double sx, | |
93 double sy, | |
94 double sz); | |
95 | |
96 bool IntersectPlaneAndSegment(Vector& p, | |
97 const Vector& normal, | |
98 double d, | |
99 const Vector& edgeFrom, | |
100 const Vector& edgeTo); | |
101 | |
102 bool IntersectPlaneAndLine(Vector& p, | |
103 const Vector& normal, | |
104 double d, | |
105 const Vector& origin, | |
106 const Vector& direction); | |
107 | |
108 void AlignVectorsWithRotation(Matrix& r, | |
109 const Vector& a, | |
110 const Vector& b); | |
111 | |
112 void ComputeNormalFromCosines(Vector& normal, | |
113 const Vector& cosines); | |
114 | |
115 bool ComputeNormal(Vector& normal, | |
116 const Orthanc::DicomMap& dicom); | |
117 | |
118 inline float ComputeBilinearInterpolationUnitSquare(float x, | |
119 float y, | |
120 float f00, // source(0, 0) | |
121 float f01, // source(1, 0) | |
122 float f10, // source(0, 1) | |
123 float f11); // source(1, 1) | |
124 | |
125 inline float ComputeTrilinearInterpolationUnitSquare(float x, | |
126 float y, | |
127 float z, | |
128 float f000, // source(0, 0, 0) | |
129 float f001, // source(1, 0, 0) | |
130 float f010, // source(0, 1, 0) | |
131 float f011, // source(1, 1, 0) | |
132 float f100, // source(0, 0, 1) | |
133 float f101, // source(1, 0, 1) | |
134 float f110, // source(0, 1, 1) | |
135 float f111); // source(1, 1, 1) | |
136 }; | |
137 } | |
138 | |
139 | |
140 float OrthancStone::GeometryToolbox::ComputeBilinearInterpolationUnitSquare(float x, | |
141 float y, | |
142 float f00, | |
143 float f01, | |
144 float f10, | |
145 float f11) | |
146 { | |
147 // This function only works within the unit square | |
148 assert(x >= 0 && y >= 0 && x <= 1 && y <= 1); | |
149 | |
150 // https://en.wikipedia.org/wiki/Bilinear_interpolation#Unit_square | |
151 return (f00 * (1.0f - x) * (1.0f - y) + | |
152 f01 * x * (1.0f - y) + | |
153 f10 * (1.0f - x) * y + | |
154 f11 * x * y); | |
155 } | |
156 | |
157 | |
158 float OrthancStone::GeometryToolbox::ComputeTrilinearInterpolationUnitSquare(float x, | |
159 float y, | |
160 float z, | |
161 float f000, | |
162 float f001, | |
163 float f010, | |
164 float f011, | |
165 float f100, | |
166 float f101, | |
167 float f110, | |
168 float f111) | |
169 { | |
170 // "In practice, a trilinear interpolation is identical to two | |
171 // bilinear interpolation combined with a linear interpolation" | |
172 // https://en.wikipedia.org/wiki/Trilinear_interpolation#Method | |
173 float a = ComputeBilinearInterpolationUnitSquare(x, y, f000, f001, f010, f011); | |
174 float b = ComputeBilinearInterpolationUnitSquare(x, y, f100, f101, f110, f111); | |
175 | |
176 return (1.0f - z) * a + z * b; | |
177 } |