Skip to content

Commit b1bd7bd

Browse files
committed
Fix AABB bounding box acquire
1 parent 5b93628 commit b1bd7bd

File tree

2 files changed

+28
-6
lines changed

2 files changed

+28
-6
lines changed

src/diffCheck/geometry/DFPointCloud.cc

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,33 @@ namespace diffCheck::geometry
118118

119119
std::vector<Eigen::Vector3d> DFPointCloud::GetAxixAlignedBoundingBox()
120120
{
121+
if (this->Points.empty()) {
122+
return {Eigen::Vector3d::Zero(), Eigen::Vector3d::Zero()};
123+
}
124+
125+
Eigen::Vector3d minBound, maxBound;
126+
127+
#ifdef __APPLE__
128+
// Compute min and max bounds directly from points
129+
minBound = this->Points.front();
130+
maxBound = this->Points.front();
131+
132+
for (const auto& point : this->Points) {
133+
minBound = minBound.cwiseMin(point);
134+
maxBound = maxBound.cwiseMax(point);
135+
}
136+
#else
121137
auto O3DPointCloud = this->Cvt2O3DPointCloud();
122138
auto boundingBox = O3DPointCloud->GetAxisAlignedBoundingBox();
123-
std::vector<Eigen::Vector3d> extremePoints;
124-
extremePoints.push_back(boundingBox.GetMinBound());
139+
140+
boundingBox.GetMinBound());
125141
extremePoints.push_back(boundingBox.GetMaxBound());
142+
143+
#endif
144+
std::vector<Eigen::Vector3d> extremePoints;
145+
extremePoints.push_back(minBound);
146+
extremePoints.push_back(maxBound);
147+
126148
return extremePoints;
127149
}
128150

tests/unit_tests/DFPointCloudTest.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,10 @@ TEST_F(DFPointCloudTestFixture, AddPoints) {
139139
EXPECT_EQ(dfPointCloud.GetNumPoints(), 7379 * 2);
140140
}
141141

142-
// TEST_F(DFPointCloudTestFixture, ComputeAABB) {
143-
// std::vector<Eigen::Vector3d> bbox = dfPointCloud.GetAxixAlignedBoundingBox();
144-
// EXPECT_EQ(bbox.size(), 2);
145-
// } // # Segfault
142+
TEST_F(DFPointCloudTestFixture, ComputeAABB) {
143+
std::vector<Eigen::Vector3d> bbox = dfPointCloud.GetAxixAlignedBoundingBox();
144+
EXPECT_EQ(bbox.size(), 2);
145+
} // # Segfault
146146

147147
TEST_F(DFPointCloudTestFixture, ComputeOBB) {
148148
std::vector<Eigen::Vector3d> obb = dfPointCloud.GetTightBoundingBox();

0 commit comments

Comments
 (0)