【问题标题】:Change color of mesh displayed by the function CGAL::draw()更改函数 CGAL::draw() 显示的网格颜色
【发布时间】:2021-12-17 03:44:14
【问题描述】:

问题描述
不知道有没有办法改变CGAL::draw()函数显示的网格颜色。我有一个 Surface_mesh,我想用 CGAL 来绘制它。所以我使用了函数CGAL::draw(),但是网格的颜色是蓝色的,在我看来这不是很漂亮。我试图改变CGAL的代码来改变颜色。我在一个名为draw_face_graoh.h的头文件中找到了一个名为DefaultColorFunctorFaceGraph的函子,在DefaultColorFunctorFaceGraph的定义上方有一个注释,上面写着“// 默认颜色函子;用户可以将其更改为具有自己的面部颜色”。我更改了仿函数,其中我将返回值更改为 CGAL::IO::gray(),但它根本不起作用,网格的颜色仍然是蓝色。
我可以更改的颜色通过更改 CGAL 的代码来网格化?是否需要更改底层代码,例如一些调用 OpenGL 的代码?

代码
这是一个关于我使用函数 draw() 方式的示例。

#include<iostream>
#include<fstream>
#include<CGAL/Surface_mesh.h>
#include<CGAL/draw_surface_mesh.h>
#include<CGAL/Exact_predicates_inexact_constructions_kernel.h>

typedef CGAL::Exact_predicates_inexact_constructions_kernel kernel;
typedef kernel::Point_3 point;
typedef CGAL::Surface_mesh<point> Mesh;

int main() {
    std::ifstream fin("test.off");
    Mesh mesh;
    fin >> mesh;
    CGAL::draw(mesh);
    
}

名为 test.off 的文件如下。

OFF
4 4 0
0 0 1
0 0 0
1 0 0 
0 1 0
3 2 0 1
3 1 0 3
3 1 3 2
3 3 0 2

这是更改后的函子。

namespace CGAL
{

// Default color functor; user can change it to have its own face color
struct DefaultColorFunctorFaceGraph
{
  template<typename Graph>
  CGAL::IO::Color operator()(const Graph&,
                         typename boost::graph_traits<Graph>::face_descriptor fh) const
  {
      if (fh == boost::graph_traits<Graph>::null_face()) // use to get the mono color
        //return CGAL::IO::Color(100,125,200); // R G B between 0-255
          return CGAL::IO::gray();//Here changed

    return get_random_color(CGAL::get_default_random());
  }
};

运行时环境
IDE:VS 2017
解决方案配置:Release x64
CGAL 版本:5.3

【问题讨论】:

    标签: cgal


    【解决方案1】:

    最后我在名为Basic_viewer_qt.h 的头文件中找到了一个名为Basic_viewer_qt 的结构。通过改变这个结构体中变量m_faces_mono_colorm_ambient_color的值,可以改变网格的颜色。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-20
      • 1970-01-01
      • 2018-02-20
      • 1970-01-01
      • 2011-09-21
      • 1970-01-01
      相关资源
      最近更新 更多