pointHit.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2016 OpenFOAM Foundation
9  Copyright (C) 2020-2022 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 Class
28  Foam::PointHit
29 
30 Description
31  Describes the interaction of a object and a (templated) point.
32  It carries the info of a successful hit and (if successful)
33  the interaction point.
34 
35 \*---------------------------------------------------------------------------*/
36 
37 #ifndef Foam_pointHit_H
38 #define Foam_pointHit_H
39 
40 #include "bool.H"
41 #include "point.H"
42 #include "token.H"
43 
44 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
45 
46 namespace Foam
47 {
48 
49 // Forward Declarations
50 template<class PointType> class PointHit;
51 
52 
53 // Standard Types
54 
55 //- A PointHit with a 3D point
57 
58 
59 /*---------------------------------------------------------------------------*\
60  Class PointHit Declaration
61 \*---------------------------------------------------------------------------*/
62 
63 template<class PointType>
64 class PointHit
65 {
66  // Private Data
67 
68  //- Point of hit; for miss holds best estimate outside the object
69  PointType point_;
70 
71  //- Distance to hit point
72  scalar distance_;
73 
74  //- Hit success
75  bool hit_;
76 
77  //- Eligible miss
78  bool eligibleMiss_;
79 
80 
81 public:
82 
83  // Public Typedefs
84 
85  //- The point type
86  typedef PointType point_type;
87 
88 
89  // Constructors
90 
91  //- Default construct. A zero point with a large distance,
92  //- no hit, no eligible misses
93  PointHit()
94  :
95  point_(Zero),
96  distance_(GREAT),
97  hit_(false),
98  eligibleMiss_(false)
99  {}
101  //- Construct from point with a large distance,
102  //- no hit, no eligible misses
103  explicit PointHit(const point_type& p)
104  :
105  point_(p),
106  distance_(GREAT),
107  hit_(false),
108  eligibleMiss_(false)
109  {}
110 
111  //- Construct from components
113  (
114  bool hit,
115  const point_type& p,
116  scalar dist,
117  bool eligibleMiss = false
118  )
119  :
120  point_(p),
121  distance_(dist),
122  hit_(hit),
123  eligibleMiss_(eligibleMiss)
124  {}
125 
126 
127  // Member Functions
128 
129  // Access
130 
131  //- Is there a hit
132  bool hit() const noexcept
133  {
134  return hit_;
135  }
136 
137  //- Is this an eligible miss
138  bool eligibleMiss() const noexcept
139  {
140  return eligibleMiss_;
141  }
142 
143  //- Return the point, no checks
144  const point_type& point() const noexcept
145  {
146  return point_;
147  }
148 
149  //- Return distance to hit
150  scalar distance() const noexcept
151  {
152  return distance_;
153  }
154 
155  //- Return the hit point. Fatal if not hit.
156  const point_type& hitPoint() const
157  {
158  if (!hit_)
159  {
161  << "Requested a hit point, but it was not hit"
162  << abort(FatalError);
163  }
164 
165  return point_;
166  }
167 
168  //- Return the miss point. Fatal if hit.
169  const point_type& missPoint() const
170  {
171  if (hit_)
172  {
174  << "Requested a miss point, but it was hit"
175  << abort(FatalError);
176  }
178  return point_;
179  }
180 
181  //- The point, no checks
182  // \deprecated(2020-10) use point()
183  const point_type& rawPoint() const noexcept { return point_; }
184 
185 
186  // Edit
187 
188  //- Set the hit status \em on
189  void setHit() noexcept
190  {
191  hit_ = true;
192  eligibleMiss_ = false;
193  }
194 
195  //- Set the hit status \em off and set the eligible miss status
196  void setMiss(const bool eligible) noexcept
197  {
198  hit_ = false;
199  eligibleMiss_ = eligible;
200  }
201 
202  //- Set the point
203  void setPoint(const point_type& p)
204  {
205  point_ = p;
206  }
207 
208  //- Set the distance
209  void setDistance(const scalar d) noexcept
210  {
211  distance_ = d;
212  }
213 
214  //- Set the point as \em hit.
215  void hitPoint(const point_type& p)
216  {
217  point_ = p;
218  hit_ = true;
219  eligibleMiss_ = false;
220  }
221 
222 
223  // Member Operators
224 
225  //- Distance comparision operator, for sorting
226  template<class AnyPointType>
227  bool operator<(const PointHit<AnyPointType>& rhs) const noexcept
228  {
229  return distance_ < rhs.distance_;
230  }
231 };
232 
233 
234 // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
236 // Ostream Operator
237 
238 template<class PointType>
239 inline Ostream& operator<<(Ostream& os, const PointHit<PointType>& pHit)
240 {
241  os << pHit.hit() << token::SPACE
242  << pHit.point() << token::SPACE
243  << pHit.distance() << token::SPACE
244  << pHit.eligibleMiss();
245 
246  return os;
247 }
248 
249 
250 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
252 } // End namespace Foam
253 
254 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
255 
256 #endif
257 
258 // ************************************************************************* //
const point_type & rawPoint() const noexcept
The point, no checks.
Definition: pointHit.H:209
void setPoint(const point_type &p)
Set the point.
Definition: pointHit.H:235
error FatalError
Error stream (stdout output on all processes), with additional &#39;FOAM FATAL ERROR&#39; header text and sta...
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:598
PointHit()
Default construct. A zero point with a large distance, no hit, no eligible misses.
Definition: pointHit.H:100
PointType point_type
The point type.
Definition: pointHit.H:91
bool hit() const noexcept
Is there a hit.
Definition: pointHit.H:145
void setHit() noexcept
Set the hit status on.
Definition: pointHit.H:217
Space [isspace].
Definition: token.H:131
void setDistance(const scalar d) noexcept
Set the distance.
Definition: pointHit.H:243
Describes the interaction of a object and a (templated) point. It carries the info of a successful hi...
Definition: pointHit.H:43
errorManip< error > abort(error &err)
Definition: errorManip.H:139
void setMiss(const bool eligible) noexcept
Set the hit status off and set the eligible miss status.
Definition: pointHit.H:226
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:56
const direction noexcept
Definition: Scalar.H:258
OBJstream os(runTime.globalPath()/outputName)
const point_type & hitPoint() const
Return the hit point. Fatal if not hit.
Definition: pointHit.H:177
scalar distance() const noexcept
Return distance to hit.
Definition: pointHit.H:169
const point_type & point() const noexcept
Return the point, no checks.
Definition: pointHit.H:161
bool eligibleMiss() const noexcept
Is this an eligible miss.
Definition: pointHit.H:153
volScalarField & p
const point_type & missPoint() const
Return the miss point. Fatal if hit.
Definition: pointHit.H:192
PointHit(const point_type &p)
Construct from point with a large distance, no hit, no eligible misses.
Definition: pointHit.H:112
System bool.
PointHit< point > pointHit
A PointHit with a 3D point.
Definition: pointHit.H:43
Namespace for OpenFOAM.
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:127