Mercurial > hg > orthanc-stone
annotate OrthancStone/Sources/Volumes/OrientedVolumeBoundingBox.cpp @ 1886:ca89fec8c48f
test
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 14 Jan 2022 19:10:30 +0100 |
parents | 7053b8a0aaec |
children | 07964689cb0b |
rev | line source |
---|---|
140 | 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 |
140 | 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 |
140 | 10 * as published by the Free Software Foundation, either version 3 of |
11 * the License, or (at your option) any later version. | |
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/>. |
140 | 21 **/ |
22 | |
23 | |
742
fa5febe0f0c2
moved OrientedBoundingBox in the Volumes folder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
735
diff
changeset
|
24 #include "OrientedVolumeBoundingBox.h" |
140 | 25 |
742
fa5febe0f0c2
moved OrientedBoundingBox in the Volumes folder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
735
diff
changeset
|
26 #include "../Toolbox/GeometryToolbox.h" |
fa5febe0f0c2
moved OrientedBoundingBox in the Volumes folder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
735
diff
changeset
|
27 #include "ImageBuffer3D.h" |
159
0a73d76333db
populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
158
diff
changeset
|
28 |
1455
30deba7bc8e2
simplifying include_directories
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1270
diff
changeset
|
29 #include <OrthancException.h> |
140 | 30 |
31 #include <cassert> | |
32 | |
33 namespace OrthancStone | |
34 { | |
742
fa5febe0f0c2
moved OrientedBoundingBox in the Volumes folder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
735
diff
changeset
|
35 OrientedVolumeBoundingBox::OrientedVolumeBoundingBox(const VolumeImageGeometry& geometry) |
140 | 36 { |
735
c3bbb130abc4
removing dependencies in ImageBuffer3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
684
diff
changeset
|
37 unsigned int n = geometry.GetDepth(); |
140 | 38 if (n < 1) |
39 { | |
40 throw Orthanc::OrthancException(Orthanc::ErrorCode_IncompatibleImageSize); | |
41 } | |
42 | |
735
c3bbb130abc4
removing dependencies in ImageBuffer3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
684
diff
changeset
|
43 Vector dim = geometry.GetVoxelDimensions(VolumeProjection_Axial); |
c3bbb130abc4
removing dependencies in ImageBuffer3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
684
diff
changeset
|
44 |
c3bbb130abc4
removing dependencies in ImageBuffer3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
684
diff
changeset
|
45 u_ = geometry.GetAxialGeometry().GetAxisX(); |
c3bbb130abc4
removing dependencies in ImageBuffer3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
684
diff
changeset
|
46 v_ = geometry.GetAxialGeometry().GetAxisY(); |
c3bbb130abc4
removing dependencies in ImageBuffer3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
684
diff
changeset
|
47 w_ = geometry.GetAxialGeometry().GetNormal(); |
140 | 48 |
735
c3bbb130abc4
removing dependencies in ImageBuffer3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
684
diff
changeset
|
49 hu_ = static_cast<double>(geometry.GetWidth() * dim[0] / 2.0); |
c3bbb130abc4
removing dependencies in ImageBuffer3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
684
diff
changeset
|
50 hv_ = static_cast<double>(geometry.GetHeight() * dim[1] / 2.0); |
c3bbb130abc4
removing dependencies in ImageBuffer3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
684
diff
changeset
|
51 hw_ = static_cast<double>(geometry.GetDepth() * dim[2] / 2.0); |
140 | 52 |
735
c3bbb130abc4
removing dependencies in ImageBuffer3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
684
diff
changeset
|
53 c_ = (geometry.GetAxialGeometry().GetOrigin() + |
140 | 54 (hu_ - dim[0] / 2.0) * u_ + |
55 (hv_ - dim[1] / 2.0) * v_ + | |
56 (hw_ - dim[2] / 2.0) * w_); | |
57 } | |
58 | |
59 | |
742
fa5febe0f0c2
moved OrientedBoundingBox in the Volumes folder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
735
diff
changeset
|
60 bool OrientedVolumeBoundingBox::HasIntersectionWithPlane(std::vector<Vector>& points, |
fa5febe0f0c2
moved OrientedBoundingBox in the Volumes folder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
735
diff
changeset
|
61 const Vector& normal, |
fa5febe0f0c2
moved OrientedBoundingBox in the Volumes folder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
735
diff
changeset
|
62 double d) const |
140 | 63 { |
64 assert(normal.size() == 3); | |
65 | |
66 double r = (hu_ * fabs(boost::numeric::ublas::inner_prod(normal, u_)) + | |
67 hv_ * fabs(boost::numeric::ublas::inner_prod(normal, v_)) + | |
68 hw_ * fabs(boost::numeric::ublas::inner_prod(normal, w_))); | |
69 | |
70 double s = boost::numeric::ublas::inner_prod(normal, c_) + d; | |
71 | |
72 if (fabs(s) >= r) | |
73 { | |
74 // No intersection, or intersection is reduced to a single point | |
75 return false; | |
76 } | |
77 else | |
78 { | |
79 Vector p; | |
80 | |
81 // Loop over all the 12 edges (segments) of the oriented | |
82 // bounding box, and check whether they intersect the plane | |
83 | |
84 // X-aligned edges | |
151
c5044bbfc303
CoordinateSystem3D::IntersectSegment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
146
diff
changeset
|
85 if (GeometryToolbox::IntersectPlaneAndSegment |
c5044bbfc303
CoordinateSystem3D::IntersectSegment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
146
diff
changeset
|
86 (p, normal, d, |
c5044bbfc303
CoordinateSystem3D::IntersectSegment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
146
diff
changeset
|
87 c_ - u_ * hu_ - v_ * hv_ - w_ * hw_, |
c5044bbfc303
CoordinateSystem3D::IntersectSegment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
146
diff
changeset
|
88 c_ + u_ * hu_ - v_ * hv_ - w_ * hw_)) |
140 | 89 { |
90 points.push_back(p); | |
91 } | |
92 | |
151
c5044bbfc303
CoordinateSystem3D::IntersectSegment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
146
diff
changeset
|
93 if (GeometryToolbox::IntersectPlaneAndSegment |
c5044bbfc303
CoordinateSystem3D::IntersectSegment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
146
diff
changeset
|
94 (p, normal, d, |
c5044bbfc303
CoordinateSystem3D::IntersectSegment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
146
diff
changeset
|
95 c_ - u_ * hu_ + v_ * hv_ - w_ * hw_, |
c5044bbfc303
CoordinateSystem3D::IntersectSegment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
146
diff
changeset
|
96 c_ + u_ * hu_ + v_ * hv_ - w_ * hw_)) |
140 | 97 { |
98 points.push_back(p); | |
99 } | |
100 | |
151
c5044bbfc303
CoordinateSystem3D::IntersectSegment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
146
diff
changeset
|
101 if (GeometryToolbox::IntersectPlaneAndSegment |
c5044bbfc303
CoordinateSystem3D::IntersectSegment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
146
diff
changeset
|
102 (p, normal, d, |
c5044bbfc303
CoordinateSystem3D::IntersectSegment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
146
diff
changeset
|
103 c_ - u_ * hu_ - v_ * hv_ + w_ * hw_, |
c5044bbfc303
CoordinateSystem3D::IntersectSegment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
146
diff
changeset
|
104 c_ + u_ * hu_ - v_ * hv_ + w_ * hw_)) |
140 | 105 { |
106 points.push_back(p); | |
107 } | |
108 | |
151
c5044bbfc303
CoordinateSystem3D::IntersectSegment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
146
diff
changeset
|
109 if (GeometryToolbox::IntersectPlaneAndSegment |
c5044bbfc303
CoordinateSystem3D::IntersectSegment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
146
diff
changeset
|
110 (p, normal, d, |
c5044bbfc303
CoordinateSystem3D::IntersectSegment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
146
diff
changeset
|
111 c_ - u_ * hu_ + v_ * hv_ + w_ * hw_, |
c5044bbfc303
CoordinateSystem3D::IntersectSegment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
146
diff
changeset
|
112 c_ + u_ * hu_ + v_ * hv_ + w_ * hw_)) |
140 | 113 { |
114 points.push_back(p); | |
115 } | |
116 | |
117 // Y-aligned edges | |
151
c5044bbfc303
CoordinateSystem3D::IntersectSegment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
146
diff
changeset
|
118 if (GeometryToolbox::IntersectPlaneAndSegment |
c5044bbfc303
CoordinateSystem3D::IntersectSegment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
146
diff
changeset
|
119 (p, normal, d, |
c5044bbfc303
CoordinateSystem3D::IntersectSegment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
146
diff
changeset
|
120 c_ - u_ * hu_ - v_ * hv_ - w_ * hw_, |
c5044bbfc303
CoordinateSystem3D::IntersectSegment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
146
diff
changeset
|
121 c_ - u_ * hu_ + v_ * hv_ - w_ * hw_)) |
140 | 122 { |
123 points.push_back(p); | |
124 } | |
125 | |
151
c5044bbfc303
CoordinateSystem3D::IntersectSegment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
146
diff
changeset
|
126 if (GeometryToolbox::IntersectPlaneAndSegment |
c5044bbfc303
CoordinateSystem3D::IntersectSegment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
146
diff
changeset
|
127 (p, normal, d, |
c5044bbfc303
CoordinateSystem3D::IntersectSegment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
146
diff
changeset
|
128 c_ + u_ * hu_ - v_ * hv_ - w_ * hw_, |
c5044bbfc303
CoordinateSystem3D::IntersectSegment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
146
diff
changeset
|
129 c_ + u_ * hu_ + v_ * hv_ - w_ * hw_)) |
140 | 130 { |
131 points.push_back(p); | |
132 } | |
133 | |
151
c5044bbfc303
CoordinateSystem3D::IntersectSegment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
146
diff
changeset
|
134 if (GeometryToolbox::IntersectPlaneAndSegment |
c5044bbfc303
CoordinateSystem3D::IntersectSegment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
146
diff
changeset
|
135 (p, normal, d, |
c5044bbfc303
CoordinateSystem3D::IntersectSegment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
146
diff
changeset
|
136 c_ - u_ * hu_ - v_ * hv_ + w_ * hw_, |
c5044bbfc303
CoordinateSystem3D::IntersectSegment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
146
diff
changeset
|
137 c_ - u_ * hu_ + v_ * hv_ + w_ * hw_)) |
140 | 138 { |
139 points.push_back(p); | |
140 } | |
141 | |
151
c5044bbfc303
CoordinateSystem3D::IntersectSegment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
146
diff
changeset
|
142 if (GeometryToolbox::IntersectPlaneAndSegment |
c5044bbfc303
CoordinateSystem3D::IntersectSegment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
146
diff
changeset
|
143 (p, normal, d, |
c5044bbfc303
CoordinateSystem3D::IntersectSegment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
146
diff
changeset
|
144 c_ + u_ * hu_ - v_ * hv_ + w_ * hw_, |
c5044bbfc303
CoordinateSystem3D::IntersectSegment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
146
diff
changeset
|
145 c_ + u_ * hu_ + v_ * hv_ + w_ * hw_)) |
140 | 146 { |
147 points.push_back(p); | |
148 } | |
149 | |
150 // Z-aligned edges | |
151
c5044bbfc303
CoordinateSystem3D::IntersectSegment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
146
diff
changeset
|
151 if (GeometryToolbox::IntersectPlaneAndSegment |
c5044bbfc303
CoordinateSystem3D::IntersectSegment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
146
diff
changeset
|
152 (p, normal, d, |
c5044bbfc303
CoordinateSystem3D::IntersectSegment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
146
diff
changeset
|
153 c_ - u_ * hu_ - v_ * hv_ - w_ * hw_, |
c5044bbfc303
CoordinateSystem3D::IntersectSegment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
146
diff
changeset
|
154 c_ - u_ * hu_ - v_ * hv_ + w_ * hw_)) |
140 | 155 { |
156 points.push_back(p); | |
157 } | |
158 | |
151
c5044bbfc303
CoordinateSystem3D::IntersectSegment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
146
diff
changeset
|
159 if (GeometryToolbox::IntersectPlaneAndSegment |
c5044bbfc303
CoordinateSystem3D::IntersectSegment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
146
diff
changeset
|
160 (p, normal, d, |
c5044bbfc303
CoordinateSystem3D::IntersectSegment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
146
diff
changeset
|
161 c_ + u_ * hu_ - v_ * hv_ - w_ * hw_, |
c5044bbfc303
CoordinateSystem3D::IntersectSegment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
146
diff
changeset
|
162 c_ + u_ * hu_ - v_ * hv_ + w_ * hw_)) |
140 | 163 { |
164 points.push_back(p); | |
165 } | |
166 | |
151
c5044bbfc303
CoordinateSystem3D::IntersectSegment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
146
diff
changeset
|
167 if (GeometryToolbox::IntersectPlaneAndSegment |
c5044bbfc303
CoordinateSystem3D::IntersectSegment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
146
diff
changeset
|
168 (p, normal, d, |
c5044bbfc303
CoordinateSystem3D::IntersectSegment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
146
diff
changeset
|
169 c_ - u_ * hu_ + v_ * hv_ - w_ * hw_, |
c5044bbfc303
CoordinateSystem3D::IntersectSegment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
146
diff
changeset
|
170 c_ - u_ * hu_ + v_ * hv_ + w_ * hw_)) |
140 | 171 { |
172 points.push_back(p); | |
173 } | |
174 | |
151
c5044bbfc303
CoordinateSystem3D::IntersectSegment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
146
diff
changeset
|
175 if (GeometryToolbox::IntersectPlaneAndSegment |
c5044bbfc303
CoordinateSystem3D::IntersectSegment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
146
diff
changeset
|
176 (p, normal, d, |
c5044bbfc303
CoordinateSystem3D::IntersectSegment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
146
diff
changeset
|
177 c_ + u_ * hu_ + v_ * hv_ - w_ * hw_, |
c5044bbfc303
CoordinateSystem3D::IntersectSegment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
146
diff
changeset
|
178 c_ + u_ * hu_ + v_ * hv_ + w_ * hw_)) |
140 | 179 { |
180 points.push_back(p); | |
181 } | |
182 | |
183 return true; | |
184 } | |
185 } | |
186 | |
187 | |
742
fa5febe0f0c2
moved OrientedBoundingBox in the Volumes folder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
735
diff
changeset
|
188 bool OrientedVolumeBoundingBox::HasIntersection(std::vector<Vector>& points, |
fa5febe0f0c2
moved OrientedBoundingBox in the Volumes folder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
735
diff
changeset
|
189 const CoordinateSystem3D& plane) const |
140 | 190 { |
191 // From the vector equation of a 3D plane (specified by origin | |
192 // and normal), to the general equation of a 3D plane (which | |
193 // looses information about the origin of the coordinate system) | |
194 const Vector& normal = plane.GetNormal(); | |
195 const Vector& origin = plane.GetOrigin(); | |
196 double d = -(normal[0] * origin[0] + normal[1] * origin[1] + normal[2] * origin[2]); | |
197 | |
198 return HasIntersectionWithPlane(points, normal, d); | |
199 } | |
200 | |
201 | |
742
fa5febe0f0c2
moved OrientedBoundingBox in the Volumes folder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
735
diff
changeset
|
202 bool OrientedVolumeBoundingBox::Contains(const Vector& p) const |
140 | 203 { |
204 assert(p.size() == 3); | |
205 | |
206 const Vector q = p - c_; | |
207 | |
208 return (fabs(boost::numeric::ublas::inner_prod(q, u_)) <= hu_ && | |
209 fabs(boost::numeric::ublas::inner_prod(q, v_)) <= hv_ && | |
210 fabs(boost::numeric::ublas::inner_prod(q, w_)) <= hw_); | |
211 } | |
212 | |
213 | |
742
fa5febe0f0c2
moved OrientedBoundingBox in the Volumes folder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
735
diff
changeset
|
214 void OrientedVolumeBoundingBox::FromInternalCoordinates(Vector& target, |
fa5febe0f0c2
moved OrientedBoundingBox in the Volumes folder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
735
diff
changeset
|
215 double x, |
fa5febe0f0c2
moved OrientedBoundingBox in the Volumes folder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
735
diff
changeset
|
216 double y, |
fa5febe0f0c2
moved OrientedBoundingBox in the Volumes folder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
735
diff
changeset
|
217 double z) const |
140 | 218 { |
219 target = (c_ + | |
220 u_ * 2.0 * hu_ * (x - 0.5) + | |
221 v_ * 2.0 * hv_ * (y - 0.5) + | |
222 w_ * 2.0 * hw_ * (z - 0.5)); | |
223 } | |
224 | |
225 | |
742
fa5febe0f0c2
moved OrientedBoundingBox in the Volumes folder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
735
diff
changeset
|
226 void OrientedVolumeBoundingBox::FromInternalCoordinates(Vector& target, |
fa5febe0f0c2
moved OrientedBoundingBox in the Volumes folder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
735
diff
changeset
|
227 const Vector& source) const |
140 | 228 { |
229 assert(source.size() == 3); | |
230 FromInternalCoordinates(target, source[0], source[1], source[2]); | |
231 } | |
232 | |
233 | |
742
fa5febe0f0c2
moved OrientedBoundingBox in the Volumes folder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
735
diff
changeset
|
234 void OrientedVolumeBoundingBox::ToInternalCoordinates(Vector& target, |
fa5febe0f0c2
moved OrientedBoundingBox in the Volumes folder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
735
diff
changeset
|
235 const Vector& source) const |
140 | 236 { |
237 assert(source.size() == 3); | |
238 const Vector q = source - c_; | |
239 | |
240 double x = boost::numeric::ublas::inner_prod(q, u_) / (2.0 * hu_) + 0.5; | |
241 double y = boost::numeric::ublas::inner_prod(q, v_) / (2.0 * hv_) + 0.5; | |
242 double z = boost::numeric::ublas::inner_prod(q, w_) / (2.0 * hw_) + 0.5; | |
243 | |
158
a053ca7fa5c6
LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
151
diff
changeset
|
244 LinearAlgebra::AssignVector(target, x, y, z); |
140 | 245 } |
146
fb7d602e7025
OrientedBoundingBox::ComputeExtent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
246 |
fb7d602e7025
OrientedBoundingBox::ComputeExtent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
247 |
742
fa5febe0f0c2
moved OrientedBoundingBox in the Volumes folder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
735
diff
changeset
|
248 bool OrientedVolumeBoundingBox::ComputeExtent(Extent2D& extent, |
fa5febe0f0c2
moved OrientedBoundingBox in the Volumes folder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
735
diff
changeset
|
249 const CoordinateSystem3D& plane) const |
146
fb7d602e7025
OrientedBoundingBox::ComputeExtent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
250 { |
1610
b7630b1a0253
ISceneLayer::GetBoundingBox() returns void
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1598
diff
changeset
|
251 extent.Clear(); |
146
fb7d602e7025
OrientedBoundingBox::ComputeExtent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
252 |
fb7d602e7025
OrientedBoundingBox::ComputeExtent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
253 std::vector<Vector> points; |
fb7d602e7025
OrientedBoundingBox::ComputeExtent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
254 if (HasIntersection(points, plane)) |
fb7d602e7025
OrientedBoundingBox::ComputeExtent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
255 { |
fb7d602e7025
OrientedBoundingBox::ComputeExtent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
256 for (size_t i = 0; i < points.size(); i++) |
fb7d602e7025
OrientedBoundingBox::ComputeExtent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
257 { |
fb7d602e7025
OrientedBoundingBox::ComputeExtent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
258 double x, y; |
fb7d602e7025
OrientedBoundingBox::ComputeExtent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
259 plane.ProjectPoint(x, y, points[i]); |
fb7d602e7025
OrientedBoundingBox::ComputeExtent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
260 extent.AddPoint(x, y); |
fb7d602e7025
OrientedBoundingBox::ComputeExtent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
261 } |
fb7d602e7025
OrientedBoundingBox::ComputeExtent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
262 |
fb7d602e7025
OrientedBoundingBox::ComputeExtent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
263 return true; |
fb7d602e7025
OrientedBoundingBox::ComputeExtent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
264 } |
fb7d602e7025
OrientedBoundingBox::ComputeExtent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
265 else |
fb7d602e7025
OrientedBoundingBox::ComputeExtent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
266 { |
fb7d602e7025
OrientedBoundingBox::ComputeExtent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
267 return false; |
fb7d602e7025
OrientedBoundingBox::ComputeExtent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
268 } |
fb7d602e7025
OrientedBoundingBox::ComputeExtent
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
140
diff
changeset
|
269 } |
140 | 270 } |