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