triFaceI.H
Go to the documentation of this file.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 #include "IOstreams.H"
00028 #include "face.H"
00029 #include "triPointRef.H"
00030
00031
00032
00033 inline int Foam::triFace::compare(const triFace& a, const triFace& b)
00034 {
00035 if
00036 (
00037 (a[0] == b[0] && a[1] == b[1] && a[2] == b[2])
00038 || (a[0] == b[1] && a[1] == b[2] && a[2] == b[0])
00039 || (a[0] == b[2] && a[1] == b[0] && a[2] == b[1])
00040 )
00041 {
00042
00043 return 1;
00044 }
00045 else if
00046 (
00047 (a[0] == b[2] && a[1] == b[1] && a[2] == b[0])
00048 || (a[0] == b[1] && a[1] == b[0] && a[2] == b[2])
00049 || (a[0] == b[0] && a[1] == b[2] && a[2] == b[1])
00050 )
00051 {
00052
00053 return -1;
00054 }
00055 else
00056 {
00057 return 0;
00058 }
00059 }
00060
00061
00062
00063
00064 inline Foam::triFace::triFace()
00065 {}
00066
00067
00068 inline Foam::triFace::triFace
00069 (
00070 const label a,
00071 const label b,
00072 const label c
00073 )
00074 {
00075 operator[](0) = a;
00076 operator[](1) = b;
00077 operator[](2) = c;
00078 }
00079
00080
00081 inline Foam::triFace::triFace(const UList<label>& lst)
00082 :
00083 FixedList<label, 3>(lst)
00084 {}
00085
00086
00087 inline Foam::triFace::triFace(Istream& is)
00088 :
00089 FixedList<label, 3>(is)
00090 {}
00091
00092
00093
00094
00095 inline Foam::label Foam::triFace::collapse()
00096 {
00097
00098
00099
00100
00101 label n = 3;
00102 if (operator[](0) == operator[](1) || operator[](1) == -1)
00103 {
00104 operator[](1) = -1;
00105 n--;
00106 }
00107 else if (operator[](1) == operator[](2) || operator[](2) == -1)
00108 {
00109 operator[](2) = -1;
00110 n--;
00111 }
00112 if (operator[](0) == operator[](2))
00113 {
00114 operator[](2) = -1;
00115 n--;
00116 }
00117
00118 return n;
00119 }
00120
00121
00122 inline Foam::pointField Foam::triFace::points(const pointField& points) const
00123 {
00124 pointField p(3);
00125
00126 p[0] = points[operator[](0)];
00127 p[1] = points[operator[](1)];
00128 p[2] = points[operator[](2)];
00129
00130 return p;
00131 }
00132
00133
00134 inline Foam::face Foam::triFace::triFaceFace() const
00135 {
00136 Foam::face f(3);
00137
00138 f[0] = operator[](0);
00139 f[1] = operator[](1);
00140 f[2] = operator[](2);
00141
00142 return f;
00143 }
00144
00145
00146 inline Foam::label Foam::triFace::nEdges() const
00147 {
00148 return 3;
00149 }
00150
00151
00152 inline Foam::edgeList Foam::triFace::edges() const
00153 {
00154 edgeList e(3);
00155
00156 e[0].start() = operator[](0);
00157 e[0].end() = operator[](1);
00158
00159 e[1].start() = operator[](1);
00160 e[1].end() = operator[](2);
00161
00162 e[2].start() = operator[](2);
00163 e[2].end() = operator[](0);
00164
00165 return e;
00166 }
00167
00168
00169
00170
00171
00172
00173 inline int Foam::triFace::edgeDirection(const edge& e) const
00174 {
00175 if
00176 (
00177 (operator[](0) == e.start() && operator[](1) == e.end())
00178 || (operator[](1) == e.start() && operator[](2) == e.end())
00179 || (operator[](2) == e.start() && operator[](0) == e.end())
00180 )
00181 {
00182 return 1;
00183 }
00184 else if
00185 (
00186 (operator[](0) == e.end() && operator[](1) == e.start())
00187 || (operator[](1) == e.end() && operator[](2) == e.start())
00188 || (operator[](2) == e.end() && operator[](0) == e.start())
00189 )
00190 {
00191 return -1;
00192 }
00193 else
00194 {
00195 return 0;
00196 }
00197 }
00198
00199
00200 inline Foam::point Foam::triFace::centre(const pointField& points) const
00201 {
00202 return (1.0/3.0)*
00203 (
00204 points[operator[](0)]
00205 + points[operator[](1)]
00206 + points[operator[](2)]
00207 );
00208 }
00209
00210
00211 inline Foam::scalar Foam::triFace::mag(const pointField& points) const
00212 {
00213 return ::Foam::mag(normal(points));
00214 }
00215
00216
00217 inline Foam::vector Foam::triFace::normal(const pointField& points) const
00218 {
00219 return 0.5*
00220 (
00221 (points[operator[](1)] - points[operator[](0)])
00222 ^(points[operator[](2)] - points[operator[](0)])
00223 );
00224 }
00225
00226
00227 inline Foam::label Foam::triFace::nTriangles() const
00228 {
00229 return 1;
00230 }
00231
00232
00233 inline Foam::triFace Foam::triFace::reverseFace() const
00234 {
00235
00236 return triFace(operator[](0), operator[](2), operator[](1));
00237 }
00238
00239
00240 inline Foam::scalar Foam::triFace::sweptVol
00241 (
00242 const pointField& opts,
00243 const pointField& npts
00244 ) const
00245 {
00246 return (1.0/6.0)*
00247 (
00248 (
00249 (npts[operator[](0)] - opts[operator[](0)])
00250 & (
00251 (opts[operator[](1)] - opts[operator[](0)])
00252 ^ (opts[operator[](2)] - opts[operator[](0)])
00253 )
00254 )
00255 + (
00256 (npts[operator[](1)] - opts[operator[](1)])
00257 & (
00258 (opts[operator[](2)] - opts[operator[](1)])
00259 ^ (npts[operator[](0)] - opts[operator[](1)])
00260 )
00261 )
00262 + (
00263 (opts[operator[](2)] - npts[operator[](2)])
00264 & (
00265 (npts[operator[](1)] - npts[operator[](2)])
00266 ^ (npts[operator[](0)] - npts[operator[](2)])
00267 )
00268 )
00269 );
00270 }
00271
00272
00273 inline Foam::pointHit Foam::triFace::ray
00274 (
00275 const point& p,
00276 const vector& q,
00277 const pointField& points,
00278 const intersection::algorithm alg,
00279 const intersection::direction dir
00280 ) const
00281 {
00282 return triPointRef
00283 (
00284 points[operator[](0)],
00285 points[operator[](1)],
00286 points[operator[](2)]
00287 ).ray(p, q, alg, dir);
00288 }
00289
00290
00291 inline Foam::triPointRef Foam::triFace::tri(const pointField& points) const
00292 {
00293 return triPointRef
00294 (
00295 points[operator[](0)],
00296 points[operator[](1)],
00297 points[operator[](2)]
00298 );
00299 }
00300
00301
00302
00303
00304 inline bool Foam::operator==(const triFace& a, const triFace& b)
00305 {
00306 return triFace::compare(a,b) != 0;
00307 }
00308
00309
00310 inline bool Foam::operator!=(const triFace& a, const triFace& b)
00311 {
00312 return triFace::compare(a,b) == 0;
00313 }
00314
00315
00316
Copyright © 2000-2009 OpenCFD Ltd