1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
11 OpenFOAM is free software; you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by the
13 Free Software Foundation; either version 2 of the License, or (at your
14 option) any later version.
16 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM; if not, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
27 #include "IOstreams.H"
29 #include "triPointRef.H"
31 // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
33 inline int Foam::triFace::compare(const triFace& a, const triFace& b)
37 (a[0] == b[0] && a[1] == b[1] && a[2] == b[2])
38 || (a[0] == b[1] && a[1] == b[2] && a[2] == b[0])
39 || (a[0] == b[2] && a[1] == b[0] && a[2] == b[1])
47 (a[0] == b[2] && a[1] == b[1] && a[2] == b[0])
48 || (a[0] == b[1] && a[1] == b[0] && a[2] == b[2])
49 || (a[0] == b[0] && a[1] == b[2] && a[2] == b[1])
52 // same face, but reversed orientation
62 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
64 inline Foam::triFace::triFace()
68 inline Foam::triFace::triFace
81 inline Foam::triFace::triFace(const UList<label>& l)
83 FixedList<label, 3>(l)
87 inline Foam::triFace::triFace(Istream& is)
89 FixedList<label, 3>(is)
93 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
95 inline Foam::label Foam::triFace::collapse()
97 // we cannot resize a FixedList, so mark duplicates with '-1'
98 // (the lower vertex is retained)
99 // catch any '-1' - ie, if called twice
102 if (operator[](0) == operator[](1) || operator[](1) == -1)
107 else if (operator[](1) == operator[](2) || operator[](2) == -1)
112 if (operator[](0) == operator[](2))
122 inline Foam::pointField Foam::triFace::points(const pointField& points) const
126 p[0] = points[operator[](0)];
127 p[1] = points[operator[](1)];
128 p[2] = points[operator[](2)];
134 inline Foam::face Foam::triFace::triFaceFace() const
138 f[0] = operator[](0);
139 f[1] = operator[](1);
140 f[2] = operator[](2);
146 inline Foam::label Foam::triFace::nEdges() const
152 inline Foam::edgeList Foam::triFace::edges() const
156 e[0].start() = operator[](0);
157 e[0].end() = operator[](1);
159 e[1].start() = operator[](1);
160 e[1].end() = operator[](2);
162 e[2].start() = operator[](2);
163 e[2].end() = operator[](0);
170 // - +1: forward (counter-clockwise) on the face
171 // - -1: reverse (clockwise) on the face
172 // - 0: edge not found on the face
173 inline int Foam::triFace::edgeDirection(const edge& e) const
177 (operator[](0) == e.start() && operator[](1) == e.end())
178 || (operator[](1) == e.start() && operator[](2) == e.end())
179 || (operator[](2) == e.start() && operator[](0) == e.end())
186 (operator[](0) == e.end() && operator[](1) == e.start())
187 || (operator[](1) == e.end() && operator[](2) == e.start())
188 || (operator[](2) == e.end() && operator[](0) == e.start())
200 inline Foam::point Foam::triFace::centre(const pointField& points) const
204 points[operator[](0)]
205 + points[operator[](1)]
206 + points[operator[](2)]
211 inline Foam::scalar Foam::triFace::mag(const pointField& points) const
213 return ::Foam::mag(normal(points));
217 inline Foam::vector Foam::triFace::normal(const pointField& points) const
221 (points[operator[](1)] - points[operator[](0)])
222 ^(points[operator[](2)] - points[operator[](0)])
227 inline Foam::scalar Foam::triFace::sweptVol
229 const pointField& opts,
230 const pointField& npts
236 (npts[operator[](0)] - opts[operator[](0)])
238 (opts[operator[](1)] - opts[operator[](0)])
239 ^ (opts[operator[](2)] - opts[operator[](0)])
243 (npts[operator[](1)] - opts[operator[](1)])
245 (opts[operator[](2)] - opts[operator[](1)])
246 ^ (npts[operator[](0)] - opts[operator[](1)])
250 (opts[operator[](2)] - npts[operator[](2)])
252 (npts[operator[](1)] - npts[operator[](2)])
253 ^ (npts[operator[](0)] - npts[operator[](2)])
260 inline Foam::pointHit Foam::triFace::ray
264 const pointField& points,
265 const intersection::algorithm alg,
266 const intersection::direction dir
271 points[operator[](0)],
272 points[operator[](1)],
273 points[operator[](2)]
274 ).ray(p, q, alg, dir);
278 inline Foam::triPointRef Foam::triFace::tri(const pointField& points) const
282 points[operator[](0)],
283 points[operator[](1)],
284 points[operator[](2)]
289 // * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
291 inline bool Foam::operator==(const triFace& a, const triFace& b)
293 return triFace::compare(a,b) != 0;
297 inline bool Foam::operator!=(const triFace& a, const triFace& b)
299 return triFace::compare(a,b) == 0;
303 // ************************************************************************* //