Skip to content

Commit

Permalink
OCC: add basic sewing
Browse files Browse the repository at this point in the history
  • Loading branch information
benoit128 committed Sep 13, 2024
1 parent 56ee29d commit f78e818
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 1 deletion.
91 changes: 91 additions & 0 deletions Cassiopee/OCC/OCC/Atomic/sewing.cpp
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
*/
// 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;
}
1 change: 0 additions & 1 deletion Cassiopee/OCC/OCC/Atomic/splitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions Cassiopee/OCC/OCC/occ.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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},

Expand Down
1 change: 1 addition & 0 deletions Cassiopee/OCC/OCC/occ.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 2 additions & 0 deletions Cassiopee/OCC/srcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']

Expand Down

0 comments on commit f78e818

Please sign in to comment.