mirror of
https://github.com/NGSolve/netgen.git
synced 2024-12-25 05:20:34 +05:00
Python opencascade interface (by Gerhard Kitzler)
This commit is contained in:
parent
ed453a5fbc
commit
0c611c339c
@ -2,7 +2,7 @@ add_definitions(-DNGINTERFACE_EXPORTS)
|
||||
add_library(occ ${NG_LIB_TYPE}
|
||||
Partition_Inter2d.cxx Partition_Inter3d.cxx
|
||||
Partition_Loop.cxx Partition_Loop2d.cxx Partition_Loop3d.cxx Partition_Spliter.cxx
|
||||
occconstruction.cpp occgenmesh.cpp occgeom.cpp occmeshsurf.cpp
|
||||
occconstruction.cpp occgenmesh.cpp occgeom.cpp occmeshsurf.cpp python_occ.cpp
|
||||
)
|
||||
|
||||
add_library(occvis ${NG_LIB_TYPE} vsocc.cpp)
|
||||
|
@ -417,10 +417,14 @@ namespace netgen
|
||||
&& (geom.face_colours->GetColor(face,XCAFDoc_ColorSurf,face_colour)))
|
||||
{
|
||||
mesh.GetFaceDescriptor(facenr).SetSurfColour(Vec3d(face_colour.Red(),face_colour.Green(),face_colour.Blue()));
|
||||
mesh.GetFaceDescriptor(facenr).SetBCName(&geom.fnames[facenr-1]);
|
||||
mesh.GetFaceDescriptor(facenr).SetBCProperty(facenr);
|
||||
}
|
||||
else
|
||||
{
|
||||
mesh.GetFaceDescriptor(facenr).SetSurfColour(Vec3d(0.0,1.0,0.0));
|
||||
mesh.GetFaceDescriptor(facenr).SetBCName(&geom.fnames[facenr-1]);
|
||||
mesh.GetFaceDescriptor(facenr).SetBCProperty(facenr);
|
||||
}
|
||||
// ACHTUNG! STIMMT NICHT ALLGEMEIN (RG)
|
||||
|
||||
@ -974,6 +978,13 @@ namespace netgen
|
||||
NgProfiler::StopTimer (timer_opt2d);
|
||||
|
||||
multithread.task = savetask;
|
||||
|
||||
// Gerhard BEGIN
|
||||
for(int i = 0; i<mesh.GetNFD();i++)
|
||||
mesh.SetBCName(i,mesh.GetFaceDescriptor(i+1).GetBCName());
|
||||
// for(int i = 0; i<mesh.GetNDomains();i++)
|
||||
// mesh.SetMaterial(i,geom.snames[i]);
|
||||
// Gerhard END
|
||||
}
|
||||
|
||||
|
||||
@ -1459,6 +1470,8 @@ namespace netgen
|
||||
for (int i = 1; i <= mesh->GetNSeg(); i++)
|
||||
(*testout) << mesh->LineSegment(i) << endl;
|
||||
|
||||
for (int i = 0; i < mesh->GetNDomains(); i++)
|
||||
mesh->SetMaterial (i+1, geom.snames[i]);
|
||||
return TCL_OK;
|
||||
}
|
||||
}
|
||||
|
@ -17,6 +17,10 @@
|
||||
#include "Partition_Spliter.hxx"
|
||||
#include "BRepAlgoAPI_Fuse.hxx"
|
||||
|
||||
#include "XSControl_WorkSession.hxx"
|
||||
#include "XSControl_TransferReader.hxx"
|
||||
#include "StepRepr_RepresentationItem.hxx"
|
||||
|
||||
#ifndef _Standard_Version_HeaderFile
|
||||
#include <Standard_Version.hxx>
|
||||
#endif
|
||||
@ -29,6 +33,44 @@
|
||||
|
||||
namespace netgen
|
||||
{
|
||||
void STEP_GetEntityName(const TopoDS_Shape & theShape, STEPCAFControl_Reader * aReader, char * acName)
|
||||
{
|
||||
const Handle(XSControl_WorkSession)& theSession = aReader->Reader().WS();
|
||||
const Handle(XSControl_TransferReader)& aTransferReader =
|
||||
theSession->TransferReader();
|
||||
|
||||
Handle(Standard_Transient) anEntity =
|
||||
aTransferReader->EntityFromShapeResult(theShape, 1);
|
||||
|
||||
if (anEntity.IsNull()) {
|
||||
// as just mapped
|
||||
anEntity = aTransferReader->EntityFromShapeResult (theShape,-1);
|
||||
}
|
||||
|
||||
if (anEntity.IsNull()) {
|
||||
// as anything
|
||||
anEntity = aTransferReader->EntityFromShapeResult (theShape,4);
|
||||
}
|
||||
|
||||
if (anEntity.IsNull()) {
|
||||
cout<<"Warning: XSInterVertex_STEPReader::ReadAttributes()\nentity not found"<<endl;
|
||||
strcpy(acName, "none");
|
||||
}
|
||||
else
|
||||
{
|
||||
Handle(StepRepr_RepresentationItem) aReprItem;
|
||||
aReprItem =
|
||||
Handle(StepRepr_RepresentationItem)::DownCast(anEntity);
|
||||
|
||||
if (aReprItem.IsNull()) {
|
||||
cout<<"Error: STEPReader::ReadAttributes():\nStepRepr_RepresentationItem Is NULL"<<endl;
|
||||
}
|
||||
else
|
||||
strcpy(acName, aReprItem->Name()->ToCString());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void OCCGeometry :: PrintNrShapes ()
|
||||
{
|
||||
TopExp_Explorer e;
|
||||
@ -1169,7 +1211,7 @@ namespace netgen
|
||||
|
||||
// Enable transfer of colours
|
||||
reader.SetColorMode(Standard_True);
|
||||
|
||||
reader.SetNameMode(Standard_True);
|
||||
Standard_Integer stat = reader.ReadFile((char*)filename);
|
||||
|
||||
if(stat != IFSelect_RetDone)
|
||||
@ -1210,7 +1252,38 @@ namespace netgen
|
||||
|
||||
occgeo->CalcBoundingBox();
|
||||
PrintContents (occgeo);
|
||||
|
||||
char * name = new char(50);
|
||||
//string name;
|
||||
STEP_GetEntityName(occgeo->shape,&reader,name);
|
||||
occgeo->snames.Append(name);
|
||||
TopExp_Explorer exp0,exp1;
|
||||
|
||||
for (exp0.Init(occgeo->shape, TopAbs_FACE); exp0.More(); exp0.Next())
|
||||
{
|
||||
TopoDS_Face face = TopoDS::Face(exp0.Current());
|
||||
STEP_GetEntityName(face,&reader,name);
|
||||
occgeo->fnames.Append(name);
|
||||
for (exp1.Init(face, TopAbs_EDGE); exp1.More(); exp1.Next())
|
||||
{
|
||||
TopoDS_Edge edge = TopoDS::Edge(exp1.Current());
|
||||
STEP_GetEntityName(edge,&reader,name);
|
||||
occgeo->enames.Append(name);
|
||||
}
|
||||
}
|
||||
// Gerhard BEGIN
|
||||
// cout << "Solid Names: "<<endl;
|
||||
// for (int i=0;i<occgeo->snames.Size();i++)
|
||||
// cout << occgeo->snames[i] << endl;
|
||||
// cout << " " <<endl;
|
||||
// cout << "Face Names: "<<endl;
|
||||
// for (int i=0;i<occgeo->fnames.Size();i++)
|
||||
// cout << occgeo->fnames[i] << endl;
|
||||
// cout << " " <<endl;
|
||||
// cout << "Edge Names: "<<endl;
|
||||
// for (int i=0;i<occgeo->enames.Size();i++)
|
||||
// cout << occgeo->enames[i] << endl;
|
||||
// cout << " " <<endl;
|
||||
// Gerhard END
|
||||
return occgeo;
|
||||
}
|
||||
|
||||
|
@ -198,7 +198,7 @@ namespace netgen
|
||||
TopTools_IndexedMapOfShape fmap, emap, vmap, somap, shmap, wmap;
|
||||
Array<bool> fsingular, esingular, vsingular;
|
||||
Box<3> boundingbox;
|
||||
|
||||
Array<string> fnames, enames, snames;
|
||||
// Philippose - 29/01/2009
|
||||
// OpenCascade XDE Support
|
||||
// XCAF Handle to make the face colours available to the rest of
|
||||
|
56
libsrc/occ/python_occ.cpp
Normal file
56
libsrc/occ/python_occ.cpp
Normal file
@ -0,0 +1,56 @@
|
||||
#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>> (m, "OCCGeometry")
|
||||
.def(py::init<>())
|
||||
;
|
||||
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);
|
||||
}));
|
||||
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;
|
||||
}))
|
||||
;
|
||||
}
|
||||
|
||||
PYBIND11_PLUGIN(libNgOCC) {
|
||||
py::module m("NgOCC", "pybind NgOCC");
|
||||
ExportNgOCC(m);
|
||||
return m.ptr();
|
||||
}
|
||||
|
||||
#endif // OCCGEOMETRY
|
||||
#endif // NG_PYTHON
|
@ -17,6 +17,7 @@ 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);
|
||||
void DLL_HEADER ExportNgOCC(py::module &m);
|
||||
|
||||
PYBIND11_PLUGIN(libngpy)
|
||||
{
|
||||
@ -29,6 +30,8 @@ PYBIND11_PLUGIN(libngpy)
|
||||
ExportGeom2d(geom2d);
|
||||
py::module stl = ngpy.def_submodule("_stl", "pybind stl module");
|
||||
ExportSTL(stl);
|
||||
py::module NgOCC = ngpy.def_submodule("_NgOCC", "pybind NgOCC module");
|
||||
ExportNgOCC(NgOCC);
|
||||
#ifdef OPENGL
|
||||
py::module meshvis = ngpy.def_submodule("meshvis", "pybind meshvis module");
|
||||
ExportMeshVis(meshvis);
|
||||
|
@ -2,7 +2,7 @@ configure_file(__init__.py ${CMAKE_CURRENT_BINARY_DIR}/__init__.py @ONLY)
|
||||
|
||||
install(FILES
|
||||
${CMAKE_CURRENT_BINARY_DIR}/__init__.py
|
||||
meshing.py csg.py geom2d.py stl.py gui.py
|
||||
meshing.py csg.py geom2d.py stl.py gui.py NgOCC.py
|
||||
DESTINATION ${NG_INSTALL_DIR_PYTHON}/${NG_INSTALL_SUFFIX}
|
||||
COMPONENT netgen
|
||||
)
|
||||
|
11
python/NgOCC.py
Normal file
11
python/NgOCC.py
Normal file
@ -0,0 +1,11 @@
|
||||
import libngpy
|
||||
from libngpy._NgOCC import *
|
||||
from libngpy._meshing import MeshingParameters
|
||||
|
||||
def NgOCC_meshing_func (geom, **args):
|
||||
if "mp" in args:
|
||||
return GenerateMesh (geom, args["mp"])
|
||||
else:
|
||||
return GenerateMesh (geom, MeshingParameters (**args))
|
||||
|
||||
OCCGeometry.GenerateMesh = NgOCC_meshing_func
|
Loading…
Reference in New Issue
Block a user