Skip to Content.
Sympa Menu

cgal-discuss - [cgal-discuss] Re: Surface mesh simplification

Subject: CGAL users discussion list

List archive

[cgal-discuss] Re: Surface mesh simplification


Chronological Thread 
  • From: tang <>
  • To:
  • Subject: [cgal-discuss] Re: Surface mesh simplification
  • Date: Wed, 3 Oct 2012 18:50:20 -0700 (PDT)

Dear

Thank you very much for your kindly reply. I have updated the code as
follows, the function is used to remove flat triangles. Now the idea is:
1) find flat triangle and split it to 2 triangles by insertting a short
edge;
2) remove the flat triangle by joining two vertices of the short edge.

However, the code crashes at this line:
/// split the facet
obj->split_facet(hnew, splitedge);

Could you please help me to take a look at it? You can take the OFF file I
posted before as your test.

Thanks,
Zhanghong Tang



PS: the updated code
void RemoveFlatTriangle(myobj *object,double edgelengthmin)
{
/// this function is used to remove flat triangles with height
smaller than
the given threshold
/// 1. a point will be inserted into one edge and the triangle will be
splitted into two
/// 2. combine the vertices of the short edge (join_vertex)
/// Zhanghong Tang @ 10/02/2012
Polyhedron *obj=(Polyhedron *)object->obj;
/// check for small area triangle
Point_3 p1, p2, p3, p;
Line_3 l;
Halfedge_handle h, hnew, h1, h2, h3, ho, splitedge;

double area, d12, d23, d31, dmax;
Facet_iterator i = obj->facets_begin();
for ( ; i != obj->facets_end(); ++i)
{
/// get 3 points of this facet(triangle)
h1 = i->halfedge();
h2 = h1->next();
h3 = h2->next();
/// (p3->p1): h1
/// (p1->p2): h->next()
/// (p2->p3): h->next()->next()
p1 = h1->vertex()->point();
p2 = h2->vertex()->point();
p3 = h3->vertex()->point();
Triangle_3 t(p1,p2,p3);
area=2.0*sqrt(CGAL::to_double(t.squared_area ()));
d12=sqrt(CGAL::to_double(CGAL::squared_distance(p1,p2)));
if(d12<=edgelengthmin)continue;
d23=sqrt(CGAL::to_double(CGAL::squared_distance(p2,p3)));
if(d23<=edgelengthmin)continue;
d31=sqrt(CGAL::to_double(CGAL::squared_distance(p3,p1)));
if(d31<=edgelengthmin)continue;
dmax=max(max(d12, d23), d31);
if(area/dmax>edgelengthmin)continue;
/// get the projection of pi to longest edge
if(dmax==d12)
{
l=Line_3(p1,p2);
p=l.projection(p3);
splitedge = h2; /// h2 will be splitted by p
h = h3;
}
else if(dmax==d23)
{
l=Line_3(p2,p3);
p=l.projection(p1);
splitedge = h3; /// h3 will be splitted by p
h = h1;
}
else
{
l=Line_3(p3,p1);
p=l.projection(p2);
splitedge = h1; /// h1 will be splitted by p
h = h2;
}
/// the opposite facet
ho = splitedge->opposite()->next();
/// split the edge
hnew = obj->split_edge(splitedge);
/// split the facet
obj->split_facet(hnew, splitedge);
/// set the new vertex
hnew->vertex()->point() = p;
/// split opposite facet
hnew = obj->split_facet(ho, splitedge->opposite());
/// combine vertices of edge h
obj->join_vertex(hnew);
/// after split the edge and facet, we reset the iterator to
the beginning
of facet list
i = obj->facets_begin();
}
}




--
View this message in context:
http://cgal-discuss.949826.n4.nabble.com/Error-when-building-CGAL4-0-2-demo-examples-64-bit-version-tp4655937p4655963.html
Sent from the cgal-discuss mailing list archive at Nabble.com.



Archive powered by MHonArc 2.6.18.

Top of Page