简体   繁体   English

给定一个点和大量的四面体,如何高效判断该点在哪个四面体中

[英]Given a point and a large number of tetrahedrons, how to efficiently determine in which tetrahedron the point is

Suppose we define a point to be a tuple of three floating-point numbers, and a tetrahedron a tuple of four points.假设我们将点定义为三个浮点数的元组,而四面体定义为四个点的元组。

Suppose we have a tetrahedron and a point, we can determine whether the point belongs to the tetrahedron following the solutions described in How to check whether the point is in the tetrahedron or not?假设我们有一个四面体和一个点,我们可以按照如何检查点是否在四面体中描述的解决方案来确定该点是否属于四面体? The key idea there is to determine whether the point is on the inner sides of the four flanks of the tetrahedron.那里的关键思想是确定该点是否在四面体的四个侧面的内侧。

My problem.我的问题。 Given a point, and N tetrahedrons, where N is about 7 million, I need to determine in which tetrahedron the point is.给定一个点和 N 个四面体,其中 N 约为 700 万,我需要确定该点在哪个四面体中。 We will care about performance of doing repeated tests, with a large number of points.我们将关心重复测试的性能,有大量的分数。

Additional info:附加信息:

  1. One could just check these tetrahedrons one by one using the methods mentioned above.可以使用上面提到的方法对这些四面体进行一一检查。 But that could be too slow, given my large number of tetrahedrons.但考虑到我有大量的四面体,这可能太慢了。

  2. There is a specific point in the problem setting.问题设置中有一个特定的点。 These tetrahedrons are obtained from a FEM (finite element method ) problem for solving a medical imaging problem (they form the brain of patients).这些四面体是从用于解决医学成像问题的 FEM(有限元方法)问题中获得的(它们构成了患者的大脑)。 Perhaps FEM itself is unrelated to the question, but we could leverage the fact that those tetrahedrons are next to each other and there are no “holes” in the space that simulated by those tetrahedrons.也许 FEM 本身与这个问题无关,但我们可以利用这些四面体彼此相邻并且在这些四面体模拟的空间中没有“洞”这一事实。

  3. The tetrahedrons have no intersections except on their adjacent boundary.除了相邻的边界外,四面体没有交点。 So, this question should have a unique solution unless at the boundary, in which case it is fine to have either of the intersected tetrahedrons the answer to my problem.所以,这个问题应该有一个唯一的解决方案,除非在边界处,在这种情况下,可以让任何一个相交的四面体来回答我的问题。

  4. There are no specific orders in which the tetrahedrons are given on inputs.没有在输入上给出四面体的特定顺序。 There are no specification on whether the shapes of the tetrahedrons are regular or not.四面体的形状是否规则并没有规定。

Any idea on an efficient solution to the problem?关于有效解决问题的任何想法? Python is preferred in solving this problem. Python 是解决这个问题的首选。

Thanks!谢谢!

You could first filter the tetrahedrons, keeping only those for which the bounding cuboid (which is parallel with the X, Y and Z axes) contains p .您可以先过滤四面体,只保留边界长方体(与 X、Y 和 Z 轴平行)包含p的四面体。 This is faster to test:这是测试更快:

So find tetrahedrons -- with points t 0 , t 1 , t 2 , and t 3 -- which have the following property with respect to the point p :因此,找到四面体——具有点t 0 、 t 1 、 t 2t 3 ——它们相对于点p具有以下属性:

  • i,j: t i x ≤ p x ≤ t j x i,j: t i x ≤ p x ≤ t j x
  • i,j: t i y ≤ p y ≤ t j y i,j: t i y ≤ p y ≤ t j y
  • i,j: t i z ≤ p z ≤ t j z i,j: t i z ≤ p z ≤ t j z

On average this will leave you with only a few tetrahedrons (often only one or two) which you then use to apply the point-in-tetrahedron test.平均而言,这只会给您留下几个四面体(通常只有一两个),然后您可以使用这些四面体进行点入四面体测试。

If you plan to test a lot of points against same set of tetrahedra, I would definitely go with a preprocessing step and build spatial structure for tetrahedra.如果您打算针对同一组四面体测试很多点,我肯定会采用预处理步骤并为四面体构建空间结构。

In my comment I mentioned octtree, but knowing that the tetrahedra fill in the space (no holes) I think that there is no need for adaptive subdivision of space, and it is best to divide it into equal parts.在我的评论中我提到了八叉树,但是知道四面体填充空间(没有孔)我认为没有必要对空间进行自适应细分,最好将其分成相等的部分。

  1. Divide the space into equal boxes (lets name them SpaceBoxes ).将空间分成相等的盒子(让它们命名为SpaceBoxes )。
  2. In each SpaceBox , keep a list of tetrahedra that collide with the box.在每个SpaceBox ,保留与盒子碰撞的四面体列表。
  • To speed it up, I would test tetrahedron's bounding box, not tetrahedron itself.为了加快速度,我将测试四面体的边界框,而不是四面体本身。
  • Note that this step can be done relatively cheaply - you know that SpaceBoxes have equal sizes, you know their position, so given tetrahedron's bounding box, it is easy to find SpaceBox candidates.请注意,此步骤可以相对便宜地完成 - 您知道 SpaceBox 具有相同的大小,您知道它们的位置,因此给定四面体的边界框,很容易找到 SpaceBox 候选对象。

Now, having this spatial structure:现在,有了这个空间结构:

For point to be tested p待测点p

  • find a corresponding SpaceBox O(1)找到对应的SpaceBox O(1)
  • you have all tetrahedra that collide with the SpaceBox , so these are candidates to test你有所有与SpaceBox碰撞的SpaceBox ,所以这些是要测试的候选者
  • first test collision of p with the bounding box of each tetrahedron p与每个四面体的边界框的第一次测试碰撞
  • only then, with the tetrahedron itself只有这样,四面体本身

Note that the performance of test depends mostly on the amount of tetrahedra in each SpaceBox.请注意,测试的性能主要取决于每个 SpaceBox 中四面体的数量。

Assuming a space is a cube:假设一个空间是一个立方体:

  • subdividing each edge to 16 parts gives you 16^3 = 4096 SpaceBoxes将每条边细分为 16 个部分给你 16^3 = 4096 个 SpaceBoxes
  • having N = 7000000, there should be roughly 1709 candidate tetrahedra to test N = 7000000,应该有大约 1709 个候选四面体来测试

Also, on the implementation side, both preprocessing and testing multiple points look like data-parallel problems, so multiprocessing may help.此外,在实现方面,预处理和测试多个点看起来像数据并行问题,因此多处理可能会有所帮助。

Put the bounding boxes of the tetrahedra in 3D R-tree.将四面体的边界框放在 3D R-tree 中。 Query the R-tree on the point.查询该点上的R-tree。 Then test each result returned by the query with the point-in-tetrahedron check.然后使用四面体中的点检查来测试查询返回的每个结果。

The nice thing about using an R-tree (or similar structure) is that if the tetrahedra do not change you can build the R-tree once and test many points.使用 R-tree(或类似结构)的好处是,如果四面体不改变,您可以构建 R-tree 一次并测试多个点。

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

相关问题 给定窗口异常,如何确定点异常? - how to determine point anomalies given window anomalies? 如何在Python中生成2个数字之间的给定小数点的随机数? - How to generate random number of given decimal point between 2 number in Python? 如何确定在 SLURM 中超出了 python 脚本步骤内存中的哪一点 - How to determine at which point in python script step memory exceeded in SLURM 如何确定哪些点在多边形内部,哪些不在(大量点)? - How to determine which points are inside of a polygon and which are not (large number of points)? 确定一个点在哪个多边形中,然后将该多边形的名称作为新列应用于大熊猫数据框 - Determine in which polygon a point is, and then apply the name of that polygon as a new column to a large pandas dataframe 如何有效地将点云数据的大型numpy数组转换为降采样的2d数组? - How to efficiently convert large numpy array of point cloud data to downsampled 2d array? 如何有效地确定给定值的区间? - How to efficiently determine the interval a given value is in? 按给定精度舍入浮点数 - Round a floating point number by a given precision 针对大量点的多边形点 - Point-in-polygon for a large number of points 为点和多边形的大 collections 有效地匹配点到几何体(多边形中的点) - Efficiently match point to geometry (point in poly) for large collections of both points and polygons
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM