Hi guys,
I am doing some tests, were I am trimming a large point collection with a given closed mesh. Basically retrieving only those points which are inside.
Foremost, I want to try to use RTree
to only get the points which are inside the mesh’s bounding box, to then test that reduced search space for containment.
The RTree method I am trying to use is this one
The pseudo code which I have in mind is:
Construct RTree from points
foreach point in points:
if point is inside bounding box:
add point to newList
return newList
After I have this new List, it would be the input to:
/// <summary>
/// Tests weather a points is inside a closed mesh
/// </summary>
/// <param name="mesh"></param>
/// <param name="ptsRTree"></param>
/// <returns></returns>
public void ContainmentB(Mesh mesh, List<Point3d> ptsRTree)
{
for (int i = 0; i < ptsRTree.Count; i++)
{
Point3d pointOnMesh;
Vector3d normalAtPoint;
int a = mesh.ClosestPoint(ptsRTree[i], out pointOnMesh, out normalAtPoint, 0);
if(a > -1)
{
double dotProduct = normalAtPoint * (pointOnMesh - ptsRTree[i]);
// if pt is inside
if(dotProduct > 0)
{
culled.Add(ptsRTree[i]);
}
}
}
}
Would the pseudo code for the RTree search seem reasonable?
currently I have this:
public void ContainmentRTree(Mesh mesh)
{
RTree rTree = RTree.CreateFromPointArray(pts);
foreach (Point3d p in pts)
{
List<Point3d> inBox = new List<Point3d>();
EventHandler<RTreeEventArgs> rTreeCallback =
(object sender, RTreeEventArgs args) =>
{
inBox.Add(pts[args.Id]);
};
if(rTree.Search(bBox, rTreeCallback))
{
ContainmentB(mesh, inBox);
}
}
}
But I know its totally wrong for the following reasons:
-
List<Point3d> inBox = new List<Point3d>();
Should be out of the loop.
if(rTree.Search(bBox, rTreeCallback))
{
ContainmentB(mesh, inBox);
}
Should also be out of the loop. It does not make sense to call this method here, because it will run in every iteration of the loop.
- For that matter the call back would have to bee defined in a different way. But right know I cant think of a way to do so.
Other details:
-
Currently without RTree and for 64 million points the code is taking roughly 3 minutes to complete. This is why I want to try to use RTree to cut down the performance a little.
-
I am not outputting the points in the viewport. I am overriding
ClippingBox
andDrawViewportWires
Any tips would be great!