Loading...
Searching...
No Matches
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-2023 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 an object (often a face)
32 and a point.
33 It carries the info of a successful hit and (if successful),
34 returns the interaction point.
35
36 Like pointHit but carries object (eg, face, cell, edge etc.) index
37
38\*---------------------------------------------------------------------------*/
39
40#ifndef Foam_pointIndexHit_H
41#define Foam_pointIndexHit_H
42
43#include "pointHit.H"
44
45// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
46
47namespace Foam
48{
49
50// Forward Declarations
51template<class PointType> class PointIndexHit;
52
53template<class PointType>
55
56template<class PointType>
59
60// Standard Types
61
62//- A PointIndexHit with a 3D point
64
65
66/*---------------------------------------------------------------------------*\
67 Class PointIndexHit Declaration
68\*---------------------------------------------------------------------------*/
69
70template<class PointType>
71class PointIndexHit
72{
73 // Private Data
74
75 //- Hit success
76 bool hit_;
77
78 //- Point of hit; invalid for misses
79 PointType point_;
80
81 //- Label of object hit
82 label index_;
83
84
85public:
86
87 // Public Typedefs
88
89 //- The point type
90 typedef PointType point_type;
91
92
93 // Constructors
94
95 //- Default construct. A zero point, with no hit and index = -1
97 :
98 hit_(false),
99 point_(Zero),
100 index_(-1)
101 {}
102
103 //- Construct from a point, with no hit and index = -1
104 explicit PointIndexHit(const point_type& p)
105 :
106 hit_(false),
107 point_(p),
108 index_(-1)
109 {}
110
111 //- Construct from hitPoint with index = -1 or specified
112 explicit PointIndexHit(const PointHit<point_type>& p, label index = -1)
113 :
114 hit_(p.hit()),
115 point_(p.point()),
116 index_(index)
117 {}
118
119 //- Copy construct with different index
122 hit_(p.hit()),
123 point_(p.point()),
124 index_(index)
125 {}
126
127 //- Construct from components
128 PointIndexHit(bool success, const point_type& p, label index)
129 :
130 hit_(success),
131 point_(p),
132 index_(index)
133 {}
134
135 //- Construct from Istream
136 explicit PointIndexHit(Istream& is)
137 {
138 is >> *this;
139 }
140
142 // Member Functions
143
144 // Access
145
146 //- Is there a hit?
147 bool hit() const noexcept
148 {
149 return hit_;
150 }
152 //- Return the hit index
153 label index() const noexcept
154 {
155 return index_;
156 }
157
158 //- Return point, no checks
159 const point_type& point() const noexcept
160 {
161 return point_;
162 }
163
164 //- Access the point, no checks
166 {
167 return point_;
168 }
169
170 //- Return hit point. Fatal if not hit.
171 const point_type& hitPoint() const
173 if (!hit_)
174 {
176 << "Requested a hit point, but it was not hit"
177 << abort(FatalError);
178 }
179 return point_;
181
182 //- Return miss point. Fatal if hit.
183 const point_type& missPoint() const
184 {
185 if (hit_)
186 {
188 << "Requested a miss point, but it was hit"
189 << abort(FatalError);
190 }
191 return point_;
192 }
193
194 //- The point, no checks. Same as point()
195 // \deprecated(2020-10) use point()
196 const point_type& rawPoint() const noexcept { return point_; }
197
198 //- The point, no checks. Same as point()
199 // \deprecated(2020-10) use point()
200 point_type& rawPoint() noexcept { return point_; }
201
202
203 // Edit
204
205 //- Set the hit status \em on
206 void setHit() noexcept
207 {
208 hit_ = true;
209 }
211 //- Set the hit status \em off
212 void setMiss() noexcept
213 {
214 hit_ = false;
215 }
216
217 //- Set the point
218 void setPoint(const point_type& p)
219 {
220 point_ = p;
221 }
222
223 //- Set the index
224 void setIndex(const label index) noexcept
225 {
226 index_ = index;
227 }
228
229 //- Set the point as \em hit without changing the hit-index
230 void hitPoint(const point_type& p)
231 {
232 point_ = p;
233 hit_ = true;
234 }
235
236 //- Set the point as \em hit and set the hit-index
237 void hitPoint(const point_type& p, const label index)
238 {
239 point_ = p;
240 hit_ = true;
241 index_ = index;
242 }
243
244
245 // Write
246
247 //- Report hit/miss status, point and index
248 void write(Ostream& os)
250 os << (hit_ ? "hit:" : "miss:")
251 << point_ << " index:" << index_;
252 }
253
254
255 // Member Operators
256
257 //- Test for equality of all components
258 bool operator==(const PointIndexHit& rhs) const
259 {
260 return
261 (
262 hit_ == rhs.hit_
263 && index_ == rhs.index_
264 && point_ == rhs.point_
265 );
266 }
267
268 //- Test for inequality of components
269 bool operator!=(const PointIndexHit& rhs) const
270 {
271 return !(*this == rhs);
272 }
274
275 // IO Operators
276
277 friend Ostream& operator<<(Ostream& os, const PointIndexHit& pHit)
278 {
279 if (os.format() == IOstreamOption::BINARY)
280 {
281 os.write
283 reinterpret_cast<const char*>(&pHit),
284 sizeof(PointIndexHit)
285 );
286 }
287 else
288 {
289 os << pHit.hit_ << token::SPACE
290 << pHit.point_ << token::SPACE
291 << pHit.index_;
292 }
293
294 os.check(FUNCTION_NAME);
295 return os;
296 }
297
298
299 friend Istream& operator>>(Istream& is, PointIndexHit& pHit)
300 {
301 if (is.format() == IOstreamOption::BINARY)
302 {
303 // TODO (2019-08-06):
304 // cannot properly handle mixed-precision reading
305 // owing to bool and Point type.
306
308 (
309 reinterpret_cast<char*>(&pHit),
310 sizeof(PointIndexHit)
311 );
312 }
313 else
314 {
315 is >> pHit.hit_ >> pHit.point_ >> pHit.index_;
316 }
317
319 return is;
321};
322
323
324// * * * * * * * * * * * * * * * * * Traits * * * * * * * * * * * * * * * * //
325
326//- Contiguous data for pointIndexHit
327template<> struct is_contiguous<pointIndexHit> : is_contiguous<point> {};
329
330// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
331
332} // End namespace Foam
333
334// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
335
336#endif
337
338// ************************************************************************* //
bool success
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:45
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition Istream.H:60
virtual Istream & read(token &)=0
Return next token from stream.
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition Ostream.H:59
Describes the interaction of a object and a (templated) point. It carries the info of a successful hi...
Definition pointHit.H:60
This class describes the interaction of an object (often a face) and a point. It carries the info of ...
void setHit() noexcept
Set the hit status on.
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.
PointIndexHit(bool success, const point_type &p, label index)
Construct from components.
void setIndex(const label index) noexcept
Set the index.
PointIndexHit(const point_type &p)
Construct from a point, with no hit and index = -1.
void hitPoint(const point_type &p)
Set the point as hit without changing the hit-index.
point_type & point() noexcept
Access the point, no checks.
void setPoint(const point_type &p)
Set the point.
PointIndexHit(const PointHit< point_type > &p, label index=-1)
Construct from hitPoint with index = -1 or specified.
label index() const noexcept
void setMiss() noexcept
Set the hit status off.
const point_type & missPoint() const
Return miss point. Fatal if hit.
bool hit() const noexcept
bool operator==(const PointIndexHit &rhs) const
Test for equality of all components.
friend Istream & operator>>(Istream &is, PointIndexHit &pHit)
PointIndexHit(const PointIndexHit< point_type > &p, label index)
Copy construct with different index.
PointIndexHit(Istream &is)
Construct from Istream.
point_type & rawPoint() noexcept
The point, no checks. Same as point().
void write(Ostream &os)
Report hit/miss status, point and index.
void hitPoint(const point_type &p, const label index)
Set the point as hit and set the hit-index.
const point_type & point() const noexcept
friend Ostream & operator<<(Ostream &os, const PointIndexHit &pHit)
const point_type & hitPoint() const
Return hit point. Fatal if not hit.
bool operator!=(const PointIndexHit &rhs) const
Test for inequality of components.
@ SPACE
Space [isspace].
Definition token.H:144
volScalarField & p
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition error.H:600
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).
Istream & operator>>(Istream &, directionInfo &)
errorManip< error > abort(error &err)
Definition errorManip.H:139
void rhs(fvMatrix< typename Expr::value_type > &m, const Expr &expression)
static constexpr const zero Zero
Global zero (0).
Definition zero.H:127
const direction noexcept
Definition scalarImpl.H:265
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
PointIndexHit< point > pointIndexHit
A PointIndexHit with a 3D point.
runTime write()
A template class to specify that a data type can be considered as being contiguous in memory.
Definition contiguous.H:70