initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / OpenFOAM / meshes / meshShapes / triFace / triFace.H
blob83beae84fef8f8b33678ad3a2729745a7df38732
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
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
19     for more details.
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 Class
26     Foam::triFace
28 Description
29     A triangle face primitive using a FixedList.
31 SourceFiles
32     triFaceI.H
34 \*---------------------------------------------------------------------------*/
36 #ifndef triFace_H
37 #define triFace_H
39 #include "FixedList.H"
40 #include "edgeList.H"
41 #include "pointHit.H"
42 #include "intersection.H"
43 #include "pointField.H"
44 #include "triPointRef.H"
46 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
48 namespace Foam
51 class face;
53 // Forward declaration of friend functions and operators
55 class triFace;
56 inline bool operator==(const triFace&, const triFace&);
57 inline bool operator!=(const triFace&, const triFace&);
60 /*---------------------------------------------------------------------------*\
61                           class triFace Declaration
62 \*---------------------------------------------------------------------------*/
64 class triFace
66     public FixedList<label, 3>
69 public:
71     // Constructors
73         //- Construct null
74         inline triFace();
76         //- Construct from three point labels
77         inline triFace
78         (
79             const label a,
80             const label b,
81             const label c
82         );
84         //- Construct from a UList<label>
85         explicit inline triFace(const UList<label>&);
87         //- Construct from Istream
88         inline triFace(Istream&);
91     // Member Functions
93         //- Collapse face by removing duplicate point labels
94         //  return the collapsed size, set collapsed point labels to -1
95         inline label collapse();
97         //- Return the edge direction on the face
98         //  - +1: forward (counter-clockwise) on the face
99         //  - -1: reverse (clockwise) on the face
100         //  -  0: edge not found on the face
101         inline int edgeDirection(const edge&) const;
104         // Properties
106             //- Return the points corresponding to this face
107             inline pointField points(const pointField& points) const;
109             //- Return triangle as a face
110             inline face triFaceFace() const;
112             //- Return number of edges
113             inline label nEdges() const;
115             //- Return edges
116             inline edgeList edges() const;
118             //- Return centre (centroid)
119             inline point centre(const pointField&) const;
121             //- Return scalar magnitude
122             inline scalar mag(const pointField&) const;
124             //- Return vector normal
125             inline vector normal(const pointField&) const;
127             //- Number of triangles after splitting
128             inline label nTriangles() const;
130             //- Return face with reverse direction
131             inline triFace reverseFace() const;
133             //- Return swept-volume
134             inline scalar sweptVol
135             (
136                 const pointField& oldPoints,
137                 const pointField& newPoints
138             ) const;
140             //- Return point intersection with a ray starting at p, with
141             //  direction n.
142             inline pointHit ray
143             (
144                 const point& p,
145                 const vector& q,
146                 const pointField& points,
147                 const intersection::algorithm = intersection::FULL_RAY,
148                 const intersection::direction dir = intersection::VECTOR
149             ) const;
151             //- Return the triangle
152             inline triPointRef tri(const pointField&) const;
154         //- compare triFaces
155         //  -  0: different
156         //  - +1: identical
157         //  - -1: same face, but different orientation
158         static inline int compare(const triFace&, const triFace&);
160     // Friend Operators
162         friend bool operator==(const triFace&, const triFace&);
163         friend bool operator!=(const triFace&, const triFace&);
167 //- Hash specialization for hashing triFace - a commutative hash value.
168 //  Hash incrementally.
169 template<>
170 inline unsigned Hash<triFace>::operator()(const triFace& t, unsigned seed) const
172     // Fortunately we don't need this very often
173     const uLabel t0(t[0]);
174     const uLabel t1(t[1]);
175     const uLabel t2(t[2]);
177     const uLabel val = (t0*t1*t2 + t0+t1+t2);
179     return Hash<uLabel>()(val, seed);
183 //- Hash specialization for hashing triFace - a commutative hash value.
184 //  Hash incrementally.
185 template<>
186 inline unsigned Hash<triFace>::operator()(const triFace& t) const
188     return Hash<triFace>::operator()(t, 0);
192 template<>
193 inline bool contiguous<triFace>()  {return true;}
196 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
198 } // End namespace Foam
200 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
202 #include "triFaceI.H"
204 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
206 #endif
208 // ************************************************************************* //