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