要给两幅点云分别赋以颜色属性,并且在两个点云凭借后依然表现出各自的颜色属性,可以使用CGAL中的Point_with_color和Point_with_normal_and_color类。

Point_with_color类表示带有颜色属性的点,其定义如下:

template <typename R_>
class Point_with_color : public CGAL::Point_3<R_> {
public:
    typedef R_ R;
    typedef CGAL::Point_3<R> Base;
    typedef typename CGAL::Kernel_traits<Base>::Kernel K;
    typedef typename K::FT FT;
    typedef typename K::Point_3 Point;
    typedef typename K::Vector_3 Vector;

    Point_with_color();
    Point_with_color(const Point& p, const Vector& n, const unsigned char& r, const unsigned char& g, const unsigned char& b);
    Point_with_color(const Point& p, const Vector& n, const unsigned char& c[3]);
    Point_with_color(const Point& p, const unsigned char& r, const unsigned char& g, const unsigned char& b);
    Point_with_color(const Point& p, const unsigned char& c[3]);
    Point_with_color(const Point& p);
    Point_with_color(const Base& p);
    Point_with_color(const Point_with_color& p);

    const Vector& normal() const;
    Vector& normal();
    void set_normal(const Vector& n);

    const unsigned char& red() const;
    unsigned char& red();
    void set_red(const unsigned char& r);

    const unsigned char& green() const;
    unsigned char& green();
    void set_green(const unsigned char& g);

    const unsigned char& blue() const;
    unsigned char& blue();
    void set_blue(const unsigned char& b);

    const unsigned char* color() const;
    unsigned char* color();
    void set_color(const unsigned char& r, const unsigned char& g, const unsigned char& b);
    void set_color(const unsigned char c[3]);
};

其中,red()、green()和blue()函数用于获取或设置颜色属性的红、绿、蓝分量,color()函数用于获取或设置颜色属性的RGB值。

Point_with_normal_and_color类则表示带有法向量和颜色属性的点,其定义如下:

template <typename R_>
class Point_with_normal_and_color : public CGAL::Point_with_normal<R_> {
public:
    typedef R_ R;
    typedef CGAL::Point_with_normal<R> Base;
    typedef typename CGAL::Kernel_traits<Base>::Kernel K;
    typedef typename K::FT FT;
    typedef typename K::Point_3 Point;
    typedef typename K::Vector_3 Vector;

    Point_with_normal_and_color();
    Point_with_normal_and_color(const Point& p, const Vector& n, const unsigned char& r, const unsigned char& g, const unsigned char& b);
    Point_with_normal_and_color(const Point& p, const Vector& n, const unsigned char c[3]);
    Point_with_normal_and_color(const Point& p, const unsigned char& r, const unsigned char& g, const unsigned char& b);
    Point_with_normal_and_color(const Point& p, const unsigned char c[3]);
    Point_with_normal_and_color(const Point& p);
    Point_with_normal_and_color(const Base& p);
    Point_with_normal_and_color(const Point_with_normal_and_color& p);

    const unsigned char& red() const;
    unsigned char& red();
    void set_red(const unsigned char& r);

    const unsigned char& green() const;
    unsigned char& green();
    void set_green(const unsigned char& g);

    const unsigned char& blue() const;
    unsigned char& blue();
    void set_blue(const unsigned char& b);

    const unsigned char* color() const;
    unsigned char* color();
    void set_color(const unsigned char& r, const unsigned char& g, const unsigned char& b);
    void set_color(const unsigned char c[3]);
};

这里的颜色属性与Point_with_color类中的相同,只是在Point_with_normal_and_color类中还带有法向量属性。

为了在两个点云凭借后依然表现出各自的颜色属性,可以在合并点云前,给每个点云中的点赋予不同的颜色属性。当合并后的点云中存在相同的点时,可以通过比较点的坐标和法向量来判断它们是否相同,如果相同则将它们的颜色属性合并,否则将它们分别添加到新的点云中

CGAL如何给两幅点云分别赋以颜色属性并且在两个点云凭借后依然表现出各自的颜色属性

原文地址: http://www.cveoy.top/t/topic/cIOC 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录