OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

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