From a5e411d0089a04a33071036593038f4d90ed1e96 Mon Sep 17 00:00:00 2001 From: Christopher Lackner Date: Mon, 12 Dec 2016 13:14:47 +0100 Subject: [PATCH] load stl fix and some vis --- libsrc/stlgeom/python_stl.cpp | 13 +++++++------ libsrc/stlgeom/vsstl.cpp | 33 +++++++++++++++++++++++++++++++++ ng/netgenpy.cpp | 3 +++ 3 files changed, 43 insertions(+), 6 deletions(-) diff --git a/libsrc/stlgeom/python_stl.cpp b/libsrc/stlgeom/python_stl.cpp index 6a0f38a0..0ab54822 100644 --- a/libsrc/stlgeom/python_stl.cpp +++ b/libsrc/stlgeom/python_stl.cpp @@ -7,6 +7,7 @@ using namespace netgen; namespace netgen { + //extern shared_ptr mesh; extern shared_ptr ng_geometry; } @@ -15,13 +16,12 @@ DLL_HEADER void ExportSTL(py::module & m) { py::class_> (m,"STLGeometry") .def(py::init<>()) - .def("Load", FunctionPointer([] (shared_ptr self, const string & filename) - { - ifstream ist(filename); - self->Load(ist); - - })) ; + m.def("LoadSTLGeometry", FunctionPointer([] (const string & filename) + { + ifstream ist(filename); + return shared_ptr(STLGeometry::Load(ist)); + })); m.def("GenerateMesh", FunctionPointer([] (shared_ptr geo, MeshingParameters ¶m) { auto mesh = make_shared(); @@ -46,4 +46,5 @@ PYBIND11_PLUGIN(libstl) { ExportSTL(m); return m.ptr(); } + #endif diff --git a/libsrc/stlgeom/vsstl.cpp b/libsrc/stlgeom/vsstl.cpp index 42d5db1c..60011f61 100644 --- a/libsrc/stlgeom/vsstl.cpp +++ b/libsrc/stlgeom/vsstl.cpp @@ -1210,3 +1210,36 @@ void VisualSceneSTLMeshing :: MouseDblClick (int px, int py) } } + + + +#ifdef NG_PYTHON +#include <../general/ngpython.hpp> + +DLL_HEADER void ExportSTLVis(py::module &m) +{ + using namespace netgen; + + py::class_> + (m, "VisualSceneSTLGeometry") + .def("Draw", &VisualSceneSTLGeometry::DrawScene) + ; + + m.def("SetBackGroundColor", &VisualSceneSTLGeometry::SetBackGroundColor); + + m.def("VS", + [](STLGeometry & geom) + { + auto vs = make_shared(); + + vs->SetGeometry(&geom); + return vs; + }); +} + +PYBIND11_PLUGIN(libcsgvis) { + py::module m("csg", "pybind csg"); + ExportSTLVis(m); + return m.ptr(); +} +#endif diff --git a/ng/netgenpy.cpp b/ng/netgenpy.cpp index e47b1f90..3a91e373 100644 --- a/ng/netgenpy.cpp +++ b/ng/netgenpy.cpp @@ -16,6 +16,7 @@ void DLL_HEADER ExportCSG(py::module &m); void DLL_HEADER ExportCSGVis(py::module &m); void DLL_HEADER ExportGeom2d(py::module &m); void DLL_HEADER ExportSTL(py::module &m); +void DLL_HEADER ExportSTLVis(py::module &m); PYBIND11_PLUGIN(libngpy) { @@ -32,6 +33,8 @@ PYBIND11_PLUGIN(libngpy) ExportGeom2d(geom2d); py::module stl = ngpy.def_submodule("_stl", "pybind stl module"); ExportSTL(stl); + py::module stlvis = ngpy.def_submodule("stlvis", "pybind stlvis module"); + ExportSTLVis(stlvis); return ngpy.ptr(); }