Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tin release 7.0 #152

Merged
merged 4 commits into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/XmsGrid-CI.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions _package/tests/unit_tests/triangulate_tests/tin_pyt.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down
2 changes: 1 addition & 1 deletion _package/xms/grid/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
from . import triangulate # NOQA: F401
from . import ugrid # NOQA: F401

__version__ = '7.7.4'
__version__ = '7.7.5'
49 changes: 28 additions & 21 deletions xmsgrid/triangulate/TrTin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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]))
{
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -1108,41 +1114,40 @@ bool TrTinImpl::OptimizeTriangulation()
{
bool modified = false;
int nTri = NumTriangles();
VecInt flags(nTri, false);
VecInt no_propagate_flags(nTri, false);

bool meshaltered;
int id;
int adjtri;

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
Expand Down Expand Up @@ -1944,11 +1949,11 @@ void TrTinUnitTests::test1()
// | | \ 3 | \ 7 |
// | | \ | \ |
// | | \ | \ |
// | | 2 \ | 6 \ |
// | | 1 \ | 5 \ |
// | | \| \|
// 10- 3------4------5
// | |\ |\ |
// | | \ 1 | \ 5 |
// | | \ 2 | \ 6 |
// | | \ | \ |
// | | \ | \ |
// | | 0 \ | 4 \ |
Expand Down Expand Up @@ -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);
Expand Down
Loading