From 84caab046b3b95964d2e1ee1ada6222c8ef00a24 Mon Sep 17 00:00:00 2001
From: sreekanth-arikatla <sreekanth.arikatla@kitware.com>
Date: Tue, 27 Apr 2021 10:09:32 -0400
Subject: [PATCH] TEST: Add sdf tests for closed-form geometry

---
 Source/Geometry/Testing/imstkCubeTest.cpp   | 16 +++++++++++++-
 Source/Geometry/Testing/imstkPlaneTest.cpp  | 23 +++++++++++++++++++++
 Source/Geometry/Testing/imstkSphereTest.cpp | 15 ++++++++++++++
 3 files changed, 53 insertions(+), 1 deletion(-)

diff --git a/Source/Geometry/Testing/imstkCubeTest.cpp b/Source/Geometry/Testing/imstkCubeTest.cpp
index 8c0c8c2b4..0ad86db1d 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 579de4a2a..892b4d343 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 48de88d1d..41b79259d 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
 ///
-- 
GitLab