Q: Sort attributes

   1644   2   1
User Avatar
Member
459 posts
Joined: Oct. 2011
Offline
Hi
I'm trying to sort some random point attribute values (“curveu”) and map them back to the points in a sorted fashion. Not sorting points, only attribute values. So in an Attribute Wrangle (Detail) i have this code:
int num_points = npoints(0);
float pt_att;
float list;
float list_two;

for (int i=0; i<num_points;i++){
list = point(0, “curveu”, i); // Filling the array
}

printf(“Array: %g\n”,list);
printf(“Sort: %g\n”,sort(list));

for (int n=0; n<num_points;n++){
//setpointattrib(0, “curveu”, n, (float)list, “set”); // Set attribute again
setattrib(0, “point”, “curveu”, n, n, list, “set”); // Set attribute with other method
list_two = point(0, “curveu”, n); // Filling the other array
}

printf(“New array: %g\n”,list_two);

The last print statement “New array” should print the attribute “curveu” in a sorted fashion but it doesn't. Why does the last print statement print the initial order of the attribute values?

Any help appreciated.

-b
http://www.racecar.no [www.racecar.no]
User Avatar
Member
387 posts
Joined: Nov. 2008
Offline
Hi, there are two problems:

1. You don't have sorted array anywhere else then in printf statement. You sorted it and then throwed it away. There is no sort in place.

Try to modify your code with this between your two for loops:


printf(“Array: %g\n”,list);
printf(“Sort: %g\n”,sort(list));
printf(“Array not sorted yet: %g\n”,list);
list = sort(list); // replace original array with sorted one
printf(“Array is now sorted: %g\n”,list);


Now the arguments will be sorted (in geometry view).
2. But your last printf statement will still return original order.

It's probably becouse it's evaluated once (Detail (Only Once)) so it reads all the values and then at the end it write them all in one go.

You can return sorted list for the print statement.
User Avatar
Member
459 posts
Joined: Oct. 2011
Offline
Ah of course Thanks!

-b
http://www.racecar.no [www.racecar.no]
  • Quick Links