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