Skip to content

Commit

Permalink
Adding marching tetrahedra to testsuite
Browse files Browse the repository at this point in the history
  • Loading branch information
ifilot committed Dec 19, 2023
1 parent 3ee8251 commit fefd6ea
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/isosurface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -503,9 +503,11 @@ void IsoSurface::construct_triangles_from_tetrahedra(float _isovalue) {
p[1] = this->interpolate_from_tetrahedra(tetrahedra_table[i], 3, 2, _isovalue);
p[2] = this->interpolate_from_tetrahedra(tetrahedra_table[i], 3, 1, _isovalue);
this->triangles.push_back(Triangle(p[0], p[1], p[2]));
break;
break;
}
}

std::cout << "Identified " << this->triangles.size() << " faces." << std::endl;
}

Vec3 IsoSurface::interpolate_from_cubes(const Cube &_cub, unsigned int _p1,
Expand Down
47 changes: 47 additions & 0 deletions src/test/test_isosurface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,53 @@ void TestIsosurface::test_marching_cubes() {
}
}

void TestIsosurface::test_marching_tetrahedra() {
// construct isosurface
IsoSurface is(this->sf.get());
is.marching_tetrahedra(0.01);

// construct mesh storage object
IsoSurfaceMesh ism(sf.get(), &is);
ism.construct_mesh(true);

CPPUNIT_ASSERT_EQUAL((size_t)24433, ism.get_vertices().size());
CPPUNIT_ASSERT_EQUAL((size_t)24433, ism.get_normals().size());
CPPUNIT_ASSERT_EQUAL((size_t)146124, ism.get_texcoords().size());

// get minimum and maximum value
float minx = 0.0;
float miny = 0.0;
float minz = 0.0;
float maxx = 0.0;
float maxy = 0.0;
float maxz = 0.0;
for(unsigned int i=0; i<ism.get_vertices().size(); i++) {
minx = std::min(minx, ism.get_vertices()[i][0]);
miny = std::min(miny, ism.get_vertices()[i][1]);
minz = std::min(minz, ism.get_vertices()[i][2]);

maxx = std::max(maxx, ism.get_vertices()[i][0]);
maxy = std::max(maxy, ism.get_vertices()[i][1]);
maxz = std::max(maxz, ism.get_vertices()[i][2]);
}

// check minimum and maximum values; note that the ordering of the
// vertices object is more-or-less random due to them being generated
// under OpenMP
CPPUNIT_ASSERT_DOUBLES_EQUAL(-1.98314094543457, minx, 1e-8);
CPPUNIT_ASSERT_DOUBLES_EQUAL(-1.98314094543457, miny, 1e-8);
CPPUNIT_ASSERT_DOUBLES_EQUAL(-1.98314094543457, minz, 1e-8);

CPPUNIT_ASSERT_DOUBLES_EQUAL(1.98314094543457, maxx, 1e-8);
CPPUNIT_ASSERT_DOUBLES_EQUAL(1.98314094543457, maxy, 1e-8);
CPPUNIT_ASSERT_DOUBLES_EQUAL(1.98314094543457, maxz, 1e-8);

// verify that all normals are, by approximation, of unit size
for(unsigned int i=0; i<ism.get_vertices().size(); i++) {
CPPUNIT_ASSERT_DOUBLES_EQUAL(1.0, ism.get_normals()[i].norm(), 1e-6);
}
}

void TestIsosurface::test_obj() {
// construct isosurface
IsoSurface is(this->sf.get());
Expand Down
2 changes: 2 additions & 0 deletions src/test/test_isosurface.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class TestIsosurface : public CppUnit::TestFixture
{
CPPUNIT_TEST_SUITE( TestIsosurface );
CPPUNIT_TEST( test_marching_cubes );
CPPUNIT_TEST( test_marching_tetrahedra );
CPPUNIT_TEST( test_obj );
CPPUNIT_TEST( test_ply );
CPPUNIT_TEST( test_stl );
Expand All @@ -42,6 +43,7 @@ class TestIsosurface : public CppUnit::TestFixture
public:
void setUp();
void test_marching_cubes();
void test_marching_tetrahedra();
void test_obj();
void test_ply();
void test_stl();
Expand Down

0 comments on commit fefd6ea

Please sign in to comment.