For all issues regarding the Forums use, please, refer to the Forum Rules.

Our Solutions

Need professional assistance?
Consider our:

Support Offerings

 

Need to speed up your development?
Have a look at our:

Samples & Tools

 

Need some functionality extending standard OCCT capabilities?
Check out our:

Adv. Components

Related pages

BRepPrimAPI_MakePrism not closing shape

Jeff Moody's picture
Forums: 

I'm creating a polygon using BRepBuilderAPI_MakePolygon, then using BRepPrimAPI_MakePrism to extrude the polygon to become a 3D shape.

However, the resulting shape isn't being closed.
E.g. if I create the polygon using coordinates in the X-Y plane, then extrude in the Z direction using BRepPrimAPI_MakePrism with the constructor that takes a gp_Vec(0, 0, 1), it creates a shape with the top being the polygon and has sides, but there's no bottom (which should be the same as the top polygon, with reversed Z normals).

Is this expected behavior?
How do you generate the bottom?

Roman Lygin's picture

Hi Jeff,

You definitively do something wrong. If your base is a face and you are doing a prism out of it, the final solid will be water-proof with top, bottom and lateral faces.
Here is a simple set of commands in DRAW that emulates what you do:

Draw> pload ALL
Draw> polyline p 0 0 0 100 50 0 50 100 0 0 0 0
Draw> mkplane f p 1
Draw> prism pr f 0 0 200

Check the source code of commands (you can get it by calling getsource , e.g. getsource polyline) and compare with your code. Hope you will find a difference somewhere.

Good luck !
Roman

---
opencascade.blogspot.com - blog on Open CASCADE
Join the Open CASCADE Group at LinkedIn

Jeff Moody's picture

Roman,
Thanks for you help.
This appears to be a bug in the BRepMesh::Mesh() function.

To make it easier for someone to look into this, what I did was use the code from my previous posting in the TopologyTriangulation project, in the TopologyTriangulationDoc.cpp, in the CTopologyTriangulationDoc::OnVisu() method.

Basically, just create the polygon as mentioned, just before the call to:
BRepMesh::Mesh(ShapeFused,1);

I.e. copy the following code:
BRepBuilderAPI_MakePolygon polygon;
polygon.Add(gp_Pnt(0, 0, 0));
polygon.Add(gp_Pnt(0, 10, 0));
polygon.Add(gp_Pnt(10, 10, 0));
polygon.Add(gp_Pnt(10, 0, 0));
polygon.Close();
TopoDS_Wire wire = polygon.Wire();
TopoDS_Face face = BRepBuilderAPI_MakeFace(wire);
ShapeFused = BRepPrimAPI_MakePrism(face, gp_Vec(0, 0, -1));

BRepMesh::Mesh(ShapeFused,1);

~~~~~~~~~~~~~~~~~

Then run the app and click on the 3rd toolbar button from the left, on the top row (it has a red icon).
If you rotate the box, you'll see that the bottom doesn't have the triangulated faces.

I'd really appreciate if someone looks into this issue.

If there's a way to submit bug reports, I'd be happy to submit this if someone would tell me where to go.

Paul Jimenez's picture

BRepBuilderAPI_MakePolygon creates a wire. Are you creating a face from that wire before calling BRepPrimAPI_MakePrism?

Jeff Moody's picture

Yes. I'm doing something like the following:

BRepBuilderAPI_MakePolygon polygon;
int numRows = points->GetRowCount();
for (int i = 0; i {
points->GetElementValue(i, 0, &x);
points->GetElementValue(i, 1, &y);
polygon.Add(gp_Pnt(x, y, 0));
}
polygon.Close();
TopoDS_Face face = BRepBuilderAPI_MakeFace(polygon.Wire());
TopoDS_Shape shape = BRepPrimAPI_MakePrism(face, gp_Vec(0, 0, depth));

Jeff Moody's picture

One more thing...
After creating the prism, I'm triangulating using:
BRepMesh::Mesh(shape, 1);

I'm then iterating over the triangulated faces and using this information to create a new shape, but it appears that one of the faces is not triangulated.

Using an example project, the following code should demonstrate that the triangulation doesn't include the bottom face:

BRepBuilderAPI_MakePolygon polygon;
polygon.Add(gp_Pnt(0, 0, 0));
polygon.Add(gp_Pnt(0, 10, 0));
polygon.Add(gp_Pnt(10, 10, 0));
polygon.Add(gp_Pnt(10, 0, 0));
polygon.Close();

TopoDS_Wire wire = polygon.Wire();
TopoDS_Face face = BRepBuilderAPI_MakeFace(wire);
TopoDS_Shape prism = BRepPrimAPI_MakePrism(face, gp_Vec(0, 0, -1));
BRepMesh::Mesh(prism, 1);
Handle (AIS_Shape)aSection = new AIS_Shape(prism);
myAISContext->SetDisplayMode(aSection,1);
myAISContext->SetColor(aSection,Quantity_NOC_RED);
myAISContext->SetMaterial(aSection,Graphic3d_NOM_GOLD);
//myAISContext->SetTransparency(aSection,0.1);
myAISContext->Display(aSection);

BRep_Builder builder;
TopoDS_Compound Comp;
builder.MakeCompound(Comp);
for (TopExp_Explorer ex(shape, TopAbs_FACE); ex.More(); ex.Next()) {
TopoDS_Face F = TopoDS::Face(ex.Current());
TopLoc_Location L;
Handle (Poly_Triangulation) facing = BRep_Tool::Triangulation(F,L);
TColgp_Array1OfPnt tab(1,(facing->NbNodes()));
tab = facing->Nodes();
Poly_Array1OfTriangle tri(1,facing->NbTriangles());
tri = facing->Triangles();
for (Standard_Integer i=1;iNbTriangles());i++) {
Poly_Triangle trian = tri.Value(i);
Standard_Integer index1,index2,index3,M,N;
trian.Get(index1,index2,index3);
for (Standard_Integer j=1;j switch (j) {
case 1 :
M = index1;
N = index2;
break;
case 2 :
N = index3;
break;
case 3 :
M = index2;
}
BRepBuilderAPI_MakeEdge ME(tab.Value(M),tab.Value(N));
if (ME.IsDone()) {
builder.Add(Comp,ME.Edge());
}
}
}
}
Handle (AIS_Shape) atriangulation = new AIS_Shape(Comp);
myAISContext->SetDisplayMode(atriangulation,0);
myAISContext->SetColor(atriangulation,Quantity_NOC_WHITE);
myAISContext->Display(atriangulation);

Fit();

Christian R. Krug's picture

Hello Jeff,

if you want to create a face from a planar wire, you should call
TopoDS_Face face = BRepBuilderAPI_MakeFace(wire, Standard_True);
The default argument is Standard_False, which is the cause for your troubles.

Using the planar constructor of MakeFace and then applying it to MakePrism creates a perfect solid. You can check this in the test harness with the 'checkshape' command.

Regards, Kris.

Jeff Moody's picture

Hi Kris,
Making the change you suggest didn't fix the issue. However, it did make me try passing non default arguments to make the prism and got it working by adding a parameter as follows:
BRepPrimAPI_MakePrism(face, gp_Vec(0, 0, -1), Standard_True);

Thanks for your help!
-Jeff

Kostadin Vrantzaliev's picture

I know it is an old topic, but to share my experience. I tried to make a cylinder as a solid and then triangulating, one of the face triangles were missing. 

The problem is that when get the triangulation, don't use BRepTools::Clean(face).

This causes problems, enumerate the triangulations of all the faces, take the triangles, then clean the faces.

I hope this will help some of the people.

Contact us

Attention: DO NOT use this form for all kind of request for the removal of your personal data. Please follow this link for such cases.