selfintersection of wires during offsetting


I am trying to offset a wire multiple no of times till no of obtained offset wires is achieved.But,instead of coming out of loop the code is crashing when it is achieved!

here is the code sample:

void CImportExportDoc::Offset(TopoDS_Wire &W)
const GeomAbs_JoinType Join=GeomAbs_Arc;
Handle(AIS_Shape) ais7=new AIS_Shape(W);
BRepOffsetAPI_MakeOffset off(W,GeomAbs_Arc);
Standard_Real dist2 = -200;
Standard_Real NoW,NoE;
off.Perform(dist2); //the code crashes here
TopoDS_Shape S5= off.Shape();
ShapeAnalysis_ShapeContents SA; //to analyse the given shape
NoW=SA.NbWires(); //no. of wires in the shape
NoE=SA.NbEdges(); //no. of edges in the wire
TopExp_Explorer Exp1;
for(Exp1.Init(S5,TopAbs_EDGE);Exp1.More();Exp1.Next()) //exploring the shape into edges
TopoDS_Edge l_edge = TopoDS::Edge(Exp1.Current());
Handle(Geom_Curve) aCurve = BRep_Tool::Curve(l_edge,u,v);
GeomAdaptor_Curve c(aCurve );

Fernando Ghedin's picture

Hello Divya,

Have you checked if the Perform() method raises an exception? It might be helpful.

(... your code ...)
catch (Standard_Failure)
Handle (Standard_Failure) lErrorHandle = Standard_Failure::Caught();
Standard_CString lErrorMessage = lErrorHandle->GetMessageString();

Now I am curious: is it possible that the Offset of a Wire creates a Shape which has no Wire? Is this what you expect?

Best Regards,

P Dolbey's picture

Simple question - whats the value of dist2 when the algorithm crashes. What happens if you change the loop to

do {
} while (dist2 != 0);


P Dolbey's picture

The above runs the risk of not terminating properly if you used dist2 = dist - 11 (or some other number that doesn't terminate). Also NoW amd NoW look like int (or Standard_Integer) to me.

Pete again

P Dolbey's picture

...should read NoW and NoE...

Divya's picture

Tts -1.83. I'm trying to get negative offset here,where it should split into 2or more offset wires if necessary!

Divya's picture

I just checked using try-catch, Perform() raises an exception.How else can I do offset if perform fails?
Any method to fix this?

Please reply

Tilman Leune's picture

I am experiencing the same Problem. I would like to use MakeOffset to 'simplify' my Shape by extruding it a small amount, then shrinking it back. Perform throws an exception if my Extrusion would result in self-intersection in the new shape.

Is this by Design, or is the BRepMakeOffsetAPI still under construction?

In the Documentation it reads alike the lines as if edge-Joining could be performed by this Function.