gpt4 book ai didi

c++ - 如何对 Eigen::Vector 的 std::vector 进行唯一排序?

转载 作者:塔克拉玛干 更新时间:2023-11-03 07:27:42 31 4
gpt4 key购买 nike

编译器无法找出该类型的小于运算符。我也尝试过使用 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 '<' : no operator found which takes a left-hand operand of type 'Eigen::Matrix<_Scalar,_Rows,_Cols>' (or there is no acceptable conversion) 1> with 1> [ 1> _Scalar=float, 1> _Rows=3, 1>
_Cols=1 1> ]

相关文章:

最佳答案

std::sort 有一个覆盖可用,它允许您指定要使用的比较器,例如:

struct vec3comp{
bool operator()(const vec3 &lhs, const vec3 &rhs){
return lhs.x() < rhs.x() && lhs.y() < rhs.y() && lhs.z() < rhs.z();
}
} mycomp;

std::sort(con.data(), con.data() + con.size(),mycomp);`

编辑:你能用 lambda 函数显示你的代码吗?它应该可以正常工作。

关于c++ - 如何对 Eigen::Vector 的 std::vector 进行唯一排序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16630138/

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