Skip to content

Commit

Permalink
duplicate case in triangulation, and convex hull tetrahedralization test
Browse files Browse the repository at this point in the history
  • Loading branch information
odedstein committed Apr 18, 2024
1 parent edfaf0f commit d1ea45a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
7 changes: 4 additions & 3 deletions src/cpp/binding_triangulate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,17 @@ void binding_triangulate(py::module& m) {
for(int i=0; i<V.rows(); ++i) {
vertices.push_back(CDT::V2d<double>::make(V(i,0), V(i,1)));
}
CDT::Triangulation<double> cdt;
cdt.insertVertices(vertices);
std::vector<CDT::Edge> edges;
if(E.size()>0) {
for(int i=0; i<E.rows(); ++i) {
edges.emplace_back(E(i,0), E(i,1));
}
cdt.conformToEdges(edges);
}
CDT::RemoveDuplicatesAndRemapEdges(vertices,edges);
CDT::Triangulation<double> cdt;
cdt.insertVertices(vertices);
if(E.size()>0) {
cdt.conformToEdges(edges);
cdt.eraseOuterTrianglesAndHoles();
} else {
cdt.eraseSuperTriangle();
Expand Down
10 changes: 9 additions & 1 deletion test/test_tetrahedralize.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@
from scipy.stats import norm
import os

class TestTriangulate(unittest.TestCase):
class TestTetrahedralize(unittest.TestCase):
def test_sphere(self):
V,F = gpy.icosphere(3)

W0,T,TF = gpy.copyleft.tetrahedralize(V)
self.assertTrue((np.linalg.norm(W0, axis=-1)<1.+1e-6).all())
self.assertTrue(W0.shape[0]>=V.shape[0])

W1,T,TF = gpy.copyleft.tetrahedralize(V,F)
self.assertTrue((np.linalg.norm(W1, axis=-1)<1.+1e-6).all())
self.assertTrue(W1.shape[0]>=V.shape[0])
Expand All @@ -34,6 +38,10 @@ def test_meshes(self):
V,F = gpy.read_mesh("test/unit_tests_data/" + mesh)
V = gpy.normalize_points(V)

W0,T,TF = gpy.copyleft.tetrahedralize(V)
self.assertTrue((np.abs(W0)<0.5+1e-6).all())
self.assertTrue(W0.shape[0]>=V.shape[0])

W1,T,TF = gpy.copyleft.tetrahedralize(V,F)
self.assertTrue((np.abs(W1)<0.5+1e-6).all())
self.assertTrue(W1.shape[0]>=V.shape[0])
Expand Down

0 comments on commit d1ea45a

Please sign in to comment.