20 #pragma warning(disable : 4512) // boost code: no assignment operator 21 #include <boost/geometry.hpp> 22 #include <boost/geometry/geometries/point_xy.hpp> 23 #include <boost/unordered_set.hpp> 24 #include <boost/unordered_map.hpp> 62 typedef boost::unordered_map<std::pair<double, double>,
int>
PtHash;
124 BSHP<MePolyRedistributePts>
127 BSHP<MeRefinePtsToPolys>
165 MePolyMesher::MePolyMesher()
171 MePolyMesher::~MePolyMesher()
185 MePolyMesherImpl::MePolyMesherImpl()
190 , m_tin(
TrTin::New())
208 MePolyMesherImpl::~MePolyMesherImpl()
316 double minX(XM_DBL_HIGHEST), minY(XM_DBL_HIGHEST);
318 for (
size_t i = 0; i < a_outPoly.size(); ++i)
320 if (a_outPoly[i].x < minX)
322 minX = a_outPoly[i].x;
323 minY = a_outPoly[i].y;
328 if (a_outPoly[i].y < minY)
330 minX = a_outPoly[i].x;
331 minY = a_outPoly[i].y;
336 std::rotate(a_outPoly.begin(), a_outPoly.begin() + minIdx, a_outPoly.end());
364 while (
m_tin->Triangles().empty())
377 a_triangles.swap(
m_tin->Triangles());
383 a_triangles.resize(0);
389 for (
Pt3d& p : a_points)
390 p.z = (double)
m_elev->InterpToPt(p);
392 catch (std::exception& e)
394 std::string msg = e.what();
417 VecPt3d outPoly(a_outPoly.size());
418 for (
size_t i = 0; i < a_outPoly.size(); ++i)
420 outPoly[i] = a_points[a_outPoly[i]];
423 for (
size_t j = 0; j < a_inPolys.size(); ++j)
425 inPolys[j].resize(a_inPolys[j].size());
426 for (
size_t i = 0; i < a_inPolys[j].size(); ++i)
428 inPolys[j][i] = a_points[a_inPolys[j][i]];
434 MeshIt(outPoly, inPolys, 1.0, points, a_triangles);
446 a_mn = XM_DBL_HIGHEST;
447 a_mx = XM_DBL_LOWEST;
448 for (
size_t i = 0; i <
m_outPoly.size(); ++i)
479 "Seed points specified with \"Patch option.\" " 480 "These points will be ignored.");
497 for (
auto& in : inPolys)
517 boost::unordered_set<std::pair<double, double>> ptSet;
520 std::pair<double, double> pp(p.x, p.y);
523 auto itEnd = ptSet.end();
524 for (
size_t i =
m_outPoly.size(); i > 0; --i)
528 auto it = ptSet.find(pp);
535 for (
size_t i = pts.size(); i > 0; --i)
538 std::pair<double, double> pp(pts[
ix].x, pts[
ix].y);
539 auto it = ptSet.find(pp);
542 pts.erase(pts.begin() +
ix);
556 throw std::runtime_error(
"Error triangulating mesh points.");
566 ofs.open(
"C:\\temp\\TrBreaklineAdder.tin");
567 m_tin->ExportTinFile(ofs);
587 adder->AddBreakline(outPolyPtIdxs);
588 adder->AddBreaklines(inPolyPtIdxs);
611 deleter->Delete(allPolys,
m_tin);
625 for (
size_t i = 0; i <
m_inPolys.size(); ++i)
628 noDeletePts.push_back(
ix);
631 noDeletePts.push_back(
ix);
632 fixer->SetUndeleteablePtIdxs(noDeletePts);
634 size_t ptsBefore(
m_tin->Points().size());
636 if (ptsBefore !=
m_tin->Points().size())
666 std::pair<std::pair<double, double>,
int> pd;
669 for (
size_t i = 0; i < nPts; ++i)
671 pd.first.first = pts[i].x;
672 pd.first.second = pts[i].y;
678 for (
size_t i = 0; i <
m_inPolys.size(); ++i)
699 a_polyPtIdxs.resize(0);
700 size_t nPts(a_poly.size());
703 std::pair<double, double> pd;
704 for (
size_t i = 0; i < nPts; ++i)
706 pd.first = a_poly[i].x;
707 pd.second = a_poly[i].y;
711 throw std::runtime_error(
"Polygon point not in mesh points.");
714 a_polyPtIdxs.push_back(it->second);
739 static VecPt3d iArrayToVecPt3d(
int* a_array,
int a_size)
742 for (
int i = 0; i < a_size; i += 2)
744 v[i / 2].x = a_array[i];
745 v[i / 2].y = a_array[i + 1];
833 int meshPtsA[] = {0, -10, 10, -10, 20, -10, 30, -10, 40, -10, 5, -5, 15, -5, 25,
834 -5, 35, -5, 0, 0, 10, 0, 20, 0, 30, 0, 5, 5, 15, 5,
835 25, 5, 35, 5, 0, 10, 10, 10, 20, 10, 30, 10, 40, 10};
836 VecPt3d points = iArrayToVecPt3d(meshPtsA, 44);
839 int outPolyA[] = {9, 17, 18, 19, 20, 21, 16, 8, 4, 3, 2, 1, 0};
840 VecInt outPoly(&outPolyA[0], &outPolyA[13]);
841 int inPoly1[] = {14, 13, 5, 10};
842 int inPoly2[] = {7, 15, 11, 6};
844 inPolys.push_back(
VecInt(&inPoly1[0], &inPoly1[4]));
845 inPolys.push_back(
VecInt(&inPoly2[0], &inPoly2[4]));
850 BSHP<MePolyMesherImpl> mesherImp = BDPC<MePolyMesherImpl>(mesher);
852 mesherImp->TestWithPoints(outPoly, inPolys, points, triangles);
855 int trisA[] = {0, 5, 9, 5, 0, 1, 1, 2, 6, 14, 6, 11, 1, 6, 5, 5, 6, 10, 9,
856 13, 17, 17, 13, 18, 14, 10, 6, 18, 14, 19, 14, 18, 13, 9, 5, 13, 6, 2,
857 7, 3, 4, 8, 3, 8, 7, 7, 2, 3, 12, 7, 8, 19, 15, 20, 15, 19, 11,
858 12, 15, 7, 15, 12, 16, 20, 16, 21, 16, 20, 15, 12, 8, 16, 11, 19, 14};
859 VecInt trisAfter(&trisA[0], &trisA[75]);
860 TS_ASSERT_EQUALS(trisAfter, triangles);
double m_xyTol
xy tolerance used in geometric comparisons
static boost::shared_ptr< TrBreaklineAdder > New()
Redistributes the point locations on a polygon based on a size function.
void test1()
Tests the part of MePolyMesher that triangulates, adds breaklines, and removes outer triangles...
BSHP< MePolyPaverToMeshPts > m_polyPaver
class for paving from a polygon definition
void SortPoly(VecPt3d &a_outPoly)
Start polygon with lower left most point so results are consistent.
std::vector< int > VecInt
void Relax()
Relaxes the mesh points for better element quality.
std::vector< MePolyInput > m_polys
Required (but some data is optional). Inputs for each polygon.
static BSHP< MeRefinePtsToPolys > New()
Creates a new instance of this class.
Utilities related to a VTK unstructured grid (from shared1\UGridUtils.cpp)
BSHP< InterpBase > m_elev
interpolator to assign elevations to mesh points
static BSHP< MePolyRedistributePts > New()
Creates an instance of this class.
int m_polyId
id of the polygon
static BSHP< MePolyPatcher > New()
Creates a new instance of this class.
VecPt3d m_boundPtsToRemove
boundary points to remove after the paving process is complete
Creates polygon from refine point information.
void TestWithPoints(const VecInt &a_outPoly, const VecInt2d &a_inPolys, const VecPt3d &a_points, VecInt &a_triangles)
Used only for testing. Test the class by supplying the polygons and mesh points.
static BSHP< MePolyPaverToMeshPts > New()
Creates a new instance of this class.
boost::unordered_map< std::pair< double, double >, int > PtHash
typdef for a short name
BSHP< TrTin > m_tin
triangles that become mesh elements
Fills a polygon with a mesh (points and cells). Honors the polygon boundary.
static BSHP< MeRelaxer > New()
Creates a new instance of the class.
VecPt3d2d m_inPolys
inside boundaries or holes in polygon
std::vector< VecInt > VecInt2d
void ProcessBoundaryPtsFlaggedToRemove()
Remove boundary points.
double m_bias
factor that affects how quickly the size of elements transitions in the mesh
void meModifyMessageWithPolygonId(int a_polyId, std::string &a_msg)
Prepends the polygon id as part of an error messge.
PtHash m_ptHash
hash for point locations
void FindPolyPointIdxs(const VecPt3d &a_poly, VecInt &a_polyPtIdxs)
See FindAllPolyPointIdxs.
static BSHP< TrTin > New()
bool ComputeExtents(Pt3d &a_mn, Pt3d &a_mx)
Computes the extents (min, max) of the polygon.
bool MeshFromInputs(std::vector< Pt3d > &a_points, VecInt &a_triangles, VecInt &a_cells)
Creates the mesh from inputs that have set member variables in the class.
BSHP< MeRelaxer > m_relaxer
class for relaxing the location of mesh nodes
virtual void GetProcessedRefinePts(std::vector< Pt3d > &a_pts) override
Gets the refine points that were inside the polygon, both points that are included in the meshing pro...
bool m_testing
flag to indicate if we are testing the class
bool m_removeInternalFourTrianglePts
flag to indicate the removal of internal pts connected to 4 triangles will occur
std::vector< MeRefinePoint > m_refPts
Optional. Refine points.
VecPt3d m_seedPts
user generated seed points.
virtual bool MeshIt(const MeMultiPolyMesherIo &a_input, size_t a_polyIdx, VecPt3d &a_points, VecInt &a_triangles, VecInt &a_cells) override
Perform MESH_PAVE, MESH_SPAVE, MESH_PATCH meshing on a polygon.
static BSHP< TrAutoFixFourTrianglePts > New()
bool EQ_TOL(const _T &A, const _U &B, const _V &tolerance)
VecPt3d2d m_refPtPolys
refine points
Provides the input to meshing multiple polygons and holds the output.
void DeleteTrianglesOutsidePolys()
Delete triangles outside the polygon boundary or in polygon holes.
static boost::shared_ptr< TrOuterTriangleDeleter > New()
static boost::shared_ptr< MePolyMesher > New()
Creates a polymesher class.
BSHP< MeRefinePtsToPolys > m_refineToPolys
class for creating polygon from refine point information
std::vector< VecPt3d > VecPt3d2d
void GenerateMeshPts()
Creates the points in interior of the input polygon that are used to create cells.
Creates a mesh inside a polygon.
void Triangulate()
Triangulate the mesh points.
Generates mesh node locations by paving a polygon.
VecPt3d m_refPtsTooClose
refine points that can not be honored because of distance constraints
void AutoFixFourTrianglePts()
Delete internal points that are only connected to 4 triangles and retriangulates. ...
void ExportTinForDebug()
Exports the tin for debugging purposes.
VecPt3d m_refMeshPts
refine point that have been made into mesh nodes
void gmAddToExtents(const Pt3d &a_pt, Pt3d &a_min, Pt3d &a_max)
BSHP< MePolyRedistributePts > m_redist
class for performing redistribution of points along a polyline
VecPt3d m_outPoly
outer boundary of polygon being meshed
BSHP< VecPt3d > m_points
resulting mesh nodes
void FindAllPolyPointIdxs()
Find the indices of the poly points among m_points. They will most likely be at the front of m_points...
VecInt m_polyCorners
corner indexes used with mesh patch generation
VecPt3d m_points
points of the triangular mesh
void ComputeTolerance()
Computes a tolerance to use based on point extents.
void AddBreaklines()
Add the polys as breaklines in the tin.
VecInt2d m_inPolyPtIdxs
indices to the mesh points that match the inner polygon boundaries
VecInt m_outPolyPtIdxs
indices to the mesh points that match the outer polygon boundary
double gmComputeXyTol(const Pt3d &a_mn, const Pt3d &a_mx)
VecInt m_cells
Cells generated by the Patcher.
VecInt m_refPtIdxs
indices to points mesh point that match refine points
BoundaryEnum
enumeration for boundary processing
std::vector< Pt3d > VecPt3d