Sorting algorithm problem



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 25/11/2003 at 04:05, xxxxxxxx wrote:

    User Information:
    Cinema 4D Version:   7.3 
    Platform:   Windows  ; Mac  ;  
    Language(s) :   C.O.F.F.E.E  ;

    ---------
    I'm importing an .OBJ animation file sequence into Cinema, re-creating it as a PLA animation with a Coffee plugin, both on Mac and Windows. Programming this I found that Cinema changes the order of points in the OBJ-sourced object on import. To compensate I included a sorter routine, which looks at the imported object at frame 0, and compares its points (pts) to the points in its originating OBJ file (npts) :

      
    if (!sorter[1]) // create sorter, to account for c4d-obj discrepancy...  
         {  
         var npts=getOBJFilePoints(curFile,op->GetPointCount()); // npts will be destroyed below...  
         for (i = 0; i < cnt; i++)  
              {  
              for (j = 0; j < cnt; j++)  
                   {  
                        if (pts _==npts[j])  
                             {  
                             sorter _=j;  
                             npts[j]=NULL;  
                             break;  
                             }  
                   }  
              }  
         }  
    

    This results in a sorter array that I can then use to read the point values for PLA keyframes for matching points of the object in the right order. Well, it works fine on the Mac, but on Windows some points don't match at all - thereby resulting in some sorter values remaining NULL, breaking my code later. However, if I don't destroy ntps as they get matched up to pts, it works fine!

    Now I'm very confused.... Shouldn't I be destroying npts so they don't get matched up to pts more than once? But then if this were true, why does it work anyway? I'm just worried I'm getting re-assuring results on my fast little tests now, but then later, when it counts and I'm working with big objects I get hammered. How should I code this to guarantee correct results?



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 25/11/2003 at 04:44, xxxxxxxx wrote:

    Oups, looks like the forum codes conflict with my own code, so here it is again with x substituting the i:

      
    if (!sorter[1])  
         {  
         var npts=getOBJFilePoints(curFile,op->GetPointCount());  
         for (x = 0; x < cnt; x++)  
              {  
              for (j = 0; j < cnt; j++)  
                   {  
                        if (pts[x]==npts[j])  
                             {  
                             sorter[x]=j;  
                             npts[j]=NULL;  
                             break;  
                             }  
                   }  
              }  
         }  
      
    

Log in to reply