【问题标题】:Point Classification in a set of Bounding Boxes一组边界框中的点分类
【发布时间】:2015-06-14 08:08:56
【问题描述】:

我在 3D 空间中有一组边界框(矩形)。每个框的边界都被计算并存储在一个名为“RegionBounds”的字典中。此外,一组点填充在名为“PointsToCategorize”的列表中给定填充列表中的点(x,y,z)坐标和要签入的边界框,我可以检查该点是否在框内或不是。问题是,这是一个大数据集。要检查的点数为 1000,边界框数为 250-300。所以,如果我循环遍历每个给定点的每个边界框;总共需要5-6分钟。有没有什么有效的方法可以更快地完成这个过程?如果可能的话,这样做的小代码会很棒

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;
    }

}

【问题讨论】:

  • 欢迎来到 SO!由于您是新人,您可能需要查看此link

标签: c# python algorithm sorting data-analysis


【解决方案1】:

您可能想要使用OcTreekD-tree 数据结构,这比遍历所有框更有效。

另请参阅 2-D 正交范围搜索部分的this article,它对可用技术和算法进行了很好的恢复,很容易扩展到 3D

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-23
    • 1970-01-01
    • 1970-01-01
    • 2010-12-09
    • 2015-02-11
    相关资源
    最近更新 更多