Jump to content
mic

foreach SOP

Recommended Posts

hello!

help me please to solve some problem. for example, i have two lines - one have 10 points and one have only two. i want somehow query, for example, the nearest points - so i want to cycle every point on one line and another and query the distance between it and those from another, and find minimum of this value.. i think i should use foreach SOP and/or VOP SOP for such task! Could you help me, how should i do - how should i use this powerful nodes?

Share this post


Link to post
Share on other sites
hello!

help me please to solve some problem. for example, i have two lines - one have 10 points and one have only two. i want somehow query, for example, the nearest points - so i want to cycle every point on one line and another and query the distance between it and those from another, and find minimum of this value.. i think i should use foreach SOP and/or VOP SOP for such task! Could you help me, how should i do - how should i use this powerful nodes?

hi mic, I've written something in vop sop :) maybe it's what You are looking for.

closest_point.hipnc.hip

cheers

EDIT:

i've forgot about comments:

	vector pts[] = array({0,0,0}, {0,0,0}); // handle information about closest points, pts[0] - input one, pts[1] - input two

	int i=0, j=0;
	int npt1 = npoints(1); // number of points in input one 
	int npt2 = npoints(2); // number of points in input two 

	float distance=100000000000000; // Max distance
	float newdistance=0; // float value where we store minimum distance
	vector tip={0,0,0}, tsp={0,0,0}; // temp points, where we store current points

	// iterate on all points on first geometry
	for(; i< npt1; i++){
		import("P", tip, 1, i); // import point from input one to tip

		// iterate on all points on second gemetry 
		for(j=0; j<npt2; j++){
			import("P", tsp, 2, j);
			newdistance = min(distance, distance(tip, tsp));

			if(newdistance < distance){ // if we found closest distance
				distance = newdistance;
				pts[0] = tip;
				pts[1] = tsp;
			}
		}
	}


P = pts[ptnum]; // ptnum - current point, global variable, point index on renference points

Edited by bareja

Share this post


Link to post
Share on other sites

Hey bareja,

MEL is boring for you? :)

Query of points in distance you get for free with point cloud methods. No loops whatsoever. Just nice, build-in kdtree structure. Look for pcopen() in help.

pozdro,

skk.

Edited by SYmek

Share this post


Link to post
Share on other sites

For a lot of the common cases, the AttribTransfer SOP can also be used.

Share this post


Link to post
Share on other sites

this is little OT but why, in this example, MERGE SOP does points on second line be displayed from number 10 - 11 and not just from 0 -1 ?

Share this post


Link to post
Share on other sites

Hi skk ;)

yea indeed, i'm bored with mel, MayaAPI and Maya.

I think some of odforce topics are good challenges for noobs, like me.

Really thanks for advice and another challenge, i'll try pcopen tomorrow, i'm too tired today, to think or... whatever ;)

Hey edward! could u upload example scene ? it will be very interesting to do that with Attribute Transfer, I'm curious :)

Nibbler, sorry but... i don't understand your question, r u asking how megrge sop numerates points indexes after merge?

merge sop is incrementing point index from left to right inputs, try to swap inputs. In this example it will be:

[first line: 10 points, second line: 2 points, result line: 2 points]

indexes:

[first line: 0-9, second line: 10-11, result line: 12-13]

when u connect as first input 'second line' it will be:

[second line: 2 points, first line: 10 points, result line: 2 points]

[second line: 0-1, first line: 2-11, result line: 12-13]

cheers.

Edited by bareja

Share this post


Link to post
Share on other sites

thank you very much, guys, i'll see the scene tomorrow - and, yes - the reason i studied this example are the 'rumors' of the powerful nodes like foreach SOP and point cloud methods - so, it would be very interesting for me to study an example with pcopen() function!

thank you very much!

Share this post


Link to post
Share on other sites
For a lot of the common cases, the AttribTransfer SOP can also be used.

Good solution Edward. I imagine than you can easily transfer a current point number from the source line to the target line with the attributeTransfer SOP, then you know in your target line which point number from your source line is the nearest.

Share this post


Link to post
Share on other sites

hi folks,

I've made it with two attribute transfer operators, one delete , please check it, is it correct ?

closest_point.hipnc.hip

Cheers

EDIT:

sorry, it doesn't work :/

Edited by bareja

Share this post


Link to post
Share on other sites

hmm i don't know how to do this using attribute transfer sop,

How do u wanna get information about closest point, from all points ? using foreach sop ? points will "snap" like on the image:

post-3353-1233153409_thumb.jpg

Edited by bareja

Share this post


Link to post
Share on other sites

hmm i'm studying point clouds functions for this task. please tell me where i'm wrong: (just simple examples)

sop
test_point_cloud(string file = ""; export float f = 0.)
{
	int handle = pcopen(file, "P", {0, 0, 0}, 0.9, 30);
	f = pcfarthest(handle);
	pcclose(handle);
}

- everything is ok.

and

sop
test_point_cloud(string file = ""; export float temp = 1.2; export int q = 0;)
{
	int handle = pcopen(file, "P", {0, 0, 0}, 0.9, 30);
	temp = pcfarthest(handle);

	while(pciterate(handle))
		{
			pcimport(handle, "point.distance", q);
			if (q > 0)
			{ 
				temp = 142.87; 
			}
		}
	 pcclose(handle);
}

- everything crashes! fatal error. if comment all except if-construction everything works. importing is ok. but when manipulating imported data, crash happens or smth like that. why?

Share this post


Link to post
Share on other sites
well, I'm not sure is that what you are after?

PS. Dzieki za przyklad bareja.

PS2.Looking forward for a pointcloud example too

kuba

hey dude! thanks for example scene, i've thought that i can do this without foreach :) thanks again!

mic i didn't try point cloud method yet, to write point maybe try pcexport() ? sounds like method to export point position, but like i said i didn't try, maybe skk will help ;)

EDIT:

maybe your temp variable is reference to value stored somewhere, maybe in kdtree, and u r writing to it something, then h. crashes. and why r u trying write to temp ? in fact i don't know vex :)

Edited by bareja

Share this post


Link to post
Share on other sites

thank you very much, guys!

with your help i solved this example by oneself with two different vex solutions - 'like MEL' as Bareja and using point clouds.

You have already posted the working test scenes, so i won't post mine, the result is simply the same.

But, if someone want to view my vex code for studying vex coding, of course i'll post it, just tell me.

so, thank you very much once more!!

Edited by mic

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

×