问题描述
我想知道是否有一种方法可以改变函数CGAL::draw()显示的网格的颜色。我有一个Surface_mesh,我想用CGAL画它。所以我使用了函数CGAL::draw(),但是网格的颜色是蓝色的,在我看来这并不是很漂亮。我试图更改CGAL的代码以更改颜色。我在一个名为DefaultColorFunctorFaceGraph的头文件中找到了一个名为draw_face_graoh.h的函子,在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的文件为follws。
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
发布于 2021-12-17 08:51:16
最后,我在一个名为Basic_viewer_qt的头文件中找到了一个名为Basic_viewer_qt.h的结构。通过改变结构中变量m_faces_mono_color和m_ambient_color的值,可以改变网格的颜色。
https://stackoverflow.com/questions/70388184
复制相似问题