Boolean operation CUT

Hi,

I have a doubt about the Boolean operations in OCC.
I have two wires W1,W2.
link: http://picasaweb.google.com/lh/photo/z9iVDzmtGA1CtkgRpOLUKQ?feat=directlink

I have the offset of wire W1 as S1.
link: http://picasaweb.google.com/lh/photo/KlriribhbdNbzSNmIiwt9w?feat=directlink

Now,I want to perform CUT operation on S1 and W2 so as to remove the common portion and get the resultant as a shape 'S'.
link: http://picasaweb.google.com/lh/photo/IzanPmnqJwu-OIJ0bRUW8g?feat=directlink

But the output obtained is either S1 or W2, but not the resultant wire.
if the Cut operation is between (S1,W2)the result is
link1: http://picasaweb.google.com/swathirao.8/BooleanOperation?feat=directlink...

if the Cut operation is between (W2,S1)the result is
link2: http://picasaweb.google.com/swathirao.8/BooleanOperation?feat=directlink...

My code is
TopoDS_Shape res1=W1;
TopoDS_Shape res2=W2;
const GeomAbs_JoinType Join=GeomAbs_Tangent;
Standard_Real dist2 = -1.5;
BRepOffsetAPI_MakeOffset off(W1,GeomAbs_Tangent);
off.Perform(dist2);
TopoDS_Shape S1= off.Shape();
BOP_WireWire Wire;
Wire.SetShapes (S1,res2);
Wire.SetOperation(BOP_CUT);
Wire.Do();
TopoDS_Shape S=Wire.Result();
Handle(AIS_Shape) ais2=new AIS_Shape(S);
aDoc->GetAISContext()->Display(ais2,Standard_True);

The Shape S should be the result obtained after cut operation.
But S is displaying either S1 or res2. The two wires are intersecting so the resultant obtained should be the combination of two wires with the common part(the purple wire inside the red wire) removed. Can anyone help me please. How can I get the resultant wire S as a combination of S and res2?

Thanks a lot,
Sindhu

Marco Matt's picture

It seems to me that you are working on a plane.
If this is tha case I suggest a different approach.

Build 2 faces with S1 and res2 using BRepBuilderAPI_MakeFace(wire, true)
Intersect the two faces with BRepAlgoAPI_Common
Extract the external wire of the resulting shape with ShapeAnalysis_FreeBounds

Roman Lygin's picture

Hi Sindhu,

As far as I remember BOP are not supposed to work on two wires (edges). And this is obvious as this operation does not make (much) sense. If you really want to cut W2 from S1 then a possible approach could be to create a solid of extrusion (i.e. prism) using a profile of W2.

Here is the result I simulated in DRAW - http://myphoto.nnov.ru/img/25a8c0f84462fb1b6aadb1babdd62377.png

The solid should not be tangential to the plane where S1 lies in (e.g. you can translate it by half its height in an opposite direction) - http://myphoto.nnov.ru/img/75bf33e3f727b4b104d9e784c26eb28e.png

Note that the resulting shape only contains segments of the original wire and thus is open. If you need it closed you will have to add missing parts.

Hope this helps.
Roman
---
opencascade.blogspot.com - the Open CASCADE blog

SINDHU's picture

Hi Marco,

I have implemented your code and got struck at a point. you have mentioned that
"Extract the external wire of the resulting shape with ShapeAnalysis_FreeBounds"
Can you please give me a sample code on how to extract the external wire of the resulting shape with ShapeAnalysis_FreeBounds?

Thanks a lot for the help,
Sindhu

Marco Matt's picture

The resulting shape of the common operation is RESULT

ShapeAnalysis_FreeBounds ana(RESULT, 1e-3, Standard_True, Standard_True);
TopExp_Explorer exp(ana.GetClosedWires(), TopAbs_WIRE);
Q_ASSERT(exp.More());
TopoDS_Wire whatYouAreSearching = TopoDS::Wire(exp.Current());
exp.Next();
Q_ASSERT(!exp.More());

[code not tested]

SINDHU's picture

Hi Roman,

I had the process of extrusion and then performing Boolean operation in mind as a last choice to implement.As, it is a complex process. But, I was trying if I can do it in any other way instead of extrusion. I wanted exactly what you said. The remaining part of the outer wire. I was trying if it works using the method Marco has suggested. The output obtained after COMMON operation is to be removed and the rest of the outer wire is to be extracted. I didn't understand how to use ShapeAnalysis_FreeBounds to extract it. Can you please help me by giving a sample code if possible?

Thanks a lot
Sindhu

SINDHU's picture

Thank you Marco and Roman for your great help.
I was able to perform the Boolean operation Cut on wires by converting them into faces.
My code goes like this:
TopoDS_Face F1=BRepBuilderAPI_MakeFace (W1,true);
TopoDS_Face F2=BRepBuilderAPI_MakeFace (W2,true);
TopoDS_Shape S1=BRepAlgoAPI_Cut (F1,F2);
ShapeAnalysis_FreeBounds Final(S1,Standard_True,Standard_False);
TopoDS_Compound T=Final.GetClosedWires();

Thanks a lot
Sindhu