Sorting Attribute Values

   7488   10   1
User Avatar
Member
29 posts
Joined: May 2011
Offline
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
User Avatar
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.

Attachments:
area_order_attr.hip (64.5 KB)

Graham Thompson, Technical Artist @ Rockstar Games
User Avatar
Member
29 posts
Joined: May 2011
Offline
Hi Graham,
Thank you so much . yours illustrations were very helpful in understanding the logic behind what i wanted to do.Thanks a lot.

Regards,
nittin
User Avatar
Member
1529 posts
Joined: July 2005
Offline
I haven't looked at Graham's files, but in the interest of completeness, you should also be able to use the sort sop.

Jump over to the primitive tab, select “by expression”, and enter $AREA in the expression field.

Cheers,

G
User Avatar
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
User Avatar
Member
1529 posts
Joined: July 2005
Offline
Well, keeping on my original train of thought, using the sort sop, I would simply append another sort sop AFTER the first one, flip over to the primitive tab, and set it to “reverse”.

Graham might have some awesome ideas too (he usually does).

G
User Avatar
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.
Graham Thompson, Technical Artist @ Rockstar Games
User Avatar
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
User Avatar
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
User Avatar
Member
29 posts
Joined: May 2011
Offline
yes graham 1/$AREA is working. Thank u so much

Regards,
nittin
User Avatar
Member
330 posts
Joined: July 2007
Offline
Nittin


Just that the -$AREA is not working properly ,it is not reversing the order, …

another way ;

> you can drop another Sort SOP after that and choose ‘reverse’ .



.cheers
except the things that cannot be seen , nothing is like it seems .
  • Quick Links