I have assembled the following using script using ghpython.
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:
point=rs.coerce3dpoint(Pt.Location)
if brep.IsPointInside(point,tol,True)==True:
Result.append(point)
except:
pass
CloudPts=Cloud.GetEnumerator()
ghpythonlib.parallel.run(TestPoints,CloudPts)
Plane=rs.PlaneFitFromPoints(Result)
Plane=rs.coerceplane(Plane)
r,Curves,points=Rhino.Geometry.Intersect.Intersection.BrepPlane(brep,Plane,tol)
if r==True:
PlanarSrf=rs.AddPlanarSrf(Curves)
The script runs fine, I am able to scan through and evaluate a set of 20 million points in around 80 seconds. I am going to explore some alternative methods for accelerating this calculation. It looks to me the Cloud.GetEnumerator() for a large cloud is a rather lengthy way to pass the points into the parallel.run().
Also I think I am having issues with garbage collection. In the script I am creating 20 million 3dpoint objects in memory, some of which are used for calculating a best fit plane and never added to the document. Other Rhino objects have .Dispose() function that address this but I don’t see that option for a 3dpoint. After running the script I’m seeing around 4 GB of RAM being used. After panning around in Rhino a bit the garbage collection seems to kick in, realize the 3dpoints are not being used and returns the expected levels. I have also tried the ClearUndo command to clear the history and seen no drop in RAM consumption.
If anyone can point me the right direction that would be great.
Thanks,
5chmidt