Introduce NetgenGeometry base class to Python. export meshing first, then csg

This commit is contained in:
Joachim Schöberl 2017-01-05 05:08:24 +01:00
parent c31240580b
commit d1de4a7cf9
5 changed files with 89 additions and 85 deletions

View File

@ -163,77 +163,9 @@ namespace netgen
}
static Transformation<3> global_trafo(Vec<3> (0,0,0));
DLL_HEADER void ExportCSG(py::module &m)
{
py::class_<NGDummyArgument>(m, "NGDummyArgument")
.def("__bool__", []( NGDummyArgument &self ) { return false; } )
;
py::class_<Point<2>> (m, "Point2d")
.def(py::init<double,double>())
.def ("__str__", &ToString<Point<2>>)
.def(py::self-py::self)
.def(py::self+Vec<2>())
.def(py::self-Vec<2>())
;
py::class_<Point<3>> (m, "Point3d")
.def(py::init<double,double,double>())
.def ("__str__", &ToString<Point<3>>)
.def(py::self-py::self)
.def(py::self+Vec<3>())
.def(py::self-Vec<3>())
;
m.def ("Pnt", FunctionPointer
([](double x, double y, double z) { return global_trafo(Point<3>(x,y,z)); }));
m.def ("Pnt", FunctionPointer
([](double x, double y) { return Point<2>(x,y); }));
m.def ("Pnt", FunctionPointer
([](double x, double y, double z) { return Point<3>(x,y,z); }));
m.def ("Pnt", FunctionPointer
([](double x, double y) { return Point<2>(x,y); }));
m.def ("SetTransformation", FunctionPointer
([](int dir, double angle)
{
if (dir > 0)
global_trafo.SetAxisRotation (dir, angle*M_PI/180);
else
global_trafo = Transformation<3> (Vec<3>(0,0,0));
}),
py::arg("dir")=int(0), py::arg("angle")=int(0));
py::class_<Vec<2>> (m, "Vec2d")
.def(py::init<double,double>())
.def ("__str__", &ToString<Vec<3>>)
.def(py::self+py::self)
.def(py::self-py::self)
.def(-py::self)
.def(double()*py::self)
.def("Norm", &Vec<2>::Length)
;
py::class_<Vec<3>> (m, "Vec3d")
.def(py::init<double,double,double>())
.def ("__str__", &ToString<Vec<3>>)
.def(py::self+py::self)
.def(py::self-py::self)
.def(-py::self)
.def(double()*py::self)
.def("Norm", &Vec<3>::Length)
;
m.def ("Vec", FunctionPointer
([] (double x, double y, double z) { return global_trafo(Vec<3>(x,y,z)); }));
m.def ("Vec", FunctionPointer
([] (double x, double y) { return Vec<2>(x,y); }));
py::class_<SplineGeometry<2>> (m, "SplineCurve2d")
.def(py::init<>())
.def ("AddPoint", FunctionPointer
@ -387,7 +319,7 @@ DLL_HEADER void ExportCSG(py::module &m)
}));
py::class_<CSGeometry,shared_ptr<CSGeometry>> (m, "CSGeometry")
py::class_<CSGeometry, NetgenGeometry, shared_ptr<CSGeometry>> (m, "CSGeometry")
.def(py::init<>())
.def("__init__",
[](CSGeometry *instance, const string & filename)

View File

@ -15,8 +15,7 @@ namespace netgen
DLL_HEADER void ExportGeom2d(py::module &m)
{
py::class_<SplineGeometry2d, shared_ptr<SplineGeometry2d>>
py::class_<SplineGeometry2d, NetgenGeometry, shared_ptr<SplineGeometry2d>>
(m, "SplineGeometry",
"a 2d boundary representation geometry model by lines and splines")
.def(py::init<>())

View File

@ -4,8 +4,8 @@
#include <mystdlib.h>
#include "meshing.hpp"
#include <csg.hpp>
#include <geometry2d.hpp>
// #include <csg.hpp>
// #include <geometry2d.hpp>
#include <../interface/writeuser.hpp>
@ -45,9 +45,77 @@ void TranslateException (const NgException & ex)
PyErr_SetString(PyExc_RuntimeError, err.c_str());
}
static Transformation<3> global_trafo(Vec<3> (0,0,0));
DLL_HEADER void ExportNetgenMeshing(py::module &m)
{
py::class_<NGDummyArgument>(m, "NGDummyArgument")
.def("__bool__", []( NGDummyArgument &self ) { return false; } )
;
py::class_<Point<2>> (m, "Point2d")
.def(py::init<double,double>())
.def ("__str__", &ToString<Point<2>>)
.def(py::self-py::self)
.def(py::self+Vec<2>())
.def(py::self-Vec<2>())
;
py::class_<Point<3>> (m, "Point3d")
.def(py::init<double,double,double>())
.def ("__str__", &ToString<Point<3>>)
.def(py::self-py::self)
.def(py::self+Vec<3>())
.def(py::self-Vec<3>())
;
m.def ("Pnt", FunctionPointer
([](double x, double y, double z) { return global_trafo(Point<3>(x,y,z)); }));
m.def ("Pnt", FunctionPointer
([](double x, double y) { return Point<2>(x,y); }));
m.def ("Pnt", FunctionPointer
([](double x, double y, double z) { return Point<3>(x,y,z); }));
m.def ("Pnt", FunctionPointer
([](double x, double y) { return Point<2>(x,y); }));
py::class_<Vec<2>> (m, "Vec2d")
.def(py::init<double,double>())
.def ("__str__", &ToString<Vec<3>>)
.def(py::self+py::self)
.def(py::self-py::self)
.def(-py::self)
.def(double()*py::self)
.def("Norm", &Vec<2>::Length)
;
py::class_<Vec<3>> (m, "Vec3d")
.def(py::init<double,double,double>())
.def ("__str__", &ToString<Vec<3>>)
.def(py::self+py::self)
.def(py::self-py::self)
.def(-py::self)
.def(double()*py::self)
.def("Norm", &Vec<3>::Length)
;
m.def ("Vec", FunctionPointer
([] (double x, double y, double z) { return global_trafo(Vec<3>(x,y,z)); }));
m.def ("Vec", FunctionPointer
([] (double x, double y) { return Vec<2>(x,y); }));
m.def ("SetTransformation", FunctionPointer
([](int dir, double angle)
{
if (dir > 0)
global_trafo.SetAxisRotation (dir, angle*M_PI/180);
else
global_trafo = Transformation<3> (Vec<3>(0,0,0));
}),
py::arg("dir")=int(0), py::arg("angle")=int(0));
py::class_<PointIndex>(m, "PointId")
@ -313,6 +381,9 @@ DLL_HEADER void ExportNetgenMeshing(py::module &m)
py::implicitly_convertible< int, PointIndex>();
py::class_<NetgenGeometry, shared_ptr<NetgenGeometry>> (m, "NetgenGeometry")
;
py::class_<Mesh,shared_ptr<Mesh>>(m, "Mesh")
// .def(py::init<>("create empty mesh"))
@ -517,17 +588,18 @@ DLL_HEADER void ExportNetgenMeshing(py::module &m)
}))
.def ("SetGeometry", FunctionPointer
([](Mesh & self, shared_ptr<CSGeometry> geo)
([](Mesh & self, shared_ptr<NetgenGeometry> geo)
{
self.SetGeometry(geo);
}))
// TODO: fix this dependency on libgeom2d.so
// .def ("SetGeometry", FunctionPointer
// ([](Mesh & self, shared_ptr<SplineGeometry2d> geo)
// {
// self.SetGeometry(geo);
// }))
/*
.def ("SetGeometry", FunctionPointer
([](Mesh & self, shared_ptr<CSGeometry> geo)
{
self.SetGeometry(geo);
}))
*/
.def ("BuildSearchTree", &Mesh::BuildElementSearchTree)

View File

@ -21,14 +21,14 @@ void DLL_HEADER ExportSTLVis(py::module &m);
PYBIND11_PLUGIN(libngpy)
{
py::module ngpy("libngpy", "pybind netgen module");
py::module csg = ngpy.def_submodule("_csg", "pybind csg module");
ExportCSG(csg);
py::module csgvis = ngpy.def_submodule("csgvis", "pybind csgvis module");
ExportCSGVis(csgvis);
py::module meshing = ngpy.def_submodule("_meshing", "pybind meshing module");
ExportNetgenMeshing(meshing);
py::module meshvis = ngpy.def_submodule("meshvis", "pybind meshvis module");
ExportMeshVis(meshvis);
py::module csg = ngpy.def_submodule("_csg", "pybind csg module");
ExportCSG(csg);
py::module csgvis = ngpy.def_submodule("csgvis", "pybind csgvis module");
ExportCSGVis(csgvis);
py::module geom2d = ngpy.def_submodule("_geom2d", "pybind geom2d module");
ExportGeom2d(geom2d);
py::module stl = ngpy.def_submodule("_stl", "pybind stl module");

View File

@ -3,6 +3,7 @@ from libngpy._csg import *
import libngpy.csgvis as csgvis
from libngpy.csgvis import MouseMove
from libngpy._meshing import MeshingParameters
from libngpy._meshing import Pnt
CSGeometry.VS = csgvis.VS