initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / OpenFOAM / meshes / primitiveShapes / triangle / triangle.H
blob3bc3ea38a809c1850057de2d25cc73d0cdc2413b
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::triangle
28 Description
29     A triangle primitive used to calculate face normals and swept volumes.
31 SourceFiles
32     triangleI.H
34 \*---------------------------------------------------------------------------*/
36 #ifndef triangle_H
37 #define triangle_H
39 #include "intersection.H"
40 #include "vector.H"
41 #include "pointHit.H"
44 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
46 namespace Foam
49 class Istream;
50 class Ostream;
52 // Forward declaration of friend functions and operators
54 template<class Point, class PointRef> class triangle;
56 template<class Point, class PointRef>
57 inline Istream& operator>>
59     Istream&,
60     triangle<Point, PointRef>&
63 template<class Point, class PointRef>
64 inline Ostream& operator<<
66     Ostream&,
67     const triangle<Point, PointRef>&
71 /*---------------------------------------------------------------------------*\
72                            class triangle Declaration
73 \*---------------------------------------------------------------------------*/
75 template<class Point, class PointRef>
76 class triangle
78     // Private data
80         PointRef a_, b_, c_;
82     // Private member functions
84         //- Fast distance to triangle calculation. From
85         //  "Distance Between Point and Trangle in 3D"
86         //  David Eberly, Magic Software Inc. Aug. 2002.
87         //  Works on function Q giving distance to point and tries to
88         //  minimize this.
89         static pointHit nearestPoint
90         (
91             const Point& baseVertex,
92             const vector& E0,
93             const vector& E1,
94             const point& P
95         );
98 public:
100     //- Return types for classify
101     enum proxType
102     {
103         NONE, 
104         POINT,  // Close to point
105         EDGE    // Close to edge
106     };
109     // Constructors
111         //- Construct from three points
112         inline triangle(const Point& a, const Point& b, const Point& c);
114         //- Construct from Istream
115         inline triangle(Istream&);
118     // Member Functions
120         // Access
122             //- Return first vertex
123             inline const Point& a() const;
125             //- Return second vertex
126             inline const Point& b() const;
128             //- Return third vertex
129             inline const Point& c() const;
132         // Properties
134             //- Return centre (centroid)
135             inline Point centre() const;
137             //- Return scalar magnitude
138             inline scalar mag() const;
140             //- Return vector normal
141             inline vector normal() const;
143             //- Return circum-centre
144             inline vector circumCentre() const;
146             //- Return circum-radius
147             inline scalar circumRadius() const;
149             //- Return quality: Ratio triangle and circum-circle area
150             inline scalar quality() const;
152             //- Return swept-volume
153             inline scalar sweptVol(const triangle& t) const;
155             //- Return point intersection with a ray.
156             //  For a hit, the distance is signed. Positive number
157             //  represents the point in front of triangle.
158             //  In case of miss pointHit is set to nearest point
159             //  on triangle and its distance to the distance between
160             //  the original point and the plane intersection point
161             inline pointHit ray
162             (
163                 const point& p,
164                 const vector& q,
165                 const intersection::algorithm = intersection::FULL_RAY,
166                 const intersection::direction dir = intersection::VECTOR
167             ) const;
169             //- Fast intersection with a ray.
170             //  For a hit, the pointHit.distance() is the line parameter t :
171             //  intersection=p+t*q. Only defined for VISIBLE, FULL_RAY or
172             //  HALF_RAY. tol increases the virtual size of the triangle
173             // by a relative factor.
174             inline pointHit intersection
175             (
176                 const point& p,
177                 const vector& q,
178                 const intersection::algorithm alg,
179                 const scalar tol = 0.0
180             ) const;
182             //- Return nearest point to p on triangle
183             inline pointHit nearestPoint
184             (
185                 const point& p
186             ) const;
188             //- Classify point in triangle plane w.r.t. triangle edges.
189             //  - inside (true returned)/outside (false returned)
190             //  - near point (nearType=POINT, nearLabel=0, 1, 2)
191             //  - near edge (nearType=EDGE, nearLabel=0, 1, 2)
192             //    Note: edges are counted from starting
193             //    vertex so e.g. edge 2 is from f[2] to f[0]
194             //  tol is fraction to account for truncation error. Is only used
195             //  when comparing normalized (0..1) numbers.
196             bool classify
197             (
198                 const point& p,
199                 const scalar tol,
200                 label& nearType,
201                 label& nearLabel
202             ) const;
205     // IOstream operators
207         friend Istream& operator>> <Point, PointRef>
208         (
209             Istream&,
210             triangle&
211         );
213         friend Ostream& operator<< <Point, PointRef>
214         (
215             Ostream&,
216             const triangle&
217         );
221 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
223 } // End namespace Foam
225 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
227 #include "triangleI.H"
229 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
231 #endif
233 // ************************************************************************* //