I am attempting to do some analysis of PointCloud objects within Rhino.
I have a pretty simple script in which I am attempting to build a best fit plane from a subset of points within a point cloud. The inputs are a cubic polysurface volume, which is used to limit the points used to create a best fit plane and a point cloud.
def PointTest(Brep,Cloud): if rs.IsPolysurfaceClosed(Brep)!=True: return brep=rs.coercebrep(Brep) Cloud=rs.coercegeometry(Cloud) Result= tol=scriptcontext.doc.ModelAbsoluteTolerance for pt in Cloud.GetEnumerator(): point=rs.coerce3dpoint(pt.Location) if brep.IsPointInside(point,tol,True)==True: Result.append(point) Plane=rs.PlaneFitFromPoints(Result) Plane=rs.coerceplane(Plane) rc,Curves,points=Rhino.Geometry.Intersect.Intersection.BrepPlane(brep,Plane,tol) if rc==True: PlanarSrf=rs.AddPlanarSrf(Curves) return PlanarSrf
Currently I am dealing with a point cloud that is around half a million points. Processing a cloud this size takes around 3.2 seconds. The lower limit for size of point cloud that I am dealing with is around 20 million points. With this in mind I attempted to create a multi-threaded solution for parsing through the enumerated point cloud, code below. I have not been able to get past the “The type arguments for method ‘ForEach’ cannot be inferred from the usage. Try specifying the type arguments explicitly.” error message. Should it possible to parse through a single point cloud using multipul threads? If so what is the proper syntax for doing so?
def Threaded_PointTest(Brep,Cloud): ## Make Sure Test Polysurface is Closed ## if rs.IsPolysurfaceClosed(Brep)!=True: print "Test brep is Not Closed" return ## Get a Private Copy for Multi-Threading ## brep=rs.coercebrep(Brep) brep.EnsurePrivateCopy() ## Turn Object into a PointCloud ## Cloud=rs.coercegeometry(Cloud) ## Holder for Points inside Surface ## Result= tol=scriptcontext.doc.ModelAbsoluteTolerance def TestPoints(Pt): try: print Pt except: pass CloudPts=Cloud.GetEnumerator() tasks.Parallel.ForEach(CloudPts,TestPoints)