Library of Assembled Shared Sources
plane_3d.inl
Go to the documentation of this file.
1/** @file
2 * @author Bram de Greve (bram@cocamware.com)
3 * @author Tom De Muer (tom@cocamware.com)
4 *
5 * *** BEGIN LICENSE INFORMATION ***
6 *
7 * The contents of this file are subject to the Common Public Attribution License
8 * Version 1.0 (the "License"); you may not use this file except in compliance with
9 * the License. You may obtain a copy of the License at
10 * http://lass.sourceforge.net/cpal-license. The License is based on the
11 * Mozilla Public License Version 1.1 but Sections 14 and 15 have been added to cover
12 * use of software over a computer network and provide for limited attribution for
13 * the Original Developer. In addition, Exhibit A has been modified to be consistent
14 * with Exhibit B.
15 *
16 * Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
17 * WARRANTY OF ANY KIND, either express or implied. See the License for the specific
18 * language governing rights and limitations under the License.
19 *
20 * The Original Code is LASS - Library of Assembled Shared Sources.
21 *
22 * The Initial Developer of the Original Code is Bram de Greve and Tom De Muer.
23 * The Original Developer is the Initial Developer.
24 *
25 * All portions of the code written by the Initial Developer are:
26 * Copyright (C) 2004-2011 the Initial Developer.
27 * All Rights Reserved.
28 *
29 * Contributor(s):
30 *
31 * Alternatively, the contents of this file may be used under the terms of the
32 * GNU General Public License Version 2 or later (the GPL), in which case the
33 * provisions of GPL are applicable instead of those above. If you wish to allow use
34 * of your version of this file only under the terms of the GPL and not to allow
35 * others to use your version of this file under the CPAL, indicate your decision by
36 * deleting the provisions above and replace them with the notice and other
37 * provisions required by the GPL License. If you do not delete the provisions above,
38 * a recipient may use your version of this file under either the CPAL or the GPL.
39 *
40 * *** END LICENSE INFORMATION ***
41 */
42
43
44
45#ifndef LASS_GUARDIAN_OF_INCLUSION_PRIM_PLANE_3D_INL
46#define LASS_GUARDIAN_OF_INCLUSION_PRIM_PLANE_3D_INL
47
48#include "prim_common.h"
49#include "plane_3d.h"
50
51namespace lass
52{
53namespace prim
54{
55
56// --- public --------------------------------------------------------------------------------------
57
58template<typename T, typename EP, typename NP>
59Plane3D<T, EP, NP>::Plane3D():
60 TImpl()
61{
62}
63
64
65
66
67template<typename T, typename EP, typename NP>
68Plane3D<T, EP, NP>::Plane3D(const TPoint& iSupport,
69 const TPoint& iPointU,
70 const TPoint& iPointV):
71 TImpl(iSupport, iPointU, iPointV)
72{
73}
74
75
76
77template<typename T, typename EP, typename NP>
78Plane3D<T, EP, NP>::Plane3D(const TPoint& iSupport,
79 const TVector& iDirU,
80 const TVector& iDirV):
81 TImpl(iSupport, iDirU, iDirV)
82{
83}
84
85
86
87template<typename T, typename EP, typename NP>
88Plane3D<T, EP, NP>::Plane3D(const TVector& iNormal, const TPoint& iSupport):
89 TImpl(iNormal, iSupport)
90{
91}
92
93
94
95template<typename T, typename EP, typename NP>
96Plane3D<T, EP, NP>::Plane3D(const TVector& iNormal, TParam iD):
97 TImpl(iNormal, iD)
98{
99}
100
101
102
103/** Return on what side a point is located.
104 */
105template<typename T, typename EP, typename NP>
106Side Plane3D<T, EP, NP>::classify(const TPoint& iPoint) const
107{
108 const TValue eq = this->equation(iPoint);
109 return eq > TNumTraits::zero ? sFront : (eq < TNumTraits::zero ? sBack : sSurface);
110}
111
112
113
114/** Return signed distance of point to plane.
115 * negative value means point is in the back.
116 */
117template<typename T, typename EP, typename NP>
118const typename Plane3D<T, EP, NP>::TValue
119Plane3D<T, EP, NP>::signedDistance(const TPoint& iPoint) const
120{
121 return NP::divideByNorm(this->equation(iPoint), this->normal());
122}
123
124
125
126/** Return squared distance of point to plane.
127 */
128template<typename T, typename EP, typename NP>
129const typename Plane3D<T, EP, NP>::TValue
130Plane3D<T, EP, NP>::squaredDistance(const TPoint& iPoint) const
131{
132 return num::sqr(this->signedDistance(iPoint));
133}
134
135
136
137/** Return on what side a point is located.
138 */
139template<typename T, typename EP, typename NP>
140Side Plane3D<T, EP, NP>::classify(const TPoint& iPoint, TParam iRelativeTolerance) const
141{
142 const TValue eq = this->equation(iPoint, iRelativeTolerance);
143 return eq > TNumTraits::zero ? sFront : (eq < TNumTraits::zero ? sBack : sSurface);
144}
145
146
147
148/** Return signed distance of point to plane.
149 * negative value means point is in the back.
150 */
151template<typename T, typename EP, typename NP>
152const typename Plane3D<T, EP, NP>::TValue
153Plane3D<T, EP, NP>::signedDistance(const TPoint& iPoint, TParam iRelativeTolerance) const
154{
155 return NP::divideByNorm(equation(iPoint, iRelativeTolerance), this->normal());
156}
157
158
159
160/** Return squared distance of point to plane.
161 */
162template<typename T, typename EP, typename NP>
163const typename Plane3D<T, EP, NP>::TValue
164Plane3D<T, EP, NP>::squaredDistance(const TPoint& iPoint, TParam iRelativeTolerance) const
165{
166 return num::sqr(signedDistance(iPoint, iRelativeTolerance));
167}
168
169
170
171/** determines the major axis of the normal vector.
172 * The major axis is the one with the largest (absolute) component value. e.g. if the normal
173 * vector is (-1, 4, -8), this will be the @e z axis because abs(-8) > abs(4) > abs(-1).
174 * In case there's more than one major axis possible, the "highest" index is choosen. e.g.
175 * if the normal vector is (1, 1, 0), then @e y axis will be choosen, because @e y has a higher
176 * index than @e x .
177 */
178template<typename T, typename EP, typename NP>
180{
181 const TVector absNormal = this->normal().transform(num::abs);
182 if (absNormal.x > absNormal.y && absNormal.x > absNormal.z)
183 {
184 return 0; // x
185 }
186 else if (absNormal.y > absNormal.z)
187 {
188 return 1; // y
189 }
190 else
191 {
192 return 2; // z
193 }
194 LASS_ASSERT(false);
195 return 0;
196}
197
198
199
200// --- protected -----------------------------------------------------------------------------------
201
202
203
204// --- private -------------------------------------------------------------------------------------
205
206
207
208// --- free ----------------------------------------------------------------------------------------
209
210
211/** @relates Plane3D
212 */
213template <typename T>
214io::XmlOStream& operator<<(io::XmlOStream& ioOStream, const Plane3D<T, Cartesian>& iPlane)
215{
216 LASS_ENFORCE_STREAM(ioOStream)
217 << "<Plane3D>\n"
218 << "<normal>" << iPlane.normal() << "</normal>\n"
219 << "<d>" << iPlane.d() << "</d>\n"
220 << "</Plane3D>\n";
221
222 return ioOStream;
223}
224
225
226
227/** @relates Plane3D
228 */
229template <typename T>
230io::XmlOStream& operator<<(io::XmlOStream& ioOStream, const Plane3D<T, Parametric>& iPlane)
231{
232 LASS_ENFORCE_STREAM(ioOStream)
233 << "<Plane3D>\n"
234 << "<support>" << iPlane.support() << "</support>\n"
235 << "<directionU>" << iPlane.directionU() << "</directionU>\n"
236 << "<directionV>" << iPlane.directionV() << "</directionV>\n"
237 << "</Plane3D>\n";
238
239 return ioOStream;
240}
241
242
243
244/** @relates Plane3D
245 */
246template <typename T>
247io::XmlOStream& operator<<(io::XmlOStream& ioOStream, const Plane3D<T, Combined>& iPlane)
248{
249 LASS_ENFORCE_STREAM(ioOStream)
250 << "<Plane3D>\n"
251 << "<support>" << iPlane.support() << "</support>\n"
252 << "<directionU>" << iPlane.directionU() << "</directionU>\n"
253 << "<directionV>" << iPlane.directionV() << "</directionV>\n"
254 << "<normal>" << iPlane.normal() << "</normal>\n"
255 << "<d>" << iPlane.d() << "</d>\n"
256 << "</Plane3D>\n";
257
258 return ioOStream;
259}
260
261
262
263}
264
265}
266
267#endif
268
269// EOF
Output stream for writing a selection of geometric primitives to XML files.
A 3D hyper plane.
Definition plane_3d.h:361
const TValue signedDistance(const TPoint &iPoint) const
Return signed distance of point to plane.
Definition plane_3d.inl:119
const TValue squaredDistance(const TPoint &iPoint) const
Return squared distance of point to plane.
Definition plane_3d.inl:130
Side classify(const TPoint &iPoint) const
Return on what side a point is located.
Definition plane_3d.inl:106
const XYZ majorAxis() const
determines the major axis of the normal vector.
Definition plane_3d.inl:179
cyclic iterator over xyz indices
Definition xyz.h:62
const TValue equation(const TPoint &iPoint) const
Return value of point in equation.
T sqr(const T &x)
return x * x
Definition basic_ops.h:162
T abs(const T &x)
if x < 0 return -x, else return x.
Definition basic_ops.h:145
set of geometrical primitives
Definition aabb_2d.h:81
Side
Different sides of a surface.
Definition side.h:79
@ sFront
in front of the surface
Definition side.h:81
@ sBack
in back of the surface
Definition side.h:83
@ sSurface
right on the surface
Definition side.h:87
Library for Assembled Shared Sources.
Definition config.h:53