library of assembled shared sources

http://lass.cocamware.com

default_object_traits.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::spat::DefaultObjectTraits
00046  *  @brief default traits for objects to be stored in spatial subdivision trees
00047  *  @author Bram de Greve [BdG]
00048  */
00049 
00050 #ifndef LASS_GUARDIAN_OF_INCLUSION_SPAT_DEFAULT_OBJECT_TRAITS_H
00051 #define LASS_GUARDIAN_OF_INCLUSION_SPAT_DEFAULT_OBJECT_TRAITS_H
00052 
00053 #include "spat_common.h"
00054 #include "../prim/result.h"
00055 
00056 namespace lass
00057 {
00058 namespace spat
00059 {
00060 
00061 template
00062 <
00063     typename AabbType, 
00064     typename RayType
00065 >
00066 struct DefaultAabbRayTraits
00067 {
00068     typedef AabbType TAabb;                     /**< an nD AABB */
00069     typedef RayType TRay;                       /**< an nD Ray */
00070 
00071     typedef typename TAabb::TPoint TPoint;      /**< an nD point */
00072     typedef typename TAabb::TVector TVector;    /**< an nD vector */
00073     typedef typename TAabb::TValue TValue;      /**< numerical type used in TPoint and TVector */
00074     typedef typename TAabb::TParam TParam;      /**< best type for function parameters of TValue */
00075     typedef typename TAabb::TReference TReference;  /**< reference to TValue */
00076     typedef typename TAabb::TConstReference TConstReference; /**< const reference to TValue */
00077     
00078     enum { dimension = TAabb::dimension };      /**< nD = number of dimensions of TPoint */
00079 
00080     // AABB
00081 
00082     /** return empty AABB
00083      */
00084     static const TAabb aabbEmpty()
00085     {
00086         return TAabb();
00087     }
00088 
00089     /** return true if AABB contains a point, return false otherwise
00090      */
00091     static const bool aabbContains(const TAabb& aabb, const TPoint& point) 
00092     { 
00093         return aabb.contains(point); 
00094     }
00095 
00096     static const bool aabbContains(const TAabb& aabb, const TAabb& other)
00097     {
00098         return aabb.contains(other);
00099     }
00100 
00101     /** return true if AABB is intersected by ray
00102      */
00103     static const bool aabbIntersect(const TAabb& aabb, const TRay& ray, TReference t, const TParam tMin)
00104     {
00105         return intersect(aabb, ray, t, tMin) != prim::rNone;
00106     }
00107     
00108     /** join two AABBs and return the result
00109      */
00110     static const TAabb aabbJoin(const TAabb& a, const TAabb& b) 
00111     { 
00112         return a + b; 
00113     }
00114     
00115     /** return the minimum corner of the AABB
00116      */
00117     static const TPoint aabbMin(const TAabb& aabb) 
00118     { 
00119         return aabb.min(); 
00120     }
00121 
00122     /** return the maximum corner of the AABB 
00123      */
00124     static const TPoint aabbMax(const TAabb& aabb) 
00125     { 
00126         return aabb.max(); 
00127     }
00128 
00129 
00130     // RAY
00131 
00132     /** return the support point of the ray
00133      */
00134     static const TPoint raySupport(const TRay& ray)
00135     {
00136         return ray.support();
00137     }
00138 
00139     /** return the direction vector of the ray
00140      */
00141     static const TVector rayDirection(const TRay& ray)
00142     {
00143         return ray.direction();
00144     }
00145 
00146 
00147 
00148     // POINTS AND VECTORS
00149 
00150     /** return the @a axis coordinate value of @a point.
00151      */
00152     static const TValue coord(const TPoint& point, size_t axis) 
00153     { 
00154         return point[axis]; 
00155     }
00156 
00157     /** set the @a axis coordinate value of @a point.
00158      */
00159     static void coord(TPoint& point, size_t axis, TParam value) 
00160     { 
00161         point[axis] = value;
00162     }
00163 
00164     /** return the @a axis component value of @a vector.
00165      */
00166     static const TValue coord(const TVector& vector, size_t axis)
00167     {
00168         return vector[axis];
00169     }
00170 
00171     /** set the @a axis component value of @a vector.
00172      */
00173     static void coord(TVector& vector, size_t axis, TParam value)
00174     {
00175         vector[axis] = value;
00176     }
00177 
00178     /** return the reciprocal vector of @a vector
00179      */
00180     static const TVector vectorReciprocal(const TVector& vector)
00181     {
00182         return vector.reciprocal();
00183     }
00184 };
00185 
00186 
00187 
00188 template 
00189 <
00190     typename ObjectType, 
00191     typename AabbType = typename ObjectType::TAabb, 
00192     typename RayType = typename ObjectType::TRay,
00193     typename ObjectIterator = const ObjectType*
00194 >
00195 struct DefaultObjectTraits: public DefaultAabbRayTraits<AabbType, RayType>
00196 {
00197     typedef ObjectType TObject; /**< type of nD object */
00198     typedef ObjectIterator TObjectIterator; /**< iterator to object */
00199     typedef const TObject& TObjectReference;    /**< const reference to object */
00200     typedef void TInfo; /**< extra info for contain/intersect operations */
00201     
00202     typedef typename DefaultAabbRayTraits<AabbType, RayType>::TAabb TAabb;
00203     typedef typename DefaultAabbRayTraits<AabbType, RayType>::TRay TRay;
00204     typedef typename DefaultAabbRayTraits<AabbType, RayType>::TPoint TPoint;
00205     typedef typename DefaultAabbRayTraits<AabbType, RayType>::TVector TVector;
00206     typedef typename DefaultAabbRayTraits<AabbType, RayType>::TValue TValue;
00207     typedef typename DefaultAabbRayTraits<AabbType, RayType>::TParam TParam;
00208     typedef typename DefaultAabbRayTraits<AabbType, RayType>::TReference TReference;
00209     typedef typename DefaultAabbRayTraits<AabbType, RayType>::TConstReference TConstReference;
00210 
00211     /** return reference to object
00212      */
00213     static TObjectReference object(TObjectIterator it)
00214     {
00215         return *it;
00216     }
00217 
00218     /** return the AABB of an object
00219      */
00220     static const TAabb objectAabb(TObjectIterator it) 
00221     { 
00222         return aabb(object(it));
00223     }
00224     
00225     /** return true if object contains a point, return false otherwise
00226      */
00227     static const bool objectContains(TObjectIterator it, const TPoint& point, const TInfo* /*iInfo*/) 
00228     { 
00229         return object(it).contains(point); 
00230     }
00231 
00232     /** return true if object is intersected by ray
00233      */
00234     static const bool objectIntersect(TObjectIterator it, const TRay& ray, TReference t, TParam tMin, const TInfo* /*iInfo*/)
00235     {
00236         return intersect(object(it), ray, t, tMin) != prim::rNone;
00237     }
00238 
00239     /** return true if object is intersected by ray
00240      */
00241     static const bool objectIntersects(TObjectIterator it, const TRay& ray, TParam tMin, TParam tMax, const TInfo* /*iInfo*/)
00242     {
00243         TValue t;
00244         return intersect(object(it), ray, t, tMin) != prim::rNone && t < tMax;
00245     }
00246 
00247     /** return true if part of the object is inside the bounding box
00248      */
00249     static const bool objectOverlaps(TObjectIterator it, const TAabb& aabb)
00250     {
00251         return intersects(object(it), aabb);
00252     }
00253 
00254     /** return squared distance between object and point)
00255      */
00256     static const TValue objectSquaredDistance(TObjectIterator it, const TPoint& point, const TInfo* /* info */)
00257     {
00258         return squaredDistance(object(it), point);
00259     }
00260 };
00261 
00262 
00263 
00264 }
00265 
00266 }
00267 
00268 #endif
00269 
00270 // EOF

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