mic Posted January 27, 2009 Share Posted January 27, 2009 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? Quote Link to comment Share on other sites More sharing options...
bareja Posted January 27, 2009 Share Posted January 27, 2009 (edited) 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 January 27, 2009 by bareja Quote Link to comment Share on other sites More sharing options...
symek Posted January 27, 2009 Share Posted January 27, 2009 (edited) 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 January 27, 2009 by SYmek Quote Link to comment Share on other sites More sharing options...
edward Posted January 27, 2009 Share Posted January 27, 2009 For a lot of the common cases, the AttribTransfer SOP can also be used. Quote Link to comment Share on other sites More sharing options...
Nibbler Posted January 27, 2009 Share Posted January 27, 2009 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 ? Quote Link to comment Share on other sites More sharing options...
bareja Posted January 27, 2009 Share Posted January 27, 2009 (edited) 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 January 27, 2009 by bareja Quote Link to comment Share on other sites More sharing options...
Nibbler Posted January 27, 2009 Share Posted January 27, 2009 thnx for answer bareja, I wasn't so clear but this is the answer I looked for Quote Link to comment Share on other sites More sharing options...
mic Posted January 27, 2009 Author Share Posted January 27, 2009 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! Quote Link to comment Share on other sites More sharing options...
Nico D. Posted January 28, 2009 Share Posted January 28, 2009 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. Quote Link to comment Share on other sites More sharing options...
bareja Posted January 28, 2009 Share Posted January 28, 2009 (edited) 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 January 28, 2009 by bareja Quote Link to comment Share on other sites More sharing options...
bareja Posted January 28, 2009 Share Posted January 28, 2009 (edited) 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: Edited January 28, 2009 by bareja Quote Link to comment Share on other sites More sharing options...
mic Posted January 28, 2009 Author Share Posted January 28, 2009 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? Quote Link to comment Share on other sites More sharing options...
kubabuk Posted January 28, 2009 Share Posted January 28, 2009 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 closest_point2.hipnc Quote Link to comment Share on other sites More sharing options...
bareja Posted January 28, 2009 Share Posted January 28, 2009 (edited) 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 January 28, 2009 by bareja Quote Link to comment Share on other sites More sharing options...
petz Posted January 28, 2009 Share Posted January 28, 2009 maybe this helps. petz closest_points.hipnc Quote Link to comment Share on other sites More sharing options...
bareja Posted January 28, 2009 Share Posted January 28, 2009 thanks! this is it! cheers Quote Link to comment Share on other sites More sharing options...
mic Posted January 29, 2009 Author Share Posted January 29, 2009 (edited) 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 January 29, 2009 by mic Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.