mirror of
https://github.com/NGSolve/netgen.git
synced 2024-11-12 00:59:16 +05:00
e72d90fcbb
derive geometry class in python from NetgenGeometry, gil call guard See merge request jschoeberl/netgen!82
68 lines
2.2 KiB
C++
68 lines
2.2 KiB
C++
#ifdef NG_PYTHON
|
|
#ifdef OCCGEOMETRY
|
|
|
|
#include <../general/ngpython.hpp>
|
|
|
|
#include <meshing.hpp>
|
|
#include <occgeom.hpp>
|
|
|
|
using namespace netgen;
|
|
|
|
namespace netgen
|
|
{
|
|
extern std::shared_ptr<NetgenGeometry> ng_geometry;
|
|
}
|
|
|
|
|
|
DLL_HEADER void ExportNgOCC(py::module &m)
|
|
{
|
|
py::class_<OCCGeometry, shared_ptr<OCCGeometry>, NetgenGeometry> (m, "OCCGeometry", R"raw_string(Use LoadOCCGeometry to load the geometry from a *.step file.)raw_string")
|
|
.def(py::init<>())
|
|
.def("Heal",[](OCCGeometry & self, double tolerance, bool fixsmalledges, bool fixspotstripfaces, bool sewfaces, bool makesolids, bool splitpartitions)
|
|
{
|
|
self.tolerance = tolerance;
|
|
self.fixsmalledges = fixsmalledges;
|
|
self.fixspotstripfaces = fixspotstripfaces;
|
|
self.sewfaces = sewfaces;
|
|
self.makesolids = makesolids;
|
|
self.splitpartitions = splitpartitions;
|
|
|
|
self.HealGeometry();
|
|
self.BuildFMap();
|
|
},py::arg("tolerance")=1e-3, py::arg("fixsmalledges")=true, py::arg("fixspotstripfaces")=true, py::arg("sewfaces")=true, py::arg("makesolids")=true, py::arg("splitpartitions")=false,R"raw_string(Heal the OCCGeometry.)raw_string",py::call_guard<py::gil_scoped_release>())
|
|
;
|
|
m.def("LoadOCCGeometry",FunctionPointer([] (const string & filename)
|
|
{
|
|
cout << "load OCC geometry";
|
|
ifstream ist(filename);
|
|
OCCGeometry * instance = new OCCGeometry();
|
|
instance = LoadOCC_STEP(filename.c_str());
|
|
return shared_ptr<OCCGeometry>(instance, NOOP_Deleter);
|
|
}),py::call_guard<py::gil_scoped_release>());
|
|
m.def("GenerateMesh", FunctionPointer([] (shared_ptr<OCCGeometry> 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;
|
|
}),py::call_guard<py::gil_scoped_release>())
|
|
;
|
|
}
|
|
|
|
PYBIND11_MODULE(libNgOCC, m) {
|
|
ExportNgOCC(m);
|
|
}
|
|
|
|
#endif // OCCGEOMETRY
|
|
#endif // NG_PYTHON
|