mirror of
https://github.com/NGSolve/netgen.git
synced 2024-11-12 00:59:16 +05:00
1430b89e39
- Replace PYBIND11_PLUGIN with PYBIND11_MODULE - Fix warnings about symbol visibility by replacing 'namespace pybind11' with 'namespace PYBIND11_NAMESPACE' - Pybind sets the default visibility of its namespace to 'hidden' Thus, our export functions like ExportCSG(py::module &m) also are hidden by default. To work around that define DLL_HEADER '__attribute__ ((visibility ("default"))) on GNUC platforms.
53 lines
1.1 KiB
C++
53 lines
1.1 KiB
C++
|
|
#ifdef NG_PYTHON
|
|
|
|
#include <../general/ngpython.hpp>
|
|
#include <stlgeom.hpp>
|
|
|
|
#ifdef WIN32
|
|
#define DLL_HEADER __declspec(dllexport)
|
|
#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_MODULE(libstl, m) {
|
|
ExportSTL(m);
|
|
}
|
|
|
|
#endif
|