Exploring A Wire

I want to collect the contours and the islands from the selected edges.

I am doing it in this way.

1- Get the edge list from screen

2- Sort list by checking connection status and collect together the connected ones. Also i need to check the orientation of edge.

After that i have a list of list (contours & islands)

This solution is a little bit complex.

There should be a ready to use class in OCC about the subject.

I tried BRep_Builder::MakeWire but it is not correcting the orientations. Because finally i want to explore the connected edges (~wire) by giving a parameter like Geom_Curve::Value(aParam).

Any ideas?

 

Benjamin Bihler's picture

Perhaps you may want to create a faulty wire and then fix it with code like this:

bool WireUtilities::isOrdered(const TopoDS_Wire& wire)
{
	ShapeAnalysis_Wire checker;
	checker.Load(wire);

	ShapeAnalysis_WireOrder wireOrder;

	return !checker.CheckOrder(wireOrder, Standard_False, Standard_True);
}

TopoDS_Wire WireUtilities::orderWire(const TopoDS_Wire& wire)
{
	TopExp_Explorer edgesExplorer;

	Handle(ShapeExtend_WireData) wireExtender = new ShapeExtend_WireData();

	for (edgesExplorer.Init(wire, TopAbs_EDGE); edgesExplorer.More();
			edgesExplorer.Next())
	{
		wireExtender->Add(TopoDS::Edge(edgesExplorer.Current()));
	}

	constexpr double tolerance = 0.1;

	ShapeFix_Wire wireFixer;
	wireFixer.Load(wireExtender);
	wireFixer.Perform();
	wireFixer.FixReorder();
	wireFixer.SetMaxTolerance(tolerance);
	wireFixer.ClosedWireMode() = Standard_True;
	wireFixer.FixConnected(Precision::Confusion());
	wireFixer.FixClosed(Precision::Confusion());

	BRepBuilderAPI_MakeWire wireMaker;
	ShapeFix_ShapeTolerance toleranceFixer;

	for (int edgeIndex = 1; edgeIndex <= wireFixer.NbEdges(); ++edgeIndex)
	{
		TopoDS_Edge fixedWireEdge = wireFixer.WireData()->Edge(edgeIndex);
		toleranceFixer.SetTolerance(fixedWireEdge, tolerance, TopAbs_WIRE);
		wireMaker.Add(fixedWireEdge);
	}

	return wireMaker.Wire();
}

Benjamin

Kadir Canik's picture

Dear Benjamin,

Thanks for your answer. I found a way like this;

void Edge_Sequence_To_Wire_Sequence(const Handle(TopTools_HSequenceOfShape) theEdges, Handle(TopTools_HSequenceOfShape)& outWires)
{
	TopTools_MapOfShape aMapEdges;
	TColStd_IndexedDataMapOfTransientTransient aMapTShapes;

	Handle(TopTools_HSequenceOfShape) aSeqEdges = new TopTools_HSequenceOfShape;

	for (int i = 1; i <= theEdges->Length(); i++) {
		TopoDS_Edge E = TopoDS::Edge(theEdges->Value(i));
		if (E.IsNull()) continue;
		if (aMapEdges.Add(E)) {
			TopoDS_Shape aShapeCopy;
			TNaming_CopyShape::CopyTool(E, aMapTShapes, aShapeCopy);
			aSeqEdges->Append(aShapeCopy);
		}
	}

	ShapeAnalysis_FreeBounds::ConnectEdgesToWires(aSeqEdges, Precision::Confusion(), Standard_False, outWires);
}