【发布时间】:2013-05-18 23:50:06
【问题描述】:
编译器无法确定该类型的小于运算符。我也尝试过使用 lambda 和谓词函数。
#include <Eigen/Dense>
typedef Eigen::Vector3f vec3;
inline bool operator<(const vec3 &lhs, const vec3 &rhs) {
return lhs.x() < rhs.x() && lhs.y() < rhs.y() && lhs.z() < rhs.z();
}
inline bool cmpVecs(const vec3 &lhs, const vec3 &rhs) {
return lhs.x() < rhs.x() && lhs.y() < rhs.y() && lhs.z() < rhs.z();
}
inline void removeDuplicates(std::vector<vec3> &con)
{
std::sort(con.data(), con.data() + con.size());
auto itr = std::unique(con.begin(), con.end(), cmpVecs);
con.resize(itr - con.begin());
}
void init(std::vector<vec3> &verts) {
removeDuplicates(verts);
}
VS 2012 错误:
algorithm(3618): error C2678: binary '”类型的左侧操作数 (或者没有可接受的转换) 1> with 1> [ 1> _Scalar=float, 1> _Rows=3, 1>
_Cols=1 1> ]
相关帖子:
【问题讨论】:
-
您的比较函数不正确,因为
std::sort需要严格的弱排序谓词。{ if (lhs.x() < rhs.x()) return true; if (rhs.x() < lhs.x()) return false; if (lhs.y() < rhs.y()) return true; if (rhs.y() < lhs.y()) return false; return lhs.z() < rhs.z(); } -
上面评论中的比较对我有用。这很难找到,尽管唯一性在 matlab 中很常见。