[MDL 2004] Insert a vertex

there is a line and line string which is intersect at different points. how to check whether the line intersect the line string at a point where there is vertex or not. if not how to insert vertex in line string?

Parents
  • Unknown said:
    there is a line and line string which is intersect at different points

    Surely they intersect at the same point?  That is the definition of an intersection.

    Perhaps you mean that the line-string and the line have multiple intersections.  That would be true if the line-string zig-zags and crosses the line several times.

    However, rather than have us guess the true meaning of your question, why not post a small DGN model that illustrates the problem?

     
    Regards, Jon Summers
    LA Solutions

  • OK: you've provided a MicroStation/J file that contains a single 3D model (V7 — any particular reason?).  There is a single red line element and a single green line string element.  They appear to be co-planar.

    • Use mdlIntersect_allBetweenElms() or mdlIntersect_betweenElmsByIndex() to obtain intersection points
    • Use mdlLinear_extract() to get a list of vertices from your line or line string element

    Now you have to work out where the intersection points lie in relation to your element's vertices. Create a new, elastic, array to hold the copied vertices.  You need to build a new array of vertices, copying from the existing array, and inserting a new intersection vertex each time you find a co-linear match. 

    1. Traverse the array of vertices 0…N-2
    2. Examine each pair of vertices (vertex[n] and vertex[n+1])
    3. Each intersection point will be co-linear with its adjacent vertices, which you can test using mdlVec_colinear()
    4. If an intersection is co-linear, copy points up to vertex[n], copy the intersection point, then copy vertex[n+1]
    5. Rinse & Repeat for each intersection point

    Finally, create a new line string element from your modified array of vertices.

     
    Regards, Jon Summers
    LA Solutions

  • 4314.example.dgn


    same problem but the condition is different. attached a dgn file, there is a linestring and lines that intersect the linestring, Now i want to insert the intersecting points of line into the linestring. I ve tried by using distance but could not get success. How to solve this?

    Regards

    Sajan

  • Unknown said:
    I've tried by using distance but could not get success

    What have you tried?  Show some code.

     
    Regards, Jon Summers
    LA Solutions

  • if(SUCCESS == mdlSelect_returnPositions(&filePosArray,&modelRefArray,&m))
        {
            for(i=0;i<m;i++)
            {
                mdlElmdscr_readToMaster (&pObject, filePosArray[i], modelRefArray[i], FALSE, NULL);
                elemType = mdlElement_getType(&pObject->el);
                if(LINE_STRING_ELM == elemType)
                {
                    mdlElement_getProperties(&level, NULL, NULL, NULL, NULL, NULL, NULL, NULL,&pObject->el);
                    mdlElement_getSymbology(&color,&weight,&style,&pObject->el);
                    mdlLinear_extract(points,&numVerts,&pObject->el,modelRefArray[i]);
                }

                for(j=i+1;j<m;j++)
                {
                    mdlElmdscr_readToMaster(&pElmNext,filePosArray[j],modelRefArray[j],FALSE,NULL);
                    number = mdlIntersect_allBetweenElms(ElmA,ElmB,MAX_VERTICES,pObject,pElmNext,NULL,0.0);
                    if(number>0)
                    {
                        intrsect[tmp].x = ElmA->x;
                        intrsect[tmp].y = ElmA->y;
                        tmp++;
                    }
                }
                
            }

            for(i=0,j=i+1;i<numVerts,j<numVerts;i++,j++)
            {
                sumDist = sumDist+sqrt(pow((points[i].x-points[j].x),2)+pow((points[i].y-points[j].y),2));
                Distance[p] = sumDist;
                p++;
            }

    for(i=0,j=i+1;i<tmp,j<tmp;i++,j++)
            {
                sumIntrDist = sumIntrDist + sqrt(pow((intrsect[i].x-intrsect[j].x),2)+pow((intrsect[i].y-intrsect[j].y),2));
                intrDist[q] = sumIntrDist;
                q++;
            }
    then Distance and intrDist is compared to check whether the intrDist lies between the Distance so that i can keep the coordinates in the linestring..

    Regards

    Sajan

  • Unknown said:
    intrsect[tmp].x = ElmA->x; intrsect[tmp].y = ElmA->y;

    Assuming that intrsect is an array of DPoint3d, then simply do this …

    intrsect[tmp] = *ElmA;

     
    Regards, Jon Summers
    LA Solutions

  • Assigning stucts

    Unknown said:
    intrsect[tmp].x = ElmA->x; intrsect[tmp].y = ElmA->y;

    Assuming that intrsect is an array of DPoint3d, then simply do this …

    intrsect[tmp] = *ElmA;

    Algorithms

    Unknown said:
    I want to insert the intersecting points of line into the linestring. I've tried by using distance but could not get success

    I'm having trouble correlating your requirement with your implementation. I don't see how distance is involved.

    You need to …

    1. get the vertices of the line into which you want to add new vertices
    2. copy those vertices into an elastic array, so you can insert those new points
      • if using C++, then std::vector  is the perfect container
      • if using MDL, but not native code, then investigate either of …
        • dynamic arrays (mdlDArray_api)
        • JMDL embedded arrays (jmdlEmbeddedDPoint3dArray_api)
    3. get intersections
    4. for each intersection
      • insert the intersection coordinate into your elastic array
    5. finally, create a new line-string from your modified vertex list

     
    Regards, Jon Summers
    LA Solutions

Reply
  • Assigning stucts

    Unknown said:
    intrsect[tmp].x = ElmA->x; intrsect[tmp].y = ElmA->y;

    Assuming that intrsect is an array of DPoint3d, then simply do this …

    intrsect[tmp] = *ElmA;

    Algorithms

    Unknown said:
    I want to insert the intersecting points of line into the linestring. I've tried by using distance but could not get success

    I'm having trouble correlating your requirement with your implementation. I don't see how distance is involved.

    You need to …

    1. get the vertices of the line into which you want to add new vertices
    2. copy those vertices into an elastic array, so you can insert those new points
      • if using C++, then std::vector  is the perfect container
      • if using MDL, but not native code, then investigate either of …
        • dynamic arrays (mdlDArray_api)
        • JMDL embedded arrays (jmdlEmbeddedDPoint3dArray_api)
    3. get intersections
    4. for each intersection
      • insert the intersection coordinate into your elastic array
    5. finally, create a new line-string from your modified vertex list

     
    Regards, Jon Summers
    LA Solutions

Children
  • Unknown said:
    1. for each intersection
      • insert the intersection coordinate into your elastic array
    2. finally, create a new line-string from your modified vertex list

    The main problem is how to insert the intersection coordinate into the elastic array? the points need to be compared? how to compare them? confused.

    Regards

    Sajan

  • Unknown said:
    The main problem is how to insert the intersection coordinate into the elastic array?

    Each intersection point must be colinear with two existing adjacent points.  Walk through the vertex list, and examine points[N], intersection-point and points[N+1].  When you find those three points colinear, then insert the intersection point.

    mdlVec_colinear will be useful.

     
    Regards, Jon Summers
    LA Solutions

  • can you show me some lines of codes as example?

    Regards

    Sajan

  • Unknown said:
    Can you show me some lines of codes as example?

    What about the suggestions I made previously in this thread (28-Aug-14)?  Did you attempt to use those?

     
    Regards, Jon Summers
    LA Solutions

  • In that thread (28 Aug 2014) I am confused in these

    Examine each pair of vertices (vertex[n] and vertex[n+1])
    Each intersection point will be co-linear with its adjacent vertices, which you can test using mdlVec_colinear()

    two points. Here what to examine in pair of vertices?

    Regards

    Sajan

  • Unknown said:
    I am confused...what to examine in pair of vertices?

    #include <embeddeddpoint3darray.fdf>
    #include <msvec.fdf>
    
    BoolInt	InsertVertex (EmbeddedDPoint3dArray *pVertices, DPoint3d const* intersection)
    {
      BoolInt inserted = FALSE;
      int     nPoints  = jmdlEmbeddedDPoint3dArray_getCount (pVertices);
      int     i;
      for (i = 0; i != nPoints - 1; ++i)
      {
         DPoint3d test [3]; 
         jmdlEmbeddedDPoint3dArray_getDPoint3d (pVertices, test + 0, i);
         test [1] = *intersection;
         jmdlEmbeddedDPoint3dArray_getDPoint3d (pVertices, test + 2, i + 1);
    if (mdlVec_colinear (test)) { jmdlEmbeddedDPoint3dArray_insertDPoint3d (pVertices, intersection, i + 1); inserted = TRUE; break; } } return inserted; }

    Search the MDL Function Reference for Embedded Arrays to find an overview of the jmdlEmbeddedArray_api.

     
    Regards, Jon Summers
    LA Solutions

  • when i used the above function and compiled it gives the following error message. what's wrong?


    ### C:\PROGRA~2\Bentley\Program\MICROS~1\mdl\library\builtin.dlo: ####Unresolved
     symbol jmdlEmbeddedDPoint3dArray_getDPoint3d in C:\PROGRA~2\Bentley\Program\MIC
    ROS~1\mdl\objects\line_coordinates.mo.

    ### C:\PROGRA~2\Bentley\Program\MICROS~1\mdl\library\builtin.dlo: ####Unresolved
     symbol jmdlEmbeddedDPoint3dArray_insertDPoint3d in C:\PROGRA~2\Bentley\Program\
    MICROS~1\mdl\objects\line_coordinates.mo.

    ### C:\PROGRA~2\Bentley\Program\MICROS~1\mdl\library\builtin.dlo: ####Unresolved
     symbol jmdlEmbeddedDPoint3dArray_getCount in C:\PROGRA~2\Bentley\Program\MICROS
    ~1\mdl\objects\line_coordinates.mo.

    ### C:\PROGRA~2\Bentley\Program\MICROS~1\mdl\library\builtin.dlo: Unrecoverable
    errors detected.  Output file not created.

    Regards

    Sajan

  • Unknown said:
    I used the above function and compiled it gives the following error message

    There is no compiler error.

    Unknown said:
    ### C:\PROGRA~2\Bentley\Program\MICROS~1\mdl\library...

    The clue lies in that message.  It's the linker that is complaining about functions such as jmdlEmbeddedDPoint3dArray_getDPoint3d.

    While you've added the appropriate #include directive to your source files, you haven't added the relevant library directives to your bmake file.  Look at the MDL Function Reference help for that function and note the Required Header and Required Library.  You already have the right header, and you must add the required library (mtg.lib) to the list of libs in your .mke file.

     
    Regards, Jon Summers
    LA Solutions

  • tried this but still could not get the goal. and in my mdl api function reference there is no any jmdlEmbeddedArray_* functions.

    Regards

    Sajan

  • Unknown said:
    tried this but still could not get the goal

    It's not clear what you've tried and what goal you have failed to reach. 

    Your previous post tells us that you compiled some code that uses jmdlEmbedded_arrays, but failed to link.  I advised you to include the library file mtg.lib in your make file.  Have you succeeded in building your application?

    Unknown said:
    in my mdl api function reference there is no any jmdlEmbeddedArray_* functions

    jmdlEmbedded_arrays have been around since MicroStation/J.  Can you see header file embeddeddpoint3darray.fdf in your \mdl\include folder?  Can you see library file mtg.lib in your \mdl\library folder?

     
    Regards, Jon Summers
    LA Solutions