更改函数CGAL::draw()显示的网格的颜色



问题描述
我想知道是否有办法更改函数CGAL::draw((显示的网格颜色。我有一个Surface_mesh,我想用CGAL画它。所以我使用了函数CGAL::draw((,但网格的颜色是蓝色,在我看来这并不好看。我试图更改CGAL的代码以更改颜色。我在一个名为draw_face_graoh.h的头文件中发现了一个函数,名为DefaultColorFunctorFaceGraph,在DefaultColorFuntorFaceGraph的定义上方有一个注释,上面写着"//默认颜色函子;用户可以将其改变为具有自己的面部颜色";。我更改了函子,其中我将返回值更改为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
解决方案配置:x64版本
CGAL版本:5.3

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

最新更新