diff --git a/libsrc/geom2d/csg2d.cpp b/libsrc/geom2d/csg2d.cpp index 880d8547..f5f85ea7 100644 --- a/libsrc/geom2d/csg2d.cpp +++ b/libsrc/geom2d/csg2d.cpp @@ -1171,8 +1171,10 @@ next_P: ; // add duplicate vertices to P and Q auto V_P = I_P->Insert(*I_P, I_P->lam); V_P->spline = I_P->spline; + V_P->pinfo = I_P->pinfo; auto V_Q = I_Q->Insert(*I_Q, I_Q->lam); V_Q->spline = I_Q->spline; + V_Q->pinfo = I_Q->pinfo; // link vertices correctly if (sP*sQ > 0) { // same local orientation @@ -1252,6 +1254,7 @@ void CreateResult(Solid2d & sp, Solid2d & sr, bool UNION) if ((status == EXIT) ^ UNION) { vnew.info = V->info; + vnew.pinfo = V->pinfo; if(V->spline) vnew.spline = *V->spline; else @@ -1270,6 +1273,7 @@ void CreateResult(Solid2d & sp, Solid2d & sr, bool UNION) else vnew.spline = nullopt; vnew.info = V->info; + vnew.pinfo = V->pinfo; V->is_intersection = false; // mark visited vertices } if(V == I) @@ -1580,7 +1584,7 @@ bool Loop :: IsInside( Point<2> r ) const } -Solid2d :: Solid2d(const Array, EdgeInfo>> & points, string name_, string bc) +Solid2d :: Solid2d(const Array, EdgeInfo, PointInfo>> & points, string name_, string bc) : name(name_) { Loop l; @@ -1590,6 +1594,8 @@ Solid2d :: Solid2d(const Array, EdgeInfo>> & points, strin l.Append(*point, true); if(auto edge_info = std::get_if(&v)) l.first->prev->info.Assign( *edge_info ); + if(auto point_info = std::get_if(&v)) + l.first->prev->pinfo.Assign(*point_info); } for(auto v : l.Vertices(ALL)) @@ -1849,17 +1855,20 @@ shared_ptr CSG2d :: GenerateSplineGeometry() }; t_points.Start(); - auto insertPoint = [&](Point<2> p ) + auto insertPoint = [&](const Vertex& p ) { int pi = getPoint(p); if(pi==-1) { // not found -> insert to tree netgen::GeomPoint<2> gp(p); - gp.name = "default"; geo->geompoints.Append(gp); + pi = geo->geompoints.Size()-1; ptree.Insert(p,p,geo->geompoints.Size()-1); } + geo->geompoints[pi].hmax = min2(geo->geompoints[pi].hmax, p.pinfo.maxh); + if(p.pinfo.name != POINT_NAME_DEFAULT) + geo->geompoints[pi].name = p.pinfo.name; }; for(auto & s : solids) diff --git a/libsrc/geom2d/csg2d.hpp b/libsrc/geom2d/csg2d.hpp index fbb4b8b0..118060f8 100644 --- a/libsrc/geom2d/csg2d.hpp +++ b/libsrc/geom2d/csg2d.hpp @@ -65,6 +65,7 @@ enum IteratorType }; inline constexpr const double MAXH_DEFAULT{1e99}; +inline const string POINT_NAME_DEFAULT{""}; inline const string BC_DEFAULT{""}; inline const string MAT_DEFAULT{""}; @@ -93,6 +94,24 @@ struct EdgeInfo } }; +struct PointInfo +{ + double maxh = MAXH_DEFAULT; + string name = POINT_NAME_DEFAULT; + PointInfo() = default; + PointInfo(const PointInfo& other) = default; + PointInfo(double amaxh) : maxh(amaxh) {} + PointInfo(string aname) : name(aname) {} + PointInfo(double amaxh, string aname) : maxh(amaxh), name(aname) {} + + void Assign(const PointInfo& other) + { + maxh = min(maxh, other.maxh); + if(other.name != POINT_NAME_DEFAULT) + name = other.name; + } +}; + struct Vertex : Point<2> { Vertex (Point<2> p) : Point<2>(p) {} @@ -100,6 +119,7 @@ struct Vertex : Point<2> { spline = v.spline; info = v.info; + pinfo = v.pinfo; is_source = true; } @@ -117,6 +137,7 @@ struct Vertex : Point<2> // In case the edge this - next is curved, store the spline information here optional spline = nullopt; EdgeInfo info; + PointInfo pinfo; DLL_HEADER Vertex * Insert(Point<2> p, double lam = -1.0); @@ -455,6 +476,7 @@ struct Loop { auto & vnew = Append( static_cast>(v), true ); vnew.info = v.info; + vnew.pinfo = v.pinfo; if(v.spline) vnew.spline = *v.spline; if(bbox) @@ -628,7 +650,7 @@ struct Solid2d Solid2d() = default; Solid2d(string name_) : name(name_) {} - DLL_HEADER Solid2d(const Array, EdgeInfo>> & points, string name_=MAT_DEFAULT, string bc_=BC_DEFAULT); + DLL_HEADER Solid2d(const Array, EdgeInfo, PointInfo>> & points, string name_=MAT_DEFAULT, string bc_=BC_DEFAULT); Solid2d(Solid2d && other) = default; Solid2d(const Solid2d & other) = default; diff --git a/libsrc/geom2d/python_geom2d.cpp b/libsrc/geom2d/python_geom2d.cpp index b5a07a1f..b8f5a871 100644 --- a/libsrc/geom2d/python_geom2d.cpp +++ b/libsrc/geom2d/python_geom2d.cpp @@ -399,7 +399,7 @@ DLL_HEADER void ExportGeom2d(py::module &m) py::class_(m, "Solid2d") .def(py::init<>()) - .def(py::init, EdgeInfo>>, std::string, std::string>(), py::arg("points"), py::arg("mat")=MAT_DEFAULT, py::arg("bc")=BC_DEFAULT) + .def(py::init, EdgeInfo, PointInfo>>, std::string, std::string>(), py::arg("points"), py::arg("mat")=MAT_DEFAULT, py::arg("bc")=BC_DEFAULT) .def(py::self+py::self) .def(py::self-py::self) @@ -431,10 +431,10 @@ DLL_HEADER void ExportGeom2d(py::module &m) { using P = Point<2>; return { { - p0, bottom ? *bottom : bc, - P{p1[0],p0[1]}, right ? *right : bc, - p1, top ? *top : bc, - P{p0[0],p1[1]}, left ? *left : bc, + p0, EdgeInfo{bottom ? *bottom : bc}, + P{p1[0],p0[1]}, EdgeInfo {right ? *right : bc}, + p1, EdgeInfo {top ? *top : bc}, + P{p0[0],p1[1]}, EdgeInfo {left ? *left : bc}, }, mat}; }, "pmin"_a, "pmax"_a, "mat"_a=MAT_DEFAULT, "bc"_a=BC_DEFAULT, @@ -475,6 +475,12 @@ DLL_HEADER void ExportGeom2d(py::module &m) .def(py::init(), py::arg("bc")) .def(py::init>, double, string>(), py::arg("control_point")=nullopt, py::arg("maxh")=MAXH_DEFAULT, py::arg("bc")=BC_DEFAULT) ; + py::class_(m, "PointInfo") + .def(py::init<>()) + .def(py::init(), "maxh"_a) + .def(py::init(), "name"_a) + .def(py::init(), "maxh"_a, "name"_a) + ; } PYBIND11_MODULE(libgeom2d, m) { diff --git a/python/geom2d.py b/python/geom2d.py index c4cdf3c7..886bfb60 100644 --- a/python/geom2d.py +++ b/python/geom2d.py @@ -1,4 +1,4 @@ -from .libngpy._geom2d import SplineGeometry, Solid2d, CSG2d, Rectangle, Circle, EdgeInfo +from .libngpy._geom2d import SplineGeometry, Solid2d, CSG2d, Rectangle, Circle, EdgeInfo, PointInfo from .meshing import meshsize unit_square = SplineGeometry()