store/retrieve selection and features of an OM

This commit is contained in:
Andreas Fabri 2024-08-20 15:16:13 +01:00
parent 65b7c09c1f
commit 0c8e489f46
1 changed files with 47 additions and 4 deletions

View File

@ -9,17 +9,20 @@
#include <CGAL/IO/polygon_mesh_io.h> #include <CGAL/IO/polygon_mesh_io.h>
#include <CGAL/mesh_segmentation.h> #include <CGAL/mesh_segmentation.h>
#include <CGAL/property_map.h> #include <CGAL/property_map.h>
#include <CGAL/Surface_mesh.h>
#include <iostream> #include <iostream>
#include <fstream> #include <fstream>
typedef CGAL::Exact_predicates_inexact_constructions_kernel Kernel; typedef CGAL::Exact_predicates_inexact_constructions_kernel Kernel;
typedef OpenMesh::PolyMesh_ArrayKernelT</* MyTraits*/> Mesh; typedef OpenMesh::PolyMesh_ArrayKernelT</* MyTraits*/> Mesh;
typedef CGAL::Surface_mesh<Kernel::Point_3> SM;
typedef boost::graph_traits<Mesh>::vertex_descriptor vertex_descriptor; typedef boost::graph_traits<Mesh>::vertex_descriptor vertex_descriptor;
typedef boost::graph_traits<SM>::vertex_descriptor sm_vertex_descriptor;
typedef boost::graph_traits<Mesh>::face_descriptor face_descriptor; typedef boost::graph_traits<Mesh>::face_descriptor face_descriptor;
typedef boost::graph_traits<Mesh>::halfedge_descriptor halfedge_descriptor; typedef boost::graph_traits<Mesh>::halfedge_descriptor halfedge_descriptor;
typedef boost::graph_traits<SM>::halfedge_descriptor sm_halfedge_descriptor;
typedef boost::graph_traits<SM>::edge_descriptor sm_edge_descriptor;
int main(int argc, char** argv ) int main(int argc, char** argv )
{ {
@ -30,28 +33,68 @@ int main(int argc, char** argv )
CGAL::IO::read_polygon_mesh(filename, mesh); CGAL::IO::read_polygon_mesh(filename, mesh);
mesh.request_vertex_status(); mesh.request_vertex_status();
mesh.request_edge_status();
int i = 0; int i = 0;
for(auto v : vertices(mesh)){ for(auto v : vertices(mesh)){
mesh.status(v).set_selected((i%2) == 0); mesh.status(v).set_selected((i%2) == 0);
++i; ++i;
} }
i = 0;
for(auto e : edges(mesh)){
mesh.status(e).set_feature(i > 2);
++i;
}
OpenMesh::IO::write_mesh(mesh, outname, OpenMesh::IO::Options::Status); OpenMesh::IO::write_mesh(mesh, outname, OpenMesh::IO::Options::Status);
Mesh mesh2; Mesh mesh2;
OpenMesh::IO::Options options = OpenMesh::IO::Options::Status; OpenMesh::IO::Options options = OpenMesh::IO::Options::Status;
bool read = OpenMesh::IO::read_mesh(mesh2, outname, options); bool read = OpenMesh::IO::read_mesh(mesh2, outname, options);
std::cout << num_vertices(mesh2) << std::endl;
assert(read); assert(read);
SM sm;
std::map<vertex_descriptor,sm_vertex_descriptor> v2v;
auto v2vpmap = boost::make_assoc_property_map(v2v);
std::map<halfedge_descriptor,sm_halfedge_descriptor> h2h;
auto h2hpmap = boost::make_assoc_property_map(h2h);
CGAL::copy_face_graph<Mesh,SM>(mesh, sm, CGAL::parameters::vertex_to_vertex_map(v2vpmap).halfedge_to_halfedge_map(h2hpmap));
std::map<sm_vertex_descriptor,bool> sm_selected_map;
auto sm_selected_pmap = boost::make_assoc_property_map(sm_selected_map);
if(options.vertex_has_status()){ if(options.vertex_has_status()){
for(auto v : vertices(mesh2)){ for(auto v : vertices(mesh2)){
put(sm_selected_pmap, v2v[v], mesh2.status(v).selected());
std::cout << std::boolalpha << mesh2.status(v).selected() << std::endl; std::cout << std::boolalpha << mesh2.status(v).selected() << std::endl;
} }
}else{ }else{
std::cout << "no vertex status" << std::endl; std::cout << "no vertex status" << std::endl;
} }
std::map<sm_edge_descriptor,bool> sm_feature_map;
auto sm_feature_pmap = boost::make_assoc_property_map(sm_feature_map);
if(options.edge_has_status()){
for(auto e : edges(mesh2)){
auto sme = edge(h2h[halfedge(e,mesh2)], sm);
put(sm_feature_pmap, sme , mesh2.status(e).feature());
std::cout << std::boolalpha << mesh2.status(e).feature() << std::endl;
}
}else{
std::cout << "no edge status" << std::endl;
}
std::cout << "vertex selection values:\n";
for(auto v : vertices(sm)){
std::cout << std::boolalpha << get(sm_selected_pmap, v) << std::endl;
}
std::cout << "edge feature values:\n";
for(auto e : edges(sm)){
std::cout << std::boolalpha << get(sm_feature_pmap, e) << std::endl;
}
return 0; return 0;
} }