Hi guys,
I have a doubt with respect to sorting attribute values. I have mesured the area of a set of primitives using the measure node and the areas have been listed under the new attribute “AREA” in the details view. I want to tag these areas by numbers 1 to 8 in a heirarchial way from the lowest area to the highest area value under a new attribute list. Can anyone help me with the possible paramteric expression which i need to feed in the attribute create node to acheive this. Is there a variable which arranges these areas in a ascending or descending way like $AREA which will list the area numbers.
Regards,
nittin
Sorting Attribute Values
7490 10 1- Nittin
- Member
- 29 posts
- Joined: May 2011
- Offline
- graham
- Member
- 1908 posts
- Joined: Nov. 2006
- Offline
Depending on your aversion to sorting your primitives you can do it pretty easily. In the attached file is 3 possible ways.
The first is simpler but doesn't involve another attribute. If you don't care about prim numbers you can just sort by area and now your primitive number represents its rank as well.
The second method you get more what you describe. It stores the original primitive number , sorts based on the area, stores the new prim number as the order index since it's ordered, then sorts back to the original ordering.
Thirdly I threw in a single Attribute Create that uses a Python expression to do it all for you.
The first is simpler but doesn't involve another attribute. If you don't care about prim numbers you can just sort by area and now your primitive number represents its rank as well.
The second method you get more what you describe. It stores the original primitive number , sorts based on the area, stores the new prim number as the order index since it's ordered, then sorts back to the original ordering.
Thirdly I threw in a single Attribute Create that uses a Python expression to do it all for you.
Graham Thompson, Technical Artist @ Rockstar Games
- Nittin
- Member
- 29 posts
- Joined: May 2011
- Offline
- keyframe
- Member
- 1529 posts
- Joined: July 2005
- Offline
- Nittin
- Member
- 29 posts
- Joined: May 2011
- Offline
guys,
one more doubt if i want to reverse the whole stuff?? in the sense i want to rank the area with the highest value as 1 and lowest value as greater number ( eg. 8 or 9), wat is the variable that i should use is there a reverse of $AREA or wether it can be done only with a python expression??
Regards,
nittin
one more doubt if i want to reverse the whole stuff?? in the sense i want to rank the area with the highest value as 1 and lowest value as greater number ( eg. 8 or 9), wat is the variable that i should use is there a reverse of $AREA or wether it can be done only with a python expression??
Regards,
nittin
- keyframe
- Member
- 1529 posts
- Joined: July 2005
- Offline
- graham
- Member
- 1908 posts
- Joined: Nov. 2006
- Offline
Don't have Houdini in front of me right now, but for the examples using sorting, if you change the Sort SOP to sort by -$AREA it should reverse the order.
In the Python example, if you add a reverse() call on the list after it is sorted you should get the desired result.
In the Python example, if you add a reverse() call on the list after it is sorted you should get the desired result.
Graham Thompson, Technical Artist @ Rockstar Games
- Nittin
- Member
- 29 posts
- Joined: May 2011
- Offline
Hi graham & keyframe,
Thank you so much. Both your suggestions are working well. Thanks a lot. Just that the -$AREA is not working properly ,it is not reversing the order, it is still showing the attributes in the same order. I dont knw wat is wrong with it , apart frm tht the other suggestions are working well. Thanks a lot.
Reagrds,
nittin
Thank you so much. Both your suggestions are working well. Thanks a lot. Just that the -$AREA is not working properly ,it is not reversing the order, it is still showing the attributes in the same order. I dont knw wat is wrong with it , apart frm tht the other suggestions are working well. Thanks a lot.
Reagrds,
nittin
- graham
- Member
- 1908 posts
- Joined: Nov. 2006
- Offline
Blah. Since it seems to have issues with negative numbers you can use 1/$AREA to get the desired result. Parameters won't complain if you divide by 0 so if you think you might have to deal with a 0 area you could do something like if($AREA == 0, 1e10, 1/$AREA)
Graham Thompson, Technical Artist @ Rockstar Games
- Nittin
- Member
- 29 posts
- Joined: May 2011
- Offline
- zarti
- Member
- 330 posts
- Joined: July 2007
- Offline
-
- Quick Links