reintegrate feature branch Surface_mesher-c2t3_to_polyhedron_bug_fix-sloriot

avoid having dangling vertices in the conversion from c2t3 to polyhedron
This commit is contained in:
Sébastien Loriot 2012-08-14 10:29:58 +00:00
parent 3161033659
commit 76417d597d
1 changed files with 20 additions and 12 deletions

View File

@ -42,6 +42,19 @@ private:
const C2t3& c2t3;
typedef CGAL::Modifier_base<typename Polyhedron::HalfedgeDS> Base;
template <class IBuilder, class Vertex_handle>
int get_vertex_index(IBuilder& builder, Vertex_handle vh, std::map<Vertex_handle, int>& V, int& inum)
{
typedef typename std::map<Vertex_handle, int>::iterator map_iterator;
std::pair<map_iterator,bool> insert_res = V.insert( std::make_pair(vh,inum) );
if ( insert_res.second ){
typename Tr::Point p = static_cast<typename Tr::Point>(vh->point());
builder.add_vertex(p);
++inum;
}
return insert_res.first->second;
}
public:
Complex_2_in_triangulation_3_polyhedron_builder(const C2t3& c2t3)
: Base(), c2t3(c2t3)
@ -64,16 +77,6 @@ public:
number_of_facets);
{
// Finite vertices coordinates.
std::map<Vertex_handle, int> V;
int inum = 0;
for(Finite_vertices_iterator vit = tr.finite_vertices_begin();
vit != tr.finite_vertices_end();
++vit)
{
V[vit] = inum++;
Point p = static_cast<Point>(vit->point());
builder.add_vertex(p);
}
Finite_facets_iterator fit = tr.finite_facets_begin();
std::set<Facet> oriented_set;
std::stack<Facet> stack;
@ -135,6 +138,10 @@ public:
const Vector Z(0, 0, 1);
bool regular_orientation = (Z * normal >= 0);
//used to set indices of vertices
std::map<Vertex_handle, int> V;
int inum = 0;
for(typename std::set<Facet>::const_iterator fit =
oriented_set.begin();
fit != oriented_set.end();
@ -143,8 +150,9 @@ public:
int indices[3];
int index = 0;
for (int i=0; i<3; i++)
indices[index++] =
V[fit->first->vertex(tr.vertex_triple_index(fit->second, i))];
indices[index++] = get_vertex_index(
builder, fit->first->vertex(tr.vertex_triple_index(fit->second, i)), V, inum
);
builder.begin_facet();
builder.add_vertex_to_facet(indices[0]);
builder.add_vertex_to_facet(regular_orientation ? indices[1] : indices[2]);