简体   繁体   English

一组边界框中的点分类

[英]Point Classification in a set of Bounding Boxes

I have a set of bounding boxes(rectangular) in a 3D space. 我在3D空间中有一组边界框(矩形)。 The bounds of each box are computed and stored in a dictionary named "RegionBounds". 计算每个框的边界并将其存储在名为“ RegionBounds”的字典中。 Also, a set of points are populated in a List named "PointsToCategorize" Given a point(x,y,z) coordinates from the List populated and a bounding box to be checked in, i can check if the point is inside the box or not. 另外,在名为“ PointsToCategorize”的列表中填充了一组点。给定列表中填充的点(x,y,z)坐标和要检查的边界框,我可以检查该点是否在框内或不。 The problem is, this is a big dataset. 问题是,这是一个很大的数据集。 The number of points to be checked are like 1000 and the no of bounding boxes are like 250-300. 要检查的点数大约是1000,边界框的数量大约是250-300。 So, if i loop through each bounding box for each given point; 因此,如果我遍历每个给定点的每个边界框; the total time it takes is like 5-6 minutes. 总的时间大约是5-6分钟。 Is there any efficient method that would do the process quicker ? 是否有任何有效的方法可以更快地完成此过程? If possible, a small code to do so would be great 如果可能的话,一个很小的代码就可以了

public struct iBounds  {

public double x1, x2;
public double y1, y2;
public double z1, z2;

}
public struct iPoint  {        

   public double x,y,z

}

Dictionary<String, iBounds> RegionBounds = new Dictionary<String, iBounds>();
List<iPoint> PointsToCategorize = new List<iPoint>();

int no_of_bounding_boxes = 300;
int no_of_points_to_categorize = 1000;

for (int i = 1; i <= no_of_bounding_boxes; i++)
{

  String boundingBoxName = "bound_" + i;
  iBounds boundingBox = new iBounds
    {

        x1 = Computed By Some Other method and Formulas,
        x2 = Computed By Some Other method and Formulas,
        y1 = Computed By Some Other method and Formulas,
        y2 = Computed By Some Other method and Formulas,
        z1 = Computed By Some Other method and Formulas,
        z2 = Computed By Some Other method and Formulas

    };

    RegionBounds.Add(boundingBoxName, boundingBox);
}



   ////////////Start of Output section /////////////////////////

 for(int i= 1; i < = PointsToCategorize.Count; i++){

  foreach(var pair in RegionBounds)
   {
     String myboxNmame = pair.Key;
     iBounds myboxBounds = pair.Value;
      Console.WriteLine(PointInside(PointsToCategorize[i],myboxBounds).ToString());

  }
}

 ////////////// End of Output section //////////////////

private bool PointInside(iPoint mypoint, iBounds boxToBeCheckedIn)
{
    if (mypoint.x > boxToBeCheckedIn.x1) && (mypoint.x < boxToBeCheckedIn.x2){
        if (mypoint.y > boxToBeCheckedIn.y1) && (mypoint.y < boxToBeCheckedIn.y2){
            if (mypoint.z > boxToBeCheckedIn.z1) && (mypoint.z < boxToBeCheckedIn.z2){
                return true;
            }
        }
    }else{
        return false;
    }

}

You may want to use a OcTree or a kD-tree data structure, which is way more efficient than iterating through all the boxes. 您可能要使用OcTreekD-tree数据结构,这比遍历所有框的效率更高。

See also this article at the section 2-D orthogonal range searching , it has a very good resume of available techniques and algorithms, which are easily extendable to 3D 另请参阅本文二维正交范围搜索”部分 ,它具有可用技术和算法的很好的履历,可以轻松扩展到3D

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM