2014-09-10 17:16:09 +06:00
|
|
|
#ifdef NG_PYTHON
|
|
|
|
|
2014-10-08 21:48:48 +06:00
|
|
|
#include <../general/ngpython.hpp>
|
2019-07-11 19:23:22 +05:00
|
|
|
#include <core/python_ngcore.hpp>
|
2019-07-26 02:25:58 +05:00
|
|
|
#include "../meshing/python_mesh.hpp"
|
2014-10-08 21:48:48 +06:00
|
|
|
|
2014-09-10 17:16:09 +06:00
|
|
|
#include <meshing.hpp>
|
|
|
|
#include <geometry2d.hpp>
|
|
|
|
|
|
|
|
using namespace netgen;
|
2016-08-26 17:33:57 +05:00
|
|
|
|
2015-08-08 15:58:41 +05:00
|
|
|
namespace netgen
|
|
|
|
{
|
|
|
|
extern std::shared_ptr<NetgenGeometry> ng_geometry;
|
|
|
|
}
|
|
|
|
|
2016-11-04 16:14:52 +05:00
|
|
|
|
|
|
|
DLL_HEADER void ExportGeom2d(py::module &m)
|
2014-09-10 17:16:09 +06:00
|
|
|
{
|
2019-01-23 14:35:20 +05:00
|
|
|
py::class_<SplineSegExt, shared_ptr<SplineSegExt>>
|
|
|
|
(m, "Spline", "Spline of a SplineGeometry object")
|
|
|
|
.def_property("leftdom", [] (SplineSegExt& self) { return self.leftdom; },
|
|
|
|
[](SplineSegExt& self, int dom) { self.leftdom = dom; })
|
|
|
|
.def_property("rightdom", [] (SplineSegExt& self) { return self.rightdom; },
|
|
|
|
[](SplineSegExt& self, int dom) { self.rightdom = dom; })
|
|
|
|
.def_property_readonly("bc", [] (SplineSegExt& self) { return self.bc; })
|
|
|
|
.def("GetNormal", [](SplineSegExt& self, double t)
|
|
|
|
{
|
|
|
|
auto tang = self.GetTangent(t).Normalize();
|
|
|
|
return Vec<2>(tang[1], -tang[0]);
|
|
|
|
})
|
|
|
|
.def("StartPoint", [](SplineSegExt& self) { return Point<2>(self.StartPI()); })
|
|
|
|
.def("EndPoint", [](SplineSegExt& self) { return Point<2>(self.EndPI()); })
|
|
|
|
;
|
|
|
|
|
2017-01-05 09:08:24 +05:00
|
|
|
py::class_<SplineGeometry2d, NetgenGeometry, shared_ptr<SplineGeometry2d>>
|
2016-11-04 16:14:52 +05:00
|
|
|
(m, "SplineGeometry",
|
2018-12-30 19:27:48 +05:00
|
|
|
"a 2d boundary representation geometry model by lines and splines",
|
|
|
|
py::multiple_inheritance())
|
2016-11-04 16:14:52 +05:00
|
|
|
.def(py::init<>())
|
2018-12-14 16:01:58 +05:00
|
|
|
.def(py::init([](const string& filename)
|
|
|
|
{
|
|
|
|
auto geo = make_shared<SplineGeometry2d>();
|
|
|
|
geo->Load(filename.c_str());
|
|
|
|
ng_geometry = geo;
|
|
|
|
return geo;
|
|
|
|
}))
|
2018-12-20 21:01:27 +05:00
|
|
|
.def(NGSPickle<SplineGeometry2d>())
|
|
|
|
.def("Load",&SplineGeometry2d::Load)
|
2015-10-15 19:11:23 +05:00
|
|
|
.def("AppendPoint", FunctionPointer
|
2018-12-04 10:58:08 +05:00
|
|
|
([](SplineGeometry2d &self, double px, double py, double maxh, double hpref, string name)
|
2015-10-15 19:11:23 +05:00
|
|
|
{
|
|
|
|
Point<2> p;
|
|
|
|
p(0) = px;
|
|
|
|
p(1) = py;
|
|
|
|
GeomPoint<2> gp(p);
|
|
|
|
gp.hmax = maxh;
|
2016-07-08 20:40:59 +05:00
|
|
|
gp.hpref = hpref;
|
2018-12-04 10:58:08 +05:00
|
|
|
gp.name = name;
|
2015-10-15 19:11:23 +05:00
|
|
|
self.geompoints.Append(gp);
|
|
|
|
return self.geompoints.Size()-1;
|
|
|
|
}),
|
2018-12-04 10:58:08 +05:00
|
|
|
py::arg("x"), py::arg("y"), py::arg("maxh") = 1e99, py::arg("hpref")=0, py::arg("name")="")
|
2016-11-04 16:14:52 +05:00
|
|
|
.def("Append", FunctionPointer([](SplineGeometry2d &self, py::list segment, int leftdomain, int rightdomain,
|
2019-08-27 17:00:44 +05:00
|
|
|
optional<variant<int, string>> bc, optional<int> copy, double maxh,
|
2019-09-13 12:09:56 +05:00
|
|
|
double hpref, double hprefleft, double hprefright)
|
2014-09-10 17:16:09 +06:00
|
|
|
{
|
2019-08-27 17:00:44 +05:00
|
|
|
auto segtype = py::cast<std::string>(segment[0]);
|
2015-10-30 23:50:40 +05:00
|
|
|
|
|
|
|
SplineSegExt * seg;
|
2019-08-27 17:00:44 +05:00
|
|
|
if (segtype == "line")
|
2015-10-30 23:50:40 +05:00
|
|
|
{
|
2019-08-27 17:00:44 +05:00
|
|
|
LineSeg<2> * l = new LineSeg<2>(self.GetPoint(py::cast<int>(segment[1])),
|
|
|
|
self.GetPoint(py::cast<int>(segment[2])));
|
2015-10-30 23:50:40 +05:00
|
|
|
seg = new SplineSegExt(*l);
|
|
|
|
}
|
2019-08-27 17:00:44 +05:00
|
|
|
else if (segtype == "spline3")
|
2015-10-30 23:50:40 +05:00
|
|
|
{
|
2019-08-27 17:00:44 +05:00
|
|
|
SplineSeg3<2> * seg3 = new SplineSeg3<2>(self.GetPoint(py::cast<int>(segment[1])),
|
|
|
|
self.GetPoint(py::cast<int>(segment[2])),
|
|
|
|
self.GetPoint(py::cast<int>(segment[3])));
|
2015-10-30 23:50:40 +05:00
|
|
|
seg = new SplineSegExt(*seg3);
|
|
|
|
}
|
|
|
|
else
|
2019-08-27 17:00:44 +05:00
|
|
|
throw Exception("Appended segment is not a line or a spline3");
|
2015-10-30 23:50:40 +05:00
|
|
|
seg->leftdom = leftdomain;
|
|
|
|
seg->rightdom = rightdomain;
|
2015-11-01 16:07:26 +05:00
|
|
|
seg->hmax = maxh;
|
2019-09-13 12:09:56 +05:00
|
|
|
seg->hpref_left = max(hpref, hprefleft);
|
|
|
|
seg->hpref_right = max(hpref,hprefright);
|
2015-10-30 23:50:40 +05:00
|
|
|
seg->reffak = 1;
|
|
|
|
seg->copyfrom = -1;
|
2019-08-27 17:00:44 +05:00
|
|
|
if (copy.has_value())
|
|
|
|
seg->copyfrom = *copy+1;
|
|
|
|
|
|
|
|
if (bc.has_value())
|
2015-10-30 23:50:40 +05:00
|
|
|
{
|
2019-08-27 17:00:44 +05:00
|
|
|
if(auto intptr = get_if<int>(&*bc); intptr)
|
|
|
|
seg->bc = *intptr;
|
|
|
|
else
|
|
|
|
{
|
2019-08-27 21:44:23 +05:00
|
|
|
auto bcname = get_if<string>(&*bc);
|
2019-08-27 17:00:44 +05:00
|
|
|
seg->bc = self.GetNSplines() + 1;
|
2019-08-27 21:44:23 +05:00
|
|
|
self.SetBCName(seg->bc, *bcname);
|
2019-08-27 17:00:44 +05:00
|
|
|
}
|
2015-10-30 23:50:40 +05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
seg->bc = self.GetNSplines()+1;
|
|
|
|
self.AppendSegment(seg);
|
2016-10-20 15:28:51 +05:00
|
|
|
return self.GetNSplines()-1;
|
2016-11-04 18:55:15 +05:00
|
|
|
}), py::arg("point_indices"), py::arg("leftdomain") = 1, py::arg("rightdomain") = py::int_(0),
|
2019-08-27 17:00:44 +05:00
|
|
|
py::arg("bc")=nullopt, py::arg("copy")=nullopt, py::arg("maxh")=1e99,
|
2019-09-13 12:09:56 +05:00
|
|
|
py::arg("hpref")=0,py::arg("hprefleft")=0,py::arg("hprefright")=0)
|
2014-09-16 22:39:54 +06:00
|
|
|
|
2015-10-30 23:50:40 +05:00
|
|
|
|
2016-11-04 16:14:52 +05:00
|
|
|
.def("AppendSegment", FunctionPointer([](SplineGeometry2d &self, py::list point_indices, int leftdomain, int rightdomain)
|
2015-10-30 23:50:40 +05:00
|
|
|
{
|
2016-11-04 16:14:52 +05:00
|
|
|
int npts = py::len(point_indices);
|
2014-09-16 22:39:54 +06:00
|
|
|
SplineSegExt * seg;
|
2016-11-04 16:14:52 +05:00
|
|
|
//int a = py::extract<int>(point_indices[0]);
|
2014-09-16 22:39:54 +06:00
|
|
|
if (npts == 2)
|
|
|
|
{
|
2016-11-04 16:14:52 +05:00
|
|
|
LineSeg<2> * l = new LineSeg<2>(self.GetPoint(py::extract<int>(point_indices[0])()), self.GetPoint(py::extract<int>(point_indices[1])()));
|
2014-09-16 22:39:54 +06:00
|
|
|
seg = new SplineSegExt(*l);
|
|
|
|
|
|
|
|
}
|
|
|
|
else if (npts == 3)
|
|
|
|
{
|
2016-11-04 16:14:52 +05:00
|
|
|
SplineSeg3<2> * seg3 = new SplineSeg3<2>(self.GetPoint(py::extract<int>(point_indices[0])()), self.GetPoint(py::extract<int>(point_indices[1])()), self.GetPoint(py::extract<int>(point_indices[2])()));
|
2014-09-16 22:39:54 +06:00
|
|
|
seg = new SplineSegExt(*seg3);
|
|
|
|
|
|
|
|
}
|
2019-08-27 17:00:44 +05:00
|
|
|
else
|
|
|
|
throw Exception("Can only append segments with 2 or 3 points!");
|
2014-09-16 22:39:54 +06:00
|
|
|
seg->leftdom = leftdomain;
|
|
|
|
seg->rightdom = rightdomain;
|
2014-09-10 17:16:09 +06:00
|
|
|
seg->hmax = 1e99;
|
|
|
|
seg->reffak = 1;
|
|
|
|
seg->copyfrom = -1;
|
|
|
|
self.AppendSegment(seg);
|
2016-11-04 18:55:15 +05:00
|
|
|
}), py::arg("point_indices"), py::arg("leftdomain") = 1, py::arg("rightdomain") = py::int_(0))
|
2015-09-12 18:02:56 +05:00
|
|
|
|
2019-05-13 11:43:54 +05:00
|
|
|
|
|
|
|
.def("AddCurve",
|
|
|
|
[] (SplineGeometry2d & self, py::object func,
|
|
|
|
int leftdomain, int rightdomain, py::object bc, double maxh)
|
|
|
|
{
|
|
|
|
int n = 1000;
|
2019-07-09 13:39:16 +05:00
|
|
|
NgArray<Point<2>> points;
|
2019-05-13 11:43:54 +05:00
|
|
|
for (int i = 0; i <= n; i++)
|
|
|
|
{
|
|
|
|
double t = double(i)/n;
|
|
|
|
py::tuple xy = func(t);
|
|
|
|
double x = py::cast<double>(xy[0]);
|
|
|
|
double y = py::cast<double>(xy[1]);
|
|
|
|
points.Append (Point<2>(x,y));
|
|
|
|
}
|
|
|
|
auto spline = new DiscretePointsSeg<2> (points);
|
|
|
|
SplineSegExt * spex = new SplineSegExt (*spline);
|
|
|
|
|
|
|
|
spex -> leftdom = leftdomain;
|
|
|
|
spex -> rightdom = rightdomain;
|
|
|
|
spex->hmax = maxh;
|
|
|
|
spex->reffak = 1;
|
|
|
|
spex->copyfrom = -1;
|
|
|
|
|
|
|
|
if (py::extract<int>(bc).check())
|
|
|
|
spex->bc = py::extract<int>(bc)();
|
|
|
|
else if (py::extract<string>(bc).check())
|
|
|
|
{
|
|
|
|
string bcname = py::extract<string>(bc)();
|
|
|
|
spex->bc = self.GetNSplines()+1;
|
|
|
|
self.SetBCName(spex->bc, bcname);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
spex->bc = self.GetNSplines()+1;
|
|
|
|
|
|
|
|
|
|
|
|
self.AppendSegment (spex);
|
|
|
|
}, py::arg("func"), py::arg("leftdomain") = 1, py::arg("rightdomain") = py::int_(0),
|
|
|
|
py::arg("bc")=NGDummyArgument(), py::arg("maxh")=1e99,
|
|
|
|
"Curve is given as parametrization on the interval [0,1]")
|
|
|
|
|
2015-09-12 18:02:56 +05:00
|
|
|
.def("SetMaterial", &SplineGeometry2d::SetMaterial)
|
2015-10-30 23:50:40 +05:00
|
|
|
.def("SetDomainMaxH", &SplineGeometry2d::SetDomainMaxh)
|
|
|
|
|
2019-01-23 14:35:20 +05:00
|
|
|
.def("GetBCName", [](SplineGeometry2d& self, size_t index) { return self.GetBCName(index); })
|
2015-10-30 23:50:40 +05:00
|
|
|
|
2019-01-23 14:35:20 +05:00
|
|
|
.def("GetNDomains", [](SplineGeometry2d& self) { return self.GetNDomains(); })
|
2015-10-30 23:50:40 +05:00
|
|
|
|
2019-01-23 14:35:20 +05:00
|
|
|
.def("GetNSplines", [](SplineGeometry2d& self) { return self.splines.Size(); })
|
|
|
|
.def("GetSpline", [](SplineGeometry2d& self, size_t index)
|
|
|
|
{ return shared_ptr<SplineSegExt>(&self.GetSpline(index), NOOP_Deleter); },
|
|
|
|
py::return_value_policy::reference_internal)
|
|
|
|
.def("GetNPoints", [](SplineGeometry2d& self) { return self.GetNP(); })
|
|
|
|
.def("GetPoint", [](SplineGeometry2d& self, size_t index) { return Point<2>(self.GetPoint(index)); })
|
2015-09-12 18:02:56 +05:00
|
|
|
|
2014-09-10 17:16:09 +06:00
|
|
|
.def("PlotData", FunctionPointer([](SplineGeometry2d &self)
|
|
|
|
{
|
|
|
|
Box<2> box(self.GetBoundingBox());
|
|
|
|
double xdist = box.PMax()(0) - box.PMin()(0);
|
|
|
|
double ydist = box.PMax()(1) - box.PMin()(1);
|
2016-11-04 16:14:52 +05:00
|
|
|
py::tuple xlim = py::make_tuple(box.PMin()(0) - 0.1*xdist, box.PMax()(0) + 0.1*xdist);
|
|
|
|
py::tuple ylim = py::make_tuple(box.PMin()(1) - 0.1*ydist, box.PMax()(1) + 0.1*ydist);
|
2014-09-10 17:16:09 +06:00
|
|
|
|
2016-11-04 16:14:52 +05:00
|
|
|
py::list xpoints, ypoints;
|
2014-09-10 17:16:09 +06:00
|
|
|
|
|
|
|
for (int i = 0; i < self.splines.Size(); i++)
|
|
|
|
{
|
2016-11-04 16:14:52 +05:00
|
|
|
py::list xp, yp;
|
2014-09-10 17:16:09 +06:00
|
|
|
if (self.splines[i]->GetType().compare("line")==0)
|
|
|
|
{
|
2014-09-16 22:39:54 +06:00
|
|
|
GeomPoint<2> p1 = self.splines[i]->StartPI();
|
|
|
|
GeomPoint<2> p2 = self.splines[i]->EndPI();
|
2016-11-04 16:14:52 +05:00
|
|
|
xp.append(py::cast(p1(0)));
|
|
|
|
xp.append(py::cast(p2(0)));
|
|
|
|
yp.append(py::cast(p1(1)));
|
|
|
|
yp.append(py::cast(p2(1)));
|
2014-09-10 17:16:09 +06:00
|
|
|
}
|
|
|
|
else if (self.splines[i]->GetType().compare("spline3")==0)
|
|
|
|
{
|
|
|
|
double len = self.splines[i]->Length();
|
|
|
|
int n = floor(len/(0.05*min(xdist,ydist)));
|
2014-09-16 22:39:54 +06:00
|
|
|
|
|
|
|
for (int j = 0; j <= n; j++)
|
2014-09-10 17:16:09 +06:00
|
|
|
{
|
|
|
|
GeomPoint<2> point = self.splines[i]->GetPoint(j*1./n);
|
2016-11-04 16:14:52 +05:00
|
|
|
xp.append(py::cast(point(0)));
|
|
|
|
yp.append(py::cast(point(1)));
|
2014-09-10 17:16:09 +06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
cout << "spline is neither line nor spline3" << endl;
|
|
|
|
}
|
2016-12-01 18:24:30 +05:00
|
|
|
xpoints.append(xp);
|
|
|
|
ypoints.append(yp);
|
2014-09-10 17:16:09 +06:00
|
|
|
|
|
|
|
}
|
2016-11-04 16:14:52 +05:00
|
|
|
return py::tuple(py::make_tuple(xlim, ylim, xpoints, ypoints));
|
2014-09-10 17:16:09 +06:00
|
|
|
|
|
|
|
}))
|
2018-07-12 19:35:52 +05:00
|
|
|
.def("_visualizationData", [](SplineGeometry2d &self)
|
|
|
|
{
|
|
|
|
Box<2> box(self.GetBoundingBox());
|
|
|
|
double xdist = box.PMax()(0) - box.PMin()(0);
|
|
|
|
double ydist = box.PMax()(1) - box.PMin()(1);
|
|
|
|
py::dict data;
|
|
|
|
py::dict segment_data;
|
|
|
|
auto min_val = py::make_tuple(box.PMin()(0), box.PMin()(1),0);
|
|
|
|
auto max_val = py::make_tuple(box.PMax()(1),box.PMax()(1),0);
|
|
|
|
py::list vertices;
|
|
|
|
py::list domains;
|
|
|
|
py::list segment_points;
|
|
|
|
py::list segment_normals;
|
|
|
|
py::list leftdom;
|
|
|
|
py::list rightdom;
|
|
|
|
int max_bcnr = 0;
|
|
|
|
for(int i = 0; i < self.splines.Size(); i++)
|
|
|
|
{
|
|
|
|
std::vector<netgen::GeomPoint<2>> lst;
|
|
|
|
if (self.splines[i]->GetType().compare("line") == 0)
|
|
|
|
lst = { self.splines[i]->StartPI(), self.splines[i]->EndPI() };
|
|
|
|
else if(self.splines[i]->GetType().compare("spline3") == 0)
|
|
|
|
{
|
|
|
|
double len = self.splines[i]->Length();
|
|
|
|
int n = floor(len/(0.05*min(xdist,ydist)));
|
|
|
|
lst.push_back(self.splines[i]->StartPI());
|
|
|
|
for (int j = 1; j < n; j++){
|
|
|
|
lst.push_back(self.splines[i]->GetPoint(j*1./n));
|
|
|
|
lst.push_back(self.splines[i]->GetPoint(j*1./n));
|
|
|
|
}
|
|
|
|
lst.push_back(self.splines[i]->EndPI());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
throw NgException("Spline is neither line nor spline3");
|
|
|
|
}
|
|
|
|
for (auto point : lst)
|
|
|
|
{
|
|
|
|
for(auto val : {point(0), point(1), 0.})
|
|
|
|
vertices.append(val);
|
|
|
|
int bcnr = self.GetSpline(i).bc;
|
|
|
|
max_bcnr = max2(max_bcnr, bcnr);
|
|
|
|
domains.append(bcnr);
|
|
|
|
domains.append(self.GetSpline(i).leftdom);
|
|
|
|
domains.append(self.GetSpline(i).rightdom);
|
|
|
|
}
|
|
|
|
|
|
|
|
// segment data
|
|
|
|
auto pnt = self.splines[i]->GetPoint(0.5);
|
|
|
|
segment_points.append(py::make_tuple(pnt(0),pnt(1)));
|
|
|
|
auto normal = self.GetSpline(i).GetTangent(0.5);
|
|
|
|
std::swap(normal(0),normal(1));
|
|
|
|
normal(1) *= -1;
|
|
|
|
normal *= 1./sqrt(normal(0) * normal(0) + normal(1)*normal(1));
|
|
|
|
segment_normals.append(py::make_tuple(normal(0),normal(1)));
|
|
|
|
leftdom.append(self.GetSpline(i).leftdom);
|
|
|
|
rightdom.append(self.GetSpline(i).rightdom);
|
|
|
|
}
|
|
|
|
py::list bcnames;
|
|
|
|
for (int i = 1; i<max_bcnr + 1; i++)
|
|
|
|
bcnames.append(self.GetBCName(i));
|
|
|
|
segment_data["midpoints"] = segment_points;
|
|
|
|
segment_data["normals"] = segment_normals;
|
|
|
|
segment_data["leftdom"] = leftdom;
|
|
|
|
segment_data["rightdom"] = rightdom;
|
|
|
|
data["segment_data"] = segment_data;
|
|
|
|
data["vertices"] = vertices;
|
|
|
|
data["domains"] = domains;
|
|
|
|
data["min"] = min_val;
|
|
|
|
data["max"] = max_val;
|
|
|
|
data["bcnames"] = bcnames;
|
|
|
|
return data;
|
|
|
|
})
|
2014-09-10 17:16:09 +06:00
|
|
|
.def("PointData", FunctionPointer([](SplineGeometry2d &self)
|
|
|
|
{
|
2016-11-04 16:14:52 +05:00
|
|
|
py::list xpoints, ypoints, pointindex;
|
2014-09-10 17:16:09 +06:00
|
|
|
|
|
|
|
for (int i = 0; i < self.geompoints.Size(); i++)
|
|
|
|
{
|
2016-11-04 16:14:52 +05:00
|
|
|
pointindex.append(py::cast(i));
|
|
|
|
xpoints.append(py::cast(self.geompoints[i][0]));
|
|
|
|
ypoints.append(py::cast(self.geompoints[i][1]));
|
2014-09-10 17:16:09 +06:00
|
|
|
}
|
2016-11-04 16:14:52 +05:00
|
|
|
return py::tuple(py::make_tuple(xpoints, ypoints, pointindex));
|
2014-09-10 17:16:09 +06:00
|
|
|
|
|
|
|
}))
|
|
|
|
.def("SegmentData", FunctionPointer([](SplineGeometry2d &self)
|
|
|
|
{
|
2016-11-04 16:14:52 +05:00
|
|
|
py::list leftpoints, rightpoints, leftdom, rightdom;
|
2014-09-10 17:16:09 +06:00
|
|
|
|
|
|
|
for (int i = 0; i < self.splines.Size(); i++)
|
|
|
|
{
|
|
|
|
GeomPoint<2> point = self.splines[i]->GetPoint(0.5);
|
|
|
|
Vec<2> normal = self.GetSpline(i).GetTangent(0.5);
|
|
|
|
double temp = normal(0);
|
|
|
|
normal(0) = normal(1);
|
|
|
|
normal(1) = -temp;
|
|
|
|
|
2016-11-04 16:14:52 +05:00
|
|
|
leftdom.append(py::cast(self.GetSpline(i).leftdom));
|
|
|
|
rightdom.append(py::cast(self.GetSpline(i).rightdom));
|
2014-09-10 17:16:09 +06:00
|
|
|
|
2016-11-04 16:14:52 +05:00
|
|
|
rightpoints.append(py::make_tuple(point(0), point(1), normal(0)<0, normal(1)<0));
|
|
|
|
leftpoints.append(py::make_tuple(point(0), point(1), normal(0)<0, normal(1)<0));
|
2014-09-10 17:16:09 +06:00
|
|
|
}
|
2016-11-04 16:14:52 +05:00
|
|
|
return py::tuple(py::make_tuple(leftpoints, rightpoints, leftdom, rightdom));
|
2014-09-10 17:16:09 +06:00
|
|
|
|
|
|
|
}))
|
|
|
|
.def("Print", FunctionPointer([](SplineGeometry2d &self)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < self.geompoints.Size(); i++)
|
|
|
|
{
|
|
|
|
cout << i << " : " << self.geompoints[i][0] << " , " << self.geompoints[i][1] << endl;
|
|
|
|
}
|
|
|
|
//Box<2> box(self.GetBoundingBox());
|
|
|
|
//cout << box.PMin() << endl;
|
|
|
|
//cout << box.PMax() << endl;
|
|
|
|
cout << self.splines.Size() << endl;
|
|
|
|
for (int i = 0; i < self.splines.Size(); i++)
|
|
|
|
{
|
|
|
|
cout << self.splines[i]->GetType() << endl;
|
|
|
|
//cout << i << " : " << self.splines[i]->GetPoint(0.1) << " , " << self.splines[i]->GetPoint(0.5) << endl;
|
|
|
|
}
|
|
|
|
}))
|
2019-12-05 18:52:14 +05:00
|
|
|
.def("Draw", FunctionPointer
|
|
|
|
([] (shared_ptr<SplineGeometry2d> self)
|
|
|
|
{
|
|
|
|
ng_geometry = self;
|
2019-12-10 21:57:20 +05:00
|
|
|
py::module::import("netgen").attr("Redraw")();
|
2019-12-05 18:52:14 +05:00
|
|
|
})
|
|
|
|
)
|
|
|
|
|
2019-07-29 10:11:57 +05:00
|
|
|
// If we change to c++17 this can become optional<MeshingParameters>
|
|
|
|
.def("GenerateMesh", [](shared_ptr<SplineGeometry2d> self,
|
|
|
|
MeshingParameters* pars, py::kwargs kwargs)
|
2014-09-10 17:16:09 +06:00
|
|
|
{
|
2019-07-26 02:25:58 +05:00
|
|
|
MeshingParameters mp;
|
2019-07-29 10:11:57 +05:00
|
|
|
if(pars) mp = *pars;
|
2019-07-26 02:25:58 +05:00
|
|
|
{
|
|
|
|
py::gil_scoped_acquire aq;
|
2019-07-29 10:11:57 +05:00
|
|
|
CreateMPfromKwargs(mp, kwargs);
|
2019-07-26 02:25:58 +05:00
|
|
|
}
|
|
|
|
auto mesh = make_shared<Mesh>();
|
2015-08-08 22:10:48 +05:00
|
|
|
mesh->SetGeometry(self);
|
2015-10-15 19:11:23 +05:00
|
|
|
SetGlobalMesh (mesh);
|
2015-08-08 15:58:41 +05:00
|
|
|
ng_geometry = self;
|
2019-11-26 21:08:21 +05:00
|
|
|
auto result = self->GenerateMesh(mesh, mp);
|
|
|
|
if(result != 0)
|
|
|
|
throw Exception("Meshing failed!");
|
2014-09-26 16:10:16 +06:00
|
|
|
return mesh;
|
2019-07-29 10:11:57 +05:00
|
|
|
}, py::arg("mp") = nullptr,
|
|
|
|
py::call_guard<py::gil_scoped_release>(),
|
|
|
|
meshingparameter_description.c_str())
|
|
|
|
;
|
2014-09-10 17:16:09 +06:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-09-01 12:33:57 +05:00
|
|
|
PYBIND11_MODULE(libgeom2d, m) {
|
2016-11-04 16:14:52 +05:00
|
|
|
ExportGeom2d(m);
|
2014-09-26 15:34:25 +06:00
|
|
|
}
|
2014-09-10 17:16:09 +06:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|