00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
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;
00069 typedef RayType TRay;
00070
00071 typedef typename TAabb::TPoint TPoint;
00072 typedef typename TAabb::TVector TVector;
00073 typedef typename TAabb::TValue TValue;
00074 typedef typename TAabb::TParam TParam;
00075 typedef typename TAabb::TReference TReference;
00076 typedef typename TAabb::TConstReference TConstReference;
00077
00078 enum { dimension = TAabb::dimension };
00079
00080
00081
00082
00083
00084 static const TAabb aabbEmpty()
00085 {
00086 return TAabb();
00087 }
00088
00089
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
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
00109
00110 static const TAabb aabbJoin(const TAabb& a, const TAabb& b)
00111 {
00112 return a + b;
00113 }
00114
00115
00116
00117 static const TPoint aabbMin(const TAabb& aabb)
00118 {
00119 return aabb.min();
00120 }
00121
00122
00123
00124 static const TPoint aabbMax(const TAabb& aabb)
00125 {
00126 return aabb.max();
00127 }
00128
00129
00130
00131
00132
00133
00134 static const TPoint raySupport(const TRay& ray)
00135 {
00136 return ray.support();
00137 }
00138
00139
00140
00141 static const TVector rayDirection(const TRay& ray)
00142 {
00143 return ray.direction();
00144 }
00145
00146
00147
00148
00149
00150
00151
00152 static const TValue coord(const TPoint& point, size_t axis)
00153 {
00154 return point[axis];
00155 }
00156
00157
00158
00159 static void coord(TPoint& point, size_t axis, TParam value)
00160 {
00161 point[axis] = value;
00162 }
00163
00164
00165
00166 static const TValue coord(const TVector& vector, size_t axis)
00167 {
00168 return vector[axis];
00169 }
00170
00171
00172
00173 static void coord(TVector& vector, size_t axis, TParam value)
00174 {
00175 vector[axis] = value;
00176 }
00177
00178
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;
00198 typedef ObjectIterator TObjectIterator;
00199 typedef const TObject& TObjectReference;
00200 typedef void TInfo;
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
00212
00213 static TObjectReference object(TObjectIterator it)
00214 {
00215 return *it;
00216 }
00217
00218
00219
00220 static const TAabb objectAabb(TObjectIterator it)
00221 {
00222 return aabb(object(it));
00223 }
00224
00225
00226
00227 static const bool objectContains(TObjectIterator it, const TPoint& point, const TInfo* )
00228 {
00229 return object(it).contains(point);
00230 }
00231
00232
00233
00234 static const bool objectIntersect(TObjectIterator it, const TRay& ray, TReference t, TParam tMin, const TInfo* )
00235 {
00236 return intersect(object(it), ray, t, tMin) != prim::rNone;
00237 }
00238
00239
00240
00241 static const bool objectIntersects(TObjectIterator it, const TRay& ray, TParam tMin, TParam tMax, const TInfo* )
00242 {
00243 TValue t;
00244 return intersect(object(it), ray, t, tMin) != prim::rNone && t < tMax;
00245 }
00246
00247
00248
00249 static const bool objectOverlaps(TObjectIterator it, const TAabb& aabb)
00250 {
00251 return intersects(object(it), aabb);
00252 }
00253
00254
00255
00256 static const TValue objectSquaredDistance(TObjectIterator it, const TPoint& point, const TInfo* )
00257 {
00258 return squaredDistance(object(it), point);
00259 }
00260 };
00261
00262
00263
00264 }
00265
00266 }
00267
00268 #endif
00269
00270