Jump to content
Valent

trying to understand how arrays work

Recommended Posts

Hi!
I'm struggling to understand how arrays work
Could somebody please explain why am I seeing different results in geometry spreadsheet and in console made by 'printf' function? I mean, why does every primitive in spreadsheet contain the same set of points in its arrays?
I'm puzzled.

One more question:  How can I compare contents of different arrays?

primitives_array_q.hipnc

Share this post


Link to post
Share on other sites

You have the same results because you are assigning the i[]@neighs attribute in side a loop, in your case 5 times. So the fifth result is all you will ever see.

Maybe you want..

i[]@neighs=primpoints(0, @primnum);

instead?

  • Like 1

Share this post


Link to post
Share on other sites

@AtomIt makes sense, thanks.
 

On 11/16/2018 at 7:22 PM, Atom said:

i[]@neighs=primpoints(0, @primnum);

no, I need to get 'primpoints' for these five primitives only because I want to check if any of them are direct neighbors. (but I don't need to declare them as an attribute)

@davpe Thanks, that was useful.
 

Share this post


Link to post
Share on other sites

I'm trying to rebuild this wrangle to be able to work on 'detail', but it seems that I can't access @primnum there, what should I use instead?

Edited by Valent

Share this post


Link to post
Share on other sites
1 hour ago, Valent said:

I'm trying to rebuild this wrangle to be able to work on 'detail', but it seams that I can't access @primnum there, what should I use instead?

@primnum would access the primitive the primitivewrangle currently processes. Since detail wrangles dont run over anything but just one time, you have to build your own loop over primtives

for(int i = 0; i != nprimitives(0); ++i)
{
  	//do stuff here and instead of @primnum use i
}

Edit: change the input for nprimitives() according to your needs

Edited by 3dome
  • Like 1

Share this post


Link to post
Share on other sites

Thanks, it works!)
Btw it looks I can use @numprim instead of nprimitives(0)

Share this post


Link to post
Share on other sites

 

Could you please explain why it works this way? My initial idea was to randomly select primitives, then put selected primitive's numbers to an array. But if you look at the file provided, in one 'wrangle' each of the primitives has their own array which contains that point only. And in another wrangle which differs from the first one only by absence of 'if(faces==@primnum)' all the primitives are in  the array. 

array_append_qq.hipnc

Share this post


Link to post
Share on other sites
11 hours ago, Valent said:

 

Could you please explain why it works this way? My initial idea was to randomly select primitives, then put selected primitive's numbers to an array. But if you look at the file provided, in one 'wrangle' each of the primitives has their own array which contains that point only. And in another wrangle which differs from the first one only by absence of 'if(faces==@primnum)' all the primitives are in  the array. 

array_append_qq.hipnc

well if you don't understand what your code is doing I suggest learning the foundations of coding first.

A primwrangle runs over all primitives, so in the left wrangle, you give every primitive numbers chances that the @primnum==random_number(faces). Only then it is appended to the array, but of course the appended value will be the primnum.

The wrangle on the right appends numbers times to the array, no condition applys. The value that gets appended is whatever random_number is generated.
Because random_number is not dependend on the current primitive the wrangle iterates over, therefor the array is the same for all prims. If you want different arrays, make the seed change per prim by adding +@primnum after ch("seed")

Edited by 3dome
  • Like 1

Share this post


Link to post
Share on other sites

@3dome Thanks, it maketh sense)
Can I somehow create the array on detail (because I need all the numbers of the selected primitives to be in one array) while my 'wrangle' works on primitives?

Share this post


Link to post
Share on other sites

you can use setdetailattrib()
http://www.sidefx.com/docs/houdini16.0/vex/functions/setdetailattrib

something like:

int yourArray[];
  /*
  stuff to build your array
  */

string selection = sprintf("selectionOfPrim%d", @primnum);
setdetailattrib(0, selection, yourArray);

note that, if this is what you actually want to do, its better just to save it as a prim attribute of course.

if you just want one attribute, then run the wrangle in detail mode and build rebuild the logic to work with that. (you'll need to change the way you read and write your data)

Edited by acey195
  • Like 1

Share this post


Link to post
Share on other sites

 Thanks, I've remade my wrangle to be able to run on detail, and it works!)

But as a result I have a couple of questions:
For some reason I have to split the wrangle into two parts because the last part was not working, but when I made separate wrangle out of it, it worked.

and the second question: If I have my wrangle on primitives/points, is it possible to use an array which is on one point/primitive and ignore other point's/primitive's arrays. 
 

array_detail_a.hipnc

Share this post


Link to post
Share on other sites

Hey, didn't have time to check the file, but I have a hunch you used the

setdetailattrib(0, "foo", yourArray);

and then tried to read from it. This you cannot do inside the same wrangle.

all the functions that write attributes, are only applied in the output of the node,
not in the local data.

so if you want to keep using it, use "yourArray" instead of "detail(0, "foo")"
this restriction is not there for bound attribs like: "@foo"

to your other question, of course.
You can for example use the group parameter at the top of the node, to only process a subset (or a single) of your primitives

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×