problem: making face from wire

Hello,

I came across a problem making face from wire: the face can not be built.
It's supposed to have a solid in the end, however i get the result like the pic shows.
Could someone tell me where am i wrong?

the code is below:

TopoDS_Wire aWire1=BRepBuilderAPI_MakeWire(aEdge1,aEdge2,aEdge3,aEdge4);
TopoDS_Wire aWire2=BRepBuilderAPI_MakeWire(aEdge3,aEdge4,aEdge5);
BRepBuilderAPI_MakeWire wire;
wire.Add(aWire1);
wire.Add(aWire2);
TopoDS_Wire aWire=wire.Wire();

////////////////
gp_Pnt origin(0,0,0);
gp_Dir xDir(0,0,1);
gp_Ax1 mirrorAxis(origin,xDir);
gp_Trsf aTrsf;
aTrsf.SetMirror(mirrorAxis);
BRepBuilderAPI_Transform aBrepTrsf(aWire,aTrsf);
TopoDS_Shape aMirrorShape=aBrepTrsf.Shape();
TopoDS_Wire aMirrorWire=TopoDS::Wire(aMirrorShape);

BRepBuilderAPI_MakeWire mkWire;
mkWire.Add(aWire);
mkWire.Add(aMirrorWire);
TopoDS_Wire profileWire=mkWire.Wire();

TopoDS_Face aFace=BRepBuilderAPI_MakeFace(profileWire);
gp_Vec aPrismVec(length,0,0);
TopoDS_Shape body=BRepPrimAPI_MakePrism(aFace,aPrismVec);

Attachments: 
Game Milky's picture

Hello shanvens,

In my case, the edges are disconnected and i somehow connected them and created a wire, and I mirrored the wire. When i try to add them to one wire (wire and mirrorWire) it doesn't work. Would you please share your idea!
With regards

Game

Game!

George Feng's picture

The wire should be reordered firstly with ShapeFix.

TopoDS_Wire OccUtility::MakeWireWithEdges(CList &aEdgeList)
{
TopoDS_Edge aEdge;
BRepBuilderAPI_MakeWire aMakeWire;
Standard_Real tol = 0.01;
ShapeFix_ShapeTolerance FTol;

Handle(ShapeExtend_WireData) sbwd1 = new ShapeExtend_WireData();
POSITION pos = aEdgeList.GetHeadPosition();

while (pos)
{
aEdge = aEdgeList.GetNext(pos);
sbwd1->Add(aEdge);
}

Handle(ShapeFix_Wire) sfw = new ShapeFix_Wire;
sfw->Load(sbwd1);
sfw->Perform();
//Reorder edges is very important
sfw->FixReorder();
sfw->SetMaxTolerance(tol);
///////////////////////////////////
sfw->ClosedWireMode() = Standard_True;
sfw->FixConnected(1.e-3);
sfw->FixClosed(1.e-3);

for (int i = 1; i <= sfw->NbEdges(); i ++)
{
TopoDS_Edge Edge = sfw->WireData()->Edge(i);
FTol.SetTolerance(Edge, tol, TopAbs_VERTEX);
aMakeWire.Add(Edge);
}

TopoDS_Wire aWire = aMakeWire.Wire();
return aWire;
}

Game Milky's picture

Dear Feng;

Thank for your reply!
I have a difficulty to implement your suggestion into my case,
I have disconnected, disordered , and wrongly oriented Edges in TopoDS_Shape shapecommon. I have order, connect, and propertly orient this edges and make a wire from them. Finally to make face...........

Standard_Real tol = 0.01;
BRepBuilderAPI_MakeWire brepMake;
ShapeFix_ShapeTolerance FTol;

Handle(ShapeExtend_WireData) aWD = new ShapeExtend_WireData();
TopExp_Explorer edgeExp; for(TopExp_Explorer edgeExp(shapeCommon, TopAbs_EDGE); edgeExp.More(); edgeExp.Next()) //TopDS_Shape shapecommon -consists disconnected edges
{
TopoDS_Edge Edge = TopoDS::Edge(edgeExp.Current());
POSITION pos = Edge.GetHeadPosition(); // Here I replaced aEdgeList with explored Edge, but it doesn't work!
While(pos) //Doesn't Understand the syntax POSITION
{
aEdge = Edge.GetNext(pos);
aWD->Add(aEdge);
}
}

Handle(ShapeFix_Wire) aShFW = new ShapeFix_Wire();
aShFW->Load(aWD);
aShFW->Perform();
// aShFW->ClosedWireMode() = Standard_True;
aShFW->FixReorder();
aShFW->SetMaxTolerance(tol);
aShFW->ClosedWireMode() = Standard_True;
aShFW->FixConnected(1.e-3);
aShFW->FixClosed(1.e-3);
for (int i = 1; i <= aShFW->NbEdges(); i ++)
{
TopoDS_Edge Edge = aShFW->WireData()->Edge(i);
FTol.SetTolerance(Edge, tol, TopAbs_VERTEX);
brepMake.Add(Edge);
}

TopoDS_Wire wire = brepMake.Wire();

So, the program doesn't work as i replaced aEdgeList with explored Edge, but it doesn't work!
Would you please suggest me how to correct!
Thank you very much

Regards
Game

George Feng's picture

TopoDS_Wire OccUtility::OrderWire(TopoDS_Wire &aWire)
{
TopoDS_Edge aEdge;
BRepBuilderAPI_MakeWire aMakeWire;
Standard_Real tol = 0.01;
ShapeFix_ShapeTolerance FTol;
TopExp_Explorer ExpEdges;

Handle(ShapeExtend_WireData) sbwd1 = new ShapeExtend_WireData();

for (ExpEdges.Init(aWire, TopAbs_EDGE); ExpEdges.More(); ExpEdges.Next())
{
aEdge = TopoDS::Edge(ExpEdges.Current());
sbwd1->Add(aEdge);
}

Handle(ShapeFix_Wire) sfw = new ShapeFix_Wire;
sfw->Load(sbwd1);
sfw->Perform();
//Reorder edges is very important
sfw->FixReorder();
sfw->SetMaxTolerance(tol);
///////////////////////////////////
sfw->ClosedWireMode() = Standard_True;
sfw->FixConnected(Precision::Confusion());
sfw->FixClosed(Precision::Confusion());

for (int i = 1; i <= sfw->NbEdges(); i ++)
{
TopoDS_Edge Edge = sfw->WireData()->Edge(i);
FTol.SetTolerance(Edge, tol, TopAbs_VERTEX);
aMakeWire.Add(Edge);
}

TopoDS_Wire aWire = aMakeWire.Wire();
return aWire;
}