library of assembled shared sources

http://lass.cocamware.com

plane_3d.inl

Go to the documentation of this file.
00001 /** @file
00002  *  @author Bram de Greve (bramz@users.sourceforge.net)
00003  *  @author Tom De Muer (tomdemuer@users.sourceforge.net)
00004  *
00005  *  *** BEGIN LICENSE INFORMATION ***
00006  *  
00007  *  The contents of this file are subject to the Common Public Attribution License 
00008  *  Version 1.0 (the "License"); you may not use this file except in compliance with 
00009  *  the License. You may obtain a copy of the License at 
00010  *  http://lass.sourceforge.net/cpal-license. The License is based on the 
00011  *  Mozilla Public License Version 1.1 but Sections 14 and 15 have been added to cover 
00012  *  use of software over a computer network and provide for limited attribution for 
00013  *  the Original Developer. In addition, Exhibit A has been modified to be consistent 
00014  *  with Exhibit B.
00015  *  
00016  *  Software distributed under the License is distributed on an "AS IS" basis, WITHOUT 
00017  *  WARRANTY OF ANY KIND, either express or implied. See the License for the specific 
00018  *  language governing rights and limitations under the License.
00019  *  
00020  *  The Original Code is LASS - Library of Assembled Shared Sources.
00021  *  
00022  *  The Initial Developer of the Original Code is Bram de Greve and Tom De Muer.
00023  *  The Original Developer is the Initial Developer.
00024  *  
00025  *  All portions of the code written by the Initial Developer are:
00026  *  Copyright (C) 2004-2007 the Initial Developer.
00027  *  All Rights Reserved.
00028  *  
00029  *  Contributor(s):
00030  *
00031  *  Alternatively, the contents of this file may be used under the terms of the 
00032  *  GNU General Public License Version 2 or later (the GPL), in which case the 
00033  *  provisions of GPL are applicable instead of those above.  If you wish to allow use
00034  *  of your version of this file only under the terms of the GPL and not to allow 
00035  *  others to use your version of this file under the CPAL, indicate your decision by 
00036  *  deleting the provisions above and replace them with the notice and other 
00037  *  provisions required by the GPL License. If you do not delete the provisions above,
00038  *  a recipient may use your version of this file under either the CPAL or the GPL.
00039  *  
00040  *  *** END LICENSE INFORMATION ***
00041  */
00042 
00043 
00044 
00045 #ifndef LASS_GUARDIAN_OF_INCLUSION_PRIM_PLANE_3D_INL
00046 #define LASS_GUARDIAN_OF_INCLUSION_PRIM_PLANE_3D_INL
00047 
00048 #include "prim_common.h"
00049 #include "plane_3d.h"
00050 
00051 namespace lass
00052 {
00053 namespace prim
00054 {
00055 
00056 // --- public --------------------------------------------------------------------------------------
00057 
00058 template<typename T, typename EP, typename NP>
00059 Plane3D<T, EP, NP>::Plane3D():
00060     TImpl()
00061 {
00062 }
00063 
00064 
00065 
00066 
00067 template<typename T, typename EP, typename NP>
00068 Plane3D<T, EP, NP>::Plane3D(const TPoint& iSupport,
00069                             const TPoint& iPointU,
00070                             const TPoint& iPointV):
00071     TImpl(iSupport, iPointU, iPointV)
00072 {
00073 }
00074 
00075 
00076 
00077 template<typename T, typename EP, typename NP>
00078 Plane3D<T, EP, NP>::Plane3D(const TPoint& iSupport,
00079                             const TVector& iDirU,
00080                             const TVector& iDirV):
00081     TImpl(iSupport, iDirU, iDirV)
00082 {
00083 }
00084 
00085 
00086 
00087 template<typename T, typename EP, typename NP>
00088 Plane3D<T, EP, NP>::Plane3D(const TVector& iNormal, const TPoint& iSupport):
00089     TImpl(iNormal, iSupport)
00090 {
00091 }
00092 
00093 
00094 
00095 template<typename T, typename EP, typename NP>
00096 Plane3D<T, EP, NP>::Plane3D(const TVector& iNormal, TParam iD):
00097     TImpl(iNormal, iD)
00098 {
00099 }
00100 
00101 
00102 
00103 /** Return on what side a point is located.
00104  */
00105 template<typename T, typename EP, typename NP>
00106 const Side Plane3D<T, EP, NP>::classify(const TPoint& iPoint) const
00107 {
00108     const TValue eq = this->equation(iPoint);
00109     return eq > TNumTraits::zero ? sFront : (eq < TNumTraits::zero ? sBack : sSurface);
00110 }
00111 
00112 
00113 
00114 /** Return signed distance of point to plane.
00115  *  negative value means point is in the back.
00116  */
00117 template<typename T, typename EP, typename NP>
00118 const typename Plane3D<T, EP, NP>::TValue
00119 Plane3D<T, EP, NP>::signedDistance(const TPoint& iPoint) const
00120 {
00121     return NP::divideByNorm(this->equation(iPoint), this->normal());
00122 }
00123 
00124 
00125 
00126 /** Return squared distance of point to plane.
00127  */
00128 template<typename T, typename EP, typename NP>
00129 const typename Plane3D<T, EP, NP>::TValue
00130 Plane3D<T, EP, NP>::squaredDistance(const TPoint& iPoint) const
00131 {
00132     return num::sqr(this->signedDistance(iPoint));
00133 }
00134 
00135 
00136 
00137 /** Return on what side a point is located.
00138  */
00139 template<typename T, typename EP, typename NP>
00140 const Side Plane3D<T, EP, NP>::classify(const TPoint& iPoint, TParam iRelativeTolerance) const
00141 {
00142     const TValue eq = this->equation(iPoint, iRelativeTolerance);
00143     return eq > TNumTraits::zero ? sFront : (eq < TNumTraits::zero ? sBack : sSurface);
00144 }
00145 
00146 
00147 
00148 /** Return signed distance of point to plane.
00149  *  negative value means point is in the back.
00150  */
00151 template<typename T, typename EP, typename NP>
00152 const typename Plane3D<T, EP, NP>::TValue
00153 Plane3D<T, EP, NP>::signedDistance(const TPoint& iPoint, TParam iRelativeTolerance) const
00154 {
00155     return NP::divideByNorm(equation(iPoint, iRelativeTolerance), this->normal());
00156 }
00157 
00158 
00159 
00160 /** Return squared distance of point to plane.
00161  */
00162 template<typename T, typename EP, typename NP>
00163 const typename Plane3D<T, EP, NP>::TValue
00164 Plane3D<T, EP, NP>::squaredDistance(const TPoint& iPoint, TParam iRelativeTolerance) const
00165 {
00166     return num::sqr(signedDistance(iPoint, iRelativeTolerance));
00167 }
00168 
00169 
00170 
00171 /** determines the major axis of the normal vector.
00172  *  The major axis is the one with the largest (absolute) component value.  e.g. if the normal
00173  *  vector is (-1, 4, -8), this will be the @e z axis because abs(-8) > abs(4) > abs(-1).
00174  *  In case there's more than one major axis possible, the "highest" index is choosen.  e.g.
00175  *  if the normal vector is (1, 1, 0), then @e y axis will be choosen, because @e y has a higher
00176  *  index than @e x .
00177  */
00178 template<typename T, typename EP, typename NP>
00179 const XYZ Plane3D<T, EP, NP>::majorAxis() const
00180 {
00181     const TVector absNormal = this->normal().transform(num::abs);
00182     if (absNormal.x > absNormal.y && absNormal.x > absNormal.z)
00183     {
00184         return 0; // x
00185     }
00186     else if (absNormal.y > absNormal.z)
00187     {
00188         return 1; // y
00189     }
00190     else
00191     {
00192         return 2; // z
00193     }
00194     LASS_ASSERT(false);
00195     return 0;
00196 }
00197 
00198 
00199 
00200 // --- protected -----------------------------------------------------------------------------------
00201 
00202 
00203 
00204 // --- private -------------------------------------------------------------------------------------
00205 
00206 
00207 
00208 // --- free ----------------------------------------------------------------------------------------
00209 
00210 
00211 /** @relates Plane3D
00212  */
00213 template <typename T>
00214 io::XmlOStream& operator<<(io::XmlOStream& ioOStream, const Plane3D<T, Cartesian>& iPlane)
00215 {
00216     LASS_ENFORCE_STREAM(ioOStream)
00217         << "<Plane3D>\n"
00218         << "<normal>" << iPlane.normal() << "</normal>\n"
00219         << "<d>" << iPlane.d() << "</d>\n"
00220         << "</Plane3D>\n";
00221 
00222     return ioOStream;
00223 }
00224 
00225 
00226 
00227 /** @relates Plane3D
00228  */
00229 template <typename T>
00230 io::XmlOStream& operator<<(io::XmlOStream& ioOStream, const Plane3D<T, Parametric>& iPlane)
00231 {
00232     LASS_ENFORCE_STREAM(ioOStream)
00233         << "<Plane3D>\n"
00234         << "<support>" << iPlane.support() << "</support>\n"
00235         << "<directionU>" << iPlane.directionU() << "</directionU>\n"
00236         << "<directionV>" << iPlane.directionV() << "</directionV>\n"
00237         << "</Plane3D>\n";
00238 
00239     return ioOStream;
00240 }
00241 
00242 
00243 
00244 /** @relates Plane3D
00245  */
00246 template <typename T>
00247 io::XmlOStream& operator<<(io::XmlOStream& ioOStream, const Plane3D<T, Combined>& iPlane)
00248 {
00249     LASS_ENFORCE_STREAM(ioOStream)
00250         << "<Plane3D>\n"
00251         << "<support>" << iPlane.support() << "</support>\n"
00252         << "<directionU>" << iPlane.directionU() << "</directionU>\n"
00253         << "<directionV>" << iPlane.directionV() << "</directionV>\n"
00254         << "<normal>" << iPlane.normal() << "</normal>\n"
00255         << "<d>" << iPlane.d() << "</d>\n"
00256         << "</Plane3D>\n";
00257 
00258     return ioOStream;
00259 }
00260 
00261 
00262 
00263 }
00264 
00265 }
00266 
00267 #endif
00268 
00269 // EOF

Generated on Mon Nov 10 14:20:41 2008 for Library of Assembled Shared Sources by doxygen 1.5.7.1
SourceForge.net Logo