Open CASCADE, the 3D modelling kernel
3D modeling & numerical simulation

Search the Forums
See All Topics


Stefan Rehling 2002/07/05 14:51
Hi eveybody,
I have a problem... I want to use OpenCASCADE in two different ways. Firstly to simply visualize motions of parts of a machine tool structure and secondly to calculate overlapping volumes between parts. This calculation cannot be done with boolean operations because I have to simulate a tool path through a workpiece, and lots of such operations have to be made during the simulation.
The 3D Data of the machine tool parts is given in STL-format and there is no way for me to get IGES or STEP representations of these parts which could be read in easyly with OpenCASCADE. So how can I import STL? Can you give me an example on how to do the import usig the OCC primitives and which works fastly. Or is there any library available which does the job?
Patrik Müller 2002/07/05 15:21

try this:

     OSD_Path aFile(FileName);
     Standard_Boolean ReturnValue = Standard_True;

     Handle(StlMesh_Mesh) aSTLMesh = RWStl::ReadFile(aFile);

     TopoDS_Compound ResultShape;
     BRep_Builder CompoundBuilder;

     Standard_Integer NumberDomains = aSTLMesh->NbDomains();
     Standard_Integer iND;
     gp_XYZ p1, p2, p3;
     TopoDS_Vertex Vertex1, Vertex2, Vertex3;
     TopoDS_Face AktFace;
     TopoDS_Wire AktWire;
     BRep_Builder B;
     Standard_Real x1, y1, z1;
     Standard_Real x2, y2, z2;
     Standard_Real x3, y3, z3;

     StlMesh_MeshExplorer aMExp (aSTLMesh);

//     BRepBuilderAPI_MakeWire WireCollector;
     for (iND=1;iND<=NumberDomains;iND++)
          for (aMExp.InitTriangle (iND); aMExp.MoreTriangle (); aMExp.NextTriangle ())
               aMExp.TriangleVertices (x1,y1,z1,x2,y2,z2,x3,y3,z3);

               if ((!(p1.IsEqual(p2,0.0))) && (!(p1.IsEqual(p3,0.0))))
                    Vertex1 = BRepBuilderAPI_MakeVertex(p1);
                    Vertex2 = BRepBuilderAPI_MakeVertex(p2);
                    Vertex3 = BRepBuilderAPI_MakeVertex(p3);
                    AktWire = BRepBuilderAPI_MakePolygon( Vertex1, Vertex2, Vertex3, Standard_True);
                    if( !AktWire.IsNull())
                         AktFace = BRepBuilderAPI_MakeFace( AktWire);
     TopoDS_Shape aShape = ResultShape;

Best regards,

Patrik Müller
Stephane Routelous 2002/07/05 15:43
Take care,

the RWSTL package is buged in the release version 4.0.
You ahve to take the file from the repository to solve the problems.

Patrik Müller 2002/07/05 17:08
My fault - I've forgotten saying that.

My routine in the repository also isn't perfect. I think it should use the source above for building Shapes instead of using sewing.

Best regards,

Patrik Müller
xlbai 2006/07/25 17:03
Hi,Patrik Müller
The listed code sames to construct a BREP model to represent a triangular mesh. Could you give me some advice about how to use TKMesh toolkit, which sames better for triangular mesh.

Patrik Müller 2006/07/25 18:11

what do you want to do?


xlbai 2006/07/26 09:44

I'm do sth about reverse engineering, and firstly point clouds are imported, then triangulate it to construct a mesh, and then segmentation and surface fitting, after that Brep model could be constructed.

So, I need a data struct of triangular mesh which could be manipulated conveniently, e.g. find all edges and triangles associate to a vertex, and find all triangles associate to an edge, and ......, I mean a data structer with enough information about manipulating triangular mesh, for most of the algorithum is based on triangular mesh.


白晓亮(Bai Xiaoliang)
Patrik Müller 2006/07/26 10:51

I think it would be easier for you if you build your own (for example half-edge based) mesh structure...


&#30333;&#26195;&#20142;(Bai Xiaolian 2006/07/26 14:58

Yes, my current work is just using half-edge based data structure. Did you mean OCC is not suit for the work?


白晓亮(Bai Xiaoliang)
Patrik Müller 2006/07/26 16:55
If you already has a data structure in use - why don't you use it inside of OCC instead of trying to map the data to an OCC structure?
OCC isn't so strong for mesh data - but it really depends on your needs...


&#30333;&#26195;&#20142;(Bai Xiaolian 2006/07/27 13:13

Thanks for your advice.

白晓亮(Bai Xiaoliang).
Marcel Janer 2006/10/13 11:17
you can do:

for fast load and render, in shade mode:

     Handle(StlMesh_Mesh) aSTLMesh = RWStl::ReadFile(aFile);
     Handle( MeshVS_Mesh ) aMesh = new MeshVS_Mesh();
     Handle( XSDRAWSTLVRML_DataSource ) aDS = new XSDRAWSTLVRML_DataSource( aSTLMesh );

     aMesh->AddBuilder( new MeshVS_MeshPrsBuilder( aMesh), Standard_True );//False -> No selection

     aMesh->GetDrawer()->SetBoolean(MeshVS_DA_DisplayNodes,Standard_False); //MeshVS_DrawerAttribute

     aMesh->SetDisplayMode( MeshVS_DMF_Shading ); // Mode as defaut
     aMesh->SetHilightMode( MeshVS_DMF_WireFrame ); // Wireframe as default hilight mode



Marcel Janer.
Jang-hom Lin 2002/07/06 09:43
OCC is not good enough to do STL operation.There are some ways which are discussed above to import STL.But OCC does not provides enough methods to do mesh operation (just like Boolean).
It may be better to use VTK as your Toolkit.
Good luck to you.
SunHongLei 2012/11/19 13:34
hello,I want to know that does VTK contains the alogrithm about triangle mesh simplification?
Thanks !
Latest news
  • Open CASCADE CAD Assistant for iOS platform is available!
  • Open CASCADE Technology 6.9.0 is available for download!
  • JT Assistant for Android

  • © OPEN CASCADE 2000 - 2015  |  Search  |  Contacts   |  Site map