C# : Fastest way to remove duplicates point3D linked to indices

标签 c# algorithm duplicates

抱歉我的英语不好。

当您使用 MeshGeometry3D 时,您必须指定:

  • MeshGeometry3D.Positions:Point3D 的集合
  • MeshGeometry3D.TriangleIndices : int 集合

TriangleIndices 中的每个索引都指向 Positions 中的 Point3D。 TriangleIndices.Count 是 3 的倍数,因为您必须指定三角形索引(因此三角形有 3 个索引)。

困难在于:在 Positions 中,如果你不检查它们是否已经存在于 Positions 中就放置它们,你可能会有重复的点。
enter image description here

在这里你可以看到 Positions[2] 和 Positions[3] 是相等的。
如果你有 1 或 2 个三角形,没关系。但是如果你有 20000 个三角形,它可能会浪费空间 + 处理大型集合需要更长的时间(添加项目需要更长的时间,获取项目,删除项目,...)。
所以一个解决方案是删除 Positions 中重复的 Point3D。但如果这样做,则必须更改 TriangleIndices 中的索引。如果我以我之前的例子为例,这将给出:
enter image description here

删除 Positions 中的重复项的一种方法是使用 Distinct()。 但是如果我使用它,我不知道他在哪里删除了重复项,所以我无法修改 TriangleIndices 集合。
另一种方法是:当我在 Positions 中添加 Point3D 时,我检查 Point3D(要添加)是否存在于 Collection 中,如果存在,我不添加它,而是在 TriangleIndices 中添加现有 Point3D 的索引。但它要求我使用 IndexOf,它很慢......真的很慢。

所以我的问题是:您知道删除链接到索引的重复 Point3D 的最快方法吗?

谢谢。

最佳答案

MeshGeometry3D 类定义了一组位置、法线和三角索引。根据定义,这三个列表具有相同的维度。

如果您需要节省空间,您可以创建一个没有重复的位置列表和一个整数列表来存储每个方面对它们的所有引用。

关于C# : Fastest way to remove duplicates point3D linked to indices,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29446061/

相关文章:

c# - 我可以在终结器中引用/使用 COM 对象吗?

c# - 具有泛型重载的 GetMethod

c# - WPF 事件触发器

php - PHP如何判断变量是否为小数且小于0.01?

algorithm - Big-O 本身有任何功能吗?

excel - 条件格式单元格,如果它的值在表的列中找到

Excel 2013 : Conditional Formatting consecutive Duplicate in 1 column

C# 代码简化查询 : The Sequential Foreach Loops

algorithm - 大用户事件序列到树

php - 多维数组值的重复数据删除