Jump to content

Something wrong with vex execution ?


nmn

Recommended Posts

Hi everyone, this thing is frustrating !!

is it normal ? that the following piece of code, that i applied as a vex sop on a grid with 75 points :

sop
my_sop()
{
 int tomtom[];
 printf("ptnum : %d\n",ptnum);
 tomtom = getneighbours(ptnum, 0);
 int count = arraylength(tomtom);
 printf("count : %d\n",ptnum);
 int i;
 for(i=1;i<=count;i++)
 addattribute("Group", ptnum, "type", "");
}

gives this output ?!!! as if it's executing each printf alone ?! ... i know about the SIMD , but still .... doesn't seem logical

ptnum : 0
ptnum : 1
ptnum : 2
ptnum : 3
ptnum : 4
ptnum : 5
ptnum : 6
.
.
.
ptnum : 70
ptnum : 71
ptnum : 72
ptnum : 73
ptnum : 74
ptnum : 75
count : 0
count : 1
count : 2
count : 3
count : 4
count : 5
count : 6
.
.
.
count : 70
count : 71
count : 72
count : 73
count : 74
count : 75

it doesn't at all look right to me, adding to that , that i'm setting the Group attribute to ptnum

so i should get the ptnum of the point being processed in the Group atribute of its neighbours

i know it's recursive and some will be recalculated, but but i don't even get close to that

what i get in the Group attribute is the ptnum of each point itself !

try this piece of code for yourself and see ...

i tried similar logic, using getneighbourcount and getneighbour

and i also tried it using VOPs and all the same ...

Please can some one explain to me what's going on, if there is something i didn't understand or something i'm doing wrong

i'm a professional C C++ programmer so i'm expecting the same behaviour ... but apparently it's NOT !

and it's giving wrong results !!

any help is really appreciated

Cheers

Edited by nmn
Link to comment
Share on other sites

what are you trying to do?

this code prints point number for all points

sop
my_sop()
{
 int tomtom[];
 printf("ptnum : %d\n",ptnum); 

this code gets neighbour ids for each point and calculates number of neighbours

but the printf prints point numbers again, because you are using ptnum instead of count

 tomtom = getneighbours(ptnum, 0);
 int count = arraylength(tomtom);
 printf("count : %d\n",ptnum);

this code repeats several times the same task:

for current point (not neighbour) create attribute named "Group" with the value of ptnum, which is current point number

 int i;
 for(i=1;i<=count;i++)
 addattribute("Group", ptnum, "type", "");
}

so you should get "Group" attribute with the point number as a value

and it does exactly that

it is obviously not what you are after, but it's what you have written

what do you want to get?

to create group attribute with the values of the neighbours you can try this

sop
my_sop()
{
 int tomtom[] = getneighbours(ptnum, 0);
 addattribute("Group", sprintf("%s",tomtom) );
}

or this

sop
my_sop()
{
 float tomtom[] = getneighbours(ptnum, 0);
 addattribute("Group", tomtom, arraylength(tomtom));
}

Link to comment
Share on other sites

Hey , thanks for all of your answers, it cleared up some things to me.

but still I'm not convinced ... or at least don't know how to tackle it,

let us say for example, on my points I have an attribute called "ActOnThis"

which is 1 for some of them and 0 for the others.

then I want the following logic

1 - getneighbours

2 - loop over neighbours

3 - for each neighbour test if ActOnThis is one

4 - set Group attribute to the number of "the acted on point" and set ActOnThis to 0

5 - else set it to -1

so if i have 100 points and i write:

tomtom = getneighbours(ptnum, 0);

for(i=1;i<=arraylength(tomtom);i++)

{

if(importAttribute(blablabla);

{ addattribute("Group", ptnum, "type", ""); addattribute("ActOnThis", 0, "type", ""); }

else addattribute("Group", -1, "type", "");

}

it will execute

tomtom = 100 times

then the for 100 times (not sure how it does that without doing the lines inside the for loop directly inside it)

then the if 100 times (another time not sure how it can do the if without executing what's inside directly)

then the first addattribute 100 times

then the second addattribute 100 times

then the else ... :S:S:S

in this case for sure it won't give me the result I need ...

I'm well aware that such codes can be done but how !

especially when one is used to the sequential nature of C for example ... this seems awkward (at least in the beginning)

but i want to get the hang of that ! so i need your help

(The question applies also to VOPs, coz using these for loops and if conditions ... and having them executed in a non expected manner is also frustrating, so what is the approach for this as well ? ... )

cheers

Edited by nmn
Link to comment
Share on other sites

...

4 - set Group attribute to the number of "the acted on point" and set ActOnThis to 0

...

for(i=1;i<=arraylength(tomtom);i++)

{

if(importAttribute(blablabla);

{ addattribute("Group", ptnum, "type", ""); addattribute("ActOnThis", 0, "type", ""); }

...

i am not sure you can do that this way

first of all: importAttribute() imports value of the attribute from input of the VOP not the changed value from inside the VOP

so you are not able to mark point as ActOnThis 0 and expect that next time it is called for the same point within the same VEX it will be 0

(it will be the same as first time, the same as in input geometry)

secondly: with addattribute you are setting value for current point

so if you are executing for loop for neighbours of n-th point, then no matter in which iteration the for loop is, you are still setting the attribute for n-th point and not for its neighbours

almost every list of IDs in houdini is zero based so for(i=0;i<arraylength(tomtom);i++) makes more sense, not that it matters in your example because you are not using i variable in commands within the for loop so it is basically the same command n-times

it's all about what the final result should be

if you cannot do some things with VEX architecture you can try python SOP, it will be slower, but you certainly have more freedom with it

but i am not the VEX pro so do not take me too seriously, i can have inaccurate understanding too

Link to comment
Share on other sites

let us say for example, on my points I have an attribute called "ActOnThis"

which is 1 for some of them and 0 for the others.

then I want the following logic

1 - getneighbours

2 - loop over neighbours

3 - for each neighbour test if ActOnThis is one

4 - set Group attribute to the number of "the acted on point" and set ActOnThis to 0

5 - else set it to -1

Just to chipping in to second what Anim said. In any case, this logic doesn't quite make sense to me. Why would you need to modify ActOnThis? What *are* you trying to accomplish? Describe this in general terms.

Link to comment
Share on other sites

Just to chipping in to second what Anim said. In any case, this logic doesn't quite make sense to me. Why would you need to modify ActOnThis? What *are* you trying to accomplish? Describe this in general terms.

simplifying what I need to do would give :

I wanted to modify ActOnThis, because for example imagine you have a bunch of points, from which you want to generate geometry

so you do your loops and conditions to detect which points you want to connect together (not that i found a solution for that using vex yet ... but in python i'm not far - though i prefer vex because it's ... well more performer especially for very high resolutions)

and then for every "group of points that form a polygon" you want to construct the polygon, check every point of that polygon to see if it's still needed in another polygon

and if not say that this point is out of the game so you won't rework on it in the next loop ... etc ...

I hope that clarifies what I'm after a bit ...

Cheers

Edited by nmn
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...