Skip to content

Commit

Permalink
-bug fix for case where the mesher would create points with NAN for t…
Browse files Browse the repository at this point in the history
…he x,y coordinates
  • Loading branch information
alemon-aquaveo authored and gagelarsen committed Jan 13, 2021
1 parent d792e04 commit e5d4435
Show file tree
Hide file tree
Showing 10 changed files with 8,855 additions and 8,721 deletions.
8,752 changes: 4,373 additions & 4,379 deletions test_files/meshing/CasePaveSanDiegoSpringRelax_base.2dm

Large diffs are not rendered by default.

8,674 changes: 4,334 additions & 4,340 deletions test_files/meshing/CasePaveSanDiego_base.2dm

Large diffs are not rendered by default.

36 changes: 36 additions & 0 deletions test_files/meshing/bug12780.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
BEGIN_POLYGON
OUTSIDE 30
537853.398 163963.544
537855.0 163960.0
537857.0 163957.961
537856.5 163955.143
537856.0 163953.0
537857.0 163953.0
537857.187 163951.199
537856.95 163948.975
537858.0 163947.0
537858.0 163946.0
537860.143 163946.5
537859.627 163949.132
537859.667 163952.667
537858.857 163955.5
537858.522 163957.931
537857.816 163960.761
537858.511 163961.681
537859.272 163957.909
537859.653 163956.024
537860.033 163954.138
537860.414 163952.252
537860.794 163950.366
537861.554 163946.6
537857.453 163945.542
537856.692 163949.413
537856.312 163951.348
537855.931 163953.284
537855.17 163957.155
537854.41 163961.02
537853.57 163962.313
BIAS 0.3
ELEVATION_FUNCTION
END_POLYGON
RETURN_CELL_POLYGONS
59 changes: 59 additions & 0 deletions test_files/meshing/bug12780_base.2dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
MESH2D
E3T 1 1 29 2 1
E3T 2 1 30 29 1
E3T 3 2 28 3 1
E3T 4 2 29 28 1
E3T 5 3 28 4 1
E3T 6 4 27 5 1
E3T 7 4 28 27 1
E3T 8 5 26 6 1
E3T 9 5 27 26 1
E3T 10 6 26 7 1
E3T 11 7 25 8 1
E3T 12 7 26 25 1
E3T 13 8 24 9 1
E3T 14 8 25 24 1
E3T 15 9 24 10 1
E3T 16 10 24 11 1
E3T 17 11 23 12 1
E3T 18 11 24 23 1
E3T 19 12 22 13 1
E3T 20 12 23 22 1
E3T 21 13 20 14 1
E3T 22 13 21 20 1
E3T 23 13 22 21 1
E3T 24 14 19 15 1
E3T 25 14 20 19 1
E3T 26 15 18 16 1
E3T 27 15 19 18 1
E3T 28 16 18 17 1
ND 1 537853.398 163963.544 0.0
ND 2 537855.0 163960.0 0.0
ND 3 537857.0 163957.961 0.0
ND 4 537856.5 163955.143 0.0
ND 5 537856.0 163953.0 0.0
ND 6 537857.0 163953.0 0.0
ND 7 537857.187 163951.199 0.0
ND 8 537856.95 163948.975 0.0
ND 9 537858.0 163947.0 0.0
ND 10 537858.0 163946.0 0.0
ND 11 537860.143 163946.5 0.0
ND 12 537859.627 163949.132 0.0
ND 13 537859.667 163952.667 0.0
ND 14 537858.857 163955.5 0.0
ND 15 537858.522 163957.931 0.0
ND 16 537857.816 163960.761 0.0
ND 17 537858.511 163961.681 0.0
ND 18 537859.272 163957.909 0.0
ND 19 537859.653 163956.024 0.0
ND 20 537860.033 163954.138 0.0
ND 21 537860.414 163952.252 0.0
ND 22 537860.794 163950.366 0.0
ND 23 537861.554 163946.6 0.0
ND 24 537857.453 163945.542 0.0
ND 25 537856.692 163949.413 0.0
ND 26 537856.312 163951.348 0.0
ND 27 537855.931 163953.284 0.0
ND 28 537855.17 163957.155 0.0
ND 29 537854.41 163961.02 0.0
ND 30 537853.57 163962.313 0.0
7 changes: 7 additions & 0 deletions xmsmesher/meshing/MeMultiPolyTo2dm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -798,4 +798,11 @@ void MeMultiPolyTo2dmIntermediateTests::testbug11646()
{
iTestFromPolyFile("bug11646", 10);
} // MeMultiPolyTo2dmIntermediateTests::testbug11646
//------------------------------------------------------------------------------
/// \brief Test for a bug where points are created with NAN coordinates
//------------------------------------------------------------------------------
void MeMultiPolyTo2dmIntermediateTests::testbug12780()
{
iTestFromPolyFile("bug12780", 10);
} // MeMultiPolyTo2dmIntermediateTests::testbug12780
#endif // CXX_TEST
1 change: 1 addition & 0 deletions xmsmesher/meshing/MeMultiPolyTo2dm.t.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class MeMultiPolyTo2dmIntermediateTests : public CxxTest::TestSuite
void testInternalFeaturesCase2();
void testInternalFeaturesCase3();
void testbug11646();
void testbug12780();
};

//} // namespace xms
Expand Down
36 changes: 36 additions & 0 deletions xmsmesher/meshing/detail/MePolyCleaner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <xmscore/misc/XmError.h>

// 5. Shared code headers
#include <xmsgrid/geometry/GmPolygon.h>
#include <xmsmesher/meshing/detail/MePolyOffsetter.h>
#include <xmsmesher/meshing/detail/MeIntersectPolys.h>
#include <xmsmesher/meshing/detail/MePolyPts.h>
Expand Down Expand Up @@ -147,6 +148,41 @@ void MePolyCleanerImpl::CleanPolyOffset(const std::vector<Pt3d>& a_input,
// we delete any polygons with an area that has
// the opposite sign from what we are expecting
polyPts.RemoveBackwardLoopsForCleanPolyOffset(loops, a_pType);
// make sure that points in a loop are inside of the original outside polygon
if (MePolyOffsetter::OUTSIDE_POLY == a_pType && !m_origOutsidePoly.empty())
{
BSHP<GmPolygon> gmPoly = GmPolygon::New();
VecPt3d2d insidePolys;
gmPoly->Setup(m_origOutsidePoly, insidePolys);
auto it = loops.begin();
while (it != loops.end())
{
VecSizet& loop(*it);
for (size_t j = loop.size(); j > 0; --j)
{
Pt3d pt = polyPts.Pts()[loop[j - 1]];
if (!gmPoly->Within(pt))
{
loop.erase(loop.begin() + j - 1);
}
}
//bool out = false;
//for (auto& idx : loop)
//{
// Pt3d pt = polyPts.Pts()[idx];
// if (!gmPoly->Within(pt))
// {
// out = true;
// }
//}
auto itToDelete = it;
it++;
if (loop.empty())
{
loops.erase(itToDelete);
}
}
}
}
else
{ // There are more rules when dealing with paving outward from polygons.
Expand Down
4 changes: 4 additions & 0 deletions xmsmesher/meshing/detail/MePolyOffsetter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,10 @@ bool MePolyOffsetterImpl::DoOffset(const std::vector<Pt3d>& a_input)
SpecialRejection(a_input, result);
if (result.size() < 3)
return false;
if (m_pType == MePolyOffsetter::OUTSIDE_POLY)
{
m_intersector->SetOriginalOutsidePolygon(a_input);
}
SelfIntersection(result);
FindDuplicatesAndOrderLoops(result);
return rval;
Expand Down
2 changes: 0 additions & 2 deletions xmsmesher/meshing/detail/MePolyPaverToMeshPts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -382,8 +382,6 @@ void MePolyPaverToMeshPtsImpl::RedistributePts()
/// \brief Create new polygons to put onto the processing stack. These are the
/// polygons that are left after paving, cleaning, redistributing points, and
/// cleaning again.
/// \param [in] a_iter Tells what iteration this is from the boundary of the
/// polygon.
//------------------------------------------------------------------------------
void MePolyPaverToMeshPtsImpl::ClassifyPolys()
{
Expand Down
5 changes: 5 additions & 0 deletions xmsmesher/meshing/detail/MeRelaxer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,11 @@ void MeRelaxerImpl::AreaRelax(int a_point, Pt3d& a_newLocation)
sumy += area * m_centroids[adjTris[i]].y;
sumarea += area;
}
if (sumarea == 0)
{
a_newLocation = m_tin->Points()[a_point];
return;
}

a_newLocation.x = sumx / sumarea;
a_newLocation.y = sumy / sumarea;
Expand Down

0 comments on commit e5d4435

Please sign in to comment.