how can i make the faces of Surface_mesh have the same direction
As shown in the figure,when i make a Surface_mesh and i try to get each face Vertex_index(in .obj file) ,i find the direction of face is not uniform but random.please tell me what should i do to make all faces one orientation,thank you.
Source Code
void PointCloud2Mesh::CreateMesh2(std::vector<Point_3> points, std::string objfile)
{
//Mesh
Mesh dsm_mesh;
Construct construct(dsm_mesh, points.begin(), points.end());
CGAL::advancing_front_surface_reconstruction(points.begin(), points.end(), construct);
auto vnormals = dsm_mesh.add_property_map<M_vertex_descriptor, Vector_3>("v:normals", CGAL::NULL_VECTOR).first;
CGAL::Polygon_mesh_processing::compute_vertex_normals(dsm_mesh, vnormals);
std::ofstream dsm_ofile(objfile, std::ios_base::binary);
CGAL::IO::set_binary_mode(dsm_ofile);
CGAL::IO::write_OBJ(dsm_ofile, dsm_mesh);
for (M_vertex_descriptor vd : vertices(dsm_mesh))
{
dsm_ofile << "vn " << vnormals[vd].x() << " "
<< vnormals[vd].y() << " "
<< vnormals[vd].z() << "\n";
}
dsm_ofile.close();
}
Environment
- Operating system (Windows/Mac/Linux, 32/64 bits):64
- Compiler:
- Release or debug mode:debug
- Specific flags used (if any):
- CGAL version:5.5.2
- Boost version:1.80
- Other libraries versions if used (Eigen, TBB, etc.):
Make construct, whatever that is, construct the mesh with a consistent orientation.
Is that you mean its my fault? Surface_mesh always with a consistent orientation?
Surface_mesh should have a consistent orientation, yes.
Perhaps Construct is building a surface mesh of unconnected faces?
I don't know, because I have no idea what Construct does.
I suggest you look there.
i'm sorry forget the Construct struct , here is the code ,could you tell me problems that make the Surface_mesh don't have a consistent orientation.and what should i do to modify the Construct .
struct Construct
{
Mesh& mesh;
template < typename PointIterator>
Construct(Mesh& mesh, PointIterator b, PointIterator e)
: mesh(mesh)
{
for (; b != e; ++b)
{
boost::graph_traits<Mesh>::vertex_descriptor v;
v = add_vertex(mesh);
mesh.point(v) = *b;
}
}
Construct& operator=(const Facet f)
{
//typedef boost::graph_traits<Mesh>::M_vertex_descriptor M_vertex_descriptor;
typedef boost::graph_traits<Mesh>::vertices_size_type size_type;
mesh.add_face(M_vertex_descriptor(static_cast<size_type>(f[0])),
M_vertex_descriptor(static_cast<size_type>(f[1])),
M_vertex_descriptor(static_cast<size_type>(f[2])));
return *this;
}
Construct&
operator*() { return *this; }
Construct&
operator++() { return *this; }
Construct
operator++(int) { return *this; }
};
I suggest checking the return value of mesh.add_face()