library of assembled shared sources

http://lass.cocamware.com

plane_3d_impl_detail.h

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 /** @class lass::prim::impl::Plane3DImplDetail
00046  *  @brief common implementation stuff for Plane3D implementations.
00047  *  @author Bram de Greve [BdG]
00048  *
00049  *  Here are some common generator functions gahtered, that are used to generate some values
00050  *  automatically from others.
00051  */
00052 
00053 #ifndef LASS_GUARDIAN_OF_INCLUSION_PRIM_IMPL_PLANE_3D_IMPL_DETAIL_H
00054 #define LASS_GUARDIAN_OF_INCLUSION_PRIM_IMPL_PLANE_3D_IMPL_DETAIL_H
00055 
00056 #include "../prim_common.h"
00057 #include "../../num/floating_point_comparison.h"
00058 
00059 namespace lass
00060 {
00061 namespace prim
00062 {
00063 namespace impl
00064 {
00065 
00066 struct Plane3DImplDetail
00067 {
00068     /** Generate cartesian equation out of parametric equation.
00069      *  Generate normal vector N and value d of cartesian equaition N.P + d == 0,
00070      *  given support point S and direction vectors U and V of parametric
00071      *  equation P = S + x*U + y*V.
00072      */
00073     template <typename T>
00074     static void generateCartesian(const Point3D<T>& iSupport,
00075                                   const Vector3D<T>& iDirU,
00076                                   const Vector3D<T>& iDirV,
00077                                   Vector3D<T>& oNormal,
00078                                   T& oD)
00079     {
00080         oNormal = cross(iDirU, iDirV);
00081         oD = -dot(oNormal, iSupport.position());
00082     }
00083 
00084     /** Generate directions vectors U and V of parametric equation P = S + x*U + y*V,
00085      *  based on the normal vector N of the cartesian equation N.P + S == 0.
00086      */
00087     template <typename T>
00088     static void generateDirections(const Vector3D<T>& iNormal,
00089                                    Vector3D<T>& oDirU,
00090                                    Vector3D<T>& oDirV)
00091     {
00092         typedef Vector3D<T> TVector;
00093         typedef typename TVector::TValue TValue;
00094         typedef typename TVector::TNumTraits TNumTraits;
00095 
00096         const TValue absX = num::abs(iNormal.x);
00097         const TValue absY = num::abs(iNormal.y);
00098         const TValue absZ = num::abs(iNormal.z);
00099 
00100         if (absZ > absX && absZ > absY)
00101         {
00102             const TVector j(TNumTraits::zero, TNumTraits::one, TNumTraits::zero);
00103             oDirU = cross(j, iNormal);
00104             oDirV = cross(iNormal, oDirU);
00105         }
00106         else if (absX > absY)
00107         {
00108             const TVector k(TNumTraits::zero, TNumTraits::zero, TNumTraits::one);
00109             oDirU = cross(k, iNormal);
00110             oDirV = cross(iNormal, oDirU);
00111         }
00112         else
00113         {
00114             const TVector i(TNumTraits::one, TNumTraits::zero, TNumTraits::zero);
00115             oDirU = cross(i, iNormal);
00116             oDirV = cross(iNormal, oDirU);
00117         }
00118     }
00119 
00120     /** generate reciprocal direction vectors Ur and Vr given directions U and V.
00121      *  Reciprocal vectors can be used to find the values x and y in A=x*U+y*V,
00122      *  given A, U and V.  With Ur and Vr, they can be found by x=A.Ur and y=A.Vr.
00123      */
00124     template <typename T>
00125     static void generateReciprocal(const Vector3D<T>& iDirU,
00126                                    const Vector3D<T>& iDirV,
00127                                    Vector3D<T>& oReciprocalDirU,
00128                                    Vector3D<T>& oReciprocalDirV)
00129     {
00130         const typename Vector3D<T>::TValue dotUV = dot(iDirU, iDirV);
00131         oReciprocalDirU = iDirU - iDirV * (dotUV / iDirV.squaredNorm());
00132         oReciprocalDirV = iDirV - iDirU * (dotUV / iDirU.squaredNorm());
00133         oReciprocalDirU /= dot(oReciprocalDirU, iDirU);
00134         oReciprocalDirV /= dot(oReciprocalDirV, iDirV);
00135     }
00136 
00137 };
00138 
00139 
00140 
00141 }
00142 
00143 }
00144 
00145 }
00146 
00147 #endif
00148 
00149 // EOF

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