1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2004-2011 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
13 the Free Software Foundation, either version 3 of the License, or
14 (at your 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, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "IOstreams.H"
28 #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 labelUList& lst)
83 FixedList<label, 3>(lst)
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' (eg, 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 void Foam::triFace::flip()
124 Swap(operator[](1), operator[](2));
128 inline Foam::pointField Foam::triFace::points(const pointField& points) const
132 p[0] = points[operator[](0)];
133 p[1] = points[operator[](1)];
134 p[2] = points[operator[](2)];
140 inline Foam::face Foam::triFace::triFaceFace() const
144 f[0] = operator[](0);
145 f[1] = operator[](1);
146 f[2] = operator[](2);
152 inline Foam::triPointRef Foam::triFace::tri(const pointField& points) const
156 points[operator[](0)],
157 points[operator[](1)],
158 points[operator[](2)]
163 inline Foam::point Foam::triFace::centre(const pointField& points) const
167 points[operator[](0)]
168 + points[operator[](1)]
169 + points[operator[](2)]
174 inline Foam::scalar Foam::triFace::mag(const pointField& points) const
176 return ::Foam::mag(normal(points));
180 // could also delegate to triPointRef(...).normal()
181 inline Foam::vector Foam::triFace::normal(const pointField& points) const
185 (points[operator[](1)] - points[operator[](0)])
186 ^(points[operator[](2)] - points[operator[](0)])
191 inline Foam::label Foam::triFace::nTriangles() const
197 inline Foam::triFace Foam::triFace::reverseFace() const
199 // The starting points of the original and reverse face are identical.
200 return triFace(operator[](0), operator[](2), operator[](1));
204 inline Foam::scalar Foam::triFace::sweptVol
206 const pointField& opts,
207 const pointField& npts
213 (npts[operator[](0)] - opts[operator[](0)])
215 (opts[operator[](1)] - opts[operator[](0)])
216 ^ (opts[operator[](2)] - opts[operator[](0)])
220 (npts[operator[](1)] - opts[operator[](1)])
222 (opts[operator[](2)] - opts[operator[](1)])
223 ^ (npts[operator[](0)] - opts[operator[](1)])
227 (opts[operator[](2)] - npts[operator[](2)])
229 (npts[operator[](1)] - npts[operator[](2)])
230 ^ (npts[operator[](0)] - npts[operator[](2)])
237 Foam::tensor Foam::triFace::inertia
239 const pointField& points,
244 // a triangle, do a direct calculation
245 return this->tri(points).inertia(refPt, density);
249 inline Foam::pointHit Foam::triFace::ray
253 const pointField& points,
254 const intersection::algorithm alg,
255 const intersection::direction dir
258 return this->tri(points).ray(p, q, alg, dir);
263 inline Foam::pointHit Foam::triFace::intersection
267 const pointField& points,
268 const intersection::algorithm alg,
272 return this->tri(points).intersection(p, q, alg, tol);
276 inline Foam::pointHit Foam::triFace::nearestPoint
279 const pointField& points
282 return this->tri(points).nearestPoint(p);
286 inline Foam::pointHit Foam::triFace::nearestPointClassify
289 const pointField& points,
294 return this->tri(points).nearestPointClassify(p, nearType, nearLabel);
298 inline Foam::label Foam::triFace::nEdges() const
304 inline Foam::edgeList Foam::triFace::edges() const
308 e[0].start() = operator[](0);
309 e[0].end() = operator[](1);
311 e[1].start() = operator[](1);
312 e[1].end() = operator[](2);
314 e[2].start() = operator[](2);
315 e[2].end() = operator[](0);
321 inline Foam::edge Foam::triFace::faceEdge(const label n) const
323 return edge(operator[](n), operator[](fcIndex(n)));
328 // - +1: forward (counter-clockwise) on the face
329 // - -1: reverse (clockwise) on the face
330 // - 0: edge not found on the face
331 inline int Foam::triFace::edgeDirection(const edge& e) const
335 (operator[](0) == e.start() && operator[](1) == e.end())
336 || (operator[](1) == e.start() && operator[](2) == e.end())
337 || (operator[](2) == e.start() && operator[](0) == e.end())
344 (operator[](0) == e.end() && operator[](1) == e.start())
345 || (operator[](1) == e.end() && operator[](2) == e.start())
346 || (operator[](2) == e.end() && operator[](0) == e.start())
358 // * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
360 inline bool Foam::operator==(const triFace& a, const triFace& b)
362 return triFace::compare(a,b) != 0;
366 inline bool Foam::operator!=(const triFace& a, const triFace& b)
368 return triFace::compare(a,b) == 0;
372 // ************************************************************************* //