diff --git a/Polyhedron/demo/Polyhedron/Polyhedron_demo_edit_polyhedron_plugin.cpp b/Polyhedron/demo/Polyhedron/Polyhedron_demo_edit_polyhedron_plugin.cpp index 055f9094b24..006455718ce 100644 --- a/Polyhedron/demo/Polyhedron/Polyhedron_demo_edit_polyhedron_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Polyhedron_demo_edit_polyhedron_plugin.cpp @@ -17,8 +17,10 @@ #include #include +typedef Polyhedron_vertex_deformation_index_map vertex_map; +typedef Polyhedron_edge_deformation_index_map edge_map; -typedef CGAL::Deform_mesh_BGL > Deform_mesh; +typedef CGAL::Deform_mesh_BGL, vertex_map, edge_map> Deform_mesh; typedef Kernel::Point_3 Point; typedef Kernel::Vector_3 Vector; @@ -323,8 +325,6 @@ void Polyhedron_demo_edit_polyhedron_plugin::edition() { Deform_mesh* deform = deform_it->second.deform_mesh; - const Point& last_position = edit_item->last_position(); - // 'orig' could be used instead of 'last_position', to get the // translation vector from the first position. const Point& orig = edit_item->original_position(); diff --git a/Polyhedron/demo/Polyhedron/Polyhedron_type.h b/Polyhedron/demo/Polyhedron/Polyhedron_type.h index 41c6bc0370b..670564c2d05 100644 --- a/Polyhedron/demo/Polyhedron/Polyhedron_type.h +++ b/Polyhedron/demo/Polyhedron/Polyhedron_type.h @@ -53,6 +53,10 @@ template class Polyhedron_demo_halfedge : public CGAL::HalfedgeDS_halfedge_base { + +public: + int dID; + private: bool feature_edge; public: @@ -168,4 +172,42 @@ put( Polyhedron_vertex_deformation_index_map

& pmap, typename P::Vertex_handl } } + +template +class Polyhedron_edge_deformation_index_map +{ +private: + + typedef P Polyhedron ; + + +public: + + typedef boost::read_write_property_map_tag category; + typedef std::size_t value_type; + typedef std::size_t reference; + typedef typename boost::graph_traits::edge_descriptor key_type; + + Polyhedron_edge_deformation_index_map(const P&) + {} + +}; + +namespace boost { + + template + std::size_t + get( Polyhedron_edge_deformation_index_map

& pmap, typename P::Halfedge_handle eh) + { + return eh->dID; + } + + template + void + put( Polyhedron_edge_deformation_index_map

& pmap, typename P::Halfedge_handle eh, std::size_t s) + { + eh->dID = s; + } +} + #endif // POLYHEDRON_TYPE_H diff --git a/Surface_modeling/include/CGAL/Deform_mesh_BGL.h b/Surface_modeling/include/CGAL/Deform_mesh_BGL.h index a8fb64c232b..5cfd330cc67 100644 --- a/Surface_modeling/include/CGAL/Deform_mesh_BGL.h +++ b/Surface_modeling/include/CGAL/Deform_mesh_BGL.h @@ -25,7 +25,8 @@ namespace CGAL { enum LapType { uni, cot }; -template +template class Deform_mesh_BGL { // Public types @@ -44,8 +45,6 @@ public: typedef typename boost::graph_traits::in_edge_iterator in_edge_iterator; // property map types - typedef std::map VertexIndexMap; - typedef boost::associative_property_map VertexIdPropertyMap; typedef std::map EdgeIndexMap; typedef boost::associative_property_map EdgeIdPropertyMap; @@ -57,22 +56,17 @@ public: std::vector roi; std::vector hdl; // user specified handles, storing the target positions std::vector ros; // region of solution, including roi and hard constraints outside roi - VertexIndexMap vertex_id_map; - VertexIdPropertyMap vertex_id_pmap; // storing indices of all vertices - VertexIndexMap ros_id_map; - VertexIdPropertyMap ros_id_pmap; // index of ros vertices - EdgeIndexMap edge_id_map; - EdgeIdPropertyMap edge_id_pmap; // storing indices of all edges - std::vector is_roi; // flag that indicates vertex inside roi or not - std::vector is_hdl; - std::vector is_ros; - - + Polyhedron_vertex_deformation_index_map vertex_id_pmap; // storing indices of all vertices + Polyhedron_edge_deformation_index_map edge_id_pmap; // storing indices of all edges + std::vector ros_id; // index of ros vertices + std::vector is_roi; // flag indicating vertex inside roi or not + std::vector is_hdl; + int iterations; // number of iterations std::vector< std::vector > rot_mtr; // rotation matrices of ros vertices std::vector edge_weight; // weight of edges SparseLinearAlgebraTraits_d m_solver; // linear sparse solver - std::vector solution; // sotring position of all vertices during iterations + std::vector solution; // storing position of all vertices during iterations @@ -81,7 +75,7 @@ public: // The constructor gets the polyhedron that we will model Deform_mesh_BGL(Polyhedron* P) - :polyhedron(P) + :polyhedron(P), vertex_id_pmap(*P), edge_id_pmap(*P) { // initialize index maps @@ -89,21 +83,15 @@ public: int idx = 0; for(boost::tie(vb,ve) = boost::vertices(*polyhedron); vb != ve; ++vb ) { - vertex_id_map[*vb] = idx; - idx++; + boost::put(vertex_id_pmap, *vb, idx++); } - VertexIdPropertyMap new_vertex_id_pmap(vertex_id_map); - vertex_id_pmap = new_vertex_id_pmap; edge_iterator eb, ee; idx = 0; for(boost::tie(eb,ee) = boost::edges(*polyhedron); eb != ee; ++eb ) { - edge_id_map[*eb] = idx; - idx++; + boost::put(edge_id_pmap, *eb, idx++); } - EdgeIdPropertyMap new_edge_id_pmap(edge_id_map); - edge_id_pmap = new_edge_id_pmap; solution.clear(); for(boost::tie(vb,ve) = boost::vertices(*polyhedron); vb != ve; ++vb ) @@ -261,13 +249,13 @@ public: } // initialize the indices of ros vertices and rotation matrices - ros_id_map.clear(); + ros_id.clear(); + ros_id.resize(boost::num_vertices(*polyhedron)); for (int i = 0; i < ros.size(); i++) { - ros_id_map[ros[i]] = i; + int idx = boost::get(vertex_id_pmap, ros[i]); + ros_id[idx] = i; } - VertexIdPropertyMap new_ros_id_pmap(ros_id_map); - ros_id_pmap = new_ros_id_pmap; rot_mtr.resize(ros.size()); for ( int i = 0; i < ros.size(); i++) @@ -292,13 +280,6 @@ public: is_hdl[idx] = 1; } - is_ros.clear(); - is_ros.resize( boost::num_vertices(*polyhedron) ); - for ( int i = 0; i < ros.size(); i++ ) - { - int idx = boost::get(vertex_id_pmap, ros[i]); - is_ros[idx] = 1; - } } @@ -323,7 +304,7 @@ public: enum LapType type = cot; assemble_laplacian(A, type); - CGAL_TRACE_STREAM << " Creates matrix: done (" << task_timer.time() << " s)\n"; + CGAL_TRACE_STREAM << " Creates " << ros.size() << "*" << ros.size() << " matrix: done (" << task_timer.time() << " s)\n"; CGAL_TRACE_STREAM << " Pre-factorizing linear system...\n"; @@ -374,7 +355,7 @@ public: { wij = edge_weight[boost::get(edge_id_pmap, *e)]; } - int ros_idx_j = boost::get(ros_id_pmap, vj); + int ros_idx_j = ros_id[ boost::get(vertex_id_pmap, vj) ]; A.set_coef(i, ros_idx_j, -wij, true); // off-diagonal coefficient diagonal += wij; } @@ -556,7 +537,7 @@ public: for (boost::tie(e,e_end) = boost::in_edges(vi, *polyhedron); e != e_end; e++) { vertex_descriptor vj = boost::source(*e, *polyhedron); - int ros_idx_j = boost::get(ros_id_pmap, vj); + int ros_idx_j = ros_id[ boost::get(vertex_id_pmap, vj) ]; Vector pij = vi->point() - vj->point(); double wij = edge_weight[boost::get(edge_id_pmap, *e)]; Vector rot_p(0, 0, 0); // vector ( r_i + r_j )*p_ij