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