Build Face / Surface from triangulation

Hello,

I'm trying to build an open cascade model from a triangulation. My current approach goes like this:

- for each triangle create a wire with BRepBuilderAPI_MakePolygon
- create a face from the wire with BRepBuilderAPI_MakeFace
- Use BRep_Builder to add the created faces to a shell

Now I'd like to merge neighbored triangles into one face, so I don't have to see the edges from the original triangulation. Is there a way to do that in open cascade? I already tried connecting the faces with BRepBuilderAPI_Sewing or BRepAlgoAPI_Fuse, but the edges still remain after these operations. I also tried BRepAlgoAPI_Fuse, which threw several exceptions.

If it's not possible to merge two adjescent faces and remove the connecting edges, is there a way to build a surface from the triangulation?

Regards

Göran

Joachim Greiner's picture

Hello Göran

I´m facing the same problem. Have you found any solution so far?

Regards
Joachim

Göran Barz's picture

Hi Joachim,

I haven't found a really satisfying solution covering all cases so far. If the triangles are planar, I create the wire surrounding all faces and then build the face with BRepBuilderAPI_MakeFace, if they aren't planar I'm currently using BRepFill_Filling, but this doesn't work for all cases.

Regards

Göran

oscar's picture

Hi, Göran, I meet the problem too. You said "If the triangles are planar, I create the wire surrounding all faces and then build the face with BRepBuilderAPI_MakeFace", can you get the source code of example? thanks.

Göran Barz's picture

BRepBuilderAPI_MakePolygon MP;

//todo: add the points from the edges to MP
//gp_Pnt pnt;
//MP.Add(pnt);

BRepBuilderAPI_MakeFace makeFace(MP.Wire());
if (makeFace.Error() == BRepBuilderAPI_FaceDone)
{
TopoDS_Face faceCurrent = makeFace.Face();
}

oscar's picture

Hi, Göran, thank you for your answer. But I think your solution is just for polygon without holes. My case is a polygon with a hole in it, and I have tried to find out all free edges through BRepBuilderAPI_Sewing and then created wires from them, but I could not found a way to check the outer wire. Do you have any idea?

Göran Barz's picture

If you know, which points belong to the outer wire and which points belong to the hole, you can first build the outer face and add the hole afterwords:
//faceCurrent contains the polygon without the hole,
//MP contains the points of the Hole

BRepBuilderAPI_MakeFace makeFace(faceCurrent);
makeFace.Add(MP.Wire());
if (makeFace.Error() == BRepBuilderAPI_FaceDone)
{
faceCurrent = makeFace.Face();
}

oscar's picture

That is the point, I can get wires belong to the face only, but can not know which wire is the outer wire. I can not find a way to check out the wire is an outer wire or not.

Sharad Verma's picture

Is it what you are looking for?

TopoDS_Wire outerWire = BRepTools::OuterWire(TopoDS::Face(face));

oscar's picture

Hi, Sharad, thank you. But it is not the answer, you know, the face is not constructed yet. we just have some wires, and want to build up the face using those wires.

Sharad Verma's picture

Try the below code. I m not sure if it will work or not. But try atleast, if you have not tried this.

int nWireCount; // Number of Wires

// Building Wire
ShapeExtend_WireData *pBoundaryWire = new ShapeExtend_WireData();

//Loop all the wires
for(int j=0; j(arr_Wires[j]);
pBoundaryWire->Add(pWire);
}

ShapeFix_Wire fixBoundaryWire;
fixBoundaryWire.Load(pBoundaryWire);
fixBoundaryWire.Perform();
fixBoundaryWire.FixReorder();
fixBoundaryWire.FixConnected();

// Creating OCCT Face
BRepBuilderAPI_MakeFace aFace(fixBoundaryWire.Wire(), Standard_True);

Sharad Verma's picture

Try the below code. I m not sure if it will work or not. But try atleast, if you have not tried this.

int nWireCount; // Number of Wires

// Building Wire
ShapeExtend_WireData *pBoundaryWire = new ShapeExtend_WireData();

//Loop all the wires
for(int j=0; j(arr_Wires[j]);
pBoundaryWire->Add(pWire);
}

ShapeFix_Wire fixBoundaryWire;
fixBoundaryWire.Load(pBoundaryWire);
fixBoundaryWire.Perform();
fixBoundaryWire.FixReorder();
fixBoundaryWire.FixConnected();

// Creating OCCT Face
BRepBuilderAPI_MakeFace aFace(fixBoundaryWire.Wire(), Standard_True);

Sharad Verma's picture

Hi,

Did my code work? Or you found out the solution?

oscar's picture

Hi, Sharad, Sorry, so late to reply you. I have tried your code, but it could not be compiled, because of the ShapeExtend_WireData instance("error C2661: 'Standard_Transient::operator new': no overloaded function takes 3 arguments"), I am finding the problem.

oscar's picture

can not define new to DEBUG_NEW

oscar's picture

Hi, Sharad, it is not work. it will remove the big wire, leave the small wire!