Commit d1c7b0c9 authored by Sreekanth Arikatla's avatar Sreekanth Arikatla Committed by Andrew Wilson
Browse files

STYLE: Clean up the collision tests

parent 2e6ad2aa
......@@ -28,16 +28,7 @@
using namespace imstk;
///
/// \brief TODO
///
class imstkMeshToMeshBruteForceCDTest : public ::testing::Test
{
protected:
MeshToMeshBruteForceCD m_meshToMeshBruteForceCD;
};
TEST_F(imstkMeshToMeshBruteForceCDTest, IntersectionTestAB_EdgeToEdge)
TEST(imstkMeshToMeshBruteForceCDTest, IntersectionTestAB_EdgeToEdge)
{
// Create two cubes
auto box1 = std::make_shared<OrientedBox>(Vec3d::Zero(), Vec3d(0.5, 0.5, 0.5), Quatd::Identity());
......@@ -50,6 +41,7 @@ TEST_F(imstkMeshToMeshBruteForceCDTest, IntersectionTestAB_EdgeToEdge)
box2Mesh->translate(Vec3d(0.0, 0.8, 0.8));
box2Mesh->updatePostTransformData();
MeshToMeshBruteForceCD m_meshToMeshBruteForceCD;
m_meshToMeshBruteForceCD.setInput(box1Mesh, 0);
m_meshToMeshBruteForceCD.setInput(box2Mesh, 1);
m_meshToMeshBruteForceCD.setGenerateCD(true, true); // Generate both A and B
......@@ -72,7 +64,7 @@ TEST_F(imstkMeshToMeshBruteForceCDTest, IntersectionTestAB_EdgeToEdge)
EXPECT_EQ(colData->elementsB[0].m_element.m_CellIndexElement.idCount, 2);
}
TEST_F(imstkMeshToMeshBruteForceCDTest, IntersectionTestAB_VertexToTriangle)
TEST(imstkMeshToMeshBruteForceCDTest, IntersectionTestAB_VertexToTriangle)
{
// Create triangle on z plane
auto triMesh = std::make_shared<SurfaceMesh>();
......@@ -94,6 +86,7 @@ TEST_F(imstkMeshToMeshBruteForceCDTest, IntersectionTestAB_VertexToTriangle)
vertexMesh->initialize(verticesPtr);
}
MeshToMeshBruteForceCD m_meshToMeshBruteForceCD;
m_meshToMeshBruteForceCD.setInput(triMesh, 0);
m_meshToMeshBruteForceCD.setInput(vertexMesh, 1);
m_meshToMeshBruteForceCD.setGenerateCD(true, true); // Generate both A and B
......@@ -116,7 +109,7 @@ TEST_F(imstkMeshToMeshBruteForceCDTest, IntersectionTestAB_VertexToTriangle)
EXPECT_EQ(colData->elementsB[0].m_element.m_CellIndexElement.idCount, 1);
}
TEST_F(imstkMeshToMeshBruteForceCDTest, IntersectionTestAB_VertexToVertex)
TEST(imstkMeshToMeshBruteForceCDTest, IntersectionTestAB_VertexToVertex)
{
// Create triangle on z plane
auto triMesh = std::make_shared<SurfaceMesh>();
......@@ -138,6 +131,7 @@ TEST_F(imstkMeshToMeshBruteForceCDTest, IntersectionTestAB_VertexToVertex)
vertexMesh->initialize(verticesPtr);
}
MeshToMeshBruteForceCD m_meshToMeshBruteForceCD;
m_meshToMeshBruteForceCD.setInput(triMesh, 0);
m_meshToMeshBruteForceCD.setInput(vertexMesh, 1);
m_meshToMeshBruteForceCD.setGenerateCD(true, true); // Generate both A and B
......@@ -160,7 +154,7 @@ TEST_F(imstkMeshToMeshBruteForceCDTest, IntersectionTestAB_VertexToVertex)
EXPECT_EQ(colData->elementsB[0].m_element.m_CellIndexElement.idCount, 1);
}
TEST_F(imstkMeshToMeshBruteForceCDTest, IntersectionTestAB_VertexToEdge)
TEST(imstkMeshToMeshBruteForceCDTest, IntersectionTestAB_VertexToEdge)
{
// Create triangle on z plane
auto triMesh = std::make_shared<SurfaceMesh>();
......@@ -182,6 +176,7 @@ TEST_F(imstkMeshToMeshBruteForceCDTest, IntersectionTestAB_VertexToEdge)
vertexMesh->initialize(verticesPtr);
}
MeshToMeshBruteForceCD m_meshToMeshBruteForceCD;
m_meshToMeshBruteForceCD.setInput(triMesh, 0);
m_meshToMeshBruteForceCD.setInput(vertexMesh, 1);
m_meshToMeshBruteForceCD.setGenerateCD(true, true); // Generate both A and B
......
......@@ -29,8 +29,6 @@ using namespace imstk;
TEST(imstkPointSetToCapsuleCDTest, IntersectionTestAB)
{
PointSetToCapsuleCD m_pointSetToCapsuleCD;
auto capsule = std::make_shared<Capsule>();
auto pointSet = std::make_shared<PointSet>();
......@@ -38,6 +36,7 @@ TEST(imstkPointSetToCapsuleCDTest, IntersectionTestAB)
(*verticesPtr)[0] = Vec3d(0.25, 0.0, 0.0);
pointSet->initialize(verticesPtr);
PointSetToCapsuleCD m_pointSetToCapsuleCD;
m_pointSetToCapsuleCD.setInput(pointSet, 0);
m_pointSetToCapsuleCD.setInput(capsule, 1);
m_pointSetToCapsuleCD.setGenerateCD(true, true);
......@@ -69,14 +68,13 @@ TEST(imstkPointSetToCapsuleCDTest, IntersectionTestAB)
TEST(imstkPointSetToCapsuleCDTest, NonIntersectionTestAB)
{
PointSetToCapsuleCD m_pointSetToCapsuleCD;
auto capsule = std::make_shared<Capsule>();
auto pointSet = std::make_shared<PointSet>();
auto verticesPtr = std::make_shared<VecDataArray<double, 3>>(1);
(*verticesPtr)[0] = Vec3d(5.0, 5.0, 5.0);
pointSet->initialize(verticesPtr);
PointSetToCapsuleCD m_pointSetToCapsuleCD;
m_pointSetToCapsuleCD.setInput(pointSet, 0);
m_pointSetToCapsuleCD.setInput(capsule, 1);
m_pointSetToCapsuleCD.setGenerateCD(true, true);
......
......@@ -27,16 +27,7 @@
using namespace imstk;
///
/// \brief TODO
///
class imstkPointSetToOrientedBoxCDTest : public ::testing::Test
{
protected:
PointSetToOrientedBoxCD m_pointSetToOrientedBoxCD;
};
TEST_F(imstkPointSetToOrientedBoxCDTest, IntersectionTestAB)
TEST(imstkPointSetToOrientedBoxCDTest, IntersectionTestAB)
{
// Cube with width 2 (max y is 1)
auto cube = std::make_shared<OrientedBox>(Vec3d(0.0, 0.0, 0.0), Vec3d(1.0, 1.0, 1.0));
......@@ -45,6 +36,7 @@ TEST_F(imstkPointSetToOrientedBoxCDTest, IntersectionTestAB)
(*verticesPtr)[0] = Vec3d(0.0, 0.9, 0.0);
pointSet->initialize(verticesPtr);
PointSetToOrientedBoxCD m_pointSetToOrientedBoxCD;
m_pointSetToOrientedBoxCD.setInput(pointSet, 0);
m_pointSetToOrientedBoxCD.setInput(cube, 1);
m_pointSetToOrientedBoxCD.setGenerateCD(true, true); // Generate both A and B
......@@ -74,7 +66,7 @@ TEST_F(imstkPointSetToOrientedBoxCDTest, IntersectionTestAB)
EXPECT_NEAR(1.0, colData->elementsB[0].m_element.m_PointDirectionElement.pt[1], 0.00001);
}
TEST_F(imstkPointSetToOrientedBoxCDTest, NonIntersectionTestAB)
TEST(imstkPointSetToOrientedBoxCDTest, NonIntersectionTestAB)
{
// Cube with width 2 (max y is 1)
auto cube = std::make_shared<OrientedBox>(Vec3d(0.0, 0.0, 0.0), Vec3d(1.0, 1.0, 1.0));
......@@ -83,6 +75,7 @@ TEST_F(imstkPointSetToOrientedBoxCDTest, NonIntersectionTestAB)
(*verticesPtr)[0] = Vec3d(0.0, 1.1, 0.0);
pointSet->initialize(verticesPtr);
PointSetToOrientedBoxCD m_pointSetToOrientedBoxCD;
m_pointSetToOrientedBoxCD.setInput(pointSet, 0);
m_pointSetToOrientedBoxCD.setInput(cube, 1);
m_pointSetToOrientedBoxCD.setGenerateCD(true, true); // Generate both A and B
......@@ -95,9 +88,6 @@ TEST_F(imstkPointSetToOrientedBoxCDTest, NonIntersectionTestAB)
EXPECT_EQ(0, colData->elementsB.getSize());
}
///
/// \brief TODO
///
int
imstkPointSetToOrientedBoxCDTest(int argc, char* argv[])
{
......
......@@ -29,8 +29,6 @@ using namespace imstk;
TEST(imstkPointSetToPlaneCDTest, IntersectionTestAB)
{
PointSetToPlaneCD m_pointSetToPlaneCD;
auto plane = std::make_shared<Plane>();
auto pointSet = std::make_shared<PointSet>();
......@@ -38,6 +36,7 @@ TEST(imstkPointSetToPlaneCDTest, IntersectionTestAB)
(*verticesPtr)[0] = Vec3d(0.0, -0.5, 0.0);
pointSet->initialize(verticesPtr);
PointSetToPlaneCD m_pointSetToPlaneCD;
m_pointSetToPlaneCD.setInput(pointSet, 0);
m_pointSetToPlaneCD.setInput(plane, 1);
m_pointSetToPlaneCD.setGenerateCD(true, true);
......@@ -70,14 +69,13 @@ TEST(imstkPointSetToPlaneCDTest, IntersectionTestAB)
TEST(imstkPointSetToPlaneCDTest, NonIntersectionTestAB)
{
PointSetToPlaneCD m_pointSetToPlaneCD;
auto plane = std::make_shared<Plane>(Vec3d(0.0, 0.0, 0.0), Vec3d(1., 1., 1.));
auto pointSet = std::make_shared<PointSet>();
auto verticesPtr = std::make_shared<VecDataArray<double, 3>>(1);
(*verticesPtr)[0] = Vec3d(1.0, 1.0, 1.0);
pointSet->initialize(verticesPtr);
PointSetToPlaneCD m_pointSetToPlaneCD;
m_pointSetToPlaneCD.setInput(pointSet, 0);
m_pointSetToPlaneCD.setInput(plane, 1);
m_pointSetToPlaneCD.setGenerateCD(true, true);
......
......@@ -27,16 +27,7 @@
using namespace imstk;
///
/// \brief TODO
///
class imstkPointSetToSphereCDTest : public ::testing::Test
{
protected:
PointSetToSphereCD m_pointSetToSphereCD;
};
TEST_F(imstkPointSetToSphereCDTest, IntersectionTestAB)
TEST(imstkPointSetToSphereCDTest, IntersectionTestAB)
{
auto sphere = std::make_shared<Sphere>(Vec3d(0.0, -2.0, 0.0), 2.1);
auto pointSet = std::make_shared<PointSet>();
......@@ -44,6 +35,7 @@ TEST_F(imstkPointSetToSphereCDTest, IntersectionTestAB)
(*verticesPtr)[0] = Vec3d(0.0, 0.0, 0.0);
pointSet->initialize(verticesPtr);
PointSetToSphereCD m_pointSetToSphereCD;
m_pointSetToSphereCD.setInput(pointSet, 0);
m_pointSetToSphereCD.setInput(sphere, 1);
m_pointSetToSphereCD.setGenerateCD(true, true); // Generate both A and B
......@@ -73,10 +65,7 @@ TEST_F(imstkPointSetToSphereCDTest, IntersectionTestAB)
EXPECT_NEAR(0.1, colData->elementsB[0].m_element.m_PointDirectionElement.pt[1], 0.00001);
}
///
/// \brief TODO
///
TEST_F(imstkPointSetToSphereCDTest, NonIntersectionTestAB)
TEST(imstkPointSetToSphereCDTest, NonIntersectionTestAB)
{
auto sphere = std::make_shared<Sphere>(Vec3d(0.0, -8.0, 0.0), 2.1);
auto pointSet = std::make_shared<PointSet>();
......@@ -84,6 +73,7 @@ TEST_F(imstkPointSetToSphereCDTest, NonIntersectionTestAB)
(*verticesPtr)[0] = Vec3d(0.0, 0.0, 0.0);
pointSet->initialize(verticesPtr);
PointSetToSphereCD m_pointSetToSphereCD;
m_pointSetToSphereCD.setInput(pointSet, 0);
m_pointSetToSphereCD.setInput(sphere, 1);
m_pointSetToSphereCD.setGenerateCD(true, true); // Generate both A and B
......@@ -96,9 +86,6 @@ TEST_F(imstkPointSetToSphereCDTest, NonIntersectionTestAB)
EXPECT_EQ(0, colData->elementsB.getSize());
}
///
/// \brief TODO
///
int
imstkPointSetToSphereCDTest(int argc, char* argv[])
{
......
......@@ -29,11 +29,10 @@ using namespace imstk;
TEST(imstkSphereToCylinderCDTest, IntersectionTestAB)
{
SphereToCylinderCD m_sphereToCylinderCD;
auto sphere = std::make_shared<Sphere>(Vec3d(0.0, 1.0, 0.0), 0.75);
auto cylinder = std::make_shared<Cylinder>();
SphereToCylinderCD m_sphereToCylinderCD;
m_sphereToCylinderCD.setInput(sphere, 0);
m_sphereToCylinderCD.setInput(cylinder, 1);
m_sphereToCylinderCD.setGenerateCD(true, true); // Generate both A and B
......@@ -64,11 +63,10 @@ TEST(imstkSphereToCylinderCDTest, IntersectionTestAB)
TEST(imstkSphereToCylinderCDTest, NonIntersectionTestAB)
{
SphereToCylinderCD m_sphereToCylinderCD;
auto sphere = std::make_shared<Sphere>(Vec3d(0.0, 1.0, 0.0), 0.4);
auto cylinder = std::make_shared<Cylinder>();
SphereToCylinderCD m_sphereToCylinderCD;
m_sphereToCylinderCD.setInput(sphere, 0);
m_sphereToCylinderCD.setInput(cylinder, 1);
m_sphereToCylinderCD.setGenerateCD(true, true); // Generate both A and B
......
......@@ -26,23 +26,12 @@
using namespace imstk;
///
/// \brief TODO
///
class imstkSphereToSphereCDTest : public ::testing::Test
{
protected:
SphereToSphereCD m_sphereToSphereCD;
};
///
/// \brief TODO
///
TEST_F(imstkSphereToSphereCDTest, IntersectionTestAB)
TEST(imstkSphereToSphereCDTest, IntersectionTestAB)
{
auto sphere1 = std::make_shared<Sphere>(Vec3d(0.0, 0.0, 0.0), 0.5);
auto sphere2 = std::make_shared<Sphere>(Vec3d(0.0, 0.5, 0.0), 0.5);
SphereToSphereCD m_sphereToSphereCD;
m_sphereToSphereCD.setInput(sphere1, 0);
m_sphereToSphereCD.setInput(sphere2, 1);
m_sphereToSphereCD.setGenerateCD(true, true); // Generate both A and B
......@@ -71,14 +60,12 @@ TEST_F(imstkSphereToSphereCDTest, IntersectionTestAB)
EXPECT_EQ(Vec3d(0.0, 0.0, 0.0), colData->elementsB[0].m_element.m_PointDirectionElement.pt);
}
///
/// \brief TODO
///
TEST_F(imstkSphereToSphereCDTest, NonIntersectionTestAB)
TEST(imstkSphereToSphereCDTest, NonIntersectionTestAB)
{
auto sphere1 = std::make_shared<Sphere>(Vec3d(-1.0, 0.0, 0.0), 0.5);
auto sphere2 = std::make_shared<Sphere>(Vec3d(1.0, 0.0, 0.0), 0.5);
SphereToSphereCD m_sphereToSphereCD;
m_sphereToSphereCD.setInput(sphere1, 0);
m_sphereToSphereCD.setInput(sphere2, 1);
m_sphereToSphereCD.setGenerateCD(true, true); // Generate both A and B
......@@ -91,9 +78,6 @@ TEST_F(imstkSphereToSphereCDTest, NonIntersectionTestAB)
EXPECT_EQ(0, colData->elementsB.getSize());
}
///
/// \brief TODO
///
int
imstkSphereToSphereCDTest(int argc, char* argv[])
{
......
......@@ -27,25 +27,31 @@
using namespace imstk;
TEST(imstkTetraToPointSetCDTest, IntersectionTestAB)
std::shared_ptr<TetrahedralMesh>
makeUnitTetrahedron_()
{
// Create tetrahedron
auto verticesPtr = std::make_shared<VecDataArray<double, 3>>(4);
auto indicesPtr = std::make_shared<VecDataArray<int, 4>>(1);
VecDataArray<double, 3>& vertices = *verticesPtr;
VecDataArray<int, 4>& indices = *indicesPtr;
vertices[0] = Vec3d(0.0, 0.0, 0.0);
vertices[1] = Vec3d(1.0, 0.0, 0.0);
vertices[2] = Vec3d(0.0, 1.0, 0.0);
vertices[3] = Vec3d(0.0, 0.0, 1.0);
(*verticesPtr)[0] = Vec3d(0.0, 0.0, 0.0);
(*verticesPtr)[1] = Vec3d(1.0, 0.0, 0.0);
(*verticesPtr)[2] = Vec3d(0.0, 1.0, 0.0);
(*verticesPtr)[3] = Vec3d(0.0, 0.0, 1.0);
indices[0] = Vec4i(0, 1, 2, 3);
(*indicesPtr)[0] = Vec4i(0, 1, 2, 3);
auto tetMesh = std::make_shared<TetrahedralMesh>();
tetMesh->initialize(verticesPtr, indicesPtr);
return tetMesh;
}
TEST(imstkTetraToPointSetCDTest, IntersectionTestAB)
{
// Create tetrahedron
auto tetMesh = makeUnitTetrahedron_();
// Create point set
auto pointSet = std::make_shared<PointSet>();
auto verxPtr = std::make_shared<VecDataArray<double, 3>>(1);
......@@ -53,15 +59,13 @@ TEST(imstkTetraToPointSetCDTest, IntersectionTestAB)
double baryCoord[4] = { 0.2, 0.3, 0.1, 0.4 };// All non-negative and should sum to 1
// Create a point inside the tetrahedron from the barycentric coordinates
for (int i = 0; i < 4; ++i)
for (size_t i = 0; i < 4; ++i)
{
(*verxPtr)[0] += baryCoord[i] * vertices[i];
}
(*verxPtr)[0] += baryCoord[i] * tetMesh->getVertexPosition(i);
}
pointSet->initialize(verxPtr);
std::cout << (*verxPtr)[0];
// create collision
TetraToPointSetCD m_tetraToPointSetCD;
......@@ -92,26 +96,12 @@ TEST(imstkTetraToPointSetCDTest, IntersectionTestAB)
TEST(imstkTetraToPointSetCDTest, NonIntersectionTestAB)
{
// Create tetrahedron
auto verticesPtr = std::make_shared<VecDataArray<double, 3>>(4);
auto indicesPtr = std::make_shared<VecDataArray<int, 4>>(1);
VecDataArray<double, 3>& vertices = *verticesPtr;
VecDataArray<int, 4>& indices = *indicesPtr;
vertices[0] = Vec3d(0.0, 0.0, 0.0);
vertices[1] = Vec3d(1.0, 0.0, 0.0);
vertices[2] = Vec3d(0.0, 1.0, 0.0);
vertices[3] = Vec3d(0.0, 0.0, 1.0);
indices[0] = Vec4i(0, 1, 2, 3);
auto tetMesh = std::make_shared<TetrahedralMesh>();
tetMesh->initialize(verticesPtr, indicesPtr);
auto tetMesh = makeUnitTetrahedron_();
// Create point set
auto pointSet = std::make_shared<PointSet>();
auto verxPtr = std::make_shared<VecDataArray<double, 3>>(1);
(*verxPtr)[0] = Vec3d(1.0, 1.0, 1.0);
(*verxPtr)[0] = Vec3d(1.0, 1.0, 1.0);// some point outside
pointSet->initialize(verxPtr);
// create collision
......
......@@ -36,7 +36,7 @@ class VolumetricMesh : public PointSet
{
public:
///
/// \brief Deconstructor
/// \brief Destructor
///
virtual ~VolumetricMesh() override = default;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment