add template parameters for property maps in mesh deformation API

This commit is contained in:
Yin Xu 2011-07-10 08:28:56 +00:00
parent aa47b30a0a
commit 68205da8da
3 changed files with 64 additions and 41 deletions

View File

@ -17,8 +17,10 @@
#include <CGAL/Deform_mesh_BGL.h>
#include <CGAL/Taucs_solver_traits.h>
typedef Polyhedron_vertex_deformation_index_map<Polyhedron> vertex_map;
typedef Polyhedron_edge_deformation_index_map<Polyhedron> edge_map;
typedef CGAL::Deform_mesh_BGL<Polyhedron, CGAL::Taucs_solver_traits<double> > Deform_mesh;
typedef CGAL::Deform_mesh_BGL<Polyhedron, CGAL::Taucs_solver_traits<double>, 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();

View File

@ -53,6 +53,10 @@ template <class Refs, class Tprev, class Tvertex, class Tface>
class Polyhedron_demo_halfedge :
public CGAL::HalfedgeDS_halfedge_base<Refs,Tprev,Tvertex,Tface>
{
public:
int dID;
private:
bool feature_edge;
public:
@ -168,4 +172,42 @@ put( Polyhedron_vertex_deformation_index_map<P>& pmap, typename P::Vertex_handl
}
}
template<class P>
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<Polyhedron>::edge_descriptor key_type;
Polyhedron_edge_deformation_index_map(const P&)
{}
};
namespace boost {
template<class P>
std::size_t
get( Polyhedron_edge_deformation_index_map<P>& pmap, typename P::Halfedge_handle eh)
{
return eh->dID;
}
template<class P>
void
put( Polyhedron_edge_deformation_index_map<P>& pmap, typename P::Halfedge_handle eh, std::size_t s)
{
eh->dID = s;
}
}
#endif // POLYHEDRON_TYPE_H

View File

@ -25,7 +25,8 @@ namespace CGAL {
enum LapType { uni, cot };
template <class Polyhedron, class SparseLinearAlgebraTraits_d>
template <class Polyhedron, class SparseLinearAlgebraTraits_d,
class Polyhedron_vertex_deformation_index_map, class Polyhedron_edge_deformation_index_map>
class Deform_mesh_BGL
{
// Public types
@ -44,8 +45,6 @@ public:
typedef typename boost::graph_traits<Polyhedron>::in_edge_iterator in_edge_iterator;
// property map types
typedef std::map<vertex_descriptor,int> VertexIndexMap;
typedef boost::associative_property_map<VertexIndexMap> VertexIdPropertyMap;
typedef std::map<edge_descriptor, int> EdgeIndexMap;
typedef boost::associative_property_map<EdgeIndexMap> EdgeIdPropertyMap;
@ -57,22 +56,17 @@ public:
std::vector<vertex_descriptor> roi;
std::vector<vertex_descriptor> hdl; // user specified handles, storing the target positions
std::vector<vertex_descriptor> 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<int> is_roi; // flag that indicates vertex inside roi or not
std::vector<int> is_hdl;
std::vector<int> 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<int> ros_id; // index of ros vertices
std::vector<int> is_roi; // flag indicating vertex inside roi or not
std::vector<int> is_hdl;
int iterations; // number of iterations
std::vector< std::vector<double> > rot_mtr; // rotation matrices of ros vertices
std::vector<double> edge_weight; // weight of edges
SparseLinearAlgebraTraits_d m_solver; // linear sparse solver
std::vector<Point> solution; // sotring position of all vertices during iterations
std::vector<Point> 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