加载.off文件很容易:
typedef CGAL::Simple_cartesian<double> Kernel;
typedef CGAL::Surface_mesh<Kernel::Point_3> SurfaceMesh;
typedef CGAL::Polyhedron_3<Kernel> Polyhedron;
...
SurfaceMesh surface;
Polyhedron poly;
std::fstream inputOffFile( "myFile.off" );
inputOffFile >> poly;
CGAL::copy_face_graph( poly, surface);
然后,我可以通过以下方式迭代顶点坐标:
std::vector<float> verts;
for( SurfaceMesh::Vertex_index vi : surface.vertices() )
{
Point pt = surface.point( vi );
verts.push_back( pt.x() );
verts.push_back( pt.y() );
verts.push_back( pt.z() );
}
但是我该如何访问存储在.off文件中的顶点颜色呢?
编辑:可能CGAL :: copy_face_graph不复制color属性,所以我想我需要其他方法?
答案 0 :(得分:1)
您需要使用SurfaceMesh的属性映射。当且仅当OFF文件具有颜色(意味着第一个指示为COFF而不是第一行为OFF),并且每个顶点且不仅每个面都有颜色时,SurfaceMesh才会具有一个内部属性图,称为“ v:颜色”。您可以通过调用
进行访问<link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" integrity="sha384-wvfXpqpZZVQGK6TAh5PVlGOfQNHSoD2xbE+QkPxCAFlNEevoEH3Sl0sibVcOQVnN" crossorigin="anonymous">
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<div class="e">
<div class="row">
<div class="col-sm-12 col-md-6 col-lg-5 col-lg-offset-1">
<div class="card-plans">
<div class="container-plans">
<br>
<p class="cred-title">Credentials</p><br>
<div class="center">
<p class="details"><strong>Username:</strong> Joha Lee</p>
<p class="details"><strong>Password:</strong>
<span class="stars">****************************</span>
<i class="x fa fa-eye" aria-hidden="true"></i>
</p>
<br>
</div>
</div>
</div>
</div>
<div class="col-sm-12 col-md-6 col-lg-5">
<div class="card-plans">
<div class="container-plans">
<br>
<p class="cred-title">Current Plan </p><br>
<div class="center">
<p class="details"><strong>Type:</strong> Dxx Emails</p>
<p class="details"><strong>Plan Cost:</strong> 3332/ Month
</p>
<br>
</div>
</div>
</div>
</div>
</div>
</div>
如果每个面都有颜色,则可以通过搜索名为“ f:color”的属性图来类似地访问它。您可以使用surface.property_map <......>(...)。second检查地图是否存在。
答案 1 :(得分:0)
好的,这是完整的解决方案,包括访问面顶点(如果要通过OpenGL渲染网格,则需要此权限)。使用SurfaceMesh是关键。
...
std::vector<Point> verts;
std::vector<Color> cols;
SurfaceMesh::Property_map<SurfaceMesh::Vertex_index, CGAL::Color> vcolors =
m_pSurface->property_map<SurfaceMesh::Vertex_index, CGAL::Color >( "v:color" ).first;
bool colorExists = m_pSurface->property_map<SurfaceMesh::Vertex_index, CGAL::Color>( "v:color" ).second;
if( !colorExists )
Error();
for( SurfaceMesh::Vertex_index vi : m_pSurface->vertices() )
{
cols.push_back( vcolors[ vi ] );
verts.push_back( m_pSurface->point( vi ) );
}
for( SurfaceMesh::Face_index face_index : m_pSurface->faces() )
{
CGAL::Vertex_around_face_circulator<SurfaceMesh> vcirc( m_pSurface->halfedge( face_index ), *m_pSurface ), done( vcirc );
signed char count = 0;
do
{
count++;
uint32_t vertexI = *vcirc++;
const Point &pt = verts[ vertexI ];
const Color &col = cols[ vertexI ];
...
} while( vcirc != done );
}
非常感谢您的有用评论!