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

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