Skip to content

Commit 4f28c82

Browse files
committed
OCC: trimFaces in OCAF
1 parent 8497df6 commit 4f28c82

File tree

11 files changed

+170
-94
lines changed

11 files changed

+170
-94
lines changed

Cassiopee/OCC/OCC/Atomic/addBox.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,13 +116,13 @@ PyObject* K_OCC::addBox(PyObject* self, PyObject* args)
116116
builder.Add(compound, face5);
117117
builder.Add(compound, face6);
118118

119+
#ifdef USEXCAF
120+
119121
BRepBuilderAPI_Sewing sewingTool;
120122
sewingTool.Add(compound);
121123
sewingTool.Perform();
122124
TopoDS_Shape sewedShape = sewingTool.SewedShape();
123125

124-
#ifdef USEXCAF
125-
126126
GETDOC;
127127
addShape2OCAF(sewedShape, name, *doc);
128128
TopoDS_Shape* newshp = copyOCAF2TopShape(*doc);
@@ -152,9 +152,9 @@ PyObject* K_OCC::addBox(PyObject* self, PyObject* args)
152152
}
153153

154154
TopTools_IndexedMapOfShape sf2 = TopTools_IndexedMapOfShape();
155-
TopExp::MapShapes(sewedShape, TopAbs_FACE, sf2);
155+
TopExp::MapShapes(compound, TopAbs_FACE, sf2);
156156
TopTools_IndexedMapOfShape se2 = TopTools_IndexedMapOfShape();
157-
TopExp::MapShapes(sewedShape, TopAbs_EDGE, se2);
157+
TopExp::MapShapes(compound, TopAbs_EDGE, se2);
158158
for (E_Int i = 1; i <= sf2.Extent(); i++)
159159
{
160160
TopoDS_Face F = TopoDS::Face(sf2(i));
@@ -166,7 +166,12 @@ PyObject* K_OCC::addBox(PyObject* self, PyObject* args)
166166
builder2.Add(compound2, E);
167167
}
168168

169-
TopoDS_Shape* newshp = new TopoDS_Shape(compound2);
169+
BRepBuilderAPI_Sewing sewingTool;
170+
sewingTool.Add(compound2);
171+
sewingTool.Perform();
172+
TopoDS_Shape sewedShape = sewingTool.SewedShape();
173+
174+
TopoDS_Shape* newshp = new TopoDS_Shape(sewedShape);
170175

171176
delete shape;
172177
SETSHAPE(newshp);

Cassiopee/OCC/OCC/Atomic/addBox2.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -118,13 +118,13 @@ PyObject* K_OCC::addBox2(PyObject* self, PyObject* args)
118118
builder.Add(compound, face5);
119119
builder.Add(compound, face6);
120120

121+
#ifdef USEXCAF
122+
121123
BRepBuilderAPI_Sewing sewingTool;
122124
sewingTool.Add(compound);
123125
sewingTool.Perform();
124126
TopoDS_Shape sewedShape = sewingTool.SewedShape();
125127

126-
#ifdef USEXCAF
127-
128128
GETDOC;
129129
addShape2OCAF(sewedShape, name, *doc);
130130
TopoDS_Shape* newshp = copyOCAF2TopShape(*doc);
@@ -154,9 +154,9 @@ PyObject* K_OCC::addBox2(PyObject* self, PyObject* args)
154154
}
155155

156156
TopTools_IndexedMapOfShape sf2 = TopTools_IndexedMapOfShape();
157-
TopExp::MapShapes(sewedShape, TopAbs_FACE, sf2);
157+
TopExp::MapShapes(compound, TopAbs_FACE, sf2);
158158
TopTools_IndexedMapOfShape se2 = TopTools_IndexedMapOfShape();
159-
TopExp::MapShapes(sewedShape, TopAbs_EDGE, se2);
159+
TopExp::MapShapes(compound, TopAbs_EDGE, se2);
160160
for (E_Int i = 1; i <= sf2.Extent(); i++)
161161
{
162162
TopoDS_Face F = TopoDS::Face(sf2(i));
@@ -168,8 +168,12 @@ PyObject* K_OCC::addBox2(PyObject* self, PyObject* args)
168168
builder2.Add(compound2, E);
169169
}
170170

171+
BRepBuilderAPI_Sewing sewingTool;
172+
sewingTool.Add(compound2);
173+
sewingTool.Perform();
174+
TopoDS_Shape sewedShape = sewingTool.SewedShape();
175+
171176
TopoDS_Shape* newshp = new TopoDS_Shape(sewedShape);
172-
173177
delete shape;
174178
SETSHAPE(newshp);
175179

Cassiopee/OCC/OCC/Atomic/addCylinder.cpp

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,16 @@
2323
#include "TopTools_IndexedMapOfShape.hxx"
2424
#include "TopExp.hxx"
2525
#include "TopExp_Explorer.hxx"
26-
#include "BRepPrimAPI_MakeSphere.hxx"
2726
#include "BRep_Builder.hxx"
2827
#include "BRepBuilderAPI_MakeEdge.hxx"
2928
#include "BRepBuilderAPI_MakeWire.hxx"
3029
#include "BRepBuilderAPI_MakeFace.hxx"
31-
#include <BRepPrimAPI_MakeCylinder.hxx>
32-
#include <gp_Cylinder.hxx>
33-
#include <gp_Ax2.hxx>
34-
#include <BRepBuilderAPI_MakeFace.hxx>
35-
#include <TopoDS_Shape.hxx>
30+
#include "BRepPrimAPI_MakeCylinder.hxx"
31+
#include "gp_Cylinder.hxx"
32+
#include "gp_Ax2.hxx"
33+
#include "BRepBuilderAPI_MakeFace.hxx"
34+
#include "TopoDS_Shape.hxx"
35+
#include "BRepBuilderAPI_Sewing.hxx"
3636

3737
//=====================================================================
3838
// Add a part cylinder to CAD hook
@@ -45,7 +45,7 @@ PyObject* K_OCC::addCylinder(PyObject* self, PyObject* args)
4545
if (!PYPARSETUPLE_(args, O_ TRRR_ TRRR_ R_ R_ S_,
4646
&hook, &xc, &yc, &zc, &xaxis, &yaxis, &zaxis, &R, &H, &name)) return NULL;
4747

48-
GETPACKET;
48+
GETPACKET;
4949
GETSHAPE;
5050

5151
// Define the radius, height, and angle of the cylinder
@@ -69,8 +69,13 @@ PyObject* K_OCC::addCylinder(PyObject* self, PyObject* args)
6969
builder.MakeCompound(compound);
7070
builder.Add(compound, face);
7171

72+
BRepBuilderAPI_Sewing sewingTool;
73+
sewingTool.Add(compound);
74+
sewingTool.Perform();
75+
TopoDS_Shape sewedShape = sewingTool.SewedShape();
76+
7277
GETDOC;
73-
addShape2OCAF(compound, name, *doc);
78+
addShape2OCAF(sewedShape, name, *doc);
7479
TopoDS_Shape* newshp = copyOCAF2TopShape(*doc);
7580
delete shape;
7681
SETSHAPE(newshp);
@@ -98,7 +103,12 @@ PyObject* K_OCC::addCylinder(PyObject* self, PyObject* args)
98103
}
99104
builder.Add(compound, face);
100105

101-
TopoDS_Shape* newshp = new TopoDS_Shape(compound);
106+
BRepBuilderAPI_Sewing sewingTool;
107+
sewingTool.Add(compound);
108+
sewingTool.Perform();
109+
TopoDS_Shape sewedShape = sewingTool.SewedShape();
110+
111+
TopoDS_Shape* newshp = new TopoDS_Shape(sewedShape);
102112

103113
delete shape;
104114
SETSHAPE(newshp);

Cassiopee/OCC/OCC/Atomic/addGordonSurface.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,6 @@ PyObject* K_OCC::addGordonSurface(PyObject* self, PyObject* args)
100100
#else
101101

102102
TopoDS_Shape* newshp = new TopoDS_Shape(face);
103-
104-
// Rebuild the hook
105103
delete shape;
106104
SETSHAPE(newshp);
107105

Cassiopee/OCC/OCC/Atomic/addSphere.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "TopExp_Explorer.hxx"
2626
#include "BRepPrimAPI_MakeSphere.hxx"
2727
#include "BRep_Builder.hxx"
28+
#include "BRepBuilderAPI_Sewing.hxx"
2829

2930
//=====================================================================
3031
// Add a sphere to CAD hook
@@ -75,18 +76,20 @@ PyObject* K_OCC::addSphere(PyObject* self, PyObject* args)
7576
}
7677

7778
// Add the sphere faces
78-
TopTools_IndexedMapOfShape* sfs = new TopTools_IndexedMapOfShape();
79-
TopExp::MapShapes(sphere, TopAbs_FACE, *sfs);
80-
TopTools_IndexedMapOfShape& surfaces2 = *(TopTools_IndexedMapOfShape*)sfs;
79+
TopTools_IndexedMapOfShape surfaces2 = TopTools_IndexedMapOfShape();
80+
TopExp::MapShapes(sphere, TopAbs_FACE, surfaces2);
8181
for (E_Int i = 1; i <= surfaces2.Extent(); i++)
8282
{
8383
TopoDS_Face F = TopoDS::Face(surfaces2(i));
8484
builder.Add(compound, F);
8585
}
86-
delete sfs;
8786

88-
TopoDS_Shape* newshp = new TopoDS_Shape(compound);
87+
BRepBuilderAPI_Sewing sewingTool;
88+
sewingTool.Add(compound);
89+
sewingTool.Perform();
90+
TopoDS_Shape sewedShape = sewingTool.SewedShape();
8991

92+
TopoDS_Shape* newshp = new TopoDS_Shape(compound);
9093
delete shape;
9194
SETSHAPE(newshp);
9295

Cassiopee/OCC/OCC/Atomic/boolean.cpp

Lines changed: 57 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@
3737
#include "BRepAlgoAPI_Cut.hxx"
3838
#include "BRepAlgoAPI_Common.hxx"
3939

40+
#include "XCAFDoc_DocumentTool.hxx"
41+
#include "TDocStd_Document.hxx"
42+
#include "XCAFDoc_ShapeTool.hxx"
43+
#include "XCAFDoc_ShapeMapTool.hxx"
44+
#include "TDataStd_Name.hxx"
45+
4046
//=====================================================================
4147
// boolean operations
4248
// op=0 (fuse), 1 (cut), 2 (common)
@@ -51,11 +57,9 @@ PyObject* K_OCC::boolean(PyObject* self, PyObject* args)
5157
GETPACKET;
5258
GETSHAPE;
5359
GETMAPSURFACES;
54-
55-
E_Int nfaces1 = PyList_Size(listFaces1);
56-
E_Int nfaces2 = PyList_Size(listFaces2);
5760

5861
// Get compound1
62+
E_Int nfaces1 = PyList_Size(listFaces1);
5963
BRep_Builder builder1;
6064
TopoDS_Compound compound1;
6165
builder1.MakeCompound(compound1);
@@ -76,6 +80,7 @@ PyObject* K_OCC::boolean(PyObject* self, PyObject* args)
7680
if (rev1 == 1) solid1 = TopoDS::Solid(solid1.Reversed());
7781

7882
// Get compound2
83+
E_Int nfaces2 = PyList_Size(listFaces2);
7984
BRep_Builder builder2;
8085
TopoDS_Compound compound2;
8186
builder2.MakeCompound(compound2);
@@ -104,15 +109,60 @@ PyObject* K_OCC::boolean(PyObject* self, PyObject* args)
104109
//unify.Build();
105110
//TopoDS_Shape unified = unify.Shape();
106111

112+
#ifdef USEXCAF
113+
114+
GETDOC;
115+
GETSHAPETOOL;
116+
117+
// suppress somes faces
118+
std::map< E_Int, std::vector<E_Int> > label2Faces;
119+
std::map< E_Int, std::vector<E_Int> > label2Edges;
120+
getLabel2Edges(*doc, label2Edges);
121+
getLabel2Faces(*doc, label2Faces);
122+
123+
for (E_Int i = 0; i < PyList_Size(listFaces1); i++)
124+
{
125+
PyObject* noFaceO = PyList_GetItem(listFaces1, i);
126+
E_Int noFace = PyInt_AsLong(noFaceO);
127+
for (size_t j = 0; j < label2Faces.size(); j++)
128+
{
129+
std::vector< E_Int >& f = label2Faces[j];
130+
f.erase(std::remove(f.begin(), f.end(), noFace), f.end());
131+
}
132+
}
133+
for (E_Int i = 0; i < PyList_Size(listFaces2); i++)
134+
{
135+
PyObject* noFaceO = PyList_GetItem(listFaces2, i);
136+
E_Int noFace = PyInt_AsLong(noFaceO);
137+
for (size_t j = 0; j < label2Faces.size(); j++)
138+
{
139+
std::vector< E_Int >& f = label2Faces[j];
140+
f.erase(std::remove(f.begin(), f.end(), noFace), f.end());
141+
}
142+
}
143+
copyTopShape2OCAF(*shape, label2Edges, label2Faces, *doc);
144+
145+
// Add compound3 as a new shape
146+
TDF_Label label = shapeTool->AddShape(result);
147+
TDataStd_Name::Set(label, "boolean");
148+
149+
// back copy
150+
TopoDS_Shape* newshp = copyOCAF2TopShape(*doc);
151+
delete shape;
152+
SETSHAPE(newshp);
153+
Py_INCREF(Py_None);
154+
return Py_None;
155+
156+
#else
157+
107158
TopoDS_Shape* newshp = new TopoDS_Shape(result);
108-
109-
// Rebuild the hook
110159
delete shape;
111160
SETSHAPE(newshp);
112161

113-
printf("INFO: after boolUnion: Nb edges=%d\n", se->Extent());
114-
printf("INFO: after boolUnion: Nb faces=%d\n", sf->Extent());
162+
printf("INFO: after boolean: Nb edges=%d\n", se->Extent());
163+
printf("INFO: after boolean: Nb faces=%d\n", sf->Extent());
115164

116165
Py_INCREF(Py_None);
117166
return Py_None;
167+
#endif
118168
}

Cassiopee/OCC/OCC/Atomic/copyTopShape2OCAF.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ void K_OCC::copyTopShape2OCAF(TopoDS_Shape& topShape,
8282
builder.Add(compound, F);
8383
}
8484

85-
BRepBuilderAPI_Sewing sewer(1.e-6);
85+
BRepBuilderAPI_Sewing sewer; // 1.e-6
8686
sewer.Add(compound);
8787
sewer.Perform();
8888

Cassiopee/OCC/OCC/Atomic/mergeFaces.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ PyObject* K_OCC::mergeFaces(PyObject* self, PyObject* args)
6060
const TopoDS_Face& F = TopoDS::Face(surfaces(noFace));
6161
builder.Add(compound, F);
6262
}
63-
BRepBuilderAPI_Sewing sewer(1.e-6);
63+
BRepBuilderAPI_Sewing sewer;
6464
sewer.Add(compound);
6565
sewer.Perform();
6666
shp = new TopoDS_Shape(sewer.SewedShape());
@@ -104,10 +104,9 @@ PyObject* K_OCC::mergeFaces(PyObject* self, PyObject* args)
104104

105105
TopTools_IndexedMapOfShape sf = TopTools_IndexedMapOfShape();
106106
TopExp::MapShapes(unifiedShape, TopAbs_FACE, sf);
107-
printf("number of faces in unified=%d\n", sf.Extent());
108107
for (E_Int i = 0; i < sf.Extent(); i++) builder.Add(compound, sf(i+1));
109108

110-
BRepBuilderAPI_Sewing sewer(1.e-6);
109+
BRepBuilderAPI_Sewing sewer;
111110
sewer.Add(compound);
112111
sewer.Perform();
113112
newshp = new TopoDS_Shape(sewer.SewedShape());

Cassiopee/OCC/OCC/Atomic/removeFaces.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ PyObject* K_OCC::removeFaces(PyObject* self, PyObject* args)
103103
GETDOC;
104104
std::map< E_Int, std::vector<E_Int> > label2Faces;
105105
std::map< E_Int, std::vector<E_Int> > label2Edges;
106-
getLabel2Edges(*doc, label2Edges);
106+
//getLabel2Edges(*doc, label2Edges);
107107
getLabel2Faces(*doc, label2Faces);
108108
for (E_Int no = 0; no < PyList_Size(listFaces); no++)
109109
{

0 commit comments

Comments
 (0)