简体   繁体   English

Eigen :: Vector的std :: vector上如何排序唯一?

[英]How sort unique on a std::vector of Eigen::Vector?

The compiler can't figure out the less than operator for the type. 编译器无法找出类型的小于运算符。 I've also tried with a lambda and predicate function. 我也尝试过使用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 error: 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> algorithm(3618):错误C2678:二进制'<':未找到采用'Eigen :: Matrix <_Scalar,_Rows,_Cols>'类型的左操作数的运算符(或没有可接受的转换)1> 1 > [1> _Scalar = float,1> _Rows = 3,1>
_Cols=1 1> ] _Cols = 1 1>]

Related Posts: 相关文章:

std::sort has an override available which allows you to specify which comparator you want to use, for example: 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);`

Edit: can you show your code with a lambda function? 编辑:您可以使用lambda函数显示代码吗? It should work fine. 它应该工作正常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM