[VEX ] How can I remap values without knowing the bounds?

   1804   3   2
User Avatar
Member
1 posts
Joined: 12月 2022
Offline
New to VEX.

I try to remap data generated from rand(@ptnum) to the bounds of 0 to 1 using the fit() function.
The fit() function requires original bounds to be input, then I get this idea, what if I don't know the bounds of original data, and just don't like to make it into an attribute and see the Geometry Spreadsheet?

Is there any way I can determine the bounds of data inside VEX code?
User Avatar
Member
4495 posts
Joined: 2月 2012
Offline
If the code is running in parallel (Run Over is not set to Detail), then you can't know the bounds until the execution finishes.

You can still get the min and max of scalar values using setdetailattrib:
https://www.sidefx.com/docs/houdini/vex/functions/setdetailattrib.html [www.sidefx.com]

But this will also require the code to finish execution.
Senior FX TD @ Industrial Light & Magic
Get to the NEXT level in Houdini & VEX with Pragmatic VEX! [www.pragmatic-vfx.com]

youtube.com/@pragmaticvfx | patreon.com/animatrix | animatrix2k7.gumroad.com
User Avatar
Member
7737 posts
Joined: 9月 2011
Offline
Quan
I try to remap data generated from rand(@ptnum) to the bounds of 0 to 1 using the fit() function.
The fit() function requires original bounds to be input, then I get this idea, what if I don't know the bounds of original data, and just don't like to make it into an attribute and see the Geometry Spreadsheet?

rand() already generates data in the bounds of 0 to 1, so no fit is required.
User Avatar
Member
67 posts
Joined: 10月 2018
Offline
Hey Quan,
if you don't mind using two additional SOPs then I'd suggest to use attribute promote, unset Delete original, set change new name the target class would be set to detail and use one to get the maximum and another to get the minimum of your attribute.

Then you can get them bounds in your vex code detail(0,"xMax,0)and detail(0,"xMin",0)
if you insist staying within VEX, you have to loop over all points and do the Min/Max explicitly.
Min=(v<=Min) ? v:Min Max=(v>=Max) ? v:Max
Thats a so called "trigraph". which is exactly the same as an if (v<=Min) then {Min=v} else {Min=Min}
  • Quick Links