gpt4 book ai didi

c++ - 使用 "approximate"STL 贴图

转载 作者:太空狗 更新时间:2023-10-29 23:08:22 28 4
gpt4 key购买 nike

我想创建一个 STL map 来查找一个项目是否足够接近 3 维空间中的另一个项目。到目前为止,我的“less-than-functor”工作得很好,粘贴到以下链接。

现在这个问题不完全是“最近邻”问题。而是“一定距离内有没有邻居”的问题。

我的示例只显示了一个维度。为了清楚起见,我跳过了 Y/Z 维度。

My attempt so far :

class ApproximateLessFunctor {
public:
ApproximateLessFunctor( float fudgeFactor ) :
mFudgeFactor( fudgeFactor ) {};

bool operator()( float a, float b ) const {
return (a < (b - mFudgeFactor) );
}

float mFudgeFactor;
};

typedef map<float, int, ApproximateLessFunctor> XAxisMap;

class XAxis {
public:
XAxisMap vMap;

XAxis(ApproximateLessFunctor functor, float x, int v)
: vMap( functor )
{
vMap.insert(make_pair(x, v));
}
};

在极少数情况下,我的意思是 - 非常罕见 - 当位置重叠时, map 找不到匹配的条目。

有什么我可以做的更好来实现这个,仍然使用 STL 容器?

最佳答案

Now this problem isn't quite the "nearest neighbor" problem. Rather it is a problem of "is there a neighbor within some distance."

不过,就前者而言,后者的措辞非常简单。找到最近的邻居,然后确定它是否足够近。考虑到任务可用的数据结构数量,这似乎是一条合理的路线。

kd-tree非常普遍并且不太难实现。同样相关的是 R-tree ,尽管我还没有实现它,也无法评论它的难度。

关于c++ - 使用 "approximate"STL 贴图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9874886/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com