FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

triFace.H

Go 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-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::triFace
00026 
00027 Description
00028     A triangle face primitive using a FixedList.
00029 
00030 SourceFiles
00031     triFaceI.H
00032 
00033 \*---------------------------------------------------------------------------*/
00034 
00035 #ifndef triFace_H
00036 #define triFace_H
00037 
00038 #include <OpenFOAM/FixedList.H>
00039 #include <OpenFOAM/edgeList.H>
00040 #include <OpenFOAM/pointHit.H>
00041 #include <OpenFOAM/intersection.H>
00042 #include <OpenFOAM/pointField.H>
00043 #include <OpenFOAM/triPointRef.H>
00044 
00045 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00046 
00047 namespace Foam
00048 {
00049 
00050 class face;
00051 
00052 // Forward declaration of friend functions and operators
00053 
00054 class triFace;
00055 inline bool operator==(const triFace&, const triFace&);
00056 inline bool operator!=(const triFace&, const triFace&);
00057 
00058 
00059 /*---------------------------------------------------------------------------*\
00060                           class triFace Declaration
00061 \*---------------------------------------------------------------------------*/
00062 
00063 class triFace
00064 :
00065     public FixedList<label, 3>
00066 {
00067 
00068 public:
00069 
00070     // Constructors
00071 
00072         //- Construct null
00073         inline triFace();
00074 
00075         //- Construct from three point labels
00076         inline triFace
00077         (
00078             const label a,
00079             const label b,
00080             const label c
00081         );
00082 
00083         //- Construct from a UList<label>
00084         explicit inline triFace(const UList<label>&);
00085 
00086         //- Construct from Istream
00087         inline triFace(Istream&);
00088 
00089 
00090     // Member Functions
00091 
00092         //- Collapse face by removing duplicate point labels
00093         //  return the collapsed size, set collapsed point labels to -1
00094         inline label collapse();
00095 
00096         //- Return the edge direction on the face
00097         //  - +1: forward (counter-clockwise) on the face
00098         //  - -1: reverse (clockwise) on the face
00099         //  -  0: edge not found on the face
00100         inline int edgeDirection(const edge&) const;
00101 
00102 
00103         // Properties
00104 
00105             //- Return the points corresponding to this face
00106             inline pointField points(const pointField& points) const;
00107 
00108             //- Return triangle as a face
00109             inline face triFaceFace() const;
00110 
00111             //- Return number of edges
00112             inline label nEdges() const;
00113 
00114             //- Return edges
00115             inline edgeList edges() const;
00116 
00117             //- Return centre (centroid)
00118             inline point centre(const pointField&) const;
00119 
00120             //- Return scalar magnitude
00121             inline scalar mag(const pointField&) const;
00122 
00123             //- Return vector normal
00124             inline vector normal(const pointField&) const;
00125 
00126             //- Number of triangles after splitting
00127             inline label nTriangles() const;
00128 
00129             //- Return face with reverse direction
00130             inline triFace reverseFace() const;
00131 
00132             //- Return swept-volume
00133             inline scalar sweptVol
00134             (
00135                 const pointField& oldPoints,
00136                 const pointField& newPoints
00137             ) const;
00138 
00139             //- Return point intersection with a ray starting at p, with
00140             //  direction n.
00141             inline pointHit ray
00142             (
00143                 const point& p,
00144                 const vector& q,
00145                 const pointField& points,
00146                 const intersection::algorithm = intersection::FULL_RAY,
00147                 const intersection::direction dir = intersection::VECTOR
00148             ) const;
00149 
00150             //- Return the triangle
00151             inline triPointRef tri(const pointField&) const;
00152 
00153         //- compare triFaces
00154         //  -  0: different
00155         //  - +1: identical
00156         //  - -1: same face, but different orientation
00157         static inline int compare(const triFace&, const triFace&);
00158 
00159     // Friend Operators
00160 
00161         friend bool operator==(const triFace&, const triFace&);
00162         friend bool operator!=(const triFace&, const triFace&);
00163 };
00164 
00165 
00166 //- Hash specialization for hashing triFace - a commutative hash value.
00167 //  Hash incrementally.
00168 template<>
00169 inline unsigned Hash<triFace>::operator()(const triFace& t, unsigned seed) const
00170 {
00171     // Fortunately we don't need this very often
00172     const uLabel t0(t[0]);
00173     const uLabel t1(t[1]);
00174     const uLabel t2(t[2]);
00175 
00176     const uLabel val = (t0*t1*t2 + t0+t1+t2);
00177 
00178     return Hash<uLabel>()(val, seed);
00179 }
00180 
00181 
00182 //- Hash specialization for hashing triFace - a commutative hash value.
00183 //  Hash incrementally.
00184 template<>
00185 inline unsigned Hash<triFace>::operator()(const triFace& t) const
00186 {
00187     return Hash<triFace>::operator()(t, 0);
00188 }
00189 
00190 
00191 template<>
00192 inline bool contiguous<triFace>()  {return true;}
00193 
00194 
00195 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00196 
00197 } // End namespace Foam
00198 
00199 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00200 
00201 #include <OpenFOAM/triFaceI.H>
00202 
00203 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00204 
00205 #endif
00206 
00207 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines