2025-02-25 00:24:28 +08:00
|
|
|
#include <Cesium3DTilesSelection/BoundingVolume.h>
|
2025-02-18 06:04:42 +08:00
|
|
|
#include <CesiumGeometry/BoundingCylinderRegion.h>
|
2024-12-21 00:56:49 +08:00
|
|
|
#include <CesiumGeometry/BoundingSphere.h>
|
|
|
|
|
#include <CesiumGeometry/OrientedBoundingBox.h>
|
2023-03-15 14:41:51 +08:00
|
|
|
#include <CesiumGeometry/QuadtreeTileID.h>
|
2025-02-18 06:04:42 +08:00
|
|
|
#include <CesiumGeometry/Transforms.h>
|
2024-12-21 00:56:49 +08:00
|
|
|
#include <CesiumGeospatial/BoundingRegion.h>
|
|
|
|
|
#include <CesiumGeospatial/BoundingRegionWithLooseFittingHeights.h>
|
|
|
|
|
#include <CesiumGeospatial/Ellipsoid.h>
|
|
|
|
|
#include <CesiumGeospatial/S2CellBoundingVolume.h>
|
|
|
|
|
#include <CesiumGeospatial/S2CellID.h>
|
2025-02-18 06:04:42 +08:00
|
|
|
#include <CesiumUtility/Math.h>
|
2023-03-15 14:41:51 +08:00
|
|
|
|
2025-01-16 05:58:03 +08:00
|
|
|
#include <doctest/doctest.h>
|
2023-03-15 14:41:51 +08:00
|
|
|
|
|
|
|
|
using namespace Cesium3DTilesSelection;
|
|
|
|
|
using namespace CesiumGeometry;
|
|
|
|
|
using namespace CesiumGeospatial;
|
|
|
|
|
|
|
|
|
|
TEST_CASE("getOrientedBoundingBoxFromBoundingVolume") {
|
2025-01-16 05:58:03 +08:00
|
|
|
SUBCASE("for OrientedBoundingBox, the box is returned directly") {
|
2023-03-15 14:41:51 +08:00
|
|
|
OrientedBoundingBox obb(
|
|
|
|
|
glm::dvec3(1.0, 2.0, 3.0),
|
|
|
|
|
glm::dmat3(
|
|
|
|
|
glm::dvec3(1.0, 2.0, 3.0),
|
|
|
|
|
glm::dvec3(4.0, 5.0, 6.0),
|
|
|
|
|
glm::dvec3(7.0, 8.0, 9.0)));
|
|
|
|
|
BoundingVolume bv = obb;
|
|
|
|
|
OrientedBoundingBox newObb = getOrientedBoundingBoxFromBoundingVolume(bv);
|
|
|
|
|
CHECK(obb.getCenter() == newObb.getCenter());
|
|
|
|
|
CHECK(obb.getHalfAxes() == newObb.getHalfAxes());
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-16 05:58:03 +08:00
|
|
|
SUBCASE("for BoundingSphere, a circumscribed box is returned") {
|
2023-03-15 14:41:51 +08:00
|
|
|
BoundingSphere bs(glm::dvec3(1.0, 2.0, 3.0), 10.0);
|
|
|
|
|
BoundingVolume bv = bs;
|
|
|
|
|
OrientedBoundingBox newObb = getOrientedBoundingBoxFromBoundingVolume(bv);
|
|
|
|
|
CHECK(newObb.getCenter() == bs.getCenter());
|
|
|
|
|
CHECK(newObb.getLengths() == glm::dvec3(20.0));
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-18 06:04:42 +08:00
|
|
|
SUBCASE("for BoundingCylinderRegion, a tightly-fitted box is returned") {
|
|
|
|
|
glm::dquat rotation(CesiumGeometry::Transforms::X_UP_TO_Y_UP);
|
|
|
|
|
glm::dvec3 translation(1.0, 2.0, 3.0);
|
|
|
|
|
|
|
|
|
|
BoundingCylinderRegion region(
|
|
|
|
|
translation,
|
|
|
|
|
rotation,
|
|
|
|
|
3.0,
|
|
|
|
|
glm::dvec2(1.0, 2.0),
|
|
|
|
|
glm::dvec2(0.0, CesiumUtility::Math::PiOverTwo));
|
|
|
|
|
|
|
|
|
|
BoundingVolume bv = region;
|
|
|
|
|
OrientedBoundingBox newObb = getOrientedBoundingBoxFromBoundingVolume(bv);
|
|
|
|
|
|
|
|
|
|
glm::dvec3 expectedCenter(0.0, 3.0, 3.0);
|
|
|
|
|
glm::dmat3 expectedHalfAxes(0.0, 1.0, 0.0, -1.0, 0.0, 0.0, 0.0, 0.0, 1.5);
|
|
|
|
|
|
|
|
|
|
CHECK(CesiumUtility::Math::equalsEpsilon(
|
|
|
|
|
newObb.getCenter(),
|
|
|
|
|
expectedCenter,
|
|
|
|
|
CesiumUtility::Math::Epsilon6));
|
|
|
|
|
|
|
|
|
|
const glm::dmat3& halfAxes = newObb.getHalfAxes();
|
|
|
|
|
for (glm::length_t i = 0; i < 3; i++) {
|
|
|
|
|
CHECK(CesiumUtility::Math::equalsEpsilon(
|
|
|
|
|
halfAxes[i],
|
|
|
|
|
expectedHalfAxes[i],
|
|
|
|
|
CesiumUtility::Math::Epsilon6));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-16 05:58:03 +08:00
|
|
|
SUBCASE("for others, their aggregated oriented bounding box is returned") {
|
2024-06-07 04:53:48 +08:00
|
|
|
BoundingRegion region(
|
|
|
|
|
GlobeRectangle(0.5, 1.0, 1.5, 2.0),
|
|
|
|
|
100.0,
|
|
|
|
|
200.0,
|
|
|
|
|
Ellipsoid::WGS84);
|
2023-03-15 14:41:51 +08:00
|
|
|
BoundingVolume bv = region;
|
|
|
|
|
OrientedBoundingBox newObb = getOrientedBoundingBoxFromBoundingVolume(bv);
|
|
|
|
|
CHECK(region.getBoundingBox().getCenter() == newObb.getCenter());
|
|
|
|
|
CHECK(region.getBoundingBox().getHalfAxes() == newObb.getHalfAxes());
|
|
|
|
|
|
|
|
|
|
BoundingRegionWithLooseFittingHeights looseRegion(region);
|
|
|
|
|
bv = looseRegion;
|
|
|
|
|
newObb = getOrientedBoundingBoxFromBoundingVolume(bv);
|
|
|
|
|
CHECK(region.getBoundingBox().getCenter() == newObb.getCenter());
|
|
|
|
|
CHECK(region.getBoundingBox().getHalfAxes() == newObb.getHalfAxes());
|
|
|
|
|
|
|
|
|
|
S2CellBoundingVolume s2(
|
|
|
|
|
S2CellID::fromQuadtreeTileID(1, QuadtreeTileID(10, 1, 2)),
|
|
|
|
|
100.0,
|
2024-06-07 04:53:48 +08:00
|
|
|
200.0,
|
|
|
|
|
Ellipsoid::WGS84);
|
2023-03-15 14:41:51 +08:00
|
|
|
bv = s2;
|
|
|
|
|
newObb = getOrientedBoundingBoxFromBoundingVolume(bv);
|
|
|
|
|
CHECK(
|
|
|
|
|
s2.computeBoundingRegion().getBoundingBox().getCenter() ==
|
|
|
|
|
newObb.getCenter());
|
|
|
|
|
CHECK(
|
|
|
|
|
s2.computeBoundingRegion().getBoundingBox().getHalfAxes() ==
|
|
|
|
|
newObb.getHalfAxes());
|
|
|
|
|
}
|
|
|
|
|
}
|