Fit Attribute max && min by Array

1

Fit attribute value to 0 and 1 is one of my favorite thing to do in Houdini and i always look for new way to do it and i wish if SideFX make node for this, it’s really important thing to get the the best result for example drive the color by attribute.
I write a blog here about this topic and this is another way to fit the attribute value to 0 and 1 “only try it with float attribute”  and this method is store all the attribute values in an array and then pop the last and first value from a sorted array.

1- store all the attribute values in an array use point wrangle.

float attrib[] = array(@attrib);
setdetailattrib(0, "attrib", attrib, "append");

2- sort the array “Returns the array sorted in increasing order” to get the attribute min value and it’s important here to use detail wrangle.

f[]@myattrib = sort(f[]@attrib);
f@attrib_min = pop(@myattrib, 0);

3- in the same detail wrangle reverse the sort array to get the attribute max value.

f[]@myattrib = reverse(sort(f[]@attrib));
f@attrib_max = pop(@myattrib, 0);

4- promote min and max attribute from detail to point use point wrangle.

setpointattrib(0, "attrib_min", @ptnum, f@attrib_min);
setpointattrib(0, "attrib_max", @ptnum, f@attrib_max);

5- fit the attribute to 0 and 1 use point wrangle.

f@attrib = fit(@attrib, @attrib_min, @attrib_max, 0, 1);

in the end this is really interesting way to get value from attribute but it’s really slow compared to other method i talk about them here.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s