![]() |
|
00001 /*---------------------------------------------------------------------------*\ 00002 ========= | 00003 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox 00004 \\ / O peration | 00005 \\ / A nd | Copyright (C) 1991-2005 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 the 00013 Free Software Foundation; either version 2 of the License, or (at your 00014 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, write to the Free Software Foundation, 00023 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00024 00025 Class 00026 triangle 00027 00028 Description 00029 A triangle primitive used to calculate face normals and swept volumes. 00030 00031 SourceFiles 00032 triangleI.H 00033 00034 \*---------------------------------------------------------------------------*/ 00035 00036 #ifndef triangle_H 00037 #define triangle_H 00038 00039 #include "point.H" 00040 #include "intersection.H" 00041 #include "vector.H" 00042 00043 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00044 00045 namespace Foam 00046 { 00047 00048 class pointHit; 00049 00050 class Istream; 00051 class Ostream; 00052 00053 // * * * * * * Forward declaration of template friend fuctions * * * * * * * // 00054 00055 template<class Point, class PointRef> class triangle; 00056 00057 template<class Point, class PointRef> 00058 inline Istream& operator>> 00059 ( 00060 Istream&, 00061 triangle<Point, PointRef>& 00062 ); 00063 00064 template<class Point, class PointRef> 00065 inline Ostream& operator<< 00066 ( 00067 Ostream&, 00068 const triangle<Point, PointRef>& 00069 ); 00070 00071 00072 /*---------------------------------------------------------------------------*\ 00073 class triangle Declaration 00074 \*---------------------------------------------------------------------------*/ 00075 00076 template<class Point, class PointRef> 00077 class triangle 00078 { 00079 // Private data 00080 00081 PointRef a_, b_, c_; 00082 00083 // Private member functions 00084 00085 //- Find intersection of triangle (origin V0, spanning edges 00086 // E0, E1) with infinite ray (origin P, direction dir) Based 00087 // on Graphics Gems - Fast Ray Triangle intersection. Since 00088 // direction is coordinate axis there is no need to do 00089 // projection, we can directly check u,v components for 00090 // inclusion in triangle. 00091 static bool intersection 00092 ( 00093 const Point& baseVertex, 00094 const vector& E0, 00095 const vector& E1, 00096 const vector& n, 00097 const point& P, 00098 const vector& dir, 00099 point& pInter 00100 ); 00101 00102 //- Fast distance to triangle calculation. From 00103 // "Distance Between Point and Trangle in 3D" 00104 // David Eberly, Magic Software Inc. Aug. 2002. 00105 // Works on function Q giving distance to point and tries to 00106 // minimize this. 00107 static pointHit nearestPoint 00108 ( 00109 const Point& baseVertex, 00110 const vector& E0, 00111 const vector& E1, 00112 const point& P 00113 ); 00114 00115 00116 public: 00117 00118 //- Return types for classify 00119 enum proxType 00120 { 00121 NONE, 00122 POINT, // Close to point 00123 EDGE // Close to edge 00124 }; 00125 00126 00127 // Constructors 00128 00129 //- Construct from three points 00130 inline triangle(const Point& a, const Point& b, const Point& c); 00131 00132 //- Construct from Istream 00133 inline triangle(Istream&); 00134 00135 00136 // Member Functions 00137 00138 // Access 00139 00140 //- Return first vertex 00141 inline const Point& a() const; 00142 00143 //- Return second vertex 00144 inline const Point& b() const; 00145 00146 //- Return third vertex 00147 inline const Point& c() const; 00148 00149 00150 // Properties 00151 00152 //- Return centre (centroid) 00153 inline Point centre() const; 00154 00155 //- Return scalar magnitude 00156 inline scalar mag() const; 00157 00158 //- Return vector normal 00159 inline vector normal() const; 00160 00161 //- Return circum-centre 00162 inline vector circumCentre() const; 00163 00164 //- Return circum-radius 00165 inline scalar circumRadius() const; 00166 00167 //- Return quality: Ratio triangle and circum-circle area 00168 inline scalar quality() const; 00169 00170 //- Return swept-volume 00171 inline scalar sweptVol(const triangle& t) const; 00172 00173 //- Return point intersection with a ray. 00174 // For a hit, the distance is signed. Positive number 00175 // represents the point in front of triangle. 00176 // In case of miss pointHit is set to nearest point 00177 // on triangle and its distance to the distance between 00178 // the original point and the plane intersection point 00179 inline pointHit ray 00180 ( 00181 const point& p, 00182 const vector& q, 00183 const intersection::algorithm = intersection::FULL_RAY, 00184 const intersection::direction dir = intersection::VECTOR 00185 ) const; 00186 00187 //- Return nearest point to p on triangle 00188 inline pointHit nearestPoint 00189 ( 00190 const point& p 00191 ) const; 00192 00193 //- Classify point in triangle plane w.r.t. triangle edges. 00194 // - inside (true returned)/outside (false returned) 00195 // - near point (nearType=POINT, nearLabel=0, 1, 2) 00196 // - near edge (nearType=EDGE, nearLabel=0, 1, 2) 00197 // Note: edges are counted from starting 00198 // vertex so e.g. edge 2 is from f[2] to f[0] 00199 bool classify 00200 ( 00201 const point& p, 00202 const scalar tol, 00203 label& nearType, 00204 label& nearLabel 00205 ) const; 00206 00207 00208 // IOstream operators 00209 00210 friend Istream& operator>> <Point, PointRef> 00211 ( 00212 Istream&, 00213 triangle& 00214 ); 00215 00216 friend Ostream& operator<< <Point, PointRef> 00217 ( 00218 Ostream&, 00219 const triangle& 00220 ); 00221 }; 00222 00223 00224 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00225 00226 } // End namespace Foam 00227 00228 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00229 00230 #include "triangleI.H" 00231 00232 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00233 00234 #endif 00235 00236 // ************************************************************************* //