mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: additional methods and improvements to plane
- signedDistance() method is like distance() but retains the positive/negative sign for the side of the plane. - the sign() method returns the sign as -1,0,+1 integer for classification purposes where it is important to distinguish between a zero value and a positive value (eg, for cutting). Optional tolerance can be supplied to round for zero. - refactor and inlined simple and frequently used methods. - add boundBox faceCentre() method, which can be useful for creating clipping planes from a bounding box. Relocated treeBoundBox faceNormals to boundBox since they apply equally there - the meaning of the faces (x-min, x-max, etc) is the same, even if the point addressing for the faces differs.
This commit is contained in:
@ -45,12 +45,22 @@ const Foam::boundBox Foam::boundBox::invertedBox
|
||||
const Foam::faceList Foam::boundBox::faces
|
||||
({
|
||||
// Point and face order as per hex cellmodel
|
||||
face{0, 4, 7, 3}, // x-min
|
||||
face{1, 2, 6, 5}, // x-max
|
||||
face{0, 1, 5, 4}, // y-min
|
||||
face{3, 7, 6, 2}, // y-max
|
||||
face{0, 3, 2, 1}, // z-min
|
||||
face{4, 5, 6, 7} // z-max
|
||||
face({0, 4, 7, 3}), // 0: x-min, left
|
||||
face({1, 2, 6, 5}), // 1: x-max, right
|
||||
face({0, 1, 5, 4}), // 2: y-min, bottom
|
||||
face({3, 7, 6, 2}), // 3: y-max, top
|
||||
face({0, 3, 2, 1}), // 4: z-min, back
|
||||
face({4, 5, 6, 7}) // 5: z-max, front
|
||||
});
|
||||
|
||||
const Foam::FixedList<Foam::vector, 6> Foam::boundBox::faceNormals
|
||||
({
|
||||
vector(-1, 0, 0), // 0: x-min, left
|
||||
vector( 1, 0, 0), // 1: x-max, right
|
||||
vector( 0, -1, 0), // 2: y-min, bottom
|
||||
vector( 0, 1, 0), // 3: y-max, top
|
||||
vector( 0, 0, -1), // 4: z-min, back
|
||||
vector( 0, 0, 1) // 5: z-max, front
|
||||
});
|
||||
|
||||
|
||||
@ -107,8 +117,8 @@ Foam::boundBox::boundBox
|
||||
|
||||
Foam::tmp<Foam::pointField> Foam::boundBox::points() const
|
||||
{
|
||||
tmp<pointField> tpoints(new pointField(8));
|
||||
pointField& pt = tpoints.ref();
|
||||
auto tpt = tmp<pointField>::New(8);
|
||||
auto& pt = tpt.ref();
|
||||
|
||||
pt[0] = min_; // min-x, min-y, min-z
|
||||
pt[1] = point(max_.x(), min_.y(), min_.z()); // max-x, min-y, min-z
|
||||
@ -119,7 +129,46 @@ Foam::tmp<Foam::pointField> Foam::boundBox::points() const
|
||||
pt[6] = max_; // max-x, max-y, max-z
|
||||
pt[7] = point(min_.x(), max_.y(), max_.z()); // min-x, max-y, max-z
|
||||
|
||||
return tpoints;
|
||||
return tpt;
|
||||
}
|
||||
|
||||
|
||||
Foam::tmp<Foam::pointField> Foam::boundBox::faceCentres() const
|
||||
{
|
||||
auto tpts = tmp<pointField>::New(6);
|
||||
auto& pts = tpts.ref();
|
||||
|
||||
forAll(pts, facei)
|
||||
{
|
||||
pts[facei] = faceCentre(facei);
|
||||
}
|
||||
|
||||
return tpts;
|
||||
}
|
||||
|
||||
|
||||
Foam::point Foam::boundBox::faceCentre(const direction facei) const
|
||||
{
|
||||
point pt = boundBox::midpoint();
|
||||
|
||||
if (facei > 5)
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< "face should be [0..5]"
|
||||
<< abort(FatalError);
|
||||
}
|
||||
|
||||
switch (facei)
|
||||
{
|
||||
case 0: pt.x() = min().x(); break; // 0: x-min, left
|
||||
case 1: pt.x() = max().x(); break; // 1: x-max, right
|
||||
case 2: pt.y() = min().y(); break; // 2: y-min, bottom
|
||||
case 3: pt.y() = max().y(); break; // 3: y-max, top
|
||||
case 4: pt.z() = min().z(); break; // 4: z-min, back
|
||||
case 5: pt.z() = max().z(); break; // 5: z-max, front
|
||||
}
|
||||
|
||||
return pt;
|
||||
}
|
||||
|
||||
|
||||
@ -160,11 +209,11 @@ bool Foam::boundBox::intersects(const plane& pln) const
|
||||
bool below = false;
|
||||
|
||||
tmp<pointField> tpts(points());
|
||||
const pointField& pts = tpts();
|
||||
const auto& pts = tpts();
|
||||
|
||||
for (const point& p : pts)
|
||||
{
|
||||
if (pln.sideOfPlane(p) == plane::NORMAL)
|
||||
if (pln.sideOfPlane(p) == plane::FRONT)
|
||||
{
|
||||
above = true;
|
||||
}
|
||||
@ -208,9 +257,9 @@ bool Foam::boundBox::contains
|
||||
return true;
|
||||
}
|
||||
|
||||
forAll(indices, i)
|
||||
for (const label pointi : indices)
|
||||
{
|
||||
if (!contains(points[indices[i]]))
|
||||
if (!contains(points[pointi]))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@ -250,9 +299,9 @@ bool Foam::boundBox::containsAny
|
||||
return true;
|
||||
}
|
||||
|
||||
forAll(indices, i)
|
||||
for (const label pointi : indices)
|
||||
{
|
||||
if (contains(points[indices[i]]))
|
||||
if (contains(points[pointi]))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user