library of assembled shared sources

http://lass.cocamware.com

prim_common.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 /** @namespace lass::prim
00046  *  @brief set of geometrical primitives
00047  *  @author Bram de Greve [BdG]
00048  *  @date 2003
00049  *
00050  *  lass::prim is the library for geometrical primitives and related constructions.  It
00051  *  consists of structures and classes to represent primitives as vectors, points, lines,
00052  *  planes, polygons etc., some policy classes that can modify the implementation of some of
00053  *  these primitives, and a few related enumerations.
00054  *
00055  *  All primitives are templated with an underlying value type (think of floats, doubles,
00056  *  fixed point, ...).  This value type can be set as by the template parameter @a T, and is
00057  *  typedef'ed in all primitives as @c TValue (convenient, isn't it? :).  It's the subatomic unit
00058  *  (proton if you like) on which more complex types are built.
00059  *
00060  *  @section overview
00061  *
00062  *  I think the best way to explore this library, is to give an overview of its components.
00063  *  Here we go ...
00064  *
00065  *  @subsection primitives
00066  *
00067  *  If @c TValue is the proton, then vectors are the smallest atomic units in lass::prim you
00068  *  can build.  Vectors represent a direction, a translation, and we have three of them
00069  *  in our library (with 2, 3 and 4 protons respective :):
00070  *
00071  *  - Vector2D: a two dimensional vector.
00072  *  - Vector3D: a three dimensional vector.
00073  *  - Vector4D: a four dimensional vector.
00074  *
00075  *  The above vectors are free vectors and have no position.  To express the position of
00076  *  a location in space, we need points.  we have two of these thingies.  It's a little
00077  *  unusual to distinguish between vectors and points.  Usually, only one is used for both
00078  *  concepts, whether they uses @e point or @e vector.  Yet, these are totally different
00079  *  mathematical entities.  You can add two vectors together, but you can't add two points
00080  *  (what would it mean?).  Transforming a vector is different that a point (a vector will
00081  *  only be rotated, a point will also be translated).  Points and vectors are clearly to
00082  *  be traited differently.  This cries for different classes or structures.  In C however, it has
00083  *  little use to do that, because of the lack of function overloading and strong type checking.
00084  *  However, here we are in C++ and the good news is: C++ does have overloading and strong
00085  *  type checking, so we can clearly distinguish between points and vectors in our code.
00086  *  And that's what we do here.  For more info on this subject, I gladly refer to [1, 2, 3].
00087  *  You can see the points as ions: vectors with some extra (or lacking) electrons:
00088  *  same number of protons (same dimension), but not completely the same thing.
00089  *
00090  *  - Point2D: a two dimensional point.
00091  *  - Point3D: a three dimensional point.
00092  *
00093  *  One problem of not being able to add and scale points is not being able to use barycentric
00094  *  combinations.  This is a linear combination of points in which the sum of all weight is
00095  *  equal to 1.  The result of such a combination is a point and is mathematical sensefull.
00096  *  In [1], I didn't find a satisfying solution to this problem, because I wanted to limit
00097  *  myself to eucledian entities.  To do barycentric combinations, I had to convert the points
00098  *  to vectors, do the combination, and the convert back to a point.  Not only this is a bit
00099  *  clumsy, it didn't guarantee that the sum of the weights would be 1.  In [2], I introduced
00100  *  homogenous points to solve this question.  And they are also introduced in here.
00101  *  Homogenous points are with the sole capability to do barycentric combinations on points.
00102  *  You can see the homogenous points as points with some extra neutrons: pretty compatible.
00103  *
00104  *  - Point2DH: a homogenous representation of a two dimensional point.
00105  *  - Point3DH: a homogenous representation of a three dimensional point.
00106  *
00107  *  So far for the essential building blocks of the more complex primitives.  Until now we had
00108  *  the atoms, now we'll build moleculs.  The simplest thing we can construct from it are
00109  *  axis-aligned-bounding-boxes.
00110  *
00111  *  - Aabb2D: a two dimensional axis aligned boundig box ... or a rectangle :)
00112  *  - Aabb3D: a three dimensional axis aligned bounding box.
00113  *
00114  *  Objects of infinite size are lines and planes.  We have them in parametric and cartesian
00115  *  versions.
00116  *
00117  *  - Line2D: a two dimensional line with different implementation policies, or a half plane.
00118  *  - Line3D: a three dimensional parametric line.
00119  *  - Plane3D: a three dimensional plane with different implementation policies, or a half space.
00120  *
00121  *  For the circular guys:
00122  *
00123  *  - Sphere3D: a sphere!
00124  *
00125  *  Objects of not so infinite size: line segments and rays.
00126  *
00127  *  - LineSegment2D: a two dimensional line segment
00128  *  - LineSegment3D: a three dimensional line segment
00129  *  - Ray2D: a two dimensional ray (or a half line)
00130  *  - Ray3D: a three dimensional ray (or a half line in 3D)
00131  *
00132  *  Polygons and stuff:
00133  *
00134  *  - SimplePolygon2D: a two dimensional convex/concave polygon
00135  *  - SimplePolygon3D: a three dimensional convex/concave polygon
00136  *  - Triangle2D: a two dimensional polygon with three vertices
00137  *  - Triangle3D: a three dimensional polygon with three vertices
00138  *
00139  *  @subsection policies
00140  *
00141  *  - @ref NormalizingPolicy: Normalized, Unnormalized
00142  *  - @ref ParameterPolicy: Bounded, Unbounded
00143  *  - @ref MinMaxPolicy: StrictMinMax, AutoMinMax
00144  *  - @ref EquationPolicy: Cartesian, Parametric, Combined
00145  *
00146  *  @subsection enumerations
00147  *
00148  *  - @ref Result
00149  *  - @ref Side
00150  *  - @ref Orientation
00151  *
00152  *  @subsection colors
00153  *
00154  *  - ColorRGBA: a four dimensional color with floating point channels red, green, blue and alpha.
00155  *
00156  *  @subsection iterators
00157  *
00158  *  These three classes are iterators over the different axes (components).  You can use
00159  *  this instead of directly calling the @c .x or @c .y members of a vector.  With
00160  *  these iterators, you can access those components through the @c operator[] .
00161  *
00162  *  - XY
00163  *  - XYZ
00164  *  - XYZW
00165  */
00166 
00167 
00168 
00169 
00170 /** @namespace lass::prim::impl
00171  *  @brief implementation details of lass::prim
00172  *  @author BdG
00173  *  @date 2003
00174  *
00175  *  @warning nothing for the faint hearted :)
00176  */
00177 
00178 
00179 
00180 #ifndef LASS_GUARDIAN_OF_INCLUSION_PRIM_PRIM_COMMON_H
00181 #define LASS_GUARDIAN_OF_INCLUSION_PRIM_PRIM_COMMON_H
00182 
00183 
00184 
00185 #include "../lass_common.h"
00186 
00187 #include "../num/num_traits.h"
00188 #include "../util/call_traits.h"
00189 
00190 #include "result.h"
00191 #include "side.h"
00192 
00193 namespace lass
00194 {
00195 namespace prim
00196 {
00197 
00198 class SingularityError: public util::Exception
00199 {
00200 public:
00201     SingularityError(const std::string& msg, const std::string& loc): util::Exception(msg, loc) {}
00202 private:
00203     LASS_UTIL_EXCEPTION_PRIVATE_IMPL(SingularityError)
00204 };
00205 
00206 }
00207 }
00208 
00209 #endif

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