forked from AcademySoftwareFoundation/openvdb
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a unit-test for LevelSetFilter::fillet.
Signed-off-by: apradhana <[email protected]>
- Loading branch information
Showing
4 changed files
with
115 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
// Copyright Contributors to the OpenVDB Project | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#include <openvdb/Types.h> | ||
#include <openvdb/openvdb.h> | ||
#include <openvdb/tools/LevelSetFilter.h> | ||
#include <openvdb/tools/LevelSetSphere.h> | ||
#include <openvdb/io/File.h> | ||
#include <openvdb/tools/Composite.h> // for csgUnion() | ||
|
||
#include <gtest/gtest.h> | ||
|
||
#include <sstream> | ||
#include <iostream> | ||
#include <utility> | ||
|
||
using namespace openvdb; | ||
|
||
class TestLevelSetFilter: public ::testing::Test | ||
{ | ||
public: | ||
void SetUp() override { openvdb::initialize(); } | ||
void TearDown() override { openvdb::uninitialize(); } | ||
|
||
void testLevelSetFillet(); | ||
}; // class TestLevelSetFilter | ||
|
||
|
||
//////////////////////////////////////// | ||
|
||
|
||
TEST_F(TestLevelSetFilter, testLevelSetFillet) | ||
{ | ||
using GridT = FloatGrid; | ||
using FilterT = tools::LevelSetFilter<GridT>; | ||
|
||
const float radius = 5.0f; | ||
const float voxelSize = 1.0f; | ||
const float halfWidth = 3.0f; | ||
typename GridT::Ptr sdfGrid = tools::createLevelSetSphere<GridT>(/*radius=*/radius, | ||
/*center=*/Vec3f(-radius, 0.0f, 0.0f), | ||
/*dx=*/voxelSize, /*halfWidth*/ halfWidth); | ||
typename GridT::Ptr sdfGridB = tools::createLevelSetSphere<GridT>(/*radius=*/radius, | ||
/*center=*/Vec3f(radius, 0.0f, 0.0f), | ||
/*dx=*/voxelSize, /*halfWidth*/ halfWidth); | ||
typename GridT::Accessor acc = sdfGrid->getAccessor(); | ||
|
||
EXPECT_TRUE(sdfGrid); | ||
EXPECT_TRUE(sdfGridB); | ||
|
||
tools::csgUnion(*sdfGrid, *sdfGridB); | ||
|
||
{ | ||
io::File file_before("mygrids_before.vdb"); | ||
GridPtrVec grids_before; | ||
grids_before.push_back(sdfGrid); | ||
// Write out the contents of the container. | ||
file_before.write(grids_before); | ||
file_before.close(); | ||
|
||
EXPECT_TRUE(sdfGrid); | ||
|
||
Coord ijk(0, 3, 0); | ||
|
||
// We expect that the intersection between the two spheres are at (0, 0, 0) | ||
// so the SDF value of the union in these offsets locations should be > 0 | ||
EXPECT_TRUE(acc.getValue(ijk) > 0.f); | ||
EXPECT_TRUE(acc.getValue(ijk.offsetBy(0, 0, 1)) > 0.0f); | ||
EXPECT_TRUE(acc.getValue(ijk.offsetBy(0, 0,-1)) > 0.0f); | ||
EXPECT_TRUE(acc.getValue(ijk.offsetBy(0,-1, 0)) > 0.0f); | ||
EXPECT_TRUE(acc.getValue(ijk.offsetBy(0,-1, 1)) > 0.0f); | ||
EXPECT_TRUE(acc.getValue(ijk.offsetBy(0,-1,-1)) > 0.0f); | ||
} | ||
|
||
FilterT filter(*sdfGrid); | ||
filter.fillet(); | ||
|
||
{ | ||
io::File file("mygrids.vdb"); | ||
GridPtrVec grids; | ||
grids.push_back(sdfGrid); | ||
// Write out the contents of the container. | ||
file.write(grids); | ||
file.close(); | ||
|
||
EXPECT_TRUE(sdfGrid); | ||
|
||
Coord ijk(0, 3, 0); | ||
|
||
// After the fillet operation, we expect that the zero-isocontour is | ||
// pushed outward. | ||
EXPECT_TRUE(acc.getValue(ijk) < 0.f); | ||
EXPECT_TRUE(acc.getValue(ijk.offsetBy(0, 0, 1)) < 0.0f); | ||
EXPECT_TRUE(acc.getValue(ijk.offsetBy(0, 0,-1)) < 0.0f); | ||
EXPECT_TRUE(acc.getValue(ijk.offsetBy(0,-1, 0)) < 0.0f); | ||
EXPECT_TRUE(acc.getValue(ijk.offsetBy(0,-1, 1)) < 0.0f); | ||
EXPECT_TRUE(acc.getValue(ijk.offsetBy(0,-1,-1)) < 0.0f); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
New Feature: | ||
- Added fillet() method in tools::LevelSetFilter to round off concave edges to create smoother transition between surfaces. [Contributed by Greg Hurst] |