【问题标题】:Recursive function to merge 3D objects合并 3D 对象的递归函数
【发布时间】:2017-05-14 13:36:45
【问题描述】:

我在 listOri 中有几个 3D 项目。对于这个例子:

listOri 有 A、B、C、D、E。

A overlaps with C.
B overlaps with D.
D overlaps with E.

我有一个接受 listOri 的递归函数,检查每个项目是否相互重叠,并生成一个包含ACBDE 的最终 listNew。

迭代 1: 循环遍历listOri中的每一项,生成包含AC,B,D,E的listNew

迭代 2: 在listNew中循环AC,B,D,E,生成(新)listNew包含,AC,BD,E

迭代 3:等等。

这是检查列表中每个 3D 对象是否重叠并递归生成新列表的 sn-p 代码。

 Private Function SimplifyModel2(ByVal listOri As List(Of Mesh3D)) As List(Of Mesh3D)  
    Dim listNew As New List(Of Mesh3D)(listOri)
    Dim indexOut, indexIn, indexInner, PercentProgressCurrent As Integer
    Dim currentMeshOutter, currentMeshInner As Mesh3D
    Dim isExitForCalled As Boolean = False

    totInnerLoops = totInnerLoops + 1   ' increment total number of inner loops

    For indexOut = 0 To (listOri.Count - 1)
        currentMeshOutter = listOri(indexOut)

        indexInner = indexOut + 1
        For indexIn = indexInner To (listOri.Count - indexInner)
            currentMeshInner = listOri(indexIn)

            If Is3DOverlap(currentMeshInner, currentMeshOutter) = True Then
                currentMeshOutter.CombineMerge(currentMeshInner)
                listNew.Remove(currentMeshInner)
                listNew.Remove(currentMeshOutter)
                listNew.Insert(0, currentMeshOutter)

                listNew = SimplifyModel2(listNew) ' recursively call the function
                isExitForCalled = True
                Exit For
            End If
        Next

        If isExitForCalled = True Then
            Exit For
        End If
    Next

    indLoopExit = indLoopExit + 1

    Return listNew
End Function

该函数与很少项目的 listOri 配合得很好。 但是,当 listOri 中有数千个 3D 项目时,这些函数需要很长时间才能生成 listNew。

  1. 如何提高递归函数的速度?
  2. 是否有另一种方法可以编写执行上述相同任务的算法?

如果您需要任何信息,请告诉我。

谢谢。

【问题讨论】:

  • 一个项目可以与多个项目重叠吗?例如,A 与 C 和 G 重叠?
  • @AzazulHaq,可能的。基本上,递归函数会将相互重叠的 3D 对象合并为一个 3D 对象。
  • listNew.Insert(0, currentMeshOutter) 我这里假设 currentMeshOutter 是合并的对象,对吧?
  • @AzazulHaq,是的,currentMeshOutter 是编写代码的合并对象:listNew.Insert(0, currentMeshOutter)

标签: vb.net recursion


【解决方案1】:

我从 Code Review StackExchange 中找到了解决方案。

请参考以下链接: Recursive function to merge 3D objects

【讨论】:

    猜你喜欢
    • 2014-05-07
    • 2019-05-08
    • 2015-09-04
    • 2017-12-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多