Home
Downloads
Documentation
Installation
User Guide
man-pages
API Documentation
README
Release Notes
Changes
License
Support
SourceForge Project
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Pages
src
meshTools
octree
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 | Copyright (C) 1991-2010 OpenCFD Ltd.
6
\\/ M anipulation |
7
-------------------------------------------------------------------------------
8
License
9
This file is part of OpenFOAM.
10
11
OpenFOAM is free software: you can redistribute it and/or modify it
12
under the terms of the GNU General Public License as published by
13
the Free Software Foundation, either version 3 of the License, or
14
(at your option) any later version.
15
16
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19
for more details.
20
21
You should have received a copy of the GNU General Public License
22
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23
24
Class
25
Foam::PointIndexHit
26
27
Description
28
This class describes the interaction of (usually) a face and a point.
29
It carries the info of a successful hit and (if successful),
30
returns the interaction point.
31
32
like pointHit but carries face (or cell, edge etc.) index
33
34
SourceFiles
35
36
\*---------------------------------------------------------------------------*/
37
38
#ifndef PointIndexHit_H
39
#define PointIndexHit_H
40
41
#include <
OpenFOAM/bool.H
>
42
#include <
OpenFOAM/point.H
>
43
44
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
45
46
namespace
Foam
47
{
48
49
/*---------------------------------------------------------------------------*\
50
Class PointIndexHit Declaration
51
\*---------------------------------------------------------------------------*/
52
53
template
<
class
Po
int
>
54
class
PointIndexHit
55
{
56
// Private data
57
58
//- Hit success
59
bool
hit_;
60
61
//- Point of hit; invalid for misses
62
Point hitPoint_;
63
64
//- label of face hit
65
label index_;
66
67
68
public
:
69
70
// Constructors
71
72
//- Construct from components
73
PointIndexHit
(
const
bool
success,
const
Point&
p
,
const
label
index
)
74
:
75
hit_(success),
76
hitPoint_(p),
77
index_(index)
78
{}
79
80
//- Construct from point. Hit and distance set later
81
PointIndexHit
(
const
Point&
p
)
82
:
83
hit_(false),
84
hitPoint_(p),
85
index_(-1)
86
{}
87
88
//- Construct null
89
PointIndexHit
()
90
:
91
hit_(false),
92
hitPoint_(
vector
::
zero
),
93
index_(-1)
94
{}
95
96
//- Construct from Istream
97
PointIndexHit
(
Istream
& is)
98
{
99
is >> *
this
;
100
}
101
102
103
// Member Functions
104
105
//- Is there a hit
106
bool
hit
()
const
107
{
108
return
hit_;
109
}
110
111
//- Return index
112
label
index
()
const
113
{
114
return
index_;
115
}
116
117
//- Return hit point
118
const
Point&
hitPoint
()
const
119
{
120
if
(!hit_)
121
{
122
FatalErrorIn
(
"PointIndexHit::hitPoint() const"
)
123
<<
"requested a hit point for a miss"
124
<<
abort
(
FatalError
);
125
}
126
127
return
hitPoint_;
128
}
129
130
//- Return miss point
131
const
Point&
missPoint
()
const
132
{
133
if
(hit_)
134
{
135
FatalErrorIn
(
"PointIndexHit::missPoint() const"
)
136
<<
"requested a miss point for a hit"
137
<<
abort
(
FatalError
);
138
}
139
140
return
hitPoint_;
141
}
142
143
//- Return point with no checking
144
const
Point&
rawPoint
()
const
145
{
146
return
hitPoint_;
147
}
148
149
Point&
rawPoint
()
150
{
151
return
hitPoint_;
152
}
153
154
void
setHit
()
155
{
156
hit_ =
true
;
157
}
158
159
void
setMiss
()
160
{
161
hit_ =
false
;
162
}
163
164
void
setPoint
(
const
Point&
p
)
165
{
166
hitPoint_ =
p
;
167
}
168
169
void
setIndex
(
const
label
index
)
170
{
171
index_ =
index
;
172
}
173
174
bool
operator==
(
const
PointIndexHit
& rhs)
const
175
{
176
return
177
hit_ == rhs.
hit
()
178
&& hitPoint_ == rhs.
rawPoint
()
179
&& index_ == rhs.
index
();
180
}
181
182
bool
operator!=
(
const
PointIndexHit
& rhs)
const
183
{
184
return
!
operator==
(rhs);
185
}
186
187
void
write
(
Ostream
& os)
188
{
189
if
(
hit
())
190
{
191
os <<
"hit:"
<<
hitPoint
() <<
" index:"
<<
index
();
192
}
193
else
194
{
195
os <<
"miss:"
<<
missPoint
() <<
" index:"
<<
index
();
196
}
197
}
198
199
friend
Ostream
&
operator<<
(
Ostream
& os,
const
PointIndexHit
& pHit)
200
{
201
if
(os.
format
() ==
IOstream::ASCII
)
202
{
203
os << pHit.hit_ <<
token::SPACE
<< pHit.hitPoint_
204
<<
token::SPACE
<< pHit.index_;
205
}
206
else
207
{
208
os.
write
209
(
210
reinterpret_cast<const char*>(&pHit),
211
sizeof
(
PointIndexHit
)
212
);
213
}
214
215
// Check state of Ostream
216
os.
check
(
"Ostream& operator<<(Ostream&, const PointIndexHit&)"
);
217
218
return
os;
219
}
220
221
friend
Istream
&
operator>>
(
Istream
& is,
PointIndexHit
& pHit)
222
{
223
if
(is.
format
() ==
IOstream::ASCII
)
224
{
225
return
is >> pHit.hit_ >> pHit.hitPoint_ >> pHit.index_;
226
}
227
else
228
{
229
is.
read
230
(
231
reinterpret_cast<char*>(&pHit),
232
sizeof
(
PointIndexHit
)
233
);
234
}
235
236
// Check state of Istream
237
is.
check
(
"Istream& operator>>(Istream&, PointIndexHit&)"
);
238
239
return
is;
240
}
241
242
};
243
244
245
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
246
247
}
// End namespace Foam
248
249
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
250
251
#endif
252
253
// ************************ vim: set sw=4 sts=4 et: ************************ //