diff --git a/.github/workflows/XmsGrid-CI.yaml b/.github/workflows/XmsGrid-CI.yaml index 449d862b..2d211eb0 100644 --- a/.github/workflows/XmsGrid-CI.yaml +++ b/.github/workflows/XmsGrid-CI.yaml @@ -202,7 +202,7 @@ jobs: - name: Install Python Dependencies run: | python -m pip install --upgrade pip - pip install conan==1.41.0 conan-package-tools==0.35.1 devpi-client wheel MarkupSafe==2.0.0 + pip install pyYAML==5.3.1 conan==1.41.0 conan-package-tools==0.35.1 devpi-client wheel MarkupSafe==2.0.0 python -m pip install -i https://public.aquapi.aquaveo.com/aquaveo/stable/+simple/ "xmsconan>=1.0.4,<2" # Login to Aquaveo Docker - name: Login to Aquaveo Docker @@ -328,7 +328,7 @@ jobs: - name: Install Python Dependencies run: | python -m pip install --upgrade pip - pip install conan==1.41.0 conan-package-tools==0.35.1 devpi-client wheel MarkupSafe==2.0.0 + pip install pyYAML==5.3.1 conan==1.41.0 conan-package-tools==0.35.1 devpi-client wheel MarkupSafe==2.0.0 python -m pip install -i https://public.aquapi.aquaveo.com/aquaveo/stable/+simple/ "xmsconan>=1.0.4,<2" # Setup Visual Studio - name: Setup Visual Studio diff --git a/_package/tests/unit_tests/triangulate_tests/tin_pyt.py b/_package/tests/unit_tests/triangulate_tests/tin_pyt.py index e42fbcbb..6574e5ad 100644 --- a/_package/tests/unit_tests/triangulate_tests/tin_pyt.py +++ b/_package/tests/unit_tests/triangulate_tests/tin_pyt.py @@ -325,8 +325,10 @@ def test_optimize_triangulation(self): tris_adj = ((0,), (0, 1, 2, 4), (4, 5, 6), (0, 1), (2, 4, 5, 3), (6, 7), (1, 2, 3), (3, 5, 6, 7), (7,)) trtin.set_geometry(pts, tris, tris_adj) - trtin.optimize_triangulation() - np.testing.assert_array_equal(np.array(tris), trtin.triangles) + self.assertTrue(trtin.optimize_triangulation()) + tris_after = (0, 1, 3, 4, 6, 3, 1, 4, 3, 4, 7, 6, 1, 2, 4, 5, 7, 4, 2, 5, 4, 5, 8, 7) + np.testing.assert_array_equal(np.array(tris_after), trtin.triangles) + self.assertFalse(trtin.optimize_triangulation()) def test_build_tris_adj_to_pts(self): """Test building triangles adjacent to points.""" diff --git a/xmsgrid/triangulate/TrTin.cpp b/xmsgrid/triangulate/TrTin.cpp index db44cce0..b7b0e871 100644 --- a/xmsgrid/triangulate/TrTin.cpp +++ b/xmsgrid/triangulate/TrTin.cpp @@ -535,7 +535,7 @@ bool TrTinImpl::CheckAndSwap(int a_triA, int a_triB, bool a_propagate, const Vec tri2id0 = trIncrementIndex(tri2id2); tri1id2 = LocalIndex(a_triA, GlobalIndex(a_triB, tri2id0)); - SwapEdge(a_triA, a_triB, false); + change = SwapEdge(a_triA, a_triB, false); int adjTri = AdjacentTriangle(a_triA, tri1id2); if (a_propagate || (!a_propagate && adjTri != XM_NONE && a_flags[adjTri])) { @@ -548,7 +548,7 @@ bool TrTinImpl::CheckAndSwap(int a_triA, int a_triB, bool a_propagate, const Vec } } - return false; + return change; } // TrTinImpl::CheckAndSwap //------------------------------------------------------------------------------ /// \brief Returns \a true if a_localPt of a_tri2 is inside a_tri1's @@ -582,8 +582,14 @@ bool TrTinImpl::CheckAndSwap(int a_triA, int a_triB, bool a_propagate, const Vec //------------------------------------------------------------------------------ bool TrTinImpl::PointIsInCircumcircle(int a_tri1, int a_tri2, int a_localPt) { + VecPt3d& pts = *m_pts; + VecInt& tris = *m_tris; + int t = a_tri1 * 3; - return (gmPtInCircumcircle((*m_pts)[GlobalIndex(a_tri2, a_localPt)], &(*m_pts)[t]) == PT_IN); + Pt3d tri1_pts[3] = {pts[tris[t]], pts[tris[t + 1]], pts[tris[t + 2]]}; + Pt3d tri2_pt = pts[GlobalIndex(a_tri2, a_localPt)]; + + return (gmPtInCircumcircle(tri2_pt, tri1_pts) == PT_IN); } // TrTinImpl::PointIsInCircumcircle //------------------------------------------------------------------------------ /// \brief Return index of common edge between triangle and neighbor. Edge @@ -1108,7 +1114,7 @@ bool TrTinImpl::OptimizeTriangulation() { bool modified = false; int nTri = NumTriangles(); - VecInt flags(nTri, false); + VecInt no_propagate_flags(nTri, false); bool meshaltered; int id; @@ -1116,33 +1122,32 @@ bool TrTinImpl::OptimizeTriangulation() do { + VecInt local_flags(nTri, true); meshaltered = false; for (int tri = 0; tri < nTri; ++tri) { - if (flags[tri]) + id = 0; + for (int i = 0; i <= 2; i++) { - id = 0; - for (int i = 0; i <= 2; i++) + // get neighboring element + adjtri = AdjacentTriangle(tri, id); + if (adjtri != XM_NONE && local_flags[adjtri]) { - // get neighboring element - adjtri = AdjacentTriangle(tri, id); - if (adjtri != XM_NONE && flags[adjtri]) + // swap if needed and propagate + if (CheckAndSwap(tri, adjtri, false, no_propagate_flags)) { - // swap if needed and propagate - if (CheckAndSwap(tri, adjtri, false, flags)) - { - meshaltered = true; - } + meshaltered = true; } - id = trIncrementIndex(id); } + id = trIncrementIndex(id); } + local_flags[tri] = false; // don't process this triangle again } if (meshaltered) modified = true; } while (meshaltered); - return true; + return modified; } // TrTinImpl::OptimizeTriangulation //------------------------------------------------------------------------------ /// \brief finds the index of adjacent triangle that points to the current @@ -1944,11 +1949,11 @@ void TrTinUnitTests::test1() // | | \ 3 | \ 7 | // | | \ | \ | // | | \ | \ | -// | | 2 \ | 6 \ | +// | | 1 \ | 5 \ | // | | \| \| // 10- 3------4------5 // | |\ |\ | -// | | \ 1 | \ 5 | +// | | \ 2 | \ 6 | // | | \ | \ | // | | \ | \ | // | | 0 \ | 4 \ | @@ -1983,8 +1988,10 @@ void TrTinUnitTests::testOptimizeTriangulation() // Optimize TS_ASSERT(tin->OptimizeTriangulation()); - VecInt trisAfter = {0, 1, 3, 1, 6, 3, 1, 4, 6, 4, 7, 6, 1, 2, 4, 2, 7, 4, 2, 5, 7, 5, 8, 7}; - TS_ASSERT_EQUALS_VEC(trisAfter, tin->Triangles()); + VecInt trisAfter = {0, 1, 3, 4, 6, 3, 1, 4, 3, 4, 7, 6, 1, 2, 4, 5, 7, 4, 2, 5, 4, 5, 8, 7}; + VecInt tris2 = tin->Triangles(); + TS_ASSERT_EQUALS_VEC(trisAfter, tris2); + TS_ASSERT(!tin->OptimizeTriangulation()); // Test GetBoundaryPoints tin->GetBoundaryPoints(boundaryPoints);