Library of Assembled Shared Sources
plane_3d_impl_detail.h
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/** @class lass::prim::impl::Plane3DImplDetail
46 * @brief common implementation stuff for Plane3D implementations.
47 * @author Bram de Greve [BdG]
48 *
49 * Here are some common generator functions gahtered, that are used to generate some values
50 * automatically from others.
51 */
52
53#ifndef LASS_GUARDIAN_OF_INCLUSION_PRIM_IMPL_PLANE_3D_IMPL_DETAIL_H
54#define LASS_GUARDIAN_OF_INCLUSION_PRIM_IMPL_PLANE_3D_IMPL_DETAIL_H
55
56#include "../prim_common.h"
58
59namespace lass
60{
61namespace prim
62{
63namespace impl
64{
65
67{
68 /** Generate cartesian equation out of parametric equation.
69 * Generate normal vector N and value d of cartesian equaition N.P + d == 0,
70 * given support point S and direction vectors U and V of parametric
71 * equation P = S + x*U + y*V.
72 */
73 template <typename T>
74 static void generateCartesian(const Point3D<T>& iSupport,
75 const Vector3D<T>& iDirU,
76 const Vector3D<T>& iDirV,
77 Vector3D<T>& oNormal,
78 T& oD)
79 {
80 oNormal = cross(iDirU, iDirV);
81 oD = -dot(oNormal, iSupport.position());
82 }
83
84 /** Generate directions vectors U and V of parametric equation P = S + x*U + y*V,
85 * based on the normal vector N of the cartesian equation N.P + S == 0.
86 */
87 template <typename T>
88 static void generateDirections(const Vector3D<T>& iNormal,
89 Vector3D<T>& oDirU,
90 Vector3D<T>& oDirV)
91 {
92 typedef Vector3D<T> TVector;
93 typedef typename TVector::TValue TValue;
94 typedef typename TVector::TNumTraits TNumTraits;
95
96 const TValue absX = num::abs(iNormal.x);
97 const TValue absY = num::abs(iNormal.y);
98 const TValue absZ = num::abs(iNormal.z);
99
100 if (absZ > absX && absZ > absY)
101 {
102 const TVector j(TNumTraits::zero, TNumTraits::one, TNumTraits::zero);
103 oDirU = cross(j, iNormal);
104 oDirV = cross(iNormal, oDirU);
105 }
106 else if (absX > absY)
107 {
108 const TVector k(TNumTraits::zero, TNumTraits::zero, TNumTraits::one);
109 oDirU = cross(k, iNormal);
110 oDirV = cross(iNormal, oDirU);
111 }
112 else
113 {
114 const TVector i(TNumTraits::one, TNumTraits::zero, TNumTraits::zero);
115 oDirU = cross(i, iNormal);
116 oDirV = cross(iNormal, oDirU);
117 }
118 }
119
120 /** generate reciprocal direction vectors Ur and Vr given directions U and V.
121 * Reciprocal vectors can be used to find the values x and y in A=x*U+y*V,
122 * given A, U and V. With Ur and Vr, they can be found by x=A.Ur and y=A.Vr.
123 */
124 template <typename T>
125 static void generateReciprocal(const Vector3D<T>& iDirU,
126 const Vector3D<T>& iDirV,
127 Vector3D<T>& oReciprocalDirU,
128 Vector3D<T>& oReciprocalDirV)
129 {
130 const typename Vector3D<T>::TValue dotUV = dot(iDirU, iDirV);
131 oReciprocalDirU = iDirU - iDirV * (dotUV / iDirV.squaredNorm());
132 oReciprocalDirV = iDirV - iDirU * (dotUV / iDirU.squaredNorm());
133 oReciprocalDirU /= dot(oReciprocalDirU, iDirU);
134 oReciprocalDirV /= dot(oReciprocalDirV, iDirV);
135 }
136
137};
138
139
140
141}
142
143}
144
145}
146
147#endif
148
149// EOF
T abs(const T &x)
if x < 0 return -x, else return x.
Definition basic_ops.h:145
implementation details of lass::prim
set of geometrical primitives
Definition aabb_2d.h:81
Library for Assembled Shared Sources.
Definition config.h:53
const TValue squaredNorm() const
Return squared norm of vector.
common implementation stuff for Plane3D implementations.
static void generateReciprocal(const Vector3D< T > &iDirU, const Vector3D< T > &iDirV, Vector3D< T > &oReciprocalDirU, Vector3D< T > &oReciprocalDirV)
generate reciprocal direction vectors Ur and Vr given directions U and V.
static void generateDirections(const Vector3D< T > &iNormal, Vector3D< T > &oDirU, Vector3D< T > &oDirV)
Generate directions vectors U and V of parametric equation P = S + x*U + y*V, based on the normal vec...
static void generateCartesian(const Point3D< T > &iSupport, const Vector3D< T > &iDirU, const Vector3D< T > &iDirV, Vector3D< T > &oNormal, T &oD)
Generate cartesian equation out of parametric equation.