PointIndexHit.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 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
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
27Class
28 Foam::PointIndexHit
29
30Description
31 This class describes the interaction of (usually) a face and a point.
32 It carries the info of a successful hit and (if successful),
33 returns the interaction point.
34
35 like pointHit but carries face (or cell, edge etc.) index
36
37SourceFiles
38
39\*---------------------------------------------------------------------------*/
40
41#ifndef PointIndexHit_H
42#define PointIndexHit_H
43
44#include "bool.H"
45#include "point.H"
46
47// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
48
49namespace Foam
50{
51
52// Forward Declarations
53template<class PointType> class PointIndexHit;
54
55template<class PointType>
57
58template<class PointType>
60
61/*---------------------------------------------------------------------------*\
62 Class PointIndexHit Declaration
63\*---------------------------------------------------------------------------*/
64
65template<class PointType>
66class PointIndexHit
67{
68 // Private Data
69
70 //- Hit success
71 bool hit_;
72
73 //- Point of hit; invalid for misses
74 PointType point_;
75
76 //- Label of face hit
77 label index_;
78
79
80public:
81
82 // Public Typedefs
83
84 //- The point type
85 typedef PointType point_type;
86
87
88 // Constructors
89
90 //- Default construct. A zero point, with no hit and index = -1
92 :
93 hit_(false),
94 point_(Zero),
95 index_(-1)
96 {}
97
98 //- Construct from a point, with no hit and index = -1
99 explicit PointIndexHit(const point_type& p)
100 :
101 hit_(false),
102 point_(p),
103 index_(-1)
104 {}
105
106 //- Construct from components
108 (
109 const bool success,
110 const point_type& p,
111 const label index
112 )
113 :
114 hit_(success),
115 point_(p),
116 index_(index)
117 {}
118
119 //- Construct from Istream
120 explicit PointIndexHit(Istream& is)
121 {
122 is >> *this;
123 }
124
125
126 // Member Functions
127
128 // Access
129
130 //- Is there a hit?
131 bool hit() const noexcept
132 {
133 return hit_;
134 }
135
136 //- Return the hit index
137 label index() const noexcept
138 {
139 return index_;
140 }
141
142 //- Return point, no checks
143 const point_type& point() const noexcept
144 {
145 return point_;
146 }
147
148 //- Access the point, no checks
150 {
151 return point_;
152 }
153
154 //- Return hit point. Fatal if not hit.
155 const point_type& hitPoint() const
156 {
157 if (!hit_)
158 {
160 << "Requested a hit point, but it was not hit"
161 << abort(FatalError);
162 }
163 return point_;
164 }
165
166 //- Return miss point. Fatal if hit.
167 const point_type& missPoint() const
168 {
169 if (hit_)
170 {
172 << "Requested a miss point, but it was hit"
173 << abort(FatalError);
174 }
175 return point_;
176 }
177
178 //- The point, no checks. Same as point()
179 const point_type& rawPoint() const noexcept
180 {
181 return point_;
182 }
183
184 //- The point, no checks. Same as point()
186 {
187 return point_;
188 }
189
190
191 // Edit
192
193 //- Set the hit status \em on
194 void setHit() noexcept
195 {
196 hit_ = true;
197 }
198
199 //- Set the hit status \em off
200 void setMiss() noexcept
201 {
202 hit_ = false;
203 }
204
205 //- Set the point
206 void setPoint(const point_type& p)
207 {
208 point_ = p;
209 }
210
211 //- Set the index
212 void setIndex(const label index) noexcept
213 {
214 index_ = index;
215 }
216
217 //- Set the point as \em hit and the hit-index
218 void hitPoint(const point_type& p, const label index)
219 {
220 point_ = p;
221 hit_ = true;
222 index_ = index;
223 }
224
225
226 // Write
228 void write(Ostream& os)
229 {
230 os << (hit_ ? "hit:" : "miss:")
231 << point_ << " index:" << index_;
232 }
233
234
235 // Member Operators
236
237 //- Test for equality of all components
238 bool operator==(const PointIndexHit& rhs) const
239 {
240 return
241 (
242 hit_ == rhs.hit_
243 && index_ == rhs.index_
244 && point_ == rhs.point_
245 );
246 }
247
248 //- Test for inequality of components
249 bool operator!=(const PointIndexHit& rhs) const
250 {
251 return !(*this == rhs);
252 }
253
254
255 // IO Operators
257 friend Ostream& operator<<(Ostream& os, const PointIndexHit& pHit)
258 {
259 if (os.format() == IOstream::ASCII)
260 {
261 os << pHit.hit_ << token::SPACE
262 << pHit.point_ << token::SPACE
263 << pHit.index_;
264 }
265 else
266 {
267 os.write
268 (
269 reinterpret_cast<const char*>(&pHit),
270 sizeof(PointIndexHit)
271 );
272 }
273
275 return os;
276 }
277
279 friend Istream& operator>>(Istream& is, PointIndexHit& pHit)
280 {
281 if (is.format() == IOstream::ASCII)
282 {
283 is >> pHit.hit_ >> pHit.point_ >> pHit.index_;
284 }
285 else
286 {
287 // TODO (2019-08-06):
288 // cannot properly handle mixed-precision reading
289 // owing to bool and Point type.
290
291 is.read
292 (
293 reinterpret_cast<char*>(&pHit),
294 sizeof(PointIndexHit)
295 );
296 }
297
299 return is;
300 }
301};
302
303
304// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
305
306} // End namespace Foam
307
308// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
309
310#endif
311
312// ************************************************************************* //
bool success
System bool.
streamFormat format() const noexcept
Get the current stream format.
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:58
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:64
virtual Istream & read(token &)=0
Return next token from stream.
virtual Ostream & write(const char c)
Write character.
Definition: OBJstream.C:78
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:62
This class describes the interaction of (usually) a face and a point. It carries the info of a succes...
Definition: PointIndexHit.H:66
void setHit() noexcept
Set the hit status on.
PointType point_type
The point type.
Definition: PointIndexHit.H:84
const point_type & rawPoint() const noexcept
The point, no checks. Same as point()
PointIndexHit()
Default construct. A zero point, with no hit and index = -1.
Definition: PointIndexHit.H:90
void setIndex(const label index) noexcept
Set the index.
PointIndexHit(const point_type &p)
Construct from a point, with no hit and index = -1.
Definition: PointIndexHit.H:98
point_type & point() noexcept
Access the point, no checks.
void setPoint(const point_type &p)
Set the point.
label index() const noexcept
Return the hit index.
void setMiss() noexcept
Set the hit status off.
const point_type & missPoint() const
Return miss point. Fatal if hit.
bool hit() const noexcept
Is there a hit?
bool operator==(const PointIndexHit &rhs) const
Test for equality of all components.
friend Istream & operator>>(Istream &is, PointIndexHit &pHit)
PointIndexHit(Istream &is)
Construct from Istream.
point_type & rawPoint() noexcept
The point, no checks. Same as point()
void write(Ostream &os)
void hitPoint(const point_type &p, const label index)
Set the point as hit and the hit-index.
const point_type & point() const noexcept
Return point, no checks.
friend Ostream & operator<<(Ostream &os, const PointIndexHit &pHit)
const point_type & hitPoint() const
Return hit point. Fatal if not hit.
PointIndexHit(const bool success, const point_type &p, const label index)
Construct from components.
bool operator!=(const PointIndexHit &rhs) const
Test for inequality of components.
@ SPACE
Space [isspace].
Definition: token.H:125
volScalarField & p
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
OBJstream os(runTime.globalPath()/outputName)
#define FUNCTION_NAME
Namespace for OpenFOAM.
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:83
Istream & operator>>(Istream &, directionInfo &)
errorManip< error > abort(error &err)
Definition: errorManip.H:144
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
const direction noexcept
Definition: Scalar.H:223
error FatalError
runTime write()