Changing shape transformation and performing boolean operations

I'm seeing some strange behavior when setting the location of a shape, then applying a boolean operation.

Here is some example code:
TopoDS_Shape box = BRepPrimAPI_MakeBox(150, 60, 10);
TopoDS_Shape cylinder = BRepPrimAPI_MakeCylinder(3, 12);
gp_Trsf transformation;
transformation.SetTranslation(gp_Vec(100, 30, 5));
cylinder.Location(TopLoc_Location(transformation));
TopoDS_Shape shape = BRepAlgoAPI_Cut(box, cylinder);
BRepMesh::Mesh(shape, 1);
~~~~~~~~~~~~~

This code is supposed to get the boolean intersection of a rectangular prism and a cylinder.
However, after triangulating the shape and iterating over the faces, the result shape triangulation includes the bottom faces of the cylinder as if they hadn't been translated.
There's similar behavior when applying a boolean union operation via BRepAlgoAPI_Fuse.

Is this a bug?

The only way I can get the desired result of the boolean operation is to use BRepBuilderAPI_Transform or BRepBuilderAPI_GTransform.
E.g.

gp_GTrsf trans;
trans.SetTranslationPart(gp_XYZ(100, 30, 5));
cylinder = BRepBuilderAPI_GTransform(cylinder, trans);

This gives me the desired result except that I'd like to retain the location information in the shape. I.e. when applying this way, the result cylinder has location at (0, 0, 0) instead of (100, 30, 5).

Perhaps I'm doing something wrong.
Is there a different way to achieve this?

Pawel's picture

Hi Jeff,

I guess meshing will always operate on the "original" faces so that the transformation has to be applied separately on the mesh.

What is the result if you visualize the resulting shape after the boolean operation (not its triangulation)? Is this shown correctly?

Pawel

Stephane Routelous's picture

if you are using Handle_Poly_Triangulation, do you transform your triangle points of your triangulation with the location from
BRep_Tool::Triangulation(aFace, theLocation); ?

P1 = Nodes3d.Value(n1).Transformed(theLocation.Transformation());

Stephane

Jeff Moody's picture

I'm using the code from the TopologyTriangulation sample project. However, this code doesn't use the location that is found by the call to BRep_Tool::Triangulation(aFace, theLocation).

After modifying the code as you suggest (i.e. calling Transformed() on the points of the triangle), it works great!

Thanks a bunch, Stephane.

Pawel's picture

One more thing,

you might have found a solution for my problem. Check out:

http://www.opencascade.org/org/forum/thread_14993/

Based on your post I guess BRepBuilderAPI_GTransform (in contrary to BRepBuilderAPI_Transform) "makes the transformation permanent".

I'll test it and let you know.

Pawel

Jeff Moody's picture

The shape that is the result of the boolean operation displays fine.
However, since I'm using the triangulation to create a shape for another environment, this isn't good enough.

As far as the problem you're having with moving shapes, I replied to your posting on that thread.