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 #ifndef LASS_GUARDIAN_OF_INCLUSION_PRIM_RAY_2D_INL
00046 #define LASS_GUARDIAN_OF_INCLUSION_PRIM_RAY_2D_INL
00047
00048
00049
00050
00051 #include "ray_2d.h"
00052
00053
00054
00055 namespace lass
00056 {
00057
00058 namespace prim
00059 {
00060
00061 template <typename T, class NP, class PP>
00062 Ray2D<T, NP, PP>::Ray2D():
00063 support_(),
00064 direction_()
00065 {
00066 LASS_ASSERT(support_.isZero());
00067 LASS_ASSERT(direction_.isZero());
00068 }
00069
00070
00071
00072 template <typename T, class NP, class PP>
00073 Ray2D<T, NP, PP>::Ray2D(const TPoint& iSupport, const TVector& iDirection):
00074 support_(iSupport),
00075 direction_(iDirection)
00076 {
00077 NP::normalize(direction_);
00078 }
00079
00080
00081
00082 template <typename T, class NP, class PP>
00083 Ray2D<T, NP, PP>::Ray2D(const TPoint& iSupport, const TPoint& iLookAt):
00084 support_(iSupport),
00085 direction_(iLookAt - iSupport)
00086 {
00087 NP::normalize(direction_);
00088 }
00089
00090
00091
00092
00093
00094
00095 template <typename T, class NP, class PP>
00096 const typename Ray2D<T, NP, PP>::TPoint&
00097 Ray2D<T, NP, PP>::support() const
00098 {
00099 return support_;
00100 }
00101
00102
00103
00104
00105
00106
00107 template <typename T, class NP, class PP>
00108 typename Ray2D<T, NP, PP>::TPoint&
00109 Ray2D<T, NP, PP>::support()
00110 {
00111 return support_;
00112 }
00113
00114
00115
00116
00117
00118 template <typename T, class NP, class PP>
00119 const typename Ray2D<T, NP, PP>::TVector&
00120 Ray2D<T, NP, PP>::direction() const
00121 {
00122 return direction_;
00123 }
00124
00125
00126
00127
00128
00129 template <typename T, class NP, class PP>
00130 void Ray2D<T, NP, PP>::setDirection(const TVector& iDirection)
00131 {
00132 direction_ = iDirection;
00133 NP::normalize(direction_);
00134 }
00135
00136
00137
00138
00139
00140 template <typename T, class NP, class PP>
00141 void Ray2D<T, NP, PP>::lookAt(const TPoint& iLookAt)
00142 {
00143 direction_ = iLookAt - support_;
00144 NP::normalize(direction_);
00145 }
00146
00147
00148
00149
00150
00151
00152
00153
00154 template <typename T, class NP, class PP>
00155 const typename Ray2D<T, NP, PP>::TPoint
00156 Ray2D<T, NP, PP>::point(TParam iT) const
00157 {
00158 TParameterPolicy::enforceRange(iT, TNumTraits::zero);
00159 return support_ + iT * direction_;
00160 }
00161
00162
00163
00164
00165
00166
00167 template <typename T, class NP, class PP>
00168 const typename Ray2D<T, NP, PP>::TValue
00169 Ray2D<T, NP, PP>::t(const TPoint& iPoint) const
00170 {
00171 return NP::divideBySquaredNorm(dot(iPoint - support_, direction_), direction_);
00172 }
00173
00174
00175
00176
00177
00178 template <typename T, class NP, class PP>
00179 const typename Ray2D<T, NP, PP>::TVector
00180 Ray2D<T, NP, PP>::project(const TVector& iVector) const
00181 {
00182 return direction_ * NP::divideBySquaredNorm(dot(iVector, direction_), direction_);
00183 }
00184
00185
00186
00187
00188
00189 template <typename T, class NP, class PP>
00190 const typename Ray2D<T, NP, PP>::TVector
00191 Ray2D<T, NP, PP>::reject(const TVector& iVector) const
00192 {
00193 return iVector - project(iVector);
00194 }
00195
00196
00197
00198
00199
00200 template <typename T, class NP, class PP>
00201 const typename Ray2D<T, NP, PP>::TVector
00202 Ray2D<T, NP, PP>::reflect(const TVector& iVector) const
00203 {
00204 return 2 * project(iVector) - iVector;
00205 }
00206
00207
00208
00209
00210
00211
00212 template <typename T, class NP, class PP>
00213 const typename Ray2D<T, NP, PP>::TPoint
00214 Ray2D<T, NP, PP>::project(const TPoint& iPoint) const
00215 {
00216 return support_ + project(iPoint - support_);
00217 }
00218
00219
00220
00221
00222
00223 template <typename T, class NP, class PP>
00224 const typename Ray2D<T, NP, PP>::TVector
00225 Ray2D<T, NP, PP>::reject(const TPoint& iPoint) const
00226 {
00227 return reject(iPoint - support_);
00228 }
00229
00230
00231
00232
00233
00234 template <typename T, class NP, class PP>
00235 const typename Ray2D<T, NP, PP>::TPoint
00236 Ray2D<T, NP, PP>::reflect(const TPoint& iPoint) const
00237 {
00238 return support_ + reflect(iPoint - support_);
00239 }
00240
00241
00242
00243
00244
00245 template <typename T, class NP, class PP>
00246 const Side Ray2D<T, NP, PP>::classify(const TPoint& iPoint) const
00247 {
00248 T surf = doubleTriangleArea(support_,support_+direction_,iPoint);
00249 if (surf>T(0))
00250 return sLeft;
00251 if (surf<T(0))
00252 return sRight;
00253 return sSurface;
00254 }
00255
00256
00257
00258
00259 template <typename T, class NP, class PP>
00260 const bool Ray2D<T, NP, PP>::isValid() const
00261 {
00262 return !direction_.isZero();
00263 }
00264
00265
00266
00267
00268
00269 template<typename T, class NP>
00270 std::ostream& operator<<(std::ostream& ioOStream, const Ray2D<T, NP>& iRay)
00271 {
00272 LASS_ENFORCE(ioOStream) << "{O=" << iRay.origin() << ", D=" << iRay.direction() << "}";
00273 return ioOStream;
00274 }
00275
00276
00277
00278
00279
00280 template<typename T, class NP>
00281 io::XmlOStream& operator<<(io::XmlOStream& ioOStream, const Ray2D<T, NP>& iRay)
00282 {
00283 LASS_ENFORCE_STREAM(ioOStream)
00284 << "<Ray2D>\n"
00285 << "<support>" << iRay.support() << "</support>\n"
00286 << "<direction>" << iRay.direction() << "</direction>\n"
00287 << "</Ray2D>\n";
00288 return ioOStream;
00289 }
00290
00291 }
00292
00293 }
00294
00295 #endif
00296
00297