@@ -38,6 +38,30 @@ bool is_inverted(
3838 return false ;
3939 return true ;
4040}
41+
42+ bool is_inverted (
43+ const wmtk::delaunay::Point2D& p0,
44+ const wmtk::delaunay::Point2D& p1,
45+ const wmtk::delaunay::Point2D& p2)
46+ {
47+ const Eigen::Vector2d v0 (p0[0 ], p0[1 ]);
48+ const Eigen::Vector2d v1 (p1[0 ], p1[1 ]);
49+ const Eigen::Vector2d v2 (p2[0 ], p2[1 ]);
50+
51+ igl::predicates::exactinit ();
52+ auto res = igl::predicates::orient2d (v0, v1, v2);
53+ int result;
54+ if (res == igl::predicates::Orientation::POSITIVE )
55+ result = 1 ;
56+ else if (res == igl::predicates::Orientation::NEGATIVE )
57+ result = -1 ;
58+ else
59+ result = 0 ;
60+
61+ if (result < 0 ) // neg result == pos tet (tet origin from geogram delaunay)
62+ return true ;
63+ return false ;
64+ }
4165} // namespace
4266
4367namespace wmtk ::delaunay {
@@ -77,19 +101,19 @@ auto delaunay3D(const std::vector<Point3D>& points)
77101 }
78102
79103 // sort tets
80- for (auto & tet : tets) {
81- std::sort (tet .begin (), tet .end ());
104+ for (auto & tri : tets) {
105+ std::sort (tri .begin (), tri .end ());
82106 }
83107 std::sort (tets.begin (), tets.end ());
84108
85- for (auto & tet : tets) {
86- const Point3D p0 = points[tet [0 ]];
87- const Point3D p1 = points[tet [1 ]];
88- const Point3D p2 = points[tet [2 ]];
89- const Point3D p3 = points[tet [3 ]];
109+ for (auto & tri : tets) {
110+ const Point3D p0 = points[tri [0 ]];
111+ const Point3D p1 = points[tri [1 ]];
112+ const Point3D p2 = points[tri [2 ]];
113+ const Point3D p3 = points[tri [3 ]];
90114 if (is_inverted (p0, p1, p2, p3)) {
91115 // std::cout << "Inverted tet found" << std::endl;
92- std::swap (tet [2 ], tet [3 ]); // invert tet
116+ std::swap (tri [2 ], tri [3 ]); // invert tet
93117 }
94118 }
95119
@@ -136,6 +160,16 @@ auto delaunay2D(const std::vector<Point2D>& points)
136160 }
137161 std::sort (triangles.begin (), triangles.end ());
138162
163+ for (auto & tri : triangles) {
164+ const Point2D p0 = points[tri[0 ]];
165+ const Point2D p1 = points[tri[1 ]];
166+ const Point2D p2 = points[tri[2 ]];
167+ if (is_inverted (p0, p1, p2)) {
168+ // std::cout << "Inverted tet found" << std::endl;
169+ std::swap (tri[1 ], tri[2 ]); // invert triangle
170+ }
171+ }
172+
139173 return {vertices, triangles};
140174}
141175
0 commit comments