Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Development
openfoam
Commits
f7ce5fbf
Commit
f7ce5fbf
authored
Nov 29, 2010
by
Mark Olesen
Browse files
ENH: Construct bounding box as subset of the pointField.
STYLE: move inline functions into boundBoxI.H STYLE: reduce duplicate methods in treeBoundBox
parent
0d662c74
Changes
9
Hide whitespace changes
Inline
Side-by-side
src/OpenFOAM/meshes/boundBox/boundBox.C
View file @
f7ce5fbf
...
...
@@ -47,7 +47,7 @@ const Foam::boundBox Foam::boundBox::invertedBox
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
void
Foam
::
boundBox
::
calculate
(
const
pointField
&
points
,
const
bool
doReduce
)
void
Foam
::
boundBox
::
calculate
(
const
UList
<
point
>
&
points
,
const
bool
doReduce
)
{
if
(
points
.
empty
())
{
...
...
@@ -84,7 +84,7 @@ void Foam::boundBox::calculate(const pointField& points, const bool doReduce)
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam
::
boundBox
::
boundBox
(
const
pointField
&
points
,
const
bool
doReduce
)
Foam
::
boundBox
::
boundBox
(
const
UList
<
point
>
&
points
,
const
bool
doReduce
)
:
min_
(
point
::
zero
),
max_
(
point
::
zero
)
...
...
@@ -103,9 +103,43 @@ Foam::boundBox::boundBox(const tmp<pointField>& points, const bool doReduce)
}
Foam
::
boundBox
::
boundBox
(
Istream
&
is
)
Foam
::
boundBox
::
boundBox
(
const
UList
<
point
>&
points
,
const
labelUList
&
indices
,
const
bool
doReduce
)
:
min_
(
point
::
zero
),
max_
(
point
::
zero
)
{
operator
>>
(
is
,
*
this
);
if
(
points
.
empty
()
||
indices
.
empty
())
{
if
(
doReduce
&&
Pstream
::
parRun
())
{
// Use values that get overwritten by reduce minOp, maxOp below
min_
=
point
(
VGREAT
,
VGREAT
,
VGREAT
);
max_
=
point
(
-
VGREAT
,
-
VGREAT
,
-
VGREAT
);
}
}
else
{
min_
=
points
[
indices
[
0
]];
max_
=
points
[
indices
[
0
]];
for
(
label
i
=
1
;
i
<
indices
.
size
();
++
i
)
{
min_
=
::
Foam
::
min
(
min_
,
points
[
indices
[
i
]]);
max_
=
::
Foam
::
max
(
max_
,
points
[
indices
[
i
]]);
}
}
// Reduce parallel information
if
(
doReduce
)
{
reduce
(
min_
,
minOp
<
point
>
());
reduce
(
max_
,
maxOp
<
point
>
());
}
}
...
...
@@ -172,4 +206,5 @@ Foam::Istream& Foam::operator>>(Istream& is, boundBox& bb)
return
is
;
}
// ************************************************************************* //
src/OpenFOAM/meshes/boundBox/boundBox.H
View file @
f7ce5fbf
...
...
@@ -44,7 +44,8 @@ namespace Foam
class
boundBox
;
template
<
class
T
>
class
tmp
;
Ostream
&
operator
<<
(
Ostream
&
os
,
const
boundBox
&
b
);
Istream
&
operator
>>
(
Istream
&
,
boundBox
&
);
Ostream
&
operator
<<
(
Ostream
&
,
const
boundBox
&
);
/*---------------------------------------------------------------------------*\
...
...
@@ -60,9 +61,9 @@ class boundBox
// Private Member Functions
//- Calculate the bounding box from the given point
Field
.
//- Calculate the bounding box from the given point
s
.
// Does parallel communication (doReduce = true)
void
calculate
(
const
pointField
&
,
const
bool
doReduce
=
true
);
void
calculate
(
const
UList
<
point
>
&
,
const
bool
doReduce
=
true
);
public:
...
...
@@ -81,29 +82,42 @@ public:
// Constructors
//- Construct null, setting points to zero
boundBox
()
:
min_
(
point
::
zero
),
max_
(
point
::
zero
)
{}
inline
boundBox
();
//- Construct from components
boundBox
(
const
point
&
min
,
const
point
&
max
)
:
min_
(
min
),
max_
(
max
)
{}
inline
boundBox
(
const
point
&
min
,
const
point
&
max
);
//- Construct as the bounding box of the given point
Field.
//- Construct as the bounding box of the given point
s
// Does parallel communication (doReduce = true)
boundBox
(
const
pointField
&
,
const
bool
doReduce
=
true
);
boundBox
(
const
UList
<
point
>
&
,
const
bool
doReduce
=
true
);
//- Construct as the bounding box of the given temporary pointField.
// Does parallel communication (doReduce = true)
boundBox
(
const
tmp
<
pointField
>&
,
const
bool
doReduce
=
true
);
//- Construct bounding box as subset of the pointField.
// The indices could be from cell/face etc.
// Does parallel communication (doReduce = true)
boundBox
(
const
UList
<
point
>&
,
const
labelUList
&
indices
,
const
bool
doReduce
=
true
);
//- Construct bounding box as subset of the pointField.
// The indices could be from edge/triFace etc.
// Does parallel communication (doReduce = true)
template
<
unsigned
Size
>
boundBox
(
const
UList
<
point
>&
,
const
FixedList
<
label
,
Size
>&
indices
,
const
bool
doReduce
=
true
);
//- Construct from Istream
boundBox
(
Istream
&
);
inline
boundBox
(
Istream
&
);
// Member functions
...
...
@@ -111,70 +125,37 @@ public:
// Access
//- Minimum describing the bounding box
const
point
&
min
()
const
{
return
min_
;
}
inline
const
point
&
min
()
const
;
//- Maximum describing the bounding box
const
point
&
max
()
const
{
return
max_
;
}
inline
const
point
&
max
()
const
;
//- Minimum describing the bounding box, non-const access
point
&
min
()
{
return
min_
;
}
inline
point
&
min
();
//- Maximum describing the bounding box, non-const access
point
&
max
()
{
return
max_
;
}
inline
point
&
max
();
//- The midpoint of the bounding box
point
midpoint
()
const
{
return
0.5
*
(
max_
+
min_
);
}
inline
point
midpoint
()
const
;
//- The bounding box span (from minimum to maximum)
vector
span
()
const
{
return
(
max_
-
min_
);
}
inline
vector
span
()
const
;
//- The magnitude of the bounding box span
scalar
mag
()
const
{
return
::
Foam
::
mag
(
max_
-
min_
);
}
inline
scalar
mag
()
const
;
//- The volume of the bound box
scalar
volume
()
const
{
return
cmptProduct
(
span
());
}
inline
scalar
volume
()
const
;
//- Smallest length/height/width dimension
scalar
minDim
()
const
{
return
cmptMin
(
span
());
}
inline
scalar
minDim
()
const
;
//- Largest length/height/width dimension
scalar
maxDim
()
const
{
return
cmptMax
(
span
());
}
inline
scalar
maxDim
()
const
;
//- Average length/height/width dimension
scalar
avgDim
()
const
{
return
cmptAv
(
span
());
}
inline
scalar
avgDim
()
const
;
//- Return corner points in an order corresponding to a 'hex' cell
tmp
<
pointField
>
corners
()
const
;
...
...
@@ -182,56 +163,28 @@ public:
// Query
//- Overlaps/touches boundingBox?
bool
overlaps
(
const
boundBox
&
bb
)
const
{
return
(
bb
.
max_
.
x
()
>=
min_
.
x
()
&&
bb
.
min_
.
x
()
<=
max_
.
x
()
&&
bb
.
max_
.
y
()
>=
min_
.
y
()
&&
bb
.
min_
.
y
()
<=
max_
.
y
()
&&
bb
.
max_
.
z
()
>=
min_
.
z
()
&&
bb
.
min_
.
z
()
<=
max_
.
z
()
);
}
inline
bool
overlaps
(
const
boundBox
&
)
const
;
//- Contains point? (inside or on edge)
bool
contains
(
const
point
&
pt
)
const
{
return
(
pt
.
x
()
>=
min_
.
x
()
&&
pt
.
x
()
<=
max_
.
x
()
&&
pt
.
y
()
>=
min_
.
y
()
&&
pt
.
y
()
<=
max_
.
y
()
&&
pt
.
z
()
>=
min_
.
z
()
&&
pt
.
z
()
<=
max_
.
z
()
);
}
inline
bool
contains
(
const
point
&
)
const
;
//- Fully contains other boundingBox?
inline
bool
contains
(
const
boundBox
&
)
const
;
//- Contains point? (inside only)
bool
containsInside
(
const
point
&
pt
)
const
{
return
(
pt
.
x
()
>
min_
.
x
()
&&
pt
.
x
()
<
max_
.
x
()
&&
pt
.
y
()
>
min_
.
y
()
&&
pt
.
y
()
<
max_
.
y
()
&&
pt
.
z
()
>
min_
.
z
()
&&
pt
.
z
()
<
max_
.
z
()
);
}
inline
bool
containsInside
(
const
point
&
)
const
;
// Friend Operators
friend
bool
operator
==
(
const
boundBox
&
a
,
const
boundBox
&
b
)
{
return
(
a
.
min_
==
b
.
min_
)
&&
(
a
.
max_
==
b
.
max_
);
}
friend
bool
operator
!=
(
const
boundBox
&
a
,
const
boundBox
&
b
)
{
return
!
(
a
==
b
);
}
inline
friend
bool
operator
==
(
const
boundBox
&
,
const
boundBox
&
);
inline
friend
bool
operator
!=
(
const
boundBox
&
,
const
boundBox
&
);
// IOstream operator
friend
Istream
&
operator
>>
(
Istream
&
is
,
boundBox
&
);
friend
Ostream
&
operator
<<
(
Ostream
&
os
,
const
boundBox
&
);
friend
Istream
&
operator
>>
(
Istream
&
,
boundBox
&
);
friend
Ostream
&
operator
<<
(
Ostream
&
,
const
boundBox
&
);
};
...
...
@@ -244,7 +197,11 @@ inline bool contiguous<boundBox>() {return contiguous<point>();}
}
// End namespace Foam
// #include "boundBoxI.H"
#include "boundBoxI.H"
#ifdef NoRepository
# include "boundBoxTemplates.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
...
...
src/OpenFOAM/meshes/boundBox/boundBoxI.H
0 → 100644
View file @
f7ce5fbf
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2010-2010 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "boundBox.H"
#include "pointField.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
inline
Foam
::
boundBox
::
boundBox
()
:
min_
(
point
::
zero
),
max_
(
point
::
zero
)
{}
inline
Foam
::
boundBox
::
boundBox
(
const
point
&
min
,
const
point
&
max
)
:
min_
(
min
),
max_
(
max
)
{}
inline
Foam
::
boundBox
::
boundBox
(
Istream
&
is
)
{
operator
>>
(
is
,
*
this
);
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
inline
const
Foam
::
point
&
Foam
::
boundBox
::
min
()
const
{
return
min_
;
}
inline
const
Foam
::
point
&
Foam
::
boundBox
::
max
()
const
{
return
max_
;
}
inline
Foam
::
point
&
Foam
::
boundBox
::
min
()
{
return
min_
;
}
inline
Foam
::
point
&
Foam
::
boundBox
::
max
()
{
return
max_
;
}
inline
Foam
::
point
Foam
::
boundBox
::
midpoint
()
const
{
return
0
.
5
*
(
max_
+
min_
);
}
inline
Foam
::
vector
Foam
::
boundBox
::
span
()
const
{
return
(
max_
-
min_
);
}
inline
Foam
::
scalar
Foam
::
boundBox
::
mag
()
const
{
return
::
Foam
::
mag
(
max_
-
min_
);
}
inline
Foam
::
scalar
Foam
::
boundBox
::
volume
()
const
{
return
cmptProduct
(
span
());
}
inline
Foam
::
scalar
Foam
::
boundBox
::
minDim
()
const
{
return
cmptMin
(
span
());
}
inline
Foam
::
scalar
Foam
::
boundBox
::
maxDim
()
const
{
return
cmptMax
(
span
());
}
inline
Foam
::
scalar
Foam
::
boundBox
::
avgDim
()
const
{
return
cmptAv
(
span
());
}
inline
bool
Foam
::
boundBox
::
overlaps
(
const
boundBox
&
bb
)
const
{
return
(
bb
.
max_
.
x
()
>=
min_
.
x
()
&&
bb
.
min_
.
x
()
<=
max_
.
x
()
&&
bb
.
max_
.
y
()
>=
min_
.
y
()
&&
bb
.
min_
.
y
()
<=
max_
.
y
()
&&
bb
.
max_
.
z
()
>=
min_
.
z
()
&&
bb
.
min_
.
z
()
<=
max_
.
z
()
);
}
inline
bool
Foam
::
boundBox
::
contains
(
const
point
&
pt
)
const
{
return
(
pt
.
x
()
>=
min_
.
x
()
&&
pt
.
x
()
<=
max_
.
x
()
&&
pt
.
y
()
>=
min_
.
y
()
&&
pt
.
y
()
<=
max_
.
y
()
&&
pt
.
z
()
>=
min_
.
z
()
&&
pt
.
z
()
<=
max_
.
z
()
);
}
// this.bb fully contains bb
inline
bool
Foam
::
boundBox
::
contains
(
const
boundBox
&
bb
)
const
{
return
contains
(
bb
.
min
())
&&
contains
(
bb
.
max
());
}
inline
bool
Foam
::
boundBox
::
containsInside
(
const
point
&
pt
)
const
{
return
(
pt
.
x
()
>
min_
.
x
()
&&
pt
.
x
()
<
max_
.
x
()
&&
pt
.
y
()
>
min_
.
y
()
&&
pt
.
y
()
<
max_
.
y
()
&&
pt
.
z
()
>
min_
.
z
()
&&
pt
.
z
()
<
max_
.
z
()
);
}
// * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
inline
bool
Foam
::
operator
==
(
const
boundBox
&
a
,
const
boundBox
&
b
)
{
return
(
a
.
min_
==
b
.
min_
)
&&
(
a
.
max_
==
b
.
max_
);
}
inline
bool
Foam
::
operator
!=
(
const
boundBox
&
a
,
const
boundBox
&
b
)
{
return
!
(
a
==
b
);
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
src/OpenFOAM/meshes/boundBox/boundBoxTemplates.C
0 → 100644
View file @
f7ce5fbf
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2010-2010 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "boundBox.H"
#include "FixedList.H"
#include "PstreamReduceOps.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template
<
unsigned
Size
>
Foam
::
boundBox
::
boundBox
(
const
UList
<
point
>&
points
,
const
FixedList
<
label
,
Size
>&
indices
,
const
bool
doReduce
)
:
min_
(
point
::
zero
),
max_
(
point
::
zero
)
{
// a FixedList is never empty
if
(
points
.
empty
())
{
if
(
doReduce
&&
Pstream
::
parRun
())
{
// Use values that get overwritten by reduce minOp, maxOp below
min_
=
point
(
VGREAT
,
VGREAT
,
VGREAT
);
max_
=
point
(
-
VGREAT
,
-
VGREAT
,
-
VGREAT
);
}
}
else
{
min_
=
points
[
indices
[
0
]];
max_
=
points
[
indices
[
0
]];
for
(
unsigned
i
=
1
;
i
<
Size
;
++
i
)
{
min_
=
::
Foam
::
min
(
min_
,
points
[
indices
[
i
]]);
max_
=
::
Foam
::
max
(
max_
,
points
[
indices
[
i
]]);
}
}
// Reduce parallel information
if
(
doReduce
)
{
reduce
(
min_
,
minOp
<
point
>
());
reduce
(
max_
,
maxOp
<
point
>
());
}
}
// ************************************************************************* //
src/OpenFOAM/meshes/meshShapes/triFace/triFace.H
View file @
f7ce5fbf
...
...
@@ -209,8 +209,8 @@ public:
// Friend Operators
friend
bool
operator
==
(
const
triFace
&
,
const
triFace
&
);
friend
bool
operator
!=
(
const
triFace
&
,
const
triFace
&
);
inline
friend
bool
operator
==
(
const
triFace
&
,
const
triFace
&
);
inline
friend
bool
operator
!=
(
const
triFace
&
,
const
triFace
&
);
};
...
...
src/meshTools/octree/treeBoundBox.C
View file @
f7ce5fbf
...
...
@@ -124,10 +124,9 @@ Foam::FixedList<Foam::vector, 6> Foam::treeBoundBox::calcFaceNormals()
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
// Construct as the bounding box of the given pointField
Foam
::
treeBoundBox
::
treeBoundBox
(
const
UList
<
point
>&
points
)
:
boundBox
()
boundBox
(
points
,
false
)
{
if
(
points
.
empty
())
{
...
...
@@ -139,57 +138,31 @@ Foam::treeBoundBox::treeBoundBox(const UList<point>& points)
return
;
}
min
()
=
points
[
0
];
max
()
=
points
[
0
];
for
(
label
i
=
1
;
i
<
points
.
size
();
i
++
)
{
min
()
=
::
Foam
::
min
(
min
(),
points
[
i
]);
max
()
=
::
Foam
::
max
(
max
(),
points
[
i
]);
}
}
// Construct as the bounding box of the given pointField
Foam
::
treeBoundBox
::
treeBoundBox
(
const
UList
<
point
>&
points
,
const
labelUList
&
meshPoint
s
const
labelUList
&
indice
s
)
:
boundBox
()
boundBox
(
points
,
indices
,
false
)
{
if
(
points
.
empty
()
||
meshPoint
s
.
empty
())
if
(
points
.
empty
()
||
indice
s
.
empty
())
{
WarningIn
(
"treeBoundBox::treeBoundBox"