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

Import/Export of shapes to custom data structure

Bernhard Mallinger's picture


I'm trying to use OCC for CSG in my application, where i have my own representation of shapes. Therefore the shapes have to be converted multiple times and somewhere the "sign" of a shape seems to flip. I.e. in some operations, actual shapes are treated as holes such that if you use BRepAlgoAPI_Fuse on two shapes, one will be subtracted from the others.

Therefore I was wondering how to do an import from and to TopoDS_Shapes properly. My shapes are only polyhedra, I'm using jCAE in case this matters.

My export to TopoDS_Shape works like this (I can provide the code if necessary):

For all faces:
For all edges of the face:
use BRepBuilderAPI_MakeEdge and end points of the edge to create a TopoDS_Edge

use bRepBuilderAPI_MakeWire on all edges to create a TopoDS_Wire
use BRepBuilderAPI_MakeFace to create a face

use BRepBuilderAPI_Sewing on all faces to create the shape

The direction from OCC to my data structures works like this (I'm only accepting results which form one single solid, no holes):

For all faces of the solid:
For all wires (according to TopExp_Explorer(face, TopAbs_ShapeEnum.WIRE)):
For all edges:
use BRep_Tool.pnt to get coordinates of vertices of edge
... basically construct my solid in a straightforward manner ...

I know that sometimes the orientation of faces is used to determine what is outside and what is inside. By playing around with this, I managed to get it to work for most of the time, when the original shapes are prisms, which have some consistent orientation. It is done by making sure that base and top of the prism are both rotated counterclockwise and exporting the side faces with points in a certain consistent order.
However tricks like this don't really seem to work for the general case, where there are arbitrary polyhedrons, passed between my code and occ for a number of times.

So is there some other way to get shapes in and out of occ? In case my approach is reasonable, how can I make sure that inside and outside are determined correctly?

Kind regards,