mirror of
https://github.com/NGSolve/netgen.git
synced 2024-12-25 21:40:33 +05:00
Merge branch 'stl_to_python' into 'master'
Stl to python See merge request !25
This commit is contained in:
commit
bf1dfb6b08
@ -1,6 +1,6 @@
|
||||
add_library(stl ${NG_LIB_TYPE}
|
||||
meshstlsurface.cpp stlgeom.cpp stlgeomchart.cpp
|
||||
stlgeommesh.cpp stlline.cpp stltool.cpp stltopology.cpp
|
||||
stlgeommesh.cpp stlline.cpp stltool.cpp stltopology.cpp python_stl.cpp
|
||||
)
|
||||
|
||||
if(NOT WIN32)
|
||||
|
56
libsrc/stlgeom/python_stl.cpp
Normal file
56
libsrc/stlgeom/python_stl.cpp
Normal file
@ -0,0 +1,56 @@
|
||||
|
||||
#ifdef NG_PYTHON
|
||||
|
||||
#include <../general/ngpython.hpp>
|
||||
#include <stlgeom.hpp>
|
||||
|
||||
#ifdef WIN32
|
||||
#define DLL_HEADER __declspec(dllexport)
|
||||
#else
|
||||
#define DLL_HEADER
|
||||
#endif
|
||||
|
||||
using namespace netgen;
|
||||
namespace netgen
|
||||
{
|
||||
//extern shared_ptr<Mesh> mesh;
|
||||
extern shared_ptr<NetgenGeometry> ng_geometry;
|
||||
}
|
||||
|
||||
|
||||
DLL_HEADER void ExportSTL(py::module & m)
|
||||
{
|
||||
py::class_<STLGeometry,shared_ptr<STLGeometry>> (m,"STLGeometry")
|
||||
.def(py::init<>())
|
||||
;
|
||||
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 ¶m)
|
||||
{
|
||||
auto mesh = make_shared<Mesh>();
|
||||
SetGlobalMesh(mesh);
|
||||
mesh->SetGeometry(geo);
|
||||
ng_geometry = geo;
|
||||
try
|
||||
{
|
||||
geo->GenerateMesh(mesh,param);
|
||||
}
|
||||
catch (NgException ex)
|
||||
{
|
||||
cout << "Caught NgException: " << ex.What() << endl;
|
||||
}
|
||||
return mesh;
|
||||
}))
|
||||
;
|
||||
}
|
||||
|
||||
PYBIND11_PLUGIN(libstl) {
|
||||
py::module m("stl", "pybind stl");
|
||||
ExportSTL(m);
|
||||
return m.ptr();
|
||||
}
|
||||
|
||||
#endif
|
@ -1210,3 +1210,44 @@ void VisualSceneSTLMeshing :: MouseDblClick (int px, int py)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
#ifdef NG_PYTHON
|
||||
|
||||
|
||||
#ifdef WIN32
|
||||
#define DLL_HEADER __declspec(dllexport)
|
||||
#else
|
||||
#define DLL_HEADER
|
||||
#endif
|
||||
|
||||
#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(libstlvis) {
|
||||
py::module m("stlvis", "pybind stl vis");
|
||||
ExportSTLVis(m);
|
||||
return m.ptr();
|
||||
}
|
||||
#endif
|
||||
|
@ -15,6 +15,8 @@ void DLL_HEADER ExportMeshVis(py::module &m);
|
||||
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)
|
||||
{
|
||||
@ -29,6 +31,10 @@ PYBIND11_PLUGIN(libngpy)
|
||||
ExportMeshVis(meshvis);
|
||||
py::module geom2d = ngpy.def_submodule("_geom2d", "pybind geom2d module");
|
||||
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();
|
||||
}
|
||||
|
||||
|
13
python/stl.py
Normal file
13
python/stl.py
Normal file
@ -0,0 +1,13 @@
|
||||
import libngpy
|
||||
from libngpy._stl import *
|
||||
from libngpy._meshing import MeshingParameters
|
||||
|
||||
|
||||
def stl_meshing_func (geom, **args):
|
||||
if "mp" in args:
|
||||
return GenerateMesh (geom, args["mp"])
|
||||
else:
|
||||
return GenerateMesh (geom, MeshingParameters (**args))
|
||||
# return GenerateMesh (geom, MeshingParameters (**args))
|
||||
|
||||
STLGeometry.GenerateMesh = stl_meshing_func
|
Loading…
Reference in New Issue
Block a user