#3644 Move hex overlap code to RigCellGeometryTools and clamp in z-direction as well.

* The latter is not important for 2d Maps because the height of the 2d extrusion is always at least as much as the cells.
* However this makes it so the code can estimate overlap with bounding boxes that do not reach the full height of the hexahedron.
* Also added unit tests.
This commit is contained in:
Gaute Lindkvist
2018-11-08 15:52:58 +01:00
parent 22a7a3da2a
commit 03cfa8f146
4 changed files with 155 additions and 59 deletions

View File

@@ -27,6 +27,8 @@
#include "clipper/clipper.hpp"
#include "cvfMath.h"
#include <vector>
#include <array>
@@ -82,6 +84,43 @@ double RigCellGeometryTools::calculateCellVolume(const std::array<cvf::Vec3d, 8>
return std::abs(volume); // Altogether 18 + 3*17 + 3 + 1 flops = 73 flops.
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::array<cvf::Vec3d, 8> RigCellGeometryTools::estimateHexOverlapWithBoundingBox(const std::array<cvf::Vec3d, 8>& hexCorners, const cvf::BoundingBox& boundingBox, cvf::BoundingBox* overlapBoundingBox)
{
CVF_ASSERT(overlapBoundingBox);
*overlapBoundingBox = cvf::BoundingBox();
std::array<cvf::Vec3d, 8> overlapCorners = hexCorners;
// A reasonable approximation to the overlap volume
cvf::Plane topPlane; topPlane.setFromPoints(hexCorners[0], hexCorners[1], hexCorners[2]);
cvf::Plane bottomPlane; bottomPlane.setFromPoints(hexCorners[4], hexCorners[5], hexCorners[6]);
for (size_t i = 0; i < 4; ++i)
{
cvf::Vec3d& corner = overlapCorners[i];
corner.x() = cvf::Math::clamp(corner.x(), boundingBox.min().x(), boundingBox.max().x());
corner.y() = cvf::Math::clamp(corner.y(), boundingBox.min().y(), boundingBox.max().y());
corner.z() = cvf::Math::clamp(corner.z(), boundingBox.min().z(), boundingBox.max().z());
cvf::Vec3d maxZCorner = corner; maxZCorner.z() = boundingBox.max().z();
cvf::Vec3d minZCorner = corner; minZCorner.z() = boundingBox.min().z();
topPlane.intersect(minZCorner, maxZCorner, &corner);
overlapBoundingBox->add(corner);
}
for (size_t i = 4; i < 8; ++i)
{
cvf::Vec3d& corner = overlapCorners[i];
corner.x() = cvf::Math::clamp(corner.x(), boundingBox.min().x(), boundingBox.max().x());
corner.y() = cvf::Math::clamp(corner.y(), boundingBox.min().y(), boundingBox.max().y());
corner.z() = cvf::Math::clamp(corner.z(), boundingBox.min().z(), boundingBox.max().z());
cvf::Vec3d maxZCorner = corner; maxZCorner.z() = boundingBox.max().z();
cvf::Vec3d minZCorner = corner; minZCorner.z() = boundingBox.min().z();
bottomPlane.intersect(minZCorner, maxZCorner, &corner);
overlapBoundingBox->add(corner);
}
return overlapCorners;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------