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_IMPL_PLANE_3D_COMBINED_INL
00046 #define LASS_GUARDIAN_OF_INCLUSION_PRIM_IMPL_PLANE_3D_COMBINED_INL
00047
00048 #include "../prim_common.h"
00049 #include "plane_3d_combined.h"
00050
00051 namespace lass
00052 {
00053 namespace prim
00054 {
00055 namespace impl
00056 {
00057
00058
00059
00060
00061
00062 template<typename T, class NP>
00063 Plane3DCombined<T, NP>::Plane3DCombined():
00064 support_(),
00065 directionU_(),
00066 directionV_(),
00067 reciprocalU_(),
00068 reciprocalV_(),
00069 normal_(),
00070 d_(TNumTraits::zero)
00071 {
00072 LASS_ASSERT(!isValid());
00073 }
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084 template<typename T, class NP>
00085 Plane3DCombined<T, NP>::Plane3DCombined(const TPoint& iSupport,
00086 const TPoint& iPointU,
00087 const TPoint& iPointV):
00088 support_(iSupport),
00089 directionU_(iPointU - iSupport),
00090 directionV_(iPointV - iSupport)
00091 {
00092 Plane3DImplDetail::generateCartesian(support_, directionU_, directionV_, normal_, d_);
00093 NP::normalize(directionU_);
00094 NP::normalize(directionV_);
00095 NP::normalizeAndScale(normal_, d_);
00096 Plane3DImplDetail::generateReciprocal(directionU_, directionV_, reciprocalU_, reciprocalV_);
00097 }
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107 template<typename T, class NP>
00108 Plane3DCombined<T, NP>::Plane3DCombined(const TPoint& iSupport,
00109 const TVector& iDirectionU,
00110 const TVector& iDirectionV):
00111 support_(iSupport),
00112 directionU_(iDirectionU),
00113 directionV_(iDirectionV)
00114 {
00115 Plane3DImplDetail::generateCartesian(support_, directionU_, directionV_, normal_, d_);
00116 NP::normalize(directionU_);
00117 NP::normalize(directionV_);
00118 NP::normalizeAndScale(normal_, d_);
00119 Plane3DImplDetail::generateReciprocal(directionU_, directionV_, reciprocalU_, reciprocalV_);
00120 }
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130 template<typename T, class NP>
00131 Plane3DCombined<T, NP>::Plane3DCombined(const TVector& iNormal, const TPoint& iSupport):
00132 support_(iSupport),
00133 normal_(iNormal),
00134 d_(-dot(iNormal, iSupport.position()))
00135 {
00136 Plane3DImplDetail::generateDirections(normal_, directionU_, directionV_);
00137 NP::normalize(directionU_);
00138 NP::normalize(directionV_);
00139 NP::normalizeAndScale(normal_, d_);
00140 Plane3DImplDetail::generateReciprocal(directionU_, directionV_, reciprocalU_, reciprocalV_);
00141 }
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151 template<typename T, class NP>
00152 Plane3DCombined<T, NP>::Plane3DCombined(const TVector& iNormal, TParam iD):
00153 support_(iNormal * (-iD / iNormal.squaredNorm())),
00154 normal_(iNormal),
00155 d_(iD)
00156 {
00157 Plane3DImplDetail::generateDirections(normal_, directionU_, directionV_);
00158 NP::normalize(directionU_);
00159 NP::normalize(directionV_);
00160 NP::normalizeAndScale(normal_, d_);
00161 Plane3DImplDetail::generateReciprocal(directionU_, directionV_, reciprocalU_, reciprocalV_);
00162 }
00163
00164
00165
00166
00167
00168 template<typename T, class NP>
00169 const typename Plane3DCombined<T, NP>::TPoint& Plane3DCombined<T, NP>::support() const
00170 {
00171 return support_;
00172 }
00173
00174
00175
00176
00177
00178 template<typename T, class NP>
00179 void Plane3DCombined<T, NP>::getDirections(TVector& oDirectionU, TVector& oDirectionV) const
00180 {
00181 oDirectionU = directionU_;
00182 oDirectionV = directionV_;
00183 }
00184
00185
00186
00187
00188
00189 template<typename T, class NP>
00190 const typename Plane3DCombined<T, NP>::TVector& Plane3DCombined<T, NP>::directionU() const
00191 {
00192 return directionU_;
00193 }
00194
00195
00196
00197
00198
00199 template<typename T, class NP>
00200 const typename Plane3DCombined<T, NP>::TVector& Plane3DCombined<T, NP>::directionV() const
00201 {
00202 return directionV_;
00203 }
00204
00205
00206
00207
00208
00209 template<typename T, class NP>
00210 void Plane3DCombined<T, NP>::getReciprocals(TVector& oReciprocalU,
00211 TVector& oReciprocalV) const
00212 {
00213 oReciprocalU = reciprocalU_;
00214 oReciprocalV = reciprocalV_;
00215 }
00216
00217
00218
00219
00220
00221 template<typename T, class NP>
00222 const typename Plane3DCombined<T, NP>::TVector& Plane3DCombined<T, NP>::reciprocalU() const
00223 {
00224 return reciprocalU_;
00225 }
00226
00227
00228
00229
00230
00231 template<typename T, class NP>
00232 const typename Plane3DCombined<T, NP>::TVector& Plane3DCombined<T, NP>::reciprocalV() const
00233 {
00234 return reciprocalV_;
00235 }
00236
00237
00238
00239 template<typename T, class NP>
00240 void Plane3DCombined<T, NP>::getCartesian(TVector& oNormal, TReference oD) const
00241 {
00242 oNormal = normal_;
00243 oD = d_;
00244 }
00245
00246
00247
00248 template<typename T, class NP>
00249 const typename Plane3DCombined<T, NP>::TVector& Plane3DCombined<T, NP>::normal() const
00250 {
00251 return normal_;
00252 }
00253
00254
00255
00256 template<typename T, class NP>
00257 const typename Plane3DCombined<T, NP>::TParam Plane3DCombined<T, NP>::d() const
00258 {
00259 return d_;
00260 }
00261
00262
00263
00264
00265
00266 template<typename T, class NP>
00267 const typename Plane3DCombined<T, NP>::TValue
00268 Plane3DCombined<T, NP>::equation(const TPoint& iPoint) const
00269 {
00270 return dot(iPoint.position(), normal_) + d_;
00271 }
00272
00273
00274
00275
00276
00277 template<typename T, class NP>
00278 const typename Plane3DCombined<T, NP>::TValue
00279 Plane3DCombined<T, NP>::equation(const TPoint& iPoint, TParam iRelativeTolerance) const
00280 {
00281 const TValue a = dot(iPoint.position(), normal_);
00282 return almostEqual(a, -d, iRelativeTolerance) ? TNumTraits::zero : (a + d_);
00283 }
00284
00285
00286
00287
00288
00289
00290 template<typename T, class NP>
00291 const typename Plane3DCombined<T, NP>::TVector
00292 Plane3DCombined<T, NP>::reject(const TPoint& iPoint) const
00293 {
00294 return normal_ * NP::divideBySquaredNorm(equation(iPoint), normal_);
00295 }
00296
00297
00298
00299
00300
00301
00302
00303 template<typename T, class NP>
00304 const typename Plane3DCombined<T, NP>::TVector
00305 Plane3DCombined<T, NP>::reject(const TVector& iVector) const
00306 {
00307 return normal_ * NP::divideBySquaredNorm(dot(normal_, iVector), normal_);
00308 }
00309
00310
00311
00312
00313
00314 template<typename T, class NP>
00315 const typename Plane3DCombined<T, NP>::TPoint
00316 Plane3DCombined<T, NP>::project(const TPoint& iPoint) const
00317 {
00318 return iPoint - reject(iPoint);
00319 }
00320
00321
00322
00323
00324
00325 template<typename T, class NP>
00326 const typename Plane3DCombined<T, NP>::TVector
00327 Plane3DCombined<T, NP>::project(const TVector& iVector) const
00328 {
00329 return iVector - reject(iVector);
00330 }
00331
00332
00333
00334
00335
00336 template<typename T, class NP>
00337 const typename Plane3DCombined<T, NP>::TPoint
00338 Plane3DCombined<T, NP>::reflect(const TPoint& iPoint) const
00339 {
00340 return iPoint - 2 * reject(iPoint);
00341 }
00342
00343
00344
00345
00346
00347 template<typename T, class NP>
00348 const typename Plane3DCombined<T, NP>::TVector
00349 Plane3DCombined<T, NP>::reflect(const TVector& iVector) const
00350 {
00351 return iVector - 2 * reject(iVector);
00352 }
00353
00354
00355
00356
00357
00358 template<typename T, class NP>
00359 const typename Plane3DCombined<T, NP>::TPoint
00360 Plane3DCombined<T, NP>::point(TParam iU, TParam iV) const
00361 {
00362 return point(TIndex(iU, iV));
00363 }
00364
00365
00366
00367
00368
00369 template<typename T, class NP>
00370 const typename Plane3DCombined<T, NP>::TPoint
00371 Plane3DCombined<T, NP>::point(const TUV& iUV) const
00372 {
00373 return support_ + iUV.x * directionU_ + iUV.y * directionV_;
00374 }
00375
00376
00377
00378
00379
00380 template<typename T, class NP>
00381 const typename Plane3DCombined<T, NP>::TUV
00382 Plane3DCombined<T, NP>::uv(const TPoint& iPoint) const
00383 {
00384 const TVector relative = iPoint - support_;
00385 return TUV(dot(relative, reciprocalU_), dot(relative, reciprocalV_));
00386 }
00387
00388
00389
00390 template <typename T, class NP>
00391 void Plane3DCombined<T, NP>::flip()
00392 {
00393 directionV_ = -directionV_;
00394 normal_ = -normal_;
00395 d_ = -d_;
00396 Plane3DImplDetail::generateReciprocal(directionU_, directionV_, reciprocalU_, reciprocalV_);
00397 }
00398
00399
00400
00401
00402
00403 template<typename T, class NP>
00404 const bool Plane3DCombined<T, NP>::isValid() const
00405 {
00406 return !normal_.isZero() && !cross(directionU_, directionV_).isZero();
00407 }
00408
00409
00410
00411
00412
00413
00414
00415
00416
00417
00418
00419
00420
00421
00422 template<typename T, class NP>
00423 std::ostream& operator<<(std::ostream& ioOStream, const Plane3DCombined<T, NP>& iPlane)
00424 {
00425 LASS_ENFORCE(ioOStream) << "{S=" << iPlane.support() << ", U=" << iPlane.directionU() << ", V="
00426 << iPlane.directionV() << ", N=" << iPlane.normal() << ", d=" << iPlane.d() << "}";
00427 return ioOStream;
00428 }
00429
00430
00431
00432 }
00433
00434 }
00435
00436 }
00437
00438 #endif
00439
00440