我正在尝试为CGAL上的triangulation_3中的点赋予颜色。我仅以CGAL中的示例描述here
我对此示例进行了简单的修改,以便能够绘制三角剖分:
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Delaunay_triangulation_3.h>
#include <CGAL/Delaunay_triangulation_cell_base_3.h>
#include <CGAL/Triangulation_vertex_base_with_info_3.h>
#include <CGAL/IO/Color.h>
#include <CGAL/draw_triangulation_3.h>
typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
typedef CGAL::Triangulation_vertex_base_with_info_3<CGAL::Color, K> Vb;
typedef CGAL::Delaunay_triangulation_cell_base_3<K> Cb;
typedef CGAL::Triangulation_data_structure_3<Vb, Cb> Tds;
typedef CGAL::Delaunay_triangulation_3<K, Tds> Delaunay;
typedef Delaunay::Point Point;
int main()
{
Delaunay T;
T.insert(Point(0,0,0));
T.insert(Point(1,0,0));
T.insert(Point(0,1,0));
T.insert(Point(0,0,1));
T.insert(Point(2,2,2));
T.insert(Point(-1,0,1));
// Set the color of finite vertices of degree 6 to red.
Delaunay::Finite_vertices_iterator vit;
for (Delaunay::Vertex_handle v : T.finite_vertex_handles())
if (T.degree(v) == 6)
v->info() = CGAL::Color(0,255,0);
CGAL::draw(T);
return 0;
}
但是无论我戴什么颜色v->info() = CGAL::Color(0,255,0);
,方法绘制总是在显示的窗口中给出相同的红色点:
我知道代码正在构造一个包含颜色信息的数据结构,但这可能与draw方法无关,因此我认为该窗口不会向我显示绿色点,因为这不是给这些点着色的方法。如果是这样,使用draw方法用绿点进行三角剖分的方法是什么?'。
以当前形式,查看器无法更改顶点或边缘的颜色。
但是更改代码很容易。
void compute_vertex(Vertex_const_handle vh)
,(此文件中的第92行)以使用带有颜色作为参数的add_point方法:void compute_vertex(Vertex_const_handle vh)