sanchez Posted April 14, 2007 Share Posted April 14, 2007 (edited) Hi. I am trying to bring in some attributes from point cloud to COPs by using custom VEX COP. So i get wrong, different, and totally unpredictable results every cook even if i neither chage values of the parameters nor change point cloud geometry. Where is a problem? My code: cop2 pc_image_gen(string pc_file = "";string attrib = "inside";float radius = 0.1;int maxpoints = 100; float scalef = 1) { int pc_handle; float d, r, sum = 0, result = 0; float tmpF; vector pos = set(X,Y,0); pos *= scalef; pc_handle = pcopen(pc_file, "P", pos, radius, maxpoints); float npoints = 0; while(pciterate(pc_handle)) { pcimport(pc_handle,"point.distance",d); pcimport(pc_handle,"radius",r); if (d <= r) { pcimport(pc_handle, attrib, tmpF); sum += tmpF; npoints++; } } result = sum / npoints; Cr = result; Cg = result; Cb = result; pcclose(pc_handle); } Edited April 14, 2007 by sanchez Quote Link to comment Share on other sites More sharing options...
MADjestic Posted April 14, 2007 Share Posted April 14, 2007 Just a guess - try initializing float tmpF; -> float tmpF=0; You certainly know that in general it's better to initialize your variables that you are using in computation. Or maybe adding an else statement after if could help as well. hope that might help. [EDIT] oh yeah - taking a second look at your code - this part can potentially be a problem - result = sum / npoints; - you iterate your 'npoints' inside the 'if' statement - in case your code doesn't get into that 'if' statement - you'll get a devision by zero, which will result in hactick artifacts, which resembles the problem you experience. Quote Link to comment Share on other sites More sharing options...
sanchez Posted April 16, 2007 Author Share Posted April 16, 2007 Thank you MADjestic. I solved broblems in the code already. It works for me now. 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.