for loop in vop
16688 9 1- danilo2
- Member
- 277 posts
- Joined: July 2006
- Offline
Hi!
I've got a sphere (builded of triangles) and a point (f.e. A0.3,0.4,0.0)) and I want to compute in VOP a sum of all lengths between point A and each of sphere vertex.
I simply cannot find to add all the results in my vex “For Loop” node.
In this node I iterate over all points, import P attribute, and I'm computing the length between this iterated sphere point and my A point.
But how to sum all of these computations in one variable?
(I simply want to color this sphere - if sum of all points is larger - the sphere shoulkd have other color)
I've got a sphere (builded of triangles) and a point (f.e. A0.3,0.4,0.0)) and I want to compute in VOP a sum of all lengths between point A and each of sphere vertex.
I simply cannot find to add all the results in my vex “For Loop” node.
In this node I iterate over all points, import P attribute, and I'm computing the length between this iterated sphere point and my A point.
But how to sum all of these computations in one variable?
(I simply want to color this sphere - if sum of all points is larger - the sphere shoulkd have other color)
Edited by - March 28, 2010 13:38:17
- Anonymous
- Member
- 678 posts
- Joined: July 2005
- Offline
- mawi
- Member
- 251 posts
- Joined: Jan. 2008
- Offline
- tamte
- Member
- 8766 posts
- Joined: July 2007
- Online
mawi's file is an example on how to use for loop in VOPs, but it's not effective solution for your problem, because the for loop runs for every point and that is N-1 times more than you need
you can simply store distance to the point as a point attribute then use Attribute Promote SOP to promote it to detail attribute with Sum mode
then in another VOP SOP do the color thing
you can simply store distance to the point as a point attribute then use Attribute Promote SOP to promote it to detail attribute with Sum mode
then in another VOP SOP do the color thing
Tomas Slancik
FX Supervisor
Method Studios, NY
FX Supervisor
Method Studios, NY
- Anonymous
- Member
- 678 posts
- Joined: July 2005
- Offline
tamte
you can simply store distance to the point as a point attribute then use Attribute Promote SOP to promote it to detail attribute with Sum mode
then in another VOP SOP do the color thing
That was my first sugestion but I removed my file because I thought that he looks for one solution that can be done using only one Vop, without using outside calculations.
Anyway, I'm curious how Mawi's solution really works. I mean, when you print distance calculation from for loop you get the same distance for each point in each iteration while it should vary because each iteration change point number that is imported. When you compare distance directly by pluging P of sphere and single point you get correct distance calculations. But when you sum it both solutions gives correct sum of lenghts. Could somebody, please, explain why Mawi's solution gives correct lenghtSum result while giving incorrect distance calculations for each point ? ?
- danilo2
- Member
- 277 posts
- Joined: July 2006
- Offline
Hi!
thank you for replies
_Swann - exactly I was looking for solution using only one VOP node - so I will be very thankfull if you publish yours file again (if yo got the solution)
I had exactly the same problem as Swann describes (my file is very simmilar to mawi's file - and I don't understeand why I got everytime the same values, when I'm testing it outside for loop (as _Swann) and when I'm testing it inside I got strabge things (see screenshot).
I'm testing the values of:
/obj/geo1/vopsop1/for1/distanc1 -> dist (screenshot)
and I understeand that VOP normally iterates over all points, for1 loop too.
if we will write in in c++ simmilar language we will become something like:
for(vop_i=0; vop_i<npt; vop_i++)
{
for(for_i=0; for_i<npt; for_i++)
{
printDistance(); //between base point and point of sphere, which number is for_i
}
}
so in result we should get npt*npt lines and output should consist of npt exactly the same blocks of npt lines of lengths.
And as you see on screenshots - output is strange, becouse it “sorts” ? the values ? (there shoudn't be 2 exactly the same lines next to each other)
thank you for replies
_Swann - exactly I was looking for solution using only one VOP node - so I will be very thankfull if you publish yours file again (if yo got the solution)
I had exactly the same problem as Swann describes (my file is very simmilar to mawi's file - and I don't understeand why I got everytime the same values, when I'm testing it outside for loop (as _Swann) and when I'm testing it inside I got strabge things (see screenshot).
I'm testing the values of:
/obj/geo1/vopsop1/for1/distanc1 -> dist (screenshot)
and I understeand that VOP normally iterates over all points, for1 loop too.
if we will write in in c++ simmilar language we will become something like:
for(vop_i=0; vop_i<npt; vop_i++)
{
for(for_i=0; for_i<npt; for_i++)
{
printDistance(); //between base point and point of sphere, which number is for_i
}
}
so in result we should get npt*npt lines and output should consist of npt exactly the same blocks of npt lines of lengths.
And as you see on screenshots - output is strange, becouse it “sorts” ? the values ? (there shoudn't be 2 exactly the same lines next to each other)
- mawi
- Member
- 251 posts
- Joined: Jan. 2008
- Offline
danilo2
And as you see on screenshots - output is strange, becouse it “sorts” ? the values ? (there shoudn't be 2 exactly the same lines next to each other)
Maybe this capture will clear things up about my file.
But as tamte said it´s not a effective solution since your doing same calculation over and over.
Edit…
Btw. You can plug more nodes into the printVOP to get a better view about what is happening.
- danilo2
- Member
- 277 posts
- Joined: July 2006
- Offline
- Anonymous
- Member
- 678 posts
- Joined: July 2005
- Offline
danilo2
Swann - exactly I was looking for solution using only one VOP node - so I will be very thankfull if you publish yours file again (if yo got the solution) )
I'm switching to writing Vex slowly so this is my one node solution.
float sumLenght(vector v; int number, test)
{
float pointDist;
float sumL = 0;
vector points;
while(test < number)
{
int suc = import(“P”, points, 0, test++);
pointDist = distance(points, v);
sumL += pointDist;
}
return sumL;
}
- danilo2
- Member
- 277 posts
- Joined: July 2006
- Offline
-
- Quick Links