sorting Arrays - COFFEE



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

    On 31/03/2009 at 08:00, xxxxxxxx wrote:

    Sorry to bump this, but surely someone must know, one way or the other, whether there are any automated array operations available in COFFEE e.g. sort, slice, splice, push etc.

    My code above, is sloooowww.

    Many Thanks

    Jon



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

    On 31/03/2009 at 08:11, xxxxxxxx wrote:

    Sorry for the late reply. Unfortunatly there are no array sorting operations avaible in COFFEE. You have to write your own.

    cheers,
    Matthias



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

    On 31/03/2009 at 08:13, xxxxxxxx wrote:

    That's a shame, but good to know. Thanks very much for the reply

    Best

    Jon



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

    On 01/04/2009 at 06:16, xxxxxxxx wrote:

    Hey Homemade,

    you may want to use QuickSort, which is pretty fast if implemented well.

    Look here:
    Wikipedia article QuickSort
    There's also some simple pseudo code which should be easy to translate to Coffee.

    Anyway, you will of course get even better performance if you write your plugins in C++.

    Greetings,
    Jack



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

    On 01/04/2009 at 15:03, xxxxxxxx wrote:

    Thanks a lot for the reply Jack - I wasn't aware of that, I'll look into it.

    As much as I'd like to get an understanding of C++, I don't use COFFEE for plug-ins, I've mainly been using it in conjunction with Xpresso for more control over TP. At the moment, I'm just experimenting really e.g. right now I'm seeing if I can get realistic flocking behaviour.

    Cheers
    Jon



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

    On 03/04/2009 at 06:23, xxxxxxxx wrote:

    Oh, flocking behaviour is not an easy thing to implement with TP. First of all, TP in Cinema 4D lacks some important functions you will definitely need (e.g. a method to find the nearest x particles).

    Second of all, you will have to build a kind of weighting system to help the particles (boids) to make certain decisions according to their situation.

    You should take a look in Craig Reinolds' SIGGRAPH paper from 1987 to get an idea of the basic approach:
    http://www.cs.toronto.edu/~dt/siggraph97-course/cwr87/

    I also once tried to make that work in TP, but I didn't come very far:
    See TP Simple Swarm further downon this page

    If you manage to get a good system working, I would also be interested in seeing the results :)

    Concerning C++: With that you could implement your own XPresso/TP operators (nodes) which also will give much better performance than a compound of separate XPresso nodes or Coffee nodes.

    Greetings,
    Jack



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

    On 03/04/2009 at 06:50, xxxxxxxx wrote:

    Thanks for the reply, it's an interesting area isn't it?

    It's taken me a while, but initially I was taking shortcuts, which it seems you can't get away with for convincing results. So, I've followed the Craig Reynolds approach to the letter, and I'm pretty much there. I'm really happy with it.

    With the obvious exceptions, it's mainly driven with one Xpresso COFFEE node, extracting particle info from a particle ID generated with a Data Channel, storing old data in arrays. The preview playback is pretty quick too.

    I'll upload a WIP movie file.

    I'm not entirely sure where I'm going with it, but I've an idea to link it with a Mograph Sound Effector (always a winner, that one!). I'll keep you posted.

    That's interesting re: C++. I wouldn't know where to start though, having never touched C++ before.

    Cheers

    Jon



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

    On 03/04/2009 at 10:15, xxxxxxxx wrote:

    Hi Jack,

    here's a WIP...

    http://www.homemaderobot.com/flock_test01.mp4

    This is literally my first test render. I've been previewing with 100 particles, but this render has 1000 which is revealing unpleasant string-like clusters of particles, I'm sure if a tweak a few parameters I can get rid of that.

    Also, there's an attraction point (a tertiary rule I've added), which acts like an inverse gravity, which isn't quite right yet.

    I think it's just a case of tweaking some numbers here and there.

    What do you think?

    Cheers

    Jon



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

    On 07/05/2009 at 21:11, xxxxxxxx wrote:

    Hi Jon,
       What a timely thread for me...just looked into the same problem earlier this week. I'll post our efforts. We translated a version of the wikipedia quicksort from the very useful C code at the bottom of the page:
    http://en.wikipedia.org/wiki/Quicksort
    into Coffee and will try to post here. Our amateur's modification is capable of sorting arrays of multiple dimension by any single user-selected dimension. I hope someone else may find use for it.... It would be great if someone wanted to add the ability to sort within the dimensions as well e.g., when there are redundancies in the current sorted dimension. Might also be nice to have a stablesort version.
    Thanks,
    Graham
    http://www.grahamj.com

    > \> // Quicksort the array... modified from C code posted at http://en.wikipedia.org/wiki/Quicksort \> // translated May/7/2009 by Graham & Mostafa \> // This functions ~10x faster than simple sorting on my test polyhedron with ~5500 polygons \> // reducing sort time from 0.62s to 0.068sec on a 2x 3GHz Dual-Core Intel Xenon running C4D v11.027 \> f_quicksort(pArray, pDimension, pLeft, pRight, pArrayWidth) \> { \>     if(pLeft >= pRight) \>         return; \>     var index = f_partition(pArray, pDimension, pLeft, pRight, pArrayWidth); \>     f_quicksort(pArray, pDimension, pLeft, index - 1, pArrayWidth); \>     f_quicksort(pArray, pDimension, index + 1, pRight, pArrayWidth); \> } \> \> // Partition the pArray into two halves and return the \> // index about which the pArray is f_partitioned \> f_partition(pArray, pDimension, pLeft, pRight, pArrayWidth) \> { \>     // Makes the leftmost element a good pivot, \>     // specifically the median of medians \>     f_find_median_of_medians(pArray, pDimension, pLeft, pRight, pArrayWidth); \>     var pivotIndex = pLeft, pivotValue = pArray[pivotIndex][pDimension], index = pLeft, i; \>     f_swap(pArray, pDimension, pivotIndex, pRight, pArrayWidth); \>     for(i = pLeft; i < pRight; i++) \>     { \>         if(pArray[I][pDimension] < pivotValue) \>         { \>             f_swap(pArray, pDimension, i, index, pArrayWidth); \>             index += 1; \>         } \>     } \>     f_swap(pArray, pDimension, pRight, index, pArrayWidth); \> \>     return index; \> } \> \> // Computes the median of each group of 5 elements and stores \> // it as the first element of the group. Recursively does this \> // till there is only one group and hence only one Median \> f_find_median_of_medians(pArray, pDimension, pLeft, pRight, pArrayWidth) \> { \>     if(pLeft == pRight) \>         return pArray[pLeft][pDimension]; \>     var i, pShift = 1; \>     while(pShift <= (pRight - pLeft)) \>     { \>         for(i = pLeft; i <= pRight; i+=pShift\*5) \>         { \>             var endIndex = (i + pShift\*5 - 1 < pRight) ? i + pShift\*5 - 1 : pRight; \>             var medianIndex = f_find_median_index(pArray, pDimension, i, endIndex, pShift, pArrayWidth); \> \>             f_swap(pArray, pDimension, i, medianIndex, pArrayWidth); \>         } \>         pShift \*= 5; \>     } \> \>     return pArray[pLeft][pDimension]; \> } \> \> // Find the index of the Median of the elements \> // of pArray that occur at every "pShift" positions. \> f_find_median_index(pArray, pDimension, pLeft, pRight, pShift, pArrayWidth) \> { \>     var i, groups = (pRight - pLeft)/pShift + 1, k = pLeft + groups/2\*pShift; \>     for(i = pLeft; i <= k; i+= pShift) \>     { \>         var minIndex = i; \>                 var minValue = pArray[minIndex][pDimension]; \>                 var j; \>         for(j = i; j <= pRight; j+=pShift) \>             if(pArray[j][pDimension] < minValue) \>             { \>                minIndex = j; \>                minValue = pArray[minIndex][pDimension]; \>             } \>         f_swap(pArray, pDimension, i, minIndex, pArrayWidth); \>     } \>     return k; \> } \> \> // Swap integer values by pArray indexes \> f_swap(pArray, pDimension, pA, pB, pArrayWidth) \>      // DO NOT DELETE THE CODE BELOW!!! You may find it useful \>      // The k looped code below is generic to sort an arrray of any dimension = pArrayWidth, \>      // but the loopless version worked ~11% faster on my ~5500 polygon \>      // test critter to sort a 2D array by its second dimension for example. \>      /\* \>      { \>      var tmp = pArray[pA][pDimension]; \>      var tmp0 = pArray[pA][0]; \>         pArray[pA][pDimension] = pArray[pB][pDimension]; \>         pArray[pB][pDimension] = tmp; \>         pArray[pA][0] = pArray[pB][0]; \>         pArray[pB][0] = tmp0; \>      }\*/      \>      { \>      var k; \>      var vTemp; \>      for (k = 0; k < pArrayWidth; k++) \>           { \>           vTemp = pArray[pA][k]; \>           pArray[pA][k] = pArray[pB][k]; \>           pArray[pB][k] = vTemp; \>           } \>      } \>



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

    On 08/05/2009 at 02:04, xxxxxxxx wrote:

    Good work Graham. Hat's off!
    Very generous of you to post.

    Cheers
    Jon



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

    On 08/05/2009 at 06:11, xxxxxxxx wrote:

    Very good, I see you have studied the article well :)
    Thank you very much for posting the code here!



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

    On 08/05/2009 at 12:02, xxxxxxxx wrote:

    I wonder if Maxon has made any progress on the Wkikification of the outdated Coffee SDK. It would be nice to have working examples for things like this posted in an online SDK (as well as repairs to its current typos!), but I guess sparking discussion of this belongs in a different thread... sigh.
    -Graham
    www.grahamj.com



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

    On 09/05/2009 at 08:35, xxxxxxxx wrote:

    There was a Coffee Wiki planned?
    Never heard of that project, but I would be happy to see it; also for the C++ SDK.

    Greetings,
    Jack



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

    On 09/05/2009 at 17:26, xxxxxxxx wrote:

    Some mention of it from Matthias, et al, but I see now that this chat was back in 2007. Seems like one hour of SDK wikification would solve all of the SDK issues...perhaps we could revive the thread below by bringing it up again:

    http://www.plugincafe.com/forum/display_topic_threads.asp?ForumID=4&TopicID;=2744&SearchPagePosition;=1&search;=wiki&searchMode;=allwords&searchIn;=Thread&forum;=0&searchSort;=dateDESC&ReturnPage;=Search


Log in to reply