load stl fix and some vis

This commit is contained in:
Christopher Lackner 2016-12-12 13:14:47 +01:00
parent 25d2e497b1
commit a5e411d008
3 changed files with 43 additions and 6 deletions

View File

@ -7,6 +7,7 @@
using namespace netgen;
namespace netgen
{
//extern shared_ptr<Mesh> mesh;
extern shared_ptr<NetgenGeometry> ng_geometry;
}
@ -15,13 +16,12 @@ DLL_HEADER void ExportSTL(py::module & m)
{
py::class_<STLGeometry,shared_ptr<STLGeometry>> (m,"STLGeometry")
.def(py::init<>())
.def("Load", FunctionPointer([] (shared_ptr<STLGeometry> self, const string & filename)
{
ifstream ist(filename);
self->Load(ist);
}))
;
m.def("LoadSTLGeometry", FunctionPointer([] (const string & filename)
{
ifstream ist(filename);
return shared_ptr<STLGeometry>(STLGeometry::Load(ist));
}));
m.def("GenerateMesh", FunctionPointer([] (shared_ptr<STLGeometry> geo, MeshingParameters &param)
{
auto mesh = make_shared<Mesh>();
@ -46,4 +46,5 @@ PYBIND11_PLUGIN(libstl) {
ExportSTL(m);
return m.ptr();
}
#endif

View File

@ -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_<VisualSceneSTLGeometry, shared_ptr<VisualSceneSTLGeometry>>
(m, "VisualSceneSTLGeometry")
.def("Draw", &VisualSceneSTLGeometry::DrawScene)
;
m.def("SetBackGroundColor", &VisualSceneSTLGeometry::SetBackGroundColor);
m.def("VS",
[](STLGeometry & geom)
{
auto vs = make_shared<VisualSceneSTLGeometry>();
vs->SetGeometry(&geom);
return vs;
});
}
PYBIND11_PLUGIN(libcsgvis) {
py::module m("csg", "pybind csg");
ExportSTLVis(m);
return m.ptr();
}
#endif

View File

@ -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();
}