Q: Attribute wrangle > Attribute promote

   15701   27   3
User Avatar
Member
2624 posts
Joined: Aug. 2006
Offline
Hi All,

Is it at all possible to promote attributes inside a Attribute wrangle SOP . ie promote a point attribute to a detail attribute at the end of the vex code ? . If so Id love an example.

Rob
Gone fishing
User Avatar
Member
8525 posts
Joined: July 2007
Offline
it really depends on what you are promoting
but let's say you want to promote Point or Prim to Detail
then set Attrib Wrangle to Point or Prim mode and use setdetailattrib();
so prototype would be setdetailattrib(0, “detailattribname”, attrib or per element value to promote, “promotion method”);

so for example:
setdetailattrib(0, “ymax”, @P.y, “max”);
setdetailattrib(0, “areasum”, @area, “add”);
etc. but for that your detail attrib has to already exist

in theory you can do :
adddetailattrib(0, “ymax”, 0);
setdetailattrib(0, “ymax”, @P.y, “max”);

to even create the attrib within the same wrangle, but for some reason it doesn't work for me, maybe because wrangle code becomes part of the snippet function and maybe addattrib() has some problems with that, it just creates the attrib, but setattrib() doesn't change the default value, which is quite surprising
so so far you'l probably have to create attrib before, or do it in Attrib VOP where addattrib/setattrib combo works

and of course you can run it in opposite way as well, so Attrib Wrangle in Detail mode and loop through all components to compute promoted value, then just bind export it to detail attrib
Tomas Slancik
FX Supervisor
Method Studios, NY
User Avatar
Member
2624 posts
Joined: Aug. 2006
Offline
Thanks so much for the answer, straight into the notebook, while I have you here in the attribute wrangle how to I set a vector as .x .y .z in vex ? .

ie v@initialvel = set(@v.x,@v.y,@v.z); . In the spreadsheet my @initialvel is listed as 0 ,1 , 2 and not x y z

Rob
Gone fishing
User Avatar
Member
8525 posts
Joined: July 2007
Offline
you'd need to define qualifier for your attribute using setattribtypeinfo();
like:

setattribtypeinfo(0, “point”, “initialvel”, “vector”);
Tomas Slancik
FX Supervisor
Method Studios, NY
User Avatar
Member
2624 posts
Joined: Aug. 2006
Offline
Got it …..

vector @initialvel;
setattribtypeinfo(0, “point”, “initialvel”, “vector”);

Cheers

Rob
Gone fishing
User Avatar
Member
8525 posts
Joined: July 2007
Offline
v@initialvel = set(@v.x,@v.y,@v.z);
setattribtypeinfo(0, “point”, “initialvel”, “vector”);
or of course for this particular case
v@initialvel = @v;
setattribtypeinfo(0, “point”, “initialvel”, “vector”);

as 3@ is matrix3 attribute, not float 3

EDIT: ignore this, it was for the question before you changed it, I forgot to refresh
Tomas Slancik
FX Supervisor
Method Studios, NY
User Avatar
Member
2624 posts
Joined: Aug. 2006
Offline
Legend , thanks

Rob
Gone fishing
User Avatar
Staff
6169 posts
Joined: July 2005
Offline
tamte
in theory you can do :
adddetailattrib(0, “ymax”, 0);
setdetailattrib(0, “ymax”, @P.y, “max”);

This works. But unfortunately it determines what type of attribute to make by the type of your value. 0 defaults to integer, not float, so you create an integer.


adddetailattrib(0, “ymax”, 0.0);
setdetailattrib(0, “ymax”, @P.y, “max”);


will work as the 0.0 forces it to float.
User Avatar
Member
670 posts
Joined: Sept. 2013
Offline
What´s the reason setting detail attributes works for “max”, but not for “min”?
“min” stays at -123.0, while “max” returns something usable.

adddetailattrib(0, "dist_min", -123.0);
setdetailattrib(0, "dist_min", @dist, "min");

adddetailattrib(0, "dist_max", -123.0);
setdetailattrib(0, "dist_max", @dist, "max");
https://procegen.konstantinmagnus.de/ [procegen.konstantinmagnus.de]
User Avatar
Member
2036 posts
Joined: Sept. 2015
Online
It is usable, just have to consider the context and adjust the code accordingly.

min and max will only use the range from 0 to the smallest negative number or 0 to largest postive number.

Then the results will make sense:

for a value >= 0 max will be the largest number, while min will be zero.

for a value <= 0 max will be zero and min will be the smallest negative number.
User Avatar
Member
8525 posts
Joined: July 2007
Offline
BabaJ
min and max will only use the range from 0 to the smallest negative number or 0 to largest postive number.
0 intrinsically doesn't play any role in min and max
it's just min or max of all the numbers, so unless 0 is one of the numbers and is minimum or maximum from the set of numbers, it doesn't affect your result
(in above cases it comes down to default value or incoming detail attrib value as one of those may be 0 which may confuse you into thinking that 0 somehow plays the role in min/max)

Konstantin Magnus
What´s the reason setting detail attributes works for “max”, but not for “min”?
“min” stays at -123.0, while “max” returns something usable.
be careful what you initialize the detail attribs to
if your default for “dist_min” is -123.0 and no @dist value is smaller, your “dist_min” stays -123.0, so you may want to set its default value higher than any possible point values
the same for max, you may want to initialize it to be lower

if you don't want to be tempering with default value of the attrib, you can as well just set those initial attribute values before this wrangle and avoid adddetailattrib() altogether

also note that adddetailattrib() may not be necessary if you are ok with default value to be 0 as setdetailattrib() will now automatically create missing attribs
Edited by tamte - April 25, 2018 11:23:32
Tomas Slancik
FX Supervisor
Method Studios, NY
User Avatar
Member
670 posts
Joined: Sept. 2013
Offline
tamte
also note that adddetailattrib() may not be necessary if you are ok with default value to be 0 as setdetailattrib() will now automatically create missing attribs

Alright, great! I mistakenly expected the initial value to be overwritten in just any case.

But something like this is way more convenient and sufficient in my case:

float height = @P.y;
setdetailattrib(0, "height_min", height, "min");
setdetailattrib(0, "height_max", height, "max");

Thank you!
https://procegen.konstantinmagnus.de/ [procegen.konstantinmagnus.de]
User Avatar
Member
8525 posts
Joined: July 2007
Offline
just be careful as now your default value is 0 so you will get into situation where 0 will be your min if all @P.y are > 0 and 0 may be your max if all @P.y < 0
so not really the safest

any reason for not using Attribute Promote?
Tomas Slancik
FX Supervisor
Method Studios, NY
User Avatar
Member
2036 posts
Joined: Sept. 2015
Online
Thanks for the comment Tomas…my bad, having a dyslexic moment…

looking at my spreadsheet…confusing @dist with @dist_min or @dist_max.
User Avatar
Member
670 posts
Joined: Sept. 2013
Offline
tamte
just be careful as now your default value is 0 so you will get into situation where 0 will be your min if all @P.y are > 0 and 0 may be your max if all @P.y < 0
so not really the safest

You are correct, my quick example was misleading. Here is a real use case, that should do its job:

// measures point distances
f@dist = 0.0;
int near_pts[] = pcfind(0, "P", @P, 1.0, 32);
foreach(int pt; near_pts){
    @dist += distance( @P, point(0, "P", pt) ); 
}
@dist /= len(near_pts);

adddetailattrib(0, "dist_min", 1e7);
adddetailattrib(0, "dist_max", -1e7);

setdetailattrib(0, "dist_min", @dist, "min");
setdetailattrib(0, "dist_max", @dist, "max");


And a visual range mapper:

float min = detail(0, "dist_min", 0);
float max = detail(0, "dist_max", 0);
float range = fit(@dist, min, max, 0, 1);
@Cd = hsvtorgb( set( range, 1, 1) );

tamte
any reason for not using Attribute Promote?
I would not want to spend extra nodes for this and find it more elegant to include it (if it works).

Here is the HIP-file in case anyone is interested:
Edited by Konstantin Magnus - April 25, 2018 17:41:42

Attachments:
range_mapper_sshot.jpg (92.6 KB)
point_distance.hiplc (225.3 KB)

https://procegen.konstantinmagnus.de/ [procegen.konstantinmagnus.de]
User Avatar
Member
527 posts
Joined: July 2005
Offline
Do you suppose someone could show the way they would handle promoting a Vertex Attribute to Point Attribute, or a Point Attribute to Primitive Attribute in a Wrangle please?
soho vfx
User Avatar
Member
2036 posts
Joined: Sept. 2015
Online
You could use the pointvertices() function that returns a list of vertices belonging to the point.

Decide which vertice you want to use and get its attribute with vertex()/vertexattrib() and assign that value to the point with setpointattrib().

Similarly going from point to prims.

Functions list on this page.

http://www.sidefx.com/docs/houdini/vex/functions/index.html [www.sidefx.com]

in the filter box just type point, prim or vert to narrow the search
Edited by BabaJ - April 25, 2018 14:57:03
User Avatar
Member
8525 posts
Joined: July 2007
Offline
Konstantin Magnus
adddetailattrib(0, "dist_max", 1e-7);
careful about that
1e-7 is 0.0000001
you probably want -1e7 which is -10000000
Edited by tamte - April 25, 2018 15:32:56
Tomas Slancik
FX Supervisor
Method Studios, NY
User Avatar
Member
670 posts
Joined: Sept. 2013
Offline
tamte
you probably want -1e7 which is -10000000
Oh yes, thank you, I corrected it in the example above.
https://procegen.konstantinmagnus.de/ [procegen.konstantinmagnus.de]
User Avatar
Member
527 posts
Joined: July 2005
Offline
BabaJ
You could use the pointvertices() function that returns a list of vertices belonging to the point.

Decide which vertice you want to use and get its attribute with vertex()/vertexattrib() and assign that value to the point with setpointattrib().

Similarly going from point to prims.


Thank you for painting the broad strokes.I appreciate it.

Though, I am still chewing on loops to get them down pat. Does someone suppose they could show the structure how they would loop through all that in vex please?
soho vfx
  • Quick Links