mirror of https://github.com/CGAL/cgal
add constrained edges map
This commit is contained in:
parent
4ff97d4b8e
commit
d93e18b1b3
|
|
@ -27,8 +27,14 @@ int main(int argc, char* argv[]){
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
CGAL::Polygon_mesh_processing::angle_remeshing(mesh, faces(mesh), CGAL::Polygon_mesh_processing::parameters::all_default());
|
CGAL::Polygon_mesh_processing::angle_remeshing(mesh,
|
||||||
CGAL::Polygon_mesh_processing::area_remeshing(mesh, faces(mesh), CGAL::Polygon_mesh_processing::parameters::all_default());
|
faces(mesh),
|
||||||
|
edges(mesh),
|
||||||
|
CGAL::Polygon_mesh_processing::parameters::all_default());
|
||||||
|
CGAL::Polygon_mesh_processing::area_remeshing(mesh,
|
||||||
|
faces(mesh),
|
||||||
|
edges(mesh),
|
||||||
|
CGAL::Polygon_mesh_processing::parameters::all_default());
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -19,10 +19,70 @@ namespace internal {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
template<typename Descriptor>
|
||||||
|
struct No_constraint_pmap
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
typedef Descriptor key_type;
|
||||||
|
typedef bool value_type;
|
||||||
|
typedef value_type& reference;
|
||||||
|
typedef boost::read_write_property_map_tag category;
|
||||||
|
|
||||||
|
friend bool get(const No_constraint_pmap& , const key_type& ) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
friend void put(No_constraint_pmap& , const key_type& , const bool ) {}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
template<typename PolygonMesh, typename EdgeRange>
|
||||||
|
struct Edge_constraint_map
|
||||||
|
{
|
||||||
|
|
||||||
|
typedef typename boost::graph_traits<PolygonMesh>::edge_descriptor edge_descriptor;
|
||||||
|
|
||||||
|
//boost::shared_ptr<std::set<edge_descriptor>> constrained_edges_ptr;
|
||||||
|
std::shared_ptr<std::set<edge_descriptor>> constrained_edges_ptr;
|
||||||
|
|
||||||
|
public:
|
||||||
|
typedef edge_descriptor key_type;
|
||||||
|
typedef bool value_type;
|
||||||
|
typedef value_type& reference;
|
||||||
|
typedef boost::read_write_property_map_tag category;
|
||||||
|
|
||||||
|
Edge_constraint_map() : constrained_edges_ptr(new std::set<edge_descriptor>() )
|
||||||
|
{}
|
||||||
|
|
||||||
|
Edge_constraint_map(const EdgeRange& edges) : constrained_edges_ptr(new std::set<edge_descriptor>() )
|
||||||
|
{
|
||||||
|
for (edge_descriptor e : edges)
|
||||||
|
{
|
||||||
|
constrained_edges_ptr->insert(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
friend bool exists(const Edge_constraint_map<PolygonMesh, EdgeRange>& map, const edge_descriptor& e)
|
||||||
|
{
|
||||||
|
// assertion on pmesh
|
||||||
|
//return map.constrained_edges_ptr->count(e)!=0;
|
||||||
|
return map.constrained_edges_ptr->find(e) != map.constrained_edges_ptr->end();
|
||||||
|
|
||||||
|
}
|
||||||
|
friend void put(const Edge_constraint_map<PolygonMesh, EdgeRange>& map, const edge_descriptor& e)
|
||||||
|
{
|
||||||
|
map.constrained_edges_ptr->insert(e);
|
||||||
|
}
|
||||||
|
friend void remove(const Edge_constraint_map<PolygonMesh, EdgeRange>& map, const edge_descriptor& e)
|
||||||
|
{
|
||||||
|
map.constrained_edges_ptr->erase(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
template<typename PolygonMesh, typename VertexPointMap, typename GeomTraits>
|
template<typename PolygonMesh, typename VertexPointMap, typename VertexConstraitMap, typename EdgeConstraintMap, typename GeomTraits>
|
||||||
class Compatible_remesher
|
class Compatible_remesher
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
@ -47,7 +107,8 @@ class Compatible_remesher
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Compatible_remesher(PolygonMesh& pmesh, VertexPointMap& vpmap) : mesh_(pmesh), vpmap_(vpmap)
|
Compatible_remesher(PolygonMesh& pmesh, VertexPointMap& vpmap, VertexConstraitMap& vcmap, EdgeConstraintMap& ecmap) :
|
||||||
|
mesh_(pmesh), vpmap_(vpmap), vcmap_(vcmap), ecmap_(ecmap)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
~Compatible_remesher()
|
~Compatible_remesher()
|
||||||
|
|
@ -60,12 +121,14 @@ public:
|
||||||
{
|
{
|
||||||
for (face_descriptor f : face_range)
|
for (face_descriptor f : face_range)
|
||||||
{
|
{
|
||||||
|
|
||||||
input_triangles_.push_back(triangle(f));
|
input_triangles_.push_back(triangle(f));
|
||||||
}
|
}
|
||||||
|
|
||||||
tree_ptr_ = new Tree(input_triangles_.begin(), input_triangles_.end());
|
tree_ptr_ = new Tree(input_triangles_.begin(), input_triangles_.end());
|
||||||
tree_ptr_->accelerate_distance_queries();
|
tree_ptr_->accelerate_distance_queries();
|
||||||
|
|
||||||
|
//update constrained edges
|
||||||
|
check_constrained_edges();
|
||||||
}
|
}
|
||||||
|
|
||||||
void angle_relaxation()
|
void angle_relaxation()
|
||||||
|
|
@ -77,7 +140,7 @@ public:
|
||||||
for(vertex_descriptor v : vertices(mesh_))
|
for(vertex_descriptor v : vertices(mesh_))
|
||||||
{
|
{
|
||||||
|
|
||||||
if(!is_border(v, mesh_))
|
if(!is_border(v, mesh_) && !is_constrained(v))
|
||||||
{
|
{
|
||||||
|
|
||||||
#ifdef CGAL_ANGLE_BASED_SMOOTHING_DEBUG
|
#ifdef CGAL_ANGLE_BASED_SMOOTHING_DEBUG
|
||||||
|
|
@ -214,7 +277,7 @@ std::cout<<" to after projection: "<<get(vpmap_, v)<<std::endl;
|
||||||
|
|
||||||
// to check if is constrained
|
// to check if is constrained
|
||||||
|
|
||||||
if(!is_border(v, mesh_))
|
if(!is_border(v, mesh_) && !is_constrained(v))
|
||||||
{
|
{
|
||||||
Point p_query = get(vpmap_, v);
|
Point p_query = get(vpmap_, v);
|
||||||
Point projected = tree_ptr_->closest_point(p_query);
|
Point projected = tree_ptr_->closest_point(p_query);
|
||||||
|
|
@ -569,13 +632,37 @@ private:
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool is_constrained(const edge_descriptor& e)
|
||||||
|
{
|
||||||
|
exists(ecmap_, e);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool is_constrained(const vertex_descriptor& v)
|
||||||
|
{
|
||||||
|
get(vcmap_, v);
|
||||||
|
}
|
||||||
|
|
||||||
|
void check_constrained_edges()
|
||||||
|
{
|
||||||
|
for(edge_descriptor e : edges(mesh_))
|
||||||
|
{
|
||||||
|
if (is_constrained(e))
|
||||||
|
{
|
||||||
|
vertex_descriptor vs = source(e, mesh_);
|
||||||
|
vertex_descriptor vt = target(e, mesh_);
|
||||||
|
put(vcmap_, vs, true);
|
||||||
|
put(vcmap_, vt, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
PolygonMesh& mesh_;
|
PolygonMesh& mesh_;
|
||||||
VertexPointMap& vpmap_;
|
VertexPointMap& vpmap_;
|
||||||
|
VertexConstraitMap vcmap_;
|
||||||
|
EdgeConstraintMap ecmap_;
|
||||||
Triangle_list input_triangles_;
|
Triangle_list input_triangles_;
|
||||||
Tree* tree_ptr_;
|
Tree* tree_ptr_;
|
||||||
unsigned int count_non_convex_energy_;
|
unsigned int count_non_convex_energy_;
|
||||||
|
|
|
||||||
|
|
@ -18,8 +18,8 @@ namespace Polygon_mesh_processing {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
template<typename PolygonMesh, typename NamedParameters, typename FaceRange>
|
template<typename PolygonMesh, typename NamedParameters, typename FaceRange, typename EdgeRange>
|
||||||
void angle_remeshing(PolygonMesh& pmesh, const FaceRange& faces, const NamedParameters& np)
|
void angle_remeshing(PolygonMesh& pmesh, const FaceRange& faces, const EdgeRange& edges, const NamedParameters& np)
|
||||||
{
|
{
|
||||||
|
|
||||||
using boost::choose_param;
|
using boost::choose_param;
|
||||||
|
|
@ -30,10 +30,53 @@ void angle_remeshing(PolygonMesh& pmesh, const FaceRange& faces, const NamedPara
|
||||||
get_const_property_map(CGAL::vertex_point, pmesh));
|
get_const_property_map(CGAL::vertex_point, pmesh));
|
||||||
|
|
||||||
|
|
||||||
typedef typename GetGeomTraits<PolygonMesh, NamedParameters>::type Traits;
|
typedef typename GetGeomTraits<PolygonMesh, NamedParameters>::type GeomTraits;
|
||||||
|
|
||||||
|
|
||||||
CGAL::Polygon_mesh_processing::internal::Compatible_remesher<PolygonMesh, VertexPointMap, Traits> remesher(pmesh, vpmap);
|
|
||||||
|
// extract some edges
|
||||||
|
/*
|
||||||
|
typedef typename boost::graph_traits<PolygonMesh>::edge_iterator edge_iterator;
|
||||||
|
typedef std::pair<edge_iterator,edge_iterator> p_edges;
|
||||||
|
|
||||||
|
typename boost::graph_traits<PolygonMesh>::edge_iterator ei, ei_end;
|
||||||
|
|
||||||
|
|
||||||
|
for(boost::tie(ei, ei_end) = edges; ei != ei_end; ++ei)
|
||||||
|
{
|
||||||
|
//std::cout<<"p: "<<p<<std::endl;
|
||||||
|
std::cout<<source(*ei, pmesh)<<"->"<<target(*ei, pmesh)<<std::endl;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
//vcmap - not sure yet
|
||||||
|
typedef typename boost::graph_traits<PolygonMesh>::vertex_descriptor vertex_descriptor;
|
||||||
|
|
||||||
|
typedef typename boost::lookup_named_param_def <
|
||||||
|
internal_np::vertex_is_constrained_t,
|
||||||
|
NamedParameters,
|
||||||
|
internal::No_constraint_pmap<vertex_descriptor>//default
|
||||||
|
> ::type VCMap;
|
||||||
|
VCMap vcmap = choose_param(get_param(np, internal_np::vertex_is_constrained),
|
||||||
|
internal::No_constraint_pmap<vertex_descriptor>());
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//create ecmap with Edge_constraint_map struct
|
||||||
|
typedef typename boost::graph_traits<PolygonMesh>::edge_descriptor edge_descriptor;
|
||||||
|
|
||||||
|
//ecmap
|
||||||
|
typedef typename boost::lookup_named_param_def <
|
||||||
|
internal_np::edge_is_constrained_t,
|
||||||
|
NamedParameters,
|
||||||
|
internal::Edge_constraint_map<PolygonMesh, EdgeRange>
|
||||||
|
> ::type ECMap;
|
||||||
|
ECMap ecmap = choose_param(get_param(np, internal_np::edge_is_constrained),
|
||||||
|
internal::Edge_constraint_map<PolygonMesh, EdgeRange>()); // pass constrained edges range in this constructor
|
||||||
|
|
||||||
|
|
||||||
|
CGAL::Polygon_mesh_processing::internal::Compatible_remesher<PolygonMesh, VertexPointMap, VCMap, ECMap, GeomTraits> remesher(pmesh, vpmap, vcmap, ecmap);
|
||||||
remesher.init_remeshing(faces);
|
remesher.init_remeshing(faces);
|
||||||
remesher.angle_relaxation();
|
remesher.angle_relaxation();
|
||||||
remesher.project_to_surface();
|
remesher.project_to_surface();
|
||||||
|
|
@ -43,8 +86,8 @@ void angle_remeshing(PolygonMesh& pmesh, const FaceRange& faces, const NamedPara
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
template<typename PolygonMesh, typename NamedParameters, typename FaceRange>
|
template<typename PolygonMesh, typename NamedParameters, typename FaceRange, typename EdgeRange>
|
||||||
void area_remeshing(PolygonMesh& pmesh, const FaceRange& faces, const NamedParameters& np)
|
void area_remeshing(PolygonMesh& pmesh, const FaceRange& faces, const EdgeRange& edges, const NamedParameters& np)
|
||||||
{
|
{
|
||||||
|
|
||||||
using boost::choose_param;
|
using boost::choose_param;
|
||||||
|
|
@ -61,7 +104,35 @@ void area_remeshing(PolygonMesh& pmesh, const FaceRange& faces, const NamedPara
|
||||||
//bool do_project = choose_param(get_param(np, internal_np::do_project), true);
|
//bool do_project = choose_param(get_param(np, internal_np::do_project), true);
|
||||||
|
|
||||||
|
|
||||||
CGAL::Polygon_mesh_processing::internal::Compatible_remesher<PolygonMesh, VertexPointMap, GeomTraits> remesher(pmesh, vpmap);
|
|
||||||
|
//vcmap - not sure yet
|
||||||
|
typedef typename boost::graph_traits<PolygonMesh>::vertex_descriptor vertex_descriptor;
|
||||||
|
|
||||||
|
typedef typename boost::lookup_named_param_def <
|
||||||
|
internal_np::vertex_is_constrained_t,
|
||||||
|
NamedParameters,
|
||||||
|
internal::No_constraint_pmap<vertex_descriptor>//default
|
||||||
|
> ::type VCMap;
|
||||||
|
VCMap vcmap = choose_param(get_param(np, internal_np::vertex_is_constrained),
|
||||||
|
internal::No_constraint_pmap<vertex_descriptor>());
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//create ecmap with Edge_constraint_map struct
|
||||||
|
typedef typename boost::graph_traits<PolygonMesh>::edge_descriptor edge_descriptor;
|
||||||
|
|
||||||
|
//ecmap
|
||||||
|
typedef typename boost::lookup_named_param_def <
|
||||||
|
internal_np::edge_is_constrained_t,
|
||||||
|
NamedParameters,
|
||||||
|
internal::Edge_constraint_map<PolygonMesh, EdgeRange>
|
||||||
|
> ::type ECMap;
|
||||||
|
ECMap ecmap = choose_param(get_param(np, internal_np::edge_is_constrained),
|
||||||
|
internal::Edge_constraint_map<PolygonMesh, EdgeRange>());
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
CGAL::Polygon_mesh_processing::internal::Compatible_remesher<PolygonMesh, VertexPointMap, VCMap, ECMap, GeomTraits> remesher(pmesh, vpmap, vcmap, ecmap);
|
||||||
remesher.init_remeshing(faces);
|
remesher.init_remeshing(faces);
|
||||||
remesher.area_relaxation();
|
remesher.area_relaxation();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -53,7 +53,6 @@ int main(int argc, char* argv[]){
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
for(auto i=0; i!= filenames.size(); ++i)
|
for(auto i=0; i!= filenames.size(); ++i)
|
||||||
{
|
{
|
||||||
filename = filenames[i]+".off";
|
filename = filenames[i]+".off";
|
||||||
|
|
@ -71,8 +70,8 @@ std::cout<<"case: "<< filename << std::endl;
|
||||||
input.close();
|
input.close();
|
||||||
|
|
||||||
|
|
||||||
CGAL::Polygon_mesh_processing::angle_remeshing(mesh, faces(mesh), CGAL::Polygon_mesh_processing::parameters::all_default());
|
CGAL::Polygon_mesh_processing::angle_remeshing(mesh, faces(mesh), edges(mesh), CGAL::Polygon_mesh_processing::parameters::all_default());
|
||||||
//CGAL::Polygon_mesh_processing::area_remeshing(mesh, faces(mesh), CGAL::Polygon_mesh_processing::parameters::all_default());
|
CGAL::Polygon_mesh_processing::area_remeshing(mesh, faces(mesh), edges(mesh), CGAL::Polygon_mesh_processing::parameters::all_default());
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue