How to add fixed edges to STL geometry?

  • DmitryVK

    DmitryVK - 2012-02-29


    I got the same question as in "Constrain edges in 2D or STL meshing" thread from 2011-05-03 06:34:14 PDT. Can I prevent some edges from STL geometry from moving?

    I tried to use Ng_STL_AddEdge, but can not get expected result. I do like the following:
    Ng_STL_Geometry * geo = Ng_STL_NewGeometry();
    // Add triengles. The figure is a tetrahedron. One its of edges is divided into 10 segments, so the figure is described with 22 triangles
    for(…) {
      Ng_STL_AddTriangle(geo, p1, p2, p3, n);
    // add 10 segments (from tetrahedron's edge division) and 5 other edges. A total of 15 edges.
    for(…) {
      Ng_STL_AddEdge( geo, p1, p2);
    Ng_Result res = Ng_STL_InitSTLGeometry( geo );

    res = Ng_STL_GenerateSurfaceMesh( geom, ngMesh, &meshingParams );
    Ng_SaveMesh( ngMesh, "testMesh_Surf.vol" );

    the mesh is empty.
    If I use Ng_STL_MakeEdges( geom, ngMesh, &meshingParams ); I get good not empty mesh, but it does not contain edges which I defined before geometry initialization.

    Could you help me to solve this problem, please?

    Thank you in advance!

  • DmitryVK

    DmitryVK - 2012-03-03

    Sorry for missing some details. I use Netgen 4.9.14 on Windows 7 OS.
    Your help is really important for me!

  • Ibán Cereijo

    Ibán Cereijo - 2012-03-15

    I had a similar problem.
    This is my invocation sequence:

    geom = Ng_STL_NewGeometry();
    Ng_STL_AddTriangle(geom, ...);
    Ng_STL_AddTriangle(geom, ...);
    Ng_STL_AddEdge(geom, ...);
    Ng_STL_AddEdge(geom, ...);
    Ng_STL_MakeEdges(geom, ...)

    The Ng_STL_AddEdge sentences seemed to be useless, until I realized that Ng_STL_InitSTLGeometry was complaining with the following error messages:

    ERROR: edgepoint does not exist!
     p=[0.5, -0.5, 0.15]
    ERROR: edgepoint does not exist!
     p=[-0.5, -0.5, 0.15]

    The point here is that the above points, p=, p=, …, were introduced via Ng_STL_AddEdge in a previous geometry, invalidating the new edges added to this geometry. Turns out that nglib stores the edges in a static vector. Indeed, in nglib.cpp, there is an array

     Array<Point<3> > readedges;

    which is only cleared in function Ng_STL_LoadGeometry (const char * filename, int binary):

     DLL_HEADER Ng_STL_Geometry * Ng_STL_LoadGeometry (const char * filename, int binary)

    I fixed the problem modifying the function Ng_STL_NewGeometry in nglib.cpp to clean the edges array, and everything went fine.

     DLL_HEADER Ng_STL_Geometry * Ng_STL_NewGeometry ()
         readedges.SetSize(0); // <-- Add this line
         return (Ng_STL_Geometry*)(void*)new STLGeometry;

    If you don't want to modify nglib, I guess you can create the geometry with Ng_STL_LoadGeometry instead of Ng_STL_NewGeometry, passing an empty (but well-formed) STL file.

    I'm using netgen 4.9.13, but I can see the problem in the current revision 434 of nglib.cpp.


Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.

No, thanks