12 December 2010 | |
![]() |
|
New Member
portfolio
Bill Tavis
USA
|
![]() Hi,
I am trying to optimize a function using qsort to sort a very large array of Point3 world coordinates. I found it was faster to precompute the values and store them in a parallel array with a for-collect loop. My question is: using qsort, how do I reference these values to sort the Point3 array directly? My current work-around requires two additional for-collect loops as in this example:
This works fine, but for large point counts it would be faster without the first and last for-collect loops. Is it possible to do something like this:
any help is appreciated. Thanks! |
12 December 2010 | |
![]() |
|
Lord of the posts
portfolio
Klunk
United Kingdom
|
the sort will be faster as it only has to swap integer values and not point3 values, I guessing about 3 times faster. If you need to actually sort the array then at some stage you are always going to have to do the point3 "swaps". You can always access the point3 array via the index array though e.g. verts[indices[i]] not very neat and probably quite slow.
|
12 December 2010 | |
![]() |
|
MAX Doctor
portfolio
Denis Trofimov
CA,
USA
|
I think the fastest way to sort this kind of data will be:
Last edited by denisT : 12 December 2010 at 12:39 AM. |
12 December 2010 | |
![]() |
|
New Member
portfolio
Bill Tavis
USA
|
thanks DenisT! Pairing the sort value along with the world coordinates is a great solution, it saves me from having an extra array floating around outside the functions, and let's me eliminate one of the for-collect loops. My code is cleaner now, and a touch faster too. Thanks again!
|
12 December 2010 | |
![]() |
|
MAX Doctor
portfolio
Denis Trofimov
CA,
USA
|
Originally Posted by theTavis:
... it saves me from having an extra array floating around outside the functions...
probably some of maxscript coders don't know that is possible to pass extra parameters to qsort function. like:
or:
PS. the last sample is just a sample. It's not a good idea to use any calculation inside qsort loop. The warranty of any fast sorting is the data prepared in advance . |
12 December 2010 | |
![]() |
|
Expert
|
Thread automatically closed
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
__________________
CGTalk Policy/Legalities Note that as CGTalk Members, you agree to the terms and conditions of using this website. |
Thread Closed share thread |
«
Previous Thread
|
Next Thread
»
|
|
|