mirror of
https://github.com/NGSolve/netgen.git
synced 2024-11-11 16:49:16 +05:00
add files
This commit is contained in:
parent
9f9a5e4304
commit
561cf4e75f
49
libsrc/stlgeom/python_stl.cpp
Normal file
49
libsrc/stlgeom/python_stl.cpp
Normal file
@ -0,0 +1,49 @@
|
||||
|
||||
#ifdef NG_PYTHON
|
||||
|
||||
#include <../general/ngpython.hpp>
|
||||
#include <stlgeom.hpp>
|
||||
|
||||
using namespace netgen;
|
||||
namespace netgen
|
||||
{
|
||||
extern shared_ptr<NetgenGeometry> ng_geometry;
|
||||
}
|
||||
|
||||
|
||||
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("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
|
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