diff --git a/Source/Geometry/Testing/imstkCubeTest.cpp b/Source/Geometry/Testing/imstkCubeTest.cpp index 8c0c8c2b45a10b88ef60c834fbbb30a796d16b5a..0ad86db1dd0d922daa4ce62e6b9623fe02e00e0b 100644 --- a/Source/Geometry/Testing/imstkCubeTest.cpp +++ b/Source/Geometry/Testing/imstkCubeTest.cpp @@ -63,11 +63,25 @@ TEST_F(imstkCubeTest, GetVolume) m_cube.setWidth(0.003); EXPECT_EQ(m_cube.getVolume(), 0.003 * 0.003 * 0.003); - double w = 400000000; + const double w = 400000000; m_cube.setWidth(400000000); EXPECT_EQ(m_cube.getVolume(), w * w * w); } +/// +/// \brief test the cube SDF evaluator +/// +TEST_F(imstkCubeTest, GetFunctionValue) +{ + m_cube.setWidth(2.); + m_cube.updatePostTransformData(); + + EXPECT_EQ(m_cube.getFunctionValue(Vec3d(0., 0., 0.)), -1.); + EXPECT_EQ(m_cube.getFunctionValue(Vec3d(0.5, 0., 0.)), -0.5); + EXPECT_EQ(m_cube.getFunctionValue(Vec3d(1., 1., 1.)), 0.); + EXPECT_EQ(m_cube.getFunctionValue(Vec3d(0., -10., 0.)), 9.); +} + /// /// \brief TODO /// diff --git a/Source/Geometry/Testing/imstkPlaneTest.cpp b/Source/Geometry/Testing/imstkPlaneTest.cpp index 579de4a2a641496671b715dc5a445961645e8630..892b4d3438266d5218c56ff9a4e14fca2c173b78 100644 --- a/Source/Geometry/Testing/imstkPlaneTest.cpp +++ b/Source/Geometry/Testing/imstkPlaneTest.cpp @@ -85,6 +85,29 @@ TEST_F(imstkPlaneTest, GetVolume) EXPECT_EQ(m_plane.getVolume(), 0); } +/// +/// \brief test the plane SDF evaluator +/// +TEST_F(imstkPlaneTest, GetFunctionValue) +{ + m_plane.setNormal(Vec3d(0., 1., 0.)); + m_plane.updatePostTransformData(); + + EXPECT_EQ(m_plane.getFunctionValue(Vec3d(0., 0., 0.)), 0.); + EXPECT_EQ(m_plane.getFunctionValue(Vec3d(0.5, 0., 0.)), 0.); + EXPECT_EQ(m_plane.getFunctionValue(Vec3d(1., 1., 1.)), 1.); + EXPECT_EQ(m_plane.getFunctionValue(Vec3d(0., -10., 0.)), -10.); + + m_plane.setPosition(Vec3d(1., 1., 1.)); + m_plane.setNormal(Vec3d(1., 1., 1.)); + m_plane.updatePostTransformData(); + + EXPECT_FLOAT_EQ(m_plane.getFunctionValue(Vec3d(0., 0., 0.)), -std::sqrt(3.0)); + EXPECT_EQ(m_plane.getFunctionValue(Vec3d(1., 1., 1.)), 0.0); + EXPECT_FLOAT_EQ(m_plane.getFunctionValue(Vec3d(1., 0., 0.)), -2.0 / std::sqrt(3.0)); + EXPECT_FLOAT_EQ(m_plane.getFunctionValue(Vec3d(0., -10., 0.)), -13.0 / std::sqrt(3.0)); +} + /// /// \brief TODO /// diff --git a/Source/Geometry/Testing/imstkSphereTest.cpp b/Source/Geometry/Testing/imstkSphereTest.cpp index 48de88d1dec9241842a6b3a584ba1b038e96999a..41b79259dc28fe15ea6dd9aaee80f1f5d5ae72bc 100644 --- a/Source/Geometry/Testing/imstkSphereTest.cpp +++ b/Source/Geometry/Testing/imstkSphereTest.cpp @@ -68,6 +68,21 @@ TEST_F(imstkSphereTest, GetVolume) EXPECT_EQ(m_sphere.getVolume(), 4.0 / 3.0 * PI * r * r * r); } +/// +/// \brief test the sphere SDF evaluator +/// +TEST_F(imstkSphereTest, GetFunctionValue) +{ + m_sphere.setRadius(20.); + m_sphere.updatePostTransformData(); + + EXPECT_EQ(m_sphere.getFunctionValue(Vec3d(0., 0., 0.)), -20.); + EXPECT_EQ(m_sphere.getFunctionValue(Vec3d(5., 0., 0.)), -15); + EXPECT_EQ(m_sphere.getFunctionValue(Vec3d(1., 1., 1.)), -20.0 + std::sqrt(3)); + EXPECT_EQ(m_sphere.getFunctionValue(Vec3d(0., 20., 0.)), 0.); + EXPECT_EQ(m_sphere.getFunctionValue(Vec3d(0., 0., 50.)), 30.); +} + /// /// \brief TODO ///