Iraklo 0 Posted August 20, 2017 Hi guys, how do I compare to each other and get max and min values of attribute for different elements. Basically I want to compare these guys and get min and max. Share this post Link to post Share on other sites
konstantin magnus 845 Posted August 20, 2017 Use an attribpromote from points, verts or prims to detail and set the promotion method to min or max. 1 Share this post Link to post Share on other sites
konstantin magnus 845 Posted August 20, 2017 As you requested a VEX solution, I would put something like this into a detail wrangle: int all = nvertices(0); @min = vertex(0, "uv", 0); @max = vertex(0, "uv", 0); for(int i = 0; i < all; i++){ float compare = vertex(0, "uv", i); if(compare < @min) @min = compare; if(compare > @max) @max = compare; } Unfortunately I would not know how to access a single vector component in this manner: @min = vertex(0, "uv.y", 0); // these lines @max = vertex(0, "uv", 0).y; // do not work Maybe someone can help me out here? 2 Share this post Link to post Share on other sites
f1480187 765 Posted August 20, 2017 @konstantin magnus, try function-style cast: vector(vertex(0, "uv", 0)) 3 Share this post Link to post Share on other sites
konstantin magnus 845 Posted August 20, 2017 @f1480187, ah thank you! So I guess, its: int all = nvertices(0); @min = vector(vertex(0, "uv", 0)).y; @max = vector(vertex(0, "uv", 0)).y; for(int i = 0; i < all; i++){ float compare = vector(vertex(0, "uv", i)).y; if(compare < @min) @min = compare; if(compare > @max) @max = compare; } 1 Share this post Link to post Share on other sites
Iraklo 0 Posted August 20, 2017 @konstantin magnus @f1480187 Thanks for help guys Share this post Link to post Share on other sites
ikoon 264 Posted August 21, 2017 (edited) I am used to access vector component like this, I hope it is a good solution as well: vector compare = vertex(0, "uv", i); if(compare[2] < @min) @min = compare[2]; Edited August 21, 2017 by ikoon grammar check 1 Share this post Link to post Share on other sites
petz 434 Posted August 21, 2017 you could put the following two lines in a vertex wrangle: setdetailattrib(geoself(), "min_val", @uv.y, "min"); setdetailattrib(geoself(), "max_val", @uv.y, "max"); 4 Share this post Link to post Share on other sites
Iraklo 0 Posted August 21, 2017 @ikoon @petz Thanks for reply guys. One quick question here: how is it possible to create array from numbers I marked in the first post's screen? Right now it's irrelevant, but in future it would help me. Share this post Link to post Share on other sites
f1480187 765 Posted August 21, 2017 You can do it in Detail Wrangle: for (int i = 0; i < @numvtx; i++) { vector uv = vertex(0, "uv", i); append(f[]@uvx, uv.x); } Or in Vertex Wrangle (very slow): float uvx[] = array(@uv.x); setdetailattrib(0, "uvx", uvx, "append"); 1 Share this post Link to post Share on other sites
petz 434 Posted August 21, 2017 depending on the number of vertices, the easiest method is most probably using setdetailattrib() like in f1's second example. however, for very dense meshes and if performance is important it's better to iterate over the vertices and resize the array in advance instead of appending in a loop. this way you avoid continuous bounds checking of the array. int num = detailintrinsic(@OpInput1, "primitivecount"); f[]@val_array; resize(@val_array, num); for(int i = 0; i < num; i++) @val_array[i] = vector(vertex(@OpInput1, "uv", i)).y; hth. petz 6 Share this post Link to post Share on other sites
Iraklo 0 Posted August 22, 2017 @petz @f1480187 Thanks again guys. Much appreciated. Share this post Link to post Share on other sites