Extrude an area into a Shape…

I’m going to manage this:

1. Create an area, for e.g. a circle, rectangle or an area of polygons.
2. Extrude the area at a given direction and length.
3. Retrieve the TopoDS_Shape for the geometry.

When I have the Shape I’m going to triangulate it so all my “custom shapes” will be in a common format.

Where can I find code-samples on how to manage this? I quite new to OpenCASCADE but I like it!

Rob Bachrach's picture

1. Create a planar (usually) face or set of sewn faces for your area. If creating a standard shape like a circle, create a curve like a Geom_Circle. Turn that into an edge (BRepBuilderAPI_MakeEdge) and a wire (BRepBuilderAPI_MakeWire). Then, you can create a planar face using BRepBuilderAPI_MakeFace. If creating a polygonal face, you can create a polygonal wire using BRepBuilderAPI_MakePolygon. Areas of multiple polygons would require the sewing of multiple faces into a shell.

2. Use BRepPrimAPI_MakePrism to extrude the shape. Use the constructor that takes a gp_Vec. The length of your vector specifies the length of the finite extrusion. The direction of the vector is the direction.

3. Use the Shape member of MakePrism to get the final shape.

d00_ape's picture

"...like a Geom_Circle. Turn that into an edge (BRepBuilderAPI_MakeEdge) and a wire (BRepBuilderAPI_MakeWire)"

sorry but I don't understand. Do you have any sample code, or do you know any of the samples I can have a look at?

I also wonder how I can create an rectangle (Face) in an easy way...

Rob Bachrach's picture

Under the samples that come with OCC (at least in the WIN32 version), one is called TopologyPrimitives. Select the toolbutton for Prism. The last example is an extrusion of a circular face to make a solid. This will show you the current shape and the code used to create it.

gp_Circ c = gp_Circ(gp_Ax2(gp_Pnt(200.,200.,0.gp_Dir(0.,0.,1.)), 80.);
TopoDS_Edge Ec = BRepBuilderAPI_MakeEdge(c);
TopoDS_Wire Wc = BRepBuilderAPI_MakeWire(Ec);
TopoDS_Face F = BRepBuilderAPI_MakeFace(gp::XOY(),Wc);
TopoDS_Shape S4 = BRepBuilderAPI_MakePrism(F,gp_Vec(0.,0.,100.));

This particular sample gives a lot of simple example code.

As for creating a rectangular face, I guess it depends on your definition of "easy". You have to remember that although a rectangle is a simple shape to us, it is not as simple to the modeler. Unlike a circle, which consists of a single un-trimmed curve, a rectangle consists of 4 trimmed infinite lines. There are several possibilities:

1 - If you are just going to extrude the rectangle to a depth, you might want to look at BRepPrimAPI_MakeBox. This is a convenience function to create a solid rectangular box in a single line of code.

2 - You can create a rectangle using BRepBuilderAPI_MakePolygon by passing the 4 corners of your rectangle and specifying it as closed. Then, create the face using BRepBuilderAPI_MakeFace as in the above example.

3 - Create a plane (gp_Pln), possibly using gce_MakePln. Then, create the rectangular face by calling BRepBuilderAPI_MakeFace and trimming the plane with parameters representing its dimensions:

gp_Pln myPlane(gp::Origin(), gp::DZ());
TopoDS_Face myFace = BRepBuilderAPI_MakeFace(myPlane, -1, 1, -1, 1);