OpenFOAM logo
Open Source CFD Toolkit

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-2005 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     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 "point.H"
00040 #include "token.H"
00041 
00042 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00043 
00044 namespace Foam
00045 {
00046 
00047 /*---------------------------------------------------------------------------*\
00048                            Class pointHit Declaration
00049 \*---------------------------------------------------------------------------*/
00050 
00051 class pointHit
00052 {
00053     // Private data
00054 
00055         //- Hit success
00056         bool hit_;
00057 
00058         //- Point of hit; for miss holds best estimate outside the object
00059         point hitPoint_;
00060 
00061         //- Distance to hit point
00062         scalar distance_;
00063 
00064         //- Eligible miss
00065         bool eligibleMiss_;
00066 
00067 
00068 public:
00069 
00070     // Constructors
00071 
00072         //- Construct from components
00073         pointHit
00074         (
00075             const bool hit,
00076             const point& p,
00077             const scalar dist,
00078             const bool eligibleMiss
00079         )
00080         :
00081             hit_(hit),
00082             hitPoint_(p),
00083             distance_(dist),
00084             eligibleMiss_(eligibleMiss)
00085         {}
00086 
00087         //- Construct from point. Hit and distance set later
00088         pointHit(const point& p)
00089         :
00090             hit_(false),
00091             hitPoint_(p),
00092             distance_(GREAT),
00093             eligibleMiss_(false)
00094         {}
00095 
00096 
00097     // Member Functions
00098 
00099         //- Is there a hit
00100         bool hit() const
00101         {
00102             return hit_;
00103         }
00104 
00105         //- Return hit point
00106         const point& hitPoint() const
00107         {
00108             if (!hit_)
00109             {
00110                 FatalErrorIn("const point& pointHit::hitPoint() const")
00111                     << "requested a hit point for a miss"
00112                     << abort(FatalError);
00113             }
00114 
00115             return hitPoint_;
00116         }
00117 
00118         //- Return distance to hit
00119         scalar distance() const
00120         {
00121             return distance_;
00122         }
00123 
00124         //- Return miss point
00125         const point& missPoint() const
00126         {
00127             if (hit_)
00128             {
00129                 FatalErrorIn("const point& pointHit::missPoint() const")
00130                     << "requested a miss point for a hit"
00131                     << abort(FatalError);
00132             }
00133 
00134             return hitPoint_;
00135         }
00136 
00137         //- Return point with no checking
00138         const point& rawPoint() const
00139         {
00140             return hitPoint_;
00141         }
00142 
00143         //- Is this an eligible miss
00144         bool eligibleMiss() const
00145         {
00146             return eligibleMiss_;
00147         }
00148 
00149         void setHit()
00150         {
00151             hit_ = true;
00152             eligibleMiss_ = false;
00153         }
00154 
00155         void setMiss(const bool eligible)
00156         {
00157             hit_ = false;
00158             eligibleMiss_ = eligible;
00159         }
00160 
00161         void setPoint(const point& p)
00162         {
00163             hitPoint_ = p;
00164         }
00165 
00166         void setDistance(const scalar d)
00167         {
00168             distance_ = d;
00169         }
00170 
00171 
00172     // Ostream operator
00173 
00174         friend Ostream& operator<<(Ostream& os, const pointHit& b)
00175         {
00176             os  << b.hit() << token::SPACE
00177                 << b.rawPoint() << token::SPACE
00178                 << b.distance() << token::SPACE
00179                 << b.eligibleMiss();
00180 
00181             return os;
00182         }
00183 };
00184 
00185 
00186 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00187 
00188 } // End namespace Foam
00189 
00190 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00191 
00192 #endif
00193 
00194 // ************************************************************************* //
For further information go to www.openfoam.org