From f78e818ca4da8834850d24ca6f31bfc112e80c9d Mon Sep 17 00:00:00 2001 From: benoit128 Date: Fri, 13 Sep 2024 09:03:46 +0200 Subject: [PATCH] OCC: add basic sewing --- Cassiopee/OCC/OCC/Atomic/sewing.cpp | 91 +++++++++++++++++++++++++++ Cassiopee/OCC/OCC/Atomic/splitter.cpp | 1 - Cassiopee/OCC/OCC/occ.cpp | 1 + Cassiopee/OCC/OCC/occ.h | 1 + Cassiopee/OCC/srcs.py | 2 + 5 files changed, 95 insertions(+), 1 deletion(-) create mode 100644 Cassiopee/OCC/OCC/Atomic/sewing.cpp diff --git a/Cassiopee/OCC/OCC/Atomic/sewing.cpp b/Cassiopee/OCC/OCC/Atomic/sewing.cpp new file mode 100644 index 000000000..2b3c38621 --- /dev/null +++ b/Cassiopee/OCC/OCC/Atomic/sewing.cpp @@ -0,0 +1,91 @@ +/* + Copyright 2013-2024 Onera. + + This file is part of Cassiopee. + + Cassiopee is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Cassiopee is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Cassiopee. If not, see . +*/ +// CAD split for parallel +#include "occ.h" + +#include "TopoDS.hxx" +#include "BRep_Tool.hxx" +#include "ShapeAnalysis.hxx" +#include "BRepAdaptor_Curve.hxx" +#include "TopExp.hxx" +#include "TopExp_Explorer.hxx" +#include "TopTools_IndexedMapOfShape.hxx" +#include "ShapeUpgrade_FaceDivide.hxx" +#include "ShapeUpgrade_ShapeDivideArea.hxx" +#include "ShapeUpgrade_ShapeDivideClosed.hxx" +#include "ShapeUpgrade_ClosedFaceDivide.hxx" +#include "ShapeUpgrade_SplitSurfaceArea.hxx" +#include "TColGeom_SequenceOfSurface.hxx" +#include "ShapeExtend_CompositeSurface.hxx" +#include "ShapeBuild_ReShape.hxx" +#include "BRep_Builder.hxx" +#include "ShapeUpgrade_ShapeDivideClosedEdges.hxx" +#include "BRepBuilderAPI_Sewing.hxx" + +//===================================================================== +// Sew faces removing extra edges +//===================================================================== +PyObject* K_OCC::sewing(PyObject* self, PyObject* args) +{ + PyObject* hook; E_Float tol; + if (!PYPARSETUPLE_(args, O_ R_, &hook, &tol)) return NULL; + + void** packet = NULL; +#if (PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION < 7) || (PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION < 1) + packet = (void**) PyCObject_AsVoidPtr(hook); +#else + packet = (void**) PyCapsule_GetPointer(hook, NULL); +#endif + + //TopTools_IndexedMapOfShape& edges = *(TopTools_IndexedMapOfShape*)packet[2]; + //TopTools_IndexedMapOfShape& surfaces = *(TopTools_IndexedMapOfShape*)packet[1]; + + // try on all shape + TopoDS_Shape* shp = (TopoDS_Shape*)packet[0]; + + + printf("sew top shape\n"); + + const Standard_Real tolerance = tol; + BRepBuilderAPI_Sewing sewer(tolerance); + sewer.Add(*shp); + sewer.Perform(); + + TopoDS_Shape* newshp = new TopoDS_Shape(sewer.SewedShape()); + + packet[0] = newshp; + // Extract surfaces + TopTools_IndexedMapOfShape* ptr = (TopTools_IndexedMapOfShape*)packet[1]; + delete ptr; + TopTools_IndexedMapOfShape* sf = new TopTools_IndexedMapOfShape(); + TopExp::MapShapes(*newshp, TopAbs_FACE, *sf); + packet[1] = sf; + + // Extract edges + TopTools_IndexedMapOfShape* ptr2 = (TopTools_IndexedMapOfShape*)packet[2]; + delete ptr2; + TopTools_IndexedMapOfShape* se = new TopTools_IndexedMapOfShape(); + TopExp::MapShapes(*newshp, TopAbs_EDGE, *se); + packet[2] = se; + printf("INFO: after sewing: Nb edges=%d\n", se->Extent()); + printf("INFO: after sewing: Nb faces=%d\n", sf->Extent()); + + Py_INCREF(Py_None); + return Py_None; +} diff --git a/Cassiopee/OCC/OCC/Atomic/splitter.cpp b/Cassiopee/OCC/OCC/Atomic/splitter.cpp index c22d01124..8d3d18e4a 100644 --- a/Cassiopee/OCC/OCC/Atomic/splitter.cpp +++ b/Cassiopee/OCC/OCC/Atomic/splitter.cpp @@ -29,7 +29,6 @@ #include "GCPnts_AbscissaPoint.hxx" #include "GCPnts_UniformDeflection.hxx" #include "GCPnts_UniformAbscissa.hxx" -#include "TopTools_IndexedMapOfShape.hxx" #include "TopExp.hxx" #include "TopExp_Explorer.hxx" #include "TopTools_IndexedMapOfShape.hxx" diff --git a/Cassiopee/OCC/OCC/occ.cpp b/Cassiopee/OCC/OCC/occ.cpp index 02dfe22c1..b7f2bcb55 100644 --- a/Cassiopee/OCC/OCC/occ.cpp +++ b/Cassiopee/OCC/OCC/occ.cpp @@ -69,6 +69,7 @@ static PyMethodDef Pyocc [] = {"splitFaces", K_OCC::splitFaces, METH_VARARGS}, {"fixShape", K_OCC::fixShape, METH_VARARGS}, {"trimFaces", K_OCC::trimFaces, METH_VARARGS}, + {"sewing", K_OCC::sewing, METH_VARARGS}, {"getOppData", K_OCC::getOppData, METH_VARARGS}, diff --git a/Cassiopee/OCC/OCC/occ.h b/Cassiopee/OCC/OCC/occ.h index e625025ce..47f74ea89 100644 --- a/Cassiopee/OCC/OCC/occ.h +++ b/Cassiopee/OCC/OCC/occ.h @@ -68,6 +68,7 @@ namespace K_OCC PyObject* splitFaces(PyObject* self, PyObject* args); PyObject* fixShape(PyObject* self, PyObject* args); PyObject* trimFaces(PyObject* self, PyObject* args); + PyObject* sewing(PyObject* self, PyObject* args); PyObject* getOppData(PyObject* self, PyObject* args); diff --git a/Cassiopee/OCC/srcs.py b/Cassiopee/OCC/srcs.py index 22762448b..689c79ec1 100644 --- a/Cassiopee/OCC/srcs.py +++ b/Cassiopee/OCC/srcs.py @@ -53,9 +53,11 @@ def getFiles(module): 'OCC/Atomic/analyse.cpp', 'OCC/Atomic/getFaceArea.cpp', 'OCC/Atomic/areEdgeIdentical.cpp', + 'OCC/Atomic/splitter.cpp', 'OCC/Atomic/fix.cpp', 'OCC/Atomic/trim.cpp', + 'OCC/Atomic/sewing.cpp', 'OCC/Atomic/getOppData.cpp']