Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@jay3sh
Created September 3, 2012 03:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jay3sh/3606545 to your computer and use it in GitHub Desktop.
Save jay3sh/3606545 to your computer and use it in GitHub Desktop.
OpenCASCADE 6.5.3 Boolean operations hang
/*
* This Program hangs for values of TOTAL >10
* consuming about 90% when run with OCC 6.5.3 on Ubuntu 11.04
*
* Build instructions
*
* g++ -o forum_main.o -c -I$OCC_INSTALL_DIR/inc forum_main.cpp
*
* g++ -o main -Xlinker -rpath -Xlinker $OCC_INSTALL_DIR/lib forum_main.o \
* -L$OCC_INSTALL_DIR/lib -lTKernel -lPTKernel -lTKMath -lTKService -lTKV3d -lTKV2d -lTKBRep -lTKIGES -lTKSTL -lTKSTEP -lTKSTEPAttr -lTKSTEP209 -lTKSTEPBase -lTKShapeSchema -lTKGeomBase -lTKGeomAlgo -lTKG3d -lTKG2d -lTKXSBase -lTKPShape -lTKShHealing -lTKHLR -lTKTopAlgo -lTKMesh -lTKPrim -lTKCDF -lTKBool -lTKBO -lTKFillet -lTKOffset
*
*/
#define HAVE_LIMITS_H 1
#define HAVE_IOSTREAM 1
#define HAVE_IOMANIP 1
#include <iostream>
#include <sys/time.h>
#include <math.h>
#include <BRepTools.hxx>
#include <BRepBndLib.hxx>
#include <BRep_Builder.hxx>
#include <BRepPrimAPI_MakeBox.hxx>
#include <BRepPrimAPI_MakeTorus.hxx>
#include <BRepPrimAPI_MakeSphere.hxx>
#include <BRepPrimAPI_MakeCylinder.hxx>
#include <BRepPrimAPI_MakeCone.hxx>
#include <BRepAlgoAPI_Fuse.hxx>
#include <BRepAlgoAPI_Cut.hxx>
#include <BRepBuilderAPI_Transform.hxx>
#include <StlAPI_Writer.hxx>
#define TOTAL 10
TopoDS_Shape Box(float x, float y, float z) {
return BRepPrimAPI_MakeBox(x, y, z).Shape();
}
TopoDS_Shape Cylinder(float r, float h) {
return BRepPrimAPI_MakeCylinder(r, h).Shape();
}
TopoDS_Shape translate(TopoDS_Shape shape, float x, float y, float z) {
gp_Trsf trsf;
gp_Vec delta(x, y, z);
trsf.SetTranslation(delta);
BRepBuilderAPI_Transform brep(shape, trsf, Standard_False);
brep.Build();
return brep.Shape();
}
TopoDS_Shape rotate(TopoDS_Shape shape, int axis, float angle) {
gp_Trsf trsf;
gp_Ax1 axe;
switch(axis) {
case 0:
axe = gp_Ax1(gp_Pnt(0,0,0),gp_Dir(1.,0.,0.));
break;
case 1:
axe = gp_Ax1(gp_Pnt(0,0,0),gp_Dir(0.,1.,0.));
break;
case 2:
axe = gp_Ax1(gp_Pnt(0,0,0),gp_Dir(0.,0.,1.));
break;
}
trsf.SetRotation(axe, angle*M_PI/180);
BRepBuilderAPI_Transform brep(shape, trsf, Standard_False);
brep.Build();
return brep.Shape();
}
TopoDS_Shape build_solid() {
TopoDS_Shape solid;
solid = Cylinder(5,10);
float step = 10/TOTAL;
for(int i=0; i<TOTAL; i++) {
float angle = 360 * i/TOTAL;
TopoDS_Shape c = Cylinder(step/1, 12);
c = translate(c,0,0,-5);
c = rotate(c, 0, 90);
c = rotate(c, 2, angle);
c = translate(c, 0,0,10-(i*step));
solid = BRepAlgoAPI_Cut(solid, c);
}
solid = BRepAlgoAPI_Cut(solid, Cylinder(3, 10));
return solid;
}
int main(int argc, char *argv[]) {
timeval t0, t1;
gettimeofday(&t0, NULL);
TopoDS_Shape solid = build_solid();
gettimeofday(&t1, NULL);
double dt = (t1.tv_sec - t0.tv_sec) + (t1.tv_usec - t0.tv_usec)/1000000.0;
std::cout << "Time " << dt << " sec" << std::endl;
StlAPI_Writer writer;
writer.Write(solid, "/tmp/0.stl");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment