correction to d4edb38234db8268907f04836d49bb93461b8a88
[OpenFOAM-1.5.x.git] / src / meshTools / triSurface / triangleFuncs / triangleFuncs.H
blob9ebc5c673189a777dcfaeed2443ca088ee2ff49b
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2008 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::triangleFuncs
28 Description
29     Various triangle functions.
31 SourceFiles
32     triangleFuncs.C
34 \*---------------------------------------------------------------------------*/
36 #ifndef triangleFuncs_H
37 #define triangleFuncs_H
39 #include "point.H"
40 #include "label.H"
41 #include "scalar.H"
42 #include "pointField.H"
44 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
46 namespace Foam
49 // Forward declaration of classes
50 class treeBoundBox;
52 /*---------------------------------------------------------------------------*\
53                            Class triangleFuncs Declaration
54 \*---------------------------------------------------------------------------*/
56 class triangleFuncs
59 public:
61     // Public data types
63         //- Enumeration defining nearness classification
64         enum proxType
65         {
66             NONE,
67             POINT,
68             EDGE
69         };
72 private:
74     // Private Member Functions
76         //- Helper function for intersect. Sets pt to be anywhere on the edge
77         //  between oppositeSidePt and thisSidePt depending on both signs.
78         static void setIntersection
79         (
80             const point& oppositeSidePt,
81             const scalar oppositeSign,
82             const point& thisSidePt,
83             const scalar thisSign,
84             const scalar tol,
85             point& pt
86         );
88         //- Helper function.
89         static void selectPt
90         (
91             const bool select0,
92             const point& p0,
93             const point& p1,
94             point& min
95         );
97 public:
99     //- Intersect triangle with parallel edges aligned with axis i0.
100     //  Returns true (and intersection in pInter) if any of them intersects
101     //  triangle. Used in intersectBb.
102     static bool intersectAxesBundle
103     (
104         const point& V0,
105         const point& V10,
106         const point& V20,
107         const label i0,
108         const pointField& origin,
109         const scalar maxLength,
110         point& pInter
111     );
113     //- Does triangle intersect bounding box.
114     static bool intersectBb
115     (
116         const point& p0,
117         const point& p1,
118         const point& p2,
119         const treeBoundBox& cubeBb
120     );
122     //- Does triangle intersect plane. Return bool and set intersection segment.
123     static bool intersect
124     (
125         const point& va0,
126         const point& va10,
127         const point& va20,
129         const point& basePoint,
130         const vector& normal,
132         point& pInter0,
133         point& pInter1
134     );
136     //- Do triangles intersect. Return bool and set intersection segment.
137     static bool intersect
138     (
139         const point& va0,
140         const point& va10,
141         const point& va20,
143         const point& vb0,
144         const point& vb10,
145         const point& vb20,
147         point& pInter0,
148         point& pInter1
149     );
152     //- Classify point on triangle plane w.r.t. triangle edges.
153     //  - inside/outside (returned)
154     //  - near point (0, 1, 2)
155     //  - near edge (0, 1, 2). Note: edges are counted from starting vertex
156     //    so e.g. edge 2 is from f[2] to f[0]
157     static bool classify
158     (
159         const point& baseVertex,
160         const vector& E0,
161         const vector& E1,
162         const vector& n,
163         const point& pInter,
164         const scalar tol,
165         label& nearType,
166         label& nearLabel
167     );
172 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
174 } // End namespace Foam
176 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
178 #endif
180 // ************************************************************************* //