|
|
|
triangle.HGo to the documentation of this file.00001 /*---------------------------------------------------------------------------*\ 00002 ========= | 00003 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox 00004 \\ / O peration | 00005 \\ / A nd | Copyright (C) 1991-2009 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 Foam::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 "intersection.H" 00040 #include "vector.H" 00041 #include "pointHit.H" 00042 00043 00044 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00045 00046 namespace Foam 00047 { 00048 00049 class Istream; 00050 class Ostream; 00051 00052 // Forward declaration of friend functions and operators 00053 00054 template<class Point, class PointRef> class triangle; 00055 00056 template<class Point, class PointRef> 00057 inline Istream& operator>> 00058 ( 00059 Istream&, 00060 triangle<Point, PointRef>& 00061 ); 00062 00063 template<class Point, class PointRef> 00064 inline Ostream& operator<< 00065 ( 00066 Ostream&, 00067 const triangle<Point, PointRef>& 00068 ); 00069 00070 00071 /*---------------------------------------------------------------------------*\ 00072 class triangle Declaration 00073 \*---------------------------------------------------------------------------*/ 00074 00075 template<class Point, class PointRef> 00076 class triangle 00077 { 00078 // Private data 00079 00080 PointRef a_, b_, c_; 00081 00082 // Private member functions 00083 00084 //- Fast distance to triangle calculation. From 00085 // "Distance Between Point and Trangle in 3D" 00086 // David Eberly, Magic Software Inc. Aug. 2002. 00087 // Works on function Q giving distance to point and tries to 00088 // minimize this. 00089 static pointHit nearestPoint 00090 ( 00091 const Point& baseVertex, 00092 const vector& E0, 00093 const vector& E1, 00094 const point& P 00095 ); 00096 00097 00098 public: 00099 00100 //- Return types for classify 00101 enum proxType 00102 { 00103 NONE, 00104 POINT, // Close to point 00105 EDGE // Close to edge 00106 }; 00107 00108 00109 // Constructors 00110 00111 //- Construct from three points 00112 inline triangle(const Point& a, const Point& b, const Point& c); 00113 00114 //- Construct from Istream 00115 inline triangle(Istream&); 00116 00117 00118 // Member Functions 00119 00120 // Access 00121 00122 //- Return first vertex 00123 inline const Point& a() const; 00124 00125 //- Return second vertex 00126 inline const Point& b() const; 00127 00128 //- Return third vertex 00129 inline const Point& c() const; 00130 00131 00132 // Properties 00133 00134 //- Return centre (centroid) 00135 inline Point centre() const; 00136 00137 //- Return scalar magnitude 00138 inline scalar mag() const; 00139 00140 //- Return vector normal 00141 inline vector normal() const; 00142 00143 //- Return circum-centre 00144 inline vector circumCentre() const; 00145 00146 //- Return circum-radius 00147 inline scalar circumRadius() const; 00148 00149 //- Return quality: Ratio triangle and circum-circle area 00150 inline scalar quality() const; 00151 00152 //- Return swept-volume 00153 inline scalar sweptVol(const triangle& t) const; 00154 00155 //- Return point intersection with a ray. 00156 // For a hit, the distance is signed. Positive number 00157 // represents the point in front of triangle. 00158 // In case of miss pointHit is set to nearest point 00159 // on triangle and its distance to the distance between 00160 // the original point and the plane intersection point 00161 inline pointHit ray 00162 ( 00163 const point& p, 00164 const vector& q, 00165 const intersection::algorithm = intersection::FULL_RAY, 00166 const intersection::direction dir = intersection::VECTOR 00167 ) const; 00168 00169 //- Fast intersection with a ray. 00170 // For a hit, the pointHit.distance() is the line parameter t : 00171 // intersection=p+t*q. Only defined for VISIBLE, FULL_RAY or 00172 // HALF_RAY. tol increases the virtual size of the triangle 00173 // by a relative factor. 00174 inline pointHit intersection 00175 ( 00176 const point& p, 00177 const vector& q, 00178 const intersection::algorithm alg, 00179 const scalar tol = 0.0 00180 ) const; 00181 00182 //- Return nearest point to p on triangle 00183 inline pointHit nearestPoint 00184 ( 00185 const point& p 00186 ) const; 00187 00188 //- Classify point in triangle plane w.r.t. triangle edges. 00189 // - inside (true returned)/outside (false returned) 00190 // - near point (nearType=POINT, nearLabel=0, 1, 2) 00191 // - near edge (nearType=EDGE, nearLabel=0, 1, 2) 00192 // Note: edges are counted from starting 00193 // vertex so e.g. edge 2 is from f[2] to f[0] 00194 // tol is fraction to account for truncation error. Is only used 00195 // when comparing normalized (0..1) numbers. 00196 bool classify 00197 ( 00198 const point& p, 00199 const scalar tol, 00200 label& nearType, 00201 label& nearLabel 00202 ) const; 00203 00204 00205 // IOstream operators 00206 00207 friend Istream& operator>> <Point, PointRef> 00208 ( 00209 Istream&, 00210 triangle& 00211 ); 00212 00213 friend Ostream& operator<< <Point, PointRef> 00214 ( 00215 Ostream&, 00216 const triangle& 00217 ); 00218 }; 00219 00220 00221 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00222 00223 } // End namespace Foam 00224 00225 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00226 00227 #include "triangleI.H" 00228 00229 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00230 00231 #endif 00232 00233 // ************************************************************************* // |