Is there a simple ON_RTree example for bounding boxes?
I would like to know how search is performed because I cannot find any sample files starting from this:
//////////////////////////////////////////////////////////////////////////////
//create the R-tree from the input points.
//////////////////////////////////////////////////////////////////////////////
ON_RTree tree;
//////////////////////////////////////////////////////////////////////////////
// Convert Parameters to ON_Box
//////////////////////////////////////////////////////////////////////////////
ON_SimpleArray<ON_Box> boxes(numberOfBoxes);
for (int i = 0; i < numberOfBoxes; i++) {
//Get AABB
ON_BoundingBox bbox = box.BoundingBox();
tree.Insert(bbox.Min(), bbox.Max(), i);
}
//Stuck already here
tree.Search()
Thank you, this helps me to get on track.
For a simple case of a list of boxes, do I make the following lines correctly?
Is there a way to skip visited closest bounding boxes to avoid duplicates?
It is a bit hard to find simple example files, due to my knowledge of C++
Bigger goal: to transfer my C# timber joinery generation project to OpenNurbs, but this will take time and learning. Right now I am trying to transfer code function by function. I already using some c++ libraries, therefore the final goal is Rhino C++ plugin since I see much better performance, rather than Pinvoking each time.
For this specific issue of RTree these are steps I am trying to do:
There are 4 steps (but I need only one - RTree in C++) and I gradually want to search from the fastest to the slowest collision detection.
Input : Planar 3d polygons
I compute both OBB and AABB
Since RTree cannot use OBB, I would like to search an AABB RTree, which is where I am stuck with now. Where pair A and B is the same B and A. For this in C# I used HashSet, but filling hashset can be quite slow.
I perform OBB intersection method that I already have
I perform more detailed intersection check with polygons.
Not sure this is exactly what you are asking about, but here’s what I use to avoid duplicate matching with RTree
var rTree = RTree.CreateFromPointArray(pts);
var indices = new List<int>[pts.Count];
var lines = new List<Line>();
for(int i = 0;i < pts.Count;i++)
{
rTree.Search(new Sphere(pts[i], range), (sender, args) =>
{
if (args.Id > i) //this avoids duplicates
{
lines.Add(new Line(pts[i], pts[args.Id]));
}
});
};
A = lines;
And is it correct that if I change this line to if (i > neighbors[j])
Then I will always have unique pairs of elements considering 0-1 is the same as 1-0 ?
Or actually it is not possible? Once bounding boxes are inserted in the tree they are actually gone because Rtree is constructed from individual points only?
The R-tree has branches and leafs, each of which contains a bounding box. Maybe you can iterate the leafs, they should contain the bounding box and id, but I’m not sure how to do this. Check the docs for ON_RTreeNode and ON_RTreeBranch.