OpenFOAM logo
Open Source CFD Toolkit

pointIndexHit.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     pointIndexHit
00027 
00028 Description
00029     This class describes the interaction of (usually) a face and a point.
00030     It carries the info of a successful hit and (if successful), 
00031     returns the interaction point.
00032 
00033     like pointHit but carries face (or cell, edge etc.) index
00034 
00035 SourceFiles
00036 
00037 \*---------------------------------------------------------------------------*/
00038 
00039 #ifndef pointIndexHit_H
00040 #define pointIndexHit_H
00041 
00042 #include "bool.H"
00043 #include "point.H"
00044 
00045 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00046 
00047 namespace Foam
00048 {
00049 
00050 /*---------------------------------------------------------------------------*\
00051                            Class pointIndexHit Declaration
00052 \*---------------------------------------------------------------------------*/
00053 
00054 class pointIndexHit
00055 {
00056     // Private data
00057 
00058         //- Hit success
00059         bool hit_;
00060 
00061         //- Point of hit; invalid for misses
00062         point hitPoint_;
00063 
00064         //- label of face hit
00065         label index_;
00066 
00067 
00068 public:
00069 
00070     // Constructors
00071 
00072         //- Construct from components
00073         pointIndexHit(const bool success, const point& p, const label index)
00074         :
00075             hit_(success),
00076             hitPoint_(p),
00077             index_(index)
00078         {}
00079 
00080         //- Construct from point. Hit and distance set later
00081         pointIndexHit(const point& p)
00082         :
00083             hit_(false),
00084             hitPoint_(p),
00085             index_(-1)
00086         {}
00087 
00088         //- Construct null
00089         pointIndexHit()
00090         :
00091             hit_(false),
00092             hitPoint_(vector::zero),
00093             index_(-1)
00094         {}
00095 
00096 
00097     // Member Functions
00098 
00099         //- Is there a hit
00100         bool hit() const
00101         {
00102             return hit_;
00103         }
00104 
00105         //- Return index
00106         label index() const
00107         {
00108             return index_;
00109         }
00110 
00111         //- Return hit point
00112         const point& hitPoint() const
00113         {
00114             if (!hit_)
00115             {
00116                 FatalErrorIn("point pointIndexHit::hitPoint() const")
00117                     << "requested a hit point for a miss"
00118                     << abort(FatalError);
00119             }
00120 
00121             return hitPoint_;
00122         }
00123 
00124         //- Return miss point
00125         const point& missPoint() const
00126         {
00127             if (hit_)
00128             {
00129                 FatalErrorIn("pointIndexHit::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         void setHit()
00144         {
00145             hit_ = true;
00146         }
00147 
00148         void setMiss()
00149         {
00150             hit_ = false;
00151         }
00152 
00153         void setPoint(const point& p)
00154         {
00155             hitPoint_ = p;
00156         }
00157 
00158         void setIndex(const label index)
00159         {
00160             index_ = index;
00161         }
00162 
00163         void write(Ostream& os)
00164         {
00165             if (hit())
00166             {
00167                 os << "hit:" << hitPoint() << " index:" << index();
00168             }
00169             else
00170             {
00171                 os << "miss:" << missPoint() << " index:" << index();
00172             }
00173         }
00174 
00175         friend Ostream& operator<< (Ostream& os, const pointIndexHit& pHit)
00176         {
00177             return os << pHit.hit_ << token::SPACE << pHit.hitPoint_
00178                 << token::SPACE << pHit.index_;
00179         }
00180 };
00181 
00182 
00183 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00184 
00185 } // End namespace Foam
00186 
00187 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00188 
00189 #endif
00190 
00191 // ************************************************************************* //
For further information go to www.openfoam.org