edge selection -> points [SOLVED]

  • On 11/10/2014 at 13:11, xxxxxxxx wrote:

    I think so. But in order to be sure, I'd either have to try or to look it up in the code. I can't do so before Monday, so I'd recommend, you try yourself.
    If this is the case, I'll add it to my notes for SDK doc improvement...

  • On 11/10/2014 at 13:12, xxxxxxxx wrote:

    ok. thank you so far.

  • On 11/10/2014 at 14:53, xxxxxxxx wrote:

    So, i wen on using the PolyInfo Example. Still some weird results.
    based on the image i posted previously i get points 1->3 which is correct, and for the other edge between points 7->5 i get 6->4. if i choose other edges the thing continues with wrong results.

    why are the results different from the indices i get in cinema when checking the vertices in the structure manager??

    any help is appreciated.

    		for (int i=0; i<fcnt; i++)
    			PolyInfo *pli = neighbor.GetPolyInfo(i);
    			for (int side=0; side<4; side++) 
    				if (pli->mark[side] || side==2 && padr[i].c==padr[i].d) continue;  
    				switch (side)
    					case 0: p1=padr[i].a; p2=padr[i].b; edge = pli->edge[0]; break;
    					case 1: p1=padr[i].b; p2=padr[i].c; edge = pli->edge[1]; break;
    					case 2: p1=padr[i].c; p2=padr[i].d; edge = pli->edge[2]; break;
    					case 3: p1=padr[i].d; p2=padr[i].a; edge = pli->edge[3]; break;
    				if (selection->IsSelected(edge)) 
    					GePrint("Selected Edge: "+LongToString(edge)+" - Points "+LongToString(p1)+"->"+LongToString(p2));

  • On 12/10/2014 at 09:29, xxxxxxxx wrote:

    I was a bit quick with my assumptions yesterday, sorry 😢

    Check the following code (it it's not complete, it assumes you a poly selection pBSPoly) :

      LONG pcnt = g_objPoly->GetPointCount();
      LONG fcnt = g_objPoly->GetPolygonCount();
      const CPolygon *fadr = g_objPoly->GetPolygonR();
      LONG p1, p2;
      if (pBSPoly) {  // starting with a polygon selection here
        SelectionChanger * pSC = SelectionChanger::Alloc();
        if (pSC->InitFromSelection(pBSPoly, Mpolygons, g_objPoly)) {
          Neighbor neighbor;
          if (neighbor.Init(pcnt, fadr, fcnt, nullptr)) {
            BaseSelect* pBSEdges = pSC->GetEdgeS();    // convert polygon selection into an edge selection
            // NOTE: edges are multiple times in this pBSEdges (once for each poly, idxPoly*4+idxEdge)
            // NOTE 2: BSEdges is owned by pSC (I think)
            if (pBSEdges) {
              for (int idxPolys = 0; idxPolys < fcnt; idxPolys++) {
                PolyInfo *pPI = neighbor.GetPolyInfo(idxPolys);
                // From example SDK docs PolyInfo struct:
                int idxSide;
                for (idxSide = 0; idxSide < 4; idxSide++) { // test all 4 sides of a polygon
                  // only proceed if edge has not already been processed
                  // and edge really exists (for triangles side 2 from c..d does not exist as c==d)
                  if (pPI->mark[idxSide] || ((idxSide == 2) && (fadr[idxPolys].c == fadr[idxPolys].d))) continue;
                  String nfo = "";
                  switch (idxSide) {
                  case 0: p1 = fadr[idxPolys].a; p2 = fadr[idxPolys].b; break;
                  case 1: p1 = fadr[idxPolys].b; p2 = fadr[idxPolys].c; break;
                  case 2: p1 = fadr[idxPolys].c; p2 = fadr[idxPolys].d; break;
                  case 3: p1 = fadr[idxPolys].d; p2 = fadr[idxPolys].a; break;
                  } // switch (idxSide...
                  if (pBSEdges->IsSelected((4 * idxPolys) + idxSide)) {
                    nfo = "selected";
                  } // if (pBSEdges->....
                  GePrint("Edge " + LongToString(p1) + "->" + LongToString(p2) + ": " + nfo);
                } // for (idxSide...
              } // for (idxPolys
            } // if (pBSEdges)...
          } // if (neighbor...
        } // if (pSC->...
      } else { // if (pBSPoly
        // Handle error: SELECTION NOT CONVERTED

    One more note:
    In your code, you had:

    fadr->EdgePoints(idxEdges, p1, p2);

    You were always addressing the first polygon with this.

    I hope this helps.

  • On 12/10/2014 at 11:16, xxxxxxxx wrote:

    I think he's looking for the point index#s Andreas.
    You're code produces edge index#s. Which he needs to be converted into point index#s and their global positions.

    While I'm watching Football on T.V. I've rolled my own EdgesToPoints code to do this. Without using the neighbor class.
    But I'd like to see how it's done using the neighbor class too.

    I can post my no-neighbors class version if you like.
    But I'm also interested in seeing how to do it using the neighbor class.


  • On 12/10/2014 at 12:25, xxxxxxxx wrote:

    Scott, my code prints point indeces. Its using the edge index only for selection checking.

    Would you mind, to post your code here as well?
    It's always good to have several ways to accomplish something, so anybody can chose the one fitting his needs best.

  • On 12/10/2014 at 12:59, xxxxxxxx wrote:

    Maybe I'm doing something wrong?
    Your code is not returning the correct point index#s. Or the correct selected edge ID#s for me.

    Here's the way I'm doing it without the neighbor class:

    //This code grabs the selected edges from an edge selection tag  
    //Then it get's their Index# and global positions of the points in them  
    //Then it selects those points on the object  
    Bool SimplePlugin::Execute(BaseDocument *doc)  
      PolygonObject *obj = (PolygonObject* ) doc->GetActiveObject();  
      if(!(obj && (obj->GetType() == Opolygon))) return FALSE;  
      CPolygon *polygons = obj->GetPolygonW();  
      Vector *points = obj->GetPointW();  
      //The edge selection tag holding the selected edges data  
      SelectionTag *etag = NULL;  
      etag = (SelectionTag* )obj->GetTag(Tedgeselection, 0);  
      if(!etag) return FALSE;  
      //Get the selected edges from the selection tag  
      BaseSelect *EdgeS = etag->GetBaseSelect();  
      if(EdgeS->GetCount() < 1) return FALSE;  
      //Create an empty selection array to hold the points we will eventually select later on  
      BaseSelect *PointS = BaseSelect::Alloc();  
      //The number of edges = the number of polygons * 4  
      LONG maxEdgeCnt = obj->GetPolygonCount()*4;  
      for(LONG i=0; i<maxEdgeCnt; i++)  
          if( EdgeS->IsSelected(i) )   
              //These edge index #s are not the same thing as point index #s  
              LONG edge = i;  
              LONG PolyInd = int(edge/4);  
              //The polygon's ID#  
              CPolygon Polygon = polygons[PolyInd];  
              //The edge within the each polygon( 0-3 )  
              LONG PolyEdgeInd = edge-4*(PolyInd);  
              if( PolyEdgeInd == 0)  
              else if( PolyEdgeInd == 1)  
              else if( PolyEdgeInd == 2)  
              else if( PolyEdgeInd == 3)  
      //Get the Index# and the global positions of the points in the PointS BaseSelect array  
      //We only need to get a or b  
      LONG seg=0,a,b,i;    
          for (i=a; i<=b; ++i)  
              Vector gPPos = points[a] * obj->GetMg();              
              GePrint( "index# "+ LongToString(a) +" "+ RealToString(gPPos.x) + " " + RealToString(gPPos.y) + " " + RealToString(gPPos.z) );  
      //Select the points in the editor view using the PointS array if desired  
      //Free the memory used  
      return TRUE;  

    It seems to work pretty good.
    But I just cranked it out while yelling at my T.V.  🙂
    I don't know how well this will handle N-Gons or Tris.


  • On 12/10/2014 at 13:11, xxxxxxxx wrote:

    can you give me a simple example, where my code fails? Because here it's working nicely. But perhaps my setup is too simple, and it only returns correct values by chance.
    You did notice though, that it starts with a poly selection?
    I'd really be interested to get mine fixed, if it contains any bugs.
    Even if I like your solution better, it's more straight forward.

  • On 12/10/2014 at 13:47, xxxxxxxx wrote:

    Doh! That's it.
    You're checking polygons. And I was checking edges.
    I figured I must have missing something.

    FYI: You've got some errors in your code.
    -pBSPoly is undefined
    -g_bs[0] is unidentified
    -for (int idxPolys = 0; idxPolys < fcnt; idxPolys++) {   is missing a closing brace

    I was able to figure them out. But others might get stuck on them.


  • On 12/10/2014 at 14:25, xxxxxxxx wrote:

    thank you both really much! i got it now working. I still use the neighbor class because scott's method gave me twice as much edges. for example i got point 1- >3 as well as 3->1... dunno, maybe i did something wrong, but since i had the neighbor class in use anyways, i took its GetEdgeCount instead of (source->GetPolygonCount()*4;).. which for example returns 24 edges for a cube (6polys*4) instead of 12

  • On 12/10/2014 at 14:49, xxxxxxxx wrote:

    You didn't do it wrong.
    My version doesn't have 'marking' in it. So it will grab duplicates as it loops through the edges.
    I thought I was able to filter those duplicates out by grabbing the verts from the PointS bs array.
    But I guess that part still needs more work.

    This may possibly fix it. But I'll have to test it more.
    It came from my head so it's bound to be buggy.

        //Get the Index# and the global positions of the points in the PointS BaseSelect array  
      LONG seg=0,a,b;  
          for (LONG i=a; i<=b; ++i)  
              Vector gPPos = points[i] * obj->GetMg();              
              GePrint( "index# "+ LongToString(i) +" "+ RealToString(gPPos.x) + " " + RealToString(gPPos.y) + " " + RealToString(gPPos.z) );  


  • On 12/10/2014 at 22:13, xxxxxxxx wrote:

    Scott, you are right, I messed it up and forgot to replace g_bs[0] with pBSPoly (and lost one brace), when I pasted into the forum. It's not a complete function though, and it's not meant to be.
    You need to provide either pBSPoly (a poly selection) or (and that's why I didn't post a function) change it to your needs, when you have a point selection or even an edge selection (which will make it simpler I guess).

    elo, glad it helped Smile

    Scott, small note on your code, not too important, though.
    You have:

     LONG PolyInd = int(edge/4); 

    LONG is not necessarily the same as int. I'd recommend to cast to the type, you are declaring. Probably never will be a problem, but if it get's a problem, you'll have a hard time tracking it down... perhaps better dump the cast here, as there's no need in this case anyway.

Log in to reply