[V8i MDL] mdlMesh_ API # create Mesh from 2 Lines

Hi,

I am a newbie to the mdlMesh_ API and I need the API Function that creates a Mesh out of 2 (or more) polylines in the same way the GUI Function "FACET TRIANGULATE CONTOURS" does.

Thanks, Stefan.

  • The key to working with meshes is the PolyfaceArray.  It's a list of point arrays, possibly of different lengths except for simple, regular structures such as a rectangle. You construct a PolyfaceArray and allocate its arrays dynamically.  It has lists of vertices and lists of edge indexes.  Except for external edges, each edge is shared by two facets.  The index arrays tell you which edges belongs to which facet. 

    Search for Mesh Elements in the MDL function reference to see more detail, including a diagram that explains more clearly what I've written above.

    Use something like mdlMesh_newPolyface() to create an element descriptor from a simple array of DPoint3d.  Use something like mdlMesh_newPolyfaceFromEmbeddedArrays() to create an element descriptor from an indexed array of points.

     
    Regards, Jon Summers
    LA Solutions

  • Stefan, MDL API does not provide such functionality, it only provides function that is able to mesh points in 2d (this is called Delaunay Triangulation).

    What you want is so called Constrained Delaunay Triangulation.
    Your polylines must be split into segments where each represents mandatory edge of triangle - so called "constraint".

    You can achieve what you want in two following passes:

    Pass 1.)

    1. Make an array of all available constraints and filter out duplicates (use some acceptable tolerance for equality)
    2. Make an array of all vertices and also filter out duplicates (also use some acceptable tolerance for equality)
    3. If any vertex lies on or is very close in XY direction to another constraint, split that constraint into two new constraints in place of that point
    4. Create a mesh using function mdlMesh_newPolyfaceFromXYTriangulation
    5. Extract triangles (faces) of mesh result or simply convert it to cell (mdlMesh_convertToShapes) and drop it

    Now you have so called Delaunay Triangulation, but it is NOT a "constrained" triangulation.

    Pass 2.)

    1. For Each line segment from contraints:
    2.   Collect all triangles from face list which intersect it in XY plane
    3.   Drop triangles into line segments and filter out all that are drawn twice (keep only outline edges)
    4.   Polygonize those segments (you may want to use mdlElmdscr_assembleChains function)
    5.   Cut this new polygon by current constraint into two separate polygons
    6.   Make a new variable polyface mesh from those two polygons using mdlMesh_newVariablePolyface
    7.   Use mdlMesh_copyTriangulated on result to get constrained triangles for current constraint
    8.   Remove triangles collected in step 2 from the face list
    9.   Add new triangles from step 7 to the face list
    10. End of For Each :)

    Advanced notes:
    In Pass 2, step 3 could be made using function mdlMesh_filterMultiplyDrawnEdges
    In Pass 2, steps 6 and 7 could be made at once using function mdlMesh_triangulateEmbeddedArrays

    [Edit:] I have added required step no. 8 in pass 2
    Also note: Pass 2, steps from 3 to 7 can be replaced by so called "diagonal swapping" method.
    You can read something about implementing contrained triangulation algorithm in this PDF.


    HTH