00001 /*---------------------------------------------------------------------------*\ 00002 ========= | 00003 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox 00004 \\ / O peration | 00005 \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd. 00006 \\/ M anipulation | 00007 ------------------------------------------------------------------------------- 00008 License 00009 This file is part of OpenFOAM. 00010 00011 OpenFOAM is free software: you can redistribute it and/or modify it 00012 under the terms of the GNU General Public License as published by 00013 the Free Software Foundation, either version 3 of the License, or 00014 (at your option) any later version. 00015 00016 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT 00017 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00018 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 00019 for more details. 00020 00021 You should have received a copy of the GNU General Public License 00022 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>. 00023 00024 Class 00025 Foam::triangle 00026 00027 Description 00028 A triangle primitive used to calculate face normals and swept volumes. 00029 00030 SourceFiles 00031 triangleI.H 00032 00033 \*---------------------------------------------------------------------------*/ 00034 00035 #ifndef triangle_H 00036 #define triangle_H 00037 00038 #include "intersection.H" 00039 #include <OpenFOAM/vector.H> 00040 #include <OpenFOAM/pointHit.H> 00041 00042 00043 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00044 00045 namespace Foam 00046 { 00047 00048 class Istream; 00049 class Ostream; 00050 00051 // Forward declaration of friend functions and operators 00052 00053 template<class Point, class PointRef> class triangle; 00054 00055 template<class Point, class PointRef> 00056 inline Istream& operator>> 00057 ( 00058 Istream&, 00059 triangle<Point, PointRef>& 00060 ); 00061 00062 template<class Point, class PointRef> 00063 inline Ostream& operator<< 00064 ( 00065 Ostream&, 00066 const triangle<Point, PointRef>& 00067 ); 00068 00069 00070 /*---------------------------------------------------------------------------*\ 00071 class triangle Declaration 00072 \*---------------------------------------------------------------------------*/ 00073 00074 template<class Point, class PointRef> 00075 class triangle 00076 { 00077 // Private data 00078 00079 PointRef a_, b_, c_; 00080 00081 // Private member functions 00082 00083 //- Fast distance to triangle calculation. From 00084 // "Distance Between Point and Trangle in 3D" 00085 // David Eberly, Magic Software Inc. Aug. 2002. 00086 // Works on function Q giving distance to point and tries to 00087 // minimize this. 00088 static pointHit nearestPoint 00089 ( 00090 const Point& baseVertex, 00091 const vector& E0, 00092 const vector& E1, 00093 const point& P 00094 ); 00095 00096 00097 public: 00098 00099 //- Return types for classify 00100 enum proxType 00101 { 00102 NONE, 00103 POINT, // Close to point 00104 EDGE // Close to edge 00105 }; 00106 00107 00108 // Constructors 00109 00110 //- Construct from three points 00111 inline triangle(const Point& a, const Point& b, const Point& c); 00112 00113 //- Construct from Istream 00114 inline triangle(Istream&); 00115 00116 00117 // Member Functions 00118 00119 // Access 00120 00121 //- Return first vertex 00122 inline const Point& a() const; 00123 00124 //- Return second vertex 00125 inline const Point& b() const; 00126 00127 //- Return third vertex 00128 inline const Point& c() const; 00129 00130 00131 // Properties 00132 00133 //- Return centre (centroid) 00134 inline Point centre() const; 00135 00136 //- Return scalar magnitude 00137 inline scalar mag() const; 00138 00139 //- Return vector normal 00140 inline vector normal() const; 00141 00142 //- Return circum-centre 00143 inline vector circumCentre() const; 00144 00145 //- Return circum-radius 00146 inline scalar circumRadius() const; 00147 00148 //- Return quality: Ratio triangle and circum-circle area 00149 inline scalar quality() const; 00150 00151 //- Return swept-volume 00152 inline scalar sweptVol(const triangle& t) const; 00153 00154 //- Return point intersection with a ray. 00155 // For a hit, the distance is signed. Positive number 00156 // represents the point in front of triangle. 00157 // In case of miss pointHit is set to nearest point 00158 // on triangle and its distance to the distance between 00159 // the original point and the plane intersection point 00160 inline pointHit ray 00161 ( 00162 const point& p, 00163 const vector& q, 00164 const intersection::algorithm = intersection::FULL_RAY, 00165 const intersection::direction dir = intersection::VECTOR 00166 ) const; 00167 00168 //- Fast intersection with a ray. 00169 // For a hit, the pointHit.distance() is the line parameter t : 00170 // intersection=p+t*q. Only defined for VISIBLE, FULL_RAY or 00171 // HALF_RAY. tol increases the virtual size of the triangle 00172 // by a relative factor. 00173 inline pointHit intersection 00174 ( 00175 const point& p, 00176 const vector& q, 00177 const intersection::algorithm alg, 00178 const scalar tol = 0.0 00179 ) const; 00180 00181 //- Return nearest point to p on triangle 00182 inline pointHit nearestPoint 00183 ( 00184 const point& p 00185 ) const; 00186 00187 //- Classify point in triangle plane w.r.t. triangle edges. 00188 // - inside (true returned)/outside (false returned) 00189 // - near point (nearType=POINT, nearLabel=0, 1, 2) 00190 // - near edge (nearType=EDGE, nearLabel=0, 1, 2) 00191 // Note: edges are counted from starting 00192 // vertex so e.g. edge 2 is from f[2] to f[0] 00193 // tol is fraction to account for truncation error. Is only used 00194 // when comparing normalized (0..1) numbers. 00195 bool classify 00196 ( 00197 const point& p, 00198 const scalar tol, 00199 label& nearType, 00200 label& nearLabel 00201 ) const; 00202 00203 00204 // IOstream operators 00205 00206 friend Istream& operator>> <Point, PointRef> 00207 ( 00208 Istream&, 00209 triangle& 00210 ); 00211 00212 friend Ostream& operator<< <Point, PointRef> 00213 ( 00214 Ostream&, 00215 const triangle& 00216 ); 00217 }; 00218 00219 00220 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00221 00222 } // End namespace Foam 00223 00224 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00225 00226 #include "triangleI.H" 00227 00228 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00229 00230 #endif 00231 00232 // ************************ vim: set sw=4 sts=4 et: ************************ //