Skip to content

Commit

Permalink
Fix mismatching surface and bbox lists when building BVH (#272)
Browse files Browse the repository at this point in the history
* Fix mismatching surface and bbox lists when building BVH

* Add unit tests
  • Loading branch information
doyubkim authored and utilForever committed Nov 25, 2019
1 parent 5a97d62 commit db0bc54
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 4 deletions.
4 changes: 3 additions & 1 deletion src/jet/implicit_surface_set2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,13 +240,15 @@ void ImplicitSurfaceSet2::invalidateBvh() { _bvhInvalidated = true; }

void ImplicitSurfaceSet2::buildBvh() const {
if (_bvhInvalidated) {
std::vector<ImplicitSurface2Ptr> surfs;
std::vector<BoundingBox2D> bounds;
for (size_t i = 0; i < _surfaces.size(); ++i) {
if (_surfaces[i]->isBounded()) {
surfs.push_back(_surfaces[i]);
bounds.push_back(_surfaces[i]->boundingBox());
}
}
_bvh.build(_surfaces, bounds);
_bvh.build(surfs, bounds);
_bvhInvalidated = false;
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/jet/implicit_surface_set3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,13 +240,15 @@ void ImplicitSurfaceSet3::invalidateBvh() { _bvhInvalidated = true; }

void ImplicitSurfaceSet3::buildBvh() const {
if (_bvhInvalidated) {
std::vector<ImplicitSurface3Ptr> surfs;
std::vector<BoundingBox3D> bounds;
for (size_t i = 0; i < _surfaces.size(); ++i) {
if (_surfaces[i]->isBounded()) {
surfs.push_back(_surfaces[i]);
bounds.push_back(_surfaces[i]->boundingBox());
}
}
_bvh.build(_surfaces, bounds);
_bvh.build(surfs, bounds);
_bvhInvalidated = false;
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/jet/surface_set2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,13 +212,15 @@ void SurfaceSet2::invalidateBvh() { _bvhInvalidated = true; }

void SurfaceSet2::buildBvh() const {
if (_bvhInvalidated) {
std::vector<Surface2Ptr> surfs;
std::vector<BoundingBox2D> bounds;
for (size_t i = 0; i < _surfaces.size(); ++i) {
if (_surfaces[i]->isBounded()) {
surfs.push_back(_surfaces[i]);
bounds.push_back(_surfaces[i]->boundingBox());
}
}
_bvh.build(_surfaces, bounds);
_bvh.build(surfs, bounds);
_bvhInvalidated = false;
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/jet/surface_set3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,13 +212,15 @@ void SurfaceSet3::invalidateBvh() { _bvhInvalidated = true; }

void SurfaceSet3::buildBvh() const {
if (_bvhInvalidated) {
std::vector<Surface3Ptr> surfs;
std::vector<BoundingBox3D> bounds;
for (size_t i = 0; i < _surfaces.size(); ++i) {
if (_surfaces[i]->isBounded()) {
surfs.push_back(_surfaces[i]);
bounds.push_back(_surfaces[i]->boundingBox());
}
}
_bvh.build(_surfaces, bounds);
_bvh.build(surfs, bounds);
_bvhInvalidated = false;
}
}
Expand Down
7 changes: 7 additions & 0 deletions src/tests/unit_tests/implicit_surface_set2_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -293,4 +293,11 @@ TEST(ImplicitSurfaceSet2, UpdateQueryEngine) {
surfaceSet->updateQueryEngine();
auto bbox3 = surfaceSet->boundingBox();
EXPECT_BOUNDING_BOX2_EQ(BoundingBox2D({-4.5, 5.5}, {-3.5, 6.5}), bbox3);

// Plane is unbounded. Total bbox should ignore it.
auto plane = Plane2::builder().withNormal({1.0, 0.0}).makeShared();
surfaceSet->addExplicitSurface(plane);
surfaceSet->updateQueryEngine();
auto bbox4 = surfaceSet->boundingBox();
EXPECT_BOUNDING_BOX2_EQ(BoundingBox2D({-4.5, 5.5}, {-3.5, 6.5}), bbox4);
}
8 changes: 8 additions & 0 deletions src/tests/unit_tests/implicit_surface_set3_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -303,4 +303,12 @@ TEST(ImplicitSurfaceSet3, UpdateQueryEngine) {
auto bbox3 = surfaceSet->boundingBox();
EXPECT_BOUNDING_BOX2_EQ(BoundingBox3D({-4.5, 5.5, 10.5}, {-3.5, 6.5, 11.5}),
bbox3);

// Plane is unbounded. Total bbox should ignore it.
auto plane = Plane3::builder().withNormal({1.0, 0.0, 0.0}).makeShared();
surfaceSet->addExplicitSurface(plane);
surfaceSet->updateQueryEngine();
auto bbox4 = surfaceSet->boundingBox();
EXPECT_BOUNDING_BOX2_EQ(BoundingBox3D({-4.5, 5.5, 10.5}, {-3.5, 6.5, 11.5}),
bbox4);
}
7 changes: 7 additions & 0 deletions src/tests/unit_tests/surface_set2_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -479,4 +479,11 @@ TEST(SurfaceSet2, UpdateQueryEngine) {
surfaceSet->updateQueryEngine();
auto bbox3 = surfaceSet->boundingBox();
EXPECT_BOUNDING_BOX2_EQ(BoundingBox2D({-4.5, 5.5}, {-3.5, 6.5}), bbox3);

// Plane is unbounded. Total bbox should ignore it.
auto plane = Plane2::builder().withNormal({1.0, 0.0}).makeShared();
surfaceSet->addSurface(plane);
surfaceSet->updateQueryEngine();
auto bbox4 = surfaceSet->boundingBox();
EXPECT_BOUNDING_BOX2_EQ(BoundingBox2D({-4.5, 5.5}, {-3.5, 6.5}), bbox4);
}
8 changes: 8 additions & 0 deletions src/tests/unit_tests/surface_set3_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -487,4 +487,12 @@ TEST(SurfaceSet3, UpdateQueryEngine) {
auto bbox3 = surfaceSet->boundingBox();
EXPECT_BOUNDING_BOX2_EQ(BoundingBox3D({-4.5, 5.5, 10.5}, {-3.5, 6.5, 11.5}),
bbox3);

// Plane is unbounded. Total bbox should ignore it.
auto plane = Plane3::builder().withNormal({1.0, 0.0, 0.0}).makeShared();
surfaceSet->addSurface(plane);
surfaceSet->updateQueryEngine();
auto bbox4 = surfaceSet->boundingBox();
EXPECT_BOUNDING_BOX2_EQ(BoundingBox3D({-4.5, 5.5, 10.5}, {-3.5, 6.5, 11.5}),
bbox4);
}

0 comments on commit db0bc54

Please sign in to comment.