20 if(!std::isfinite(maxArea) || maxArea<=0.0)
22 throw std::invalid_argument(
"Plane mesh area must be finite and positive");
24 const double scale=(
mesh.xMax()-
mesh.xMin()).norm();
25 const double tolerance=1.e-10*scale;
27 std::vector<std::deque<Eigen::Vector2d>> sections;
30 std::vector<Eigen::Vector2d> points;
31 const auto addPoint=[&](
const Eigen::Vector3d& point)
33 const Eigen::Vector2d local=plane.localPosition(point);
34 for(
const auto& existing : points)
36 if((existing-local).norm()<=tolerance)
41 points.push_back(local);
43 for(
const auto& entry : region.second->faces())
45 const auto& hull=entry.second->convexHull();
46 for(
size_t k=0;
k<hull.size();++
k)
48 const auto&
a=hull[
k]->P0;
49 const auto&
b=hull[(
k+1)%hull.size()]->P0;
50 const double da=(
a-plane.P).dot(plane.unitNormal);
51 const double db=(
b-plane.P).dot(plane.unitNormal);
52 if(std::abs(da)<=tolerance)
56 if((da>tolerance && db< -tolerance) || (da< -tolerance && db>tolerance))
58 addPoint(
a+(da/(da-db))*(
b-
a));
66 std::sort(points.begin(),points.end(),[](
const auto&
a,
const auto&
b)
68 return a.x()<b.x() || (a.x()==b.x() && a.y()<b.y());
70 const auto cross=[](
const Eigen::Vector2d&
a,
const Eigen::Vector2d&
b,
const Eigen::Vector2d&
c)
72 return (
b.x()-
a.x())*(
c.y()-
a.y())-(
b.y()-
a.y())*(
c.x()-
a.x());
74 std::deque<Eigen::Vector2d> hull;
75 for(
const auto& point : points)
77 while(hull.size()>1 && cross(hull[hull.size()-2],hull.back(),point)<=tolerance*tolerance)
81 hull.push_back(point);
83 const auto lowerSize=hull.size();
84 for(
auto it=points.rbegin()+1;it!=points.rend();++it)
86 while(hull.size()>lowerSize && cross(hull[hull.size()-2],hull.back(),*it)<=tolerance*tolerance)
100 for(
const auto& previous : sections)
102 if(previous.size()!=hull.size())
107 for(
const auto& point : hull)
109 same=same && std::any_of(previous.begin(),previous.end(),[&](
const auto& other)
111 return (point-other).norm()<=tolerance;
114 duplicate=duplicate || same;
120 sections.push_back(hull);
122 part.
reMesh(hull,std::deque<Eigen::Vector2d>(),maxArea,
"pazqQ");
123 const int offset=
result.vertices().size();
127 result.triangles().push_back(
triangle+Eigen::Vector3i::Constant(offset));
void reMesh(const std::deque< Eigen::Matrix< double, 2, 1 > > &boundaryPts, const std::deque< Eigen::Matrix< double, 2, 1 > > &internalPts, const double &meshSize, const std::string &flags)