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

PointHit_.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::PointHit
00026 
00027 Description
00028     This class describes the interaction of a face and a point. It
00029     carries the info of a successful hit and (if successful), returns
00030     the interaction point.
00031 
00032 \*---------------------------------------------------------------------------*/
00033 
00034 #ifndef PointHit__H
00035 #define PointHit__H
00036 
00037 #include <OpenFOAM/bool.H>
00038 #include <OpenFOAM/token.H>
00039 
00040 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00041 
00042 namespace Foam
00043 {
00044 
00045 // Forward declaration of classes
00046 
00047 class Ostream;
00048 
00049 
00050 // Forward declaration of friend functions and operators
00051 
00052 template<class Point> class PointHit;
00053 
00054 template<class Point>
00055 inline Ostream& operator<<(Ostream&, const PointHit<Point>&);
00056 
00057 
00058 /*---------------------------------------------------------------------------*\
00059                            Class PointHit Declaration
00060 \*---------------------------------------------------------------------------*/
00061 
00062 template<class Point>
00063 class PointHit
00064 {
00065     // Private data
00066 
00067         //- Hit success
00068         bool hit_;
00069 
00070         //- Point of hit; for miss holds best estimate outside the object
00071         Point hitPoint_;
00072 
00073         //- Distance to hit point
00074         scalar distance_;
00075 
00076         //- Eligible miss
00077         bool eligibleMiss_;
00078 
00079 
00080 public:
00081 
00082     // Constructors
00083 
00084         //- Construct from components
00085         PointHit
00086         (
00087             const bool hit,
00088             const Point& p,
00089             const scalar dist,
00090             const bool eligibleMiss
00091         )
00092         :
00093             hit_(hit),
00094             hitPoint_(p),
00095             distance_(dist),
00096             eligibleMiss_(eligibleMiss)
00097         {}
00098 
00099         //- Construct from point. Hit and distance set later
00100         PointHit(const Point& p)
00101         :
00102             hit_(false),
00103             hitPoint_(p),
00104             distance_(GREAT),
00105             eligibleMiss_(false)
00106         {}
00107 
00108 
00109     // Member Functions
00110 
00111         //- Is there a hit
00112         bool hit() const
00113         {
00114             return hit_;
00115         }
00116 
00117         //- Return hit point
00118         const Point& hitPoint() const
00119         {
00120             if (!hit_)
00121             {
00122                 FatalErrorIn("const Point& PointHit::hitPoint() const")
00123                     << "requested a hit point for a miss"
00124                     << abort(FatalError);
00125             }
00126 
00127             return hitPoint_;
00128         }
00129 
00130         //- Return distance to hit
00131         scalar distance() const
00132         {
00133             return distance_;
00134         }
00135 
00136         //- Return miss point
00137         const Point& missPoint() const
00138         {
00139             if (hit_)
00140             {
00141                 FatalErrorIn("const Point& PointHit::missPoint() const")
00142                     << "requested a miss point for a hit"
00143                     << abort(FatalError);
00144             }
00145 
00146             return hitPoint_;
00147         }
00148 
00149         //- Return point with no checking
00150         const Point& rawPoint() const
00151         {
00152             return hitPoint_;
00153         }
00154 
00155         //- Is this an eligible miss
00156         bool eligibleMiss() const
00157         {
00158             return eligibleMiss_;
00159         }
00160 
00161         void setHit()
00162         {
00163             hit_ = true;
00164             eligibleMiss_ = false;
00165         }
00166 
00167         void setMiss(const bool eligible)
00168         {
00169             hit_ = false;
00170             eligibleMiss_ = eligible;
00171         }
00172 
00173         void setPoint(const Point& p)
00174         {
00175             hitPoint_ = p;
00176         }
00177 
00178         void setDistance(const scalar d)
00179         {
00180             distance_ = d;
00181         }
00182 
00183 
00184     // Ostream operator
00185 
00186         friend Ostream& operator<< <Point>
00187         (
00188             Ostream& os,
00189             const PointHit<Point>& b
00190         );
00191 };
00192 
00193 
00194 template<class Point>
00195 inline Ostream& operator<<(Ostream& os, const PointHit<Point>& b)
00196 {
00197     os  << b.hit() << token::SPACE
00198         << b.rawPoint() << token::SPACE
00199         << b.distance() << token::SPACE
00200         << b.eligibleMiss();
00201 
00202     return os;
00203 }
00204 
00205 
00206 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00207 
00208 } // End namespace Foam
00209 
00210 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00211 
00212 #endif
00213 
00214 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines