27 #ifndef _POLYGON_MESH_ 28 #define _POLYGON_MESH_ 31 #include <CGAL/Cartesian.h> 32 #include <CGAL/Polyhedron_3.h> 34 #include "utility/geom/cgal_types.h" 35 #include "PolygonMap.h" 42 template <
class Refs,
class T,
class P,
class Norm>
58 const int& tag(
void) {
return m_tag; }
59 void tag(
const int& t) { m_tag = t; }
62 typedef Norm Normal_3;
63 Normal_3& normal(
void) {
return m_normal; }
64 const Normal_3& normal(
void)
const {
return m_normal; }
70 template <
class Refs,
class Tprev,
class Tvertex,
class Tface,
class Norm>
83 { m_control_edge =
true; }
86 const int& tag(
void)
const {
return m_tag; }
87 int& tag(
void) {
return m_tag; }
88 void tag(
const int& t) { m_tag = t; }
91 bool& control_edge(
void) {
return m_control_edge; }
92 const bool& control_edge(
void)
const {
return m_control_edge; }
93 void control_edge(
const bool& flag) { m_control_edge = flag; }
97 template <
class Refs,
class T,
class P,
class Norm>
111 :CGAL::HalfedgeDS_vertex_base<Refs, T, P>(pt)
115 typedef Norm Normal_3;
116 Normal_3& normal(
void) {
return m_normal; }
117 const Normal_3& normal(
void)
const {
return m_normal; }
120 int& tag(
void) {
return m_tag; }
121 const int& tag(
void)
const {
return m_tag; }
122 void tag(
const int& t) { m_tag = t; }
136 template <
class Refs,
class Traits>
139 typedef typename Traits::Point_3 Point;
140 typedef typename Traits::Vector_3 Normal;
148 template <
class Refs,
class Traits>
151 typedef typename Traits::Point_3 Point;
152 typedef typename Traits::Vector_3 Normal;
160 template <
class Refs,
class Traits>
163 typedef typename Traits::Vector_3 Normal;
173 template <
class kernel,
class items>
177 typedef typename kernel::FT FT;
178 typedef typename kernel::Point_3 Point;
179 typedef typename kernel::Vector_3 Vector;
180 typedef typename kernel::Iso_cuboid_3 Iso_cuboid;
182 typedef typename CGAL::Polyhedron_3<kernel,items>::Point_iterator Point_iterator;
183 typedef typename CGAL::Polyhedron_3<kernel,items>::Vertex_iterator Vertex_iterator;
184 typedef typename CGAL::Polyhedron_3<kernel,items>::Facet_iterator Facet_iterator;
185 typedef typename CGAL::Polyhedron_3<kernel,items>::Edge_iterator Edge_iterator;
186 typedef typename CGAL::Polyhedron_3<kernel,items>::Halfedge_iterator Halfedge_iterator;
187 typedef typename CGAL::Polyhedron_3<kernel,items>::Halfedge_around_facet_circulator Halfedge_around_facet_circulator;
188 typedef typename CGAL::Polyhedron_3<kernel,items>::Halfedge_around_vertex_circulator Halfedge_around_vertex_circulator;
189 typedef typename CGAL::Polyhedron_3<kernel,items>::Vertex_handle Vertex_handle;
190 typedef typename CGAL::Polyhedron_3<kernel,items>::Facet_handle Facet_handle;
191 typedef typename CGAL::Polyhedron_3<kernel,items>::Halfedge_handle Halfedge_handle;
200 bool m_pure_triangle;
205 : CGAL::Polyhedron_3<kernel,items>()
208 m_pure_triangle =
false;
213 bool is_pure_triangle(
void) {
return m_pure_triangle; }
214 bool is_pure_quad(
void) {
return m_pure_quad; }
217 void compute_normals_per_facet(
void)
218 { std::for_each(this->facets_begin(),this->facets_end(),this->
Facet_normal()); }
219 void compute_normals_per_vertex(
void)
220 { std::for_each(this->vertices_begin(),this->vertices_end(),this->
Vertex_normal()); }
221 void compute_normals(
void)
223 compute_normals_per_facet();
224 compute_normals_per_vertex();
228 Iso_cuboid& bbox(
void) {
return m_bbox; }
229 const Iso_cuboid bbox(
void)
const {
return m_bbox; }
232 void compute_bounding_box(
void);
235 FT xmin(
void) {
return m_bbox.xmin(); }
236 FT xmax(
void) {
return m_bbox.xmax(); }
237 FT ymin(
void) {
return m_bbox.ymin(); }
238 FT ymax(
void) {
return m_bbox.ymax(); }
239 FT zmin(
void) {
return m_bbox.zmin(); }
240 FT zmax(
void) {
return m_bbox.zmax(); }
244 { m_bbox = pMesh->bbox(); }
247 static unsigned int degree(Facet_handle pFace)
248 {
return CGAL::circulator_size(pFace->facet_begin()); }
251 static unsigned int valence(Vertex_handle pVertex)
252 {
return CGAL::circulator_size(pVertex->vertex_begin()); }
255 static bool is_border(Vertex_handle pVertex);
258 Halfedge_handle get_border_halfedge(Vertex_handle pVertex);
261 void tag_halfedges(
const int tag);
263 void tag_facets(
const int tag);
266 void set_index_vertices(
void);
269 bool is_pure_degree(
unsigned int d);
272 void compute_type(
void)
274 m_pure_quad = is_pure_degree(4);
275 m_pure_triangle = is_pure_degree(3);
279 void compute_facet_center(Facet_handle pFace,Point ¢er);
282 FT average_edge_length_around(Vertex_handle pVertex);
285 void gl_draw(
bool smooth_shading,
bool use_normals);
287 void gl_draw_facet(Facet_handle pFacet,
bool smooth_shading,
bool use_normals);
290 void superimpose_edges(
bool skip_ordinary_edges =
true,
bool skip_control_edges =
false,
bool voronoi_edge =
false);
292 void superimpose_vertices(
void);
294 void superimpose_spheres(GEOM_FT scale);
297 void write_obj(
char *pFilename,
int incr = 1);
300 void gl_draw_bounding_box(
void);
303 unsigned int nb_boundaries(
void);
306 void tag_component(Facet_handle pSeedFacet,
const int tag_free,
const int tag_done);
309 unsigned int nb_components(
void);
317 int genus(
int c,
int v,
int f,
int e,
int b);
320 template <
class kernel,
class items>
323 if(this->size_of_vertices() == 0)
329 FT xmin,xmax,ymin,ymax,zmin,zmax;
330 Vertex_iterator pVertex = this->vertices_begin();
331 xmin = xmax = pVertex->point().x();
332 ymin = ymax = pVertex->point().y();
333 zmin = zmax = pVertex->point().z();
334 for(;pVertex != this->vertices_end();pVertex++)
336 const Point& p = pVertex->point();
338 xmin = std::min(xmin,p.x());
339 ymin = std::min(ymin,p.y());
340 zmin = std::min(zmin,p.z());
342 xmax = std::max(xmax,p.x());
343 ymax = std::max(ymax,p.y());
344 zmax = std::max(zmax,p.z());
346 m_bbox= Iso_cuboid(xmin,ymin,zmin,xmax,ymax,zmax);
350 template <
class kernel,
class items>
353 Halfedge_around_vertex_circulator pHalfEdge = pVertex->vertex_begin();
354 if(pHalfEdge ==
nullptr)
356 Halfedge_around_vertex_circulator d = pHalfEdge;
357 CGAL_For_all(pHalfEdge,d)
358 if(pHalfEdge->is_border())
364 template <
class kernel,
class items>
367 Halfedge_around_vertex_circulator pHalfEdge = pVertex->vertex_begin();
368 Halfedge_around_vertex_circulator d = pHalfEdge;
369 CGAL_For_all(pHalfEdge,d)
370 if(pHalfEdge->is_border())
376 template <
class kernel,
class items>
379 for(Halfedge_iterator pHalfedge = this->halfedges_begin();
380 pHalfedge != this->halfedges_end();
386 template <
class kernel,
class items>
389 for(Facet_iterator pFacet = this->facets_begin();
390 pFacet != this->facets_end();
396 template <
class kernel,
class items>
400 for(Vertex_iterator pVertex = this->vertices_begin();
401 pVertex != this->vertices_end();
403 pVertex->tag(index++);
407 template <
class kernel,
class items>
410 for(Facet_iterator pFace = this->facets_begin();
411 pFace != this->facets_end();
413 if(degree(pFace) != d)
419 template <
class kernel,
class items>
422 Halfedge_around_facet_circulator pHalfEdge = pFace->facet_begin();
423 Halfedge_around_facet_circulator end = pHalfEdge;
424 Vector vec(0.0,0.0,0.0);
426 CGAL_For_all(pHalfEdge,end)
428 vec = vec + (pHalfEdge->vertex()->point()-CGAL::ORIGIN);
431 center = CGAL::ORIGIN + (vec/(
typename kernel::FT)degree);
435 template <
class kernel,
class items>
439 Halfedge_around_vertex_circulator pHalfEdge = pVertex->vertex_begin();
440 Halfedge_around_vertex_circulator end = pHalfEdge;
441 Vector vec(0.0,0.0,0.0);
443 CGAL_For_all(pHalfEdge,end)
445 Vector vec = pHalfEdge->vertex()->point()-
446 pHalfEdge->opposite()->vertex()->point();
447 sum += sqrt_FT(vec*vec);
450 return sum / (FT) degree;
454 template <
class kernel,
class items>
458 Facet_iterator pFacet= this->facets_begin();
459 for(;pFacet != this->facets_end();pFacet++)
463 gl_draw_facet(pFacet,smooth_shading,use_normals);
469 template <
class kernel,
class items>
473 if(use_normals && !smooth_shading)
476 ::glNormal3f(this->normal[0],this->normal[1],this->normal[2]);
480 Halfedge_around_facet_circulator pHalfedge = pFacet->facet_begin();
484 if(use_normals && smooth_shading)
487 ::glNormal3f(normal[0],normal[1],normal[2]);
491 const Point& point = pHalfedge->vertex()->point();
492 ::glVertex3d(point[0],point[1],point[2]);
494 while(++pHalfedge != pFacet->facet_begin());
498 template <
class kernel,
class items>
502 for(Edge_iterator h = this->edges_begin();h != this->edges_end(); h++)
505 if(skip_ordinary_edges && !h->control_edge())
continue;
508 if(skip_control_edges && h->control_edge())
continue;
512 Facet_handle pFace1 = h->facet();
513 Facet_handle pFace2 = h->opposite()->facet();
514 if(pFace1 ==
nullptr || pFace2 ==
nullptr)
continue;
516 const Point &p1 = h->vertex()->point();
517 const Point &p2 = h->next()->vertex()->point();
518 const Point &p3 = h->next()->next()->vertex()->point();
521 Point d1 = k.construct_circumcenter_3_object()(p1,p2,p3);
522 glVertex3f(d1[0],d1[1],d1[2]);
524 const Point &pp1 = h->opposite()->vertex()->point();
525 const Point &pp2 = h->opposite()->next()->vertex()->point();
526 const Point &pp3 = h->opposite()->next()->next()->vertex()->point();
527 Point d2 = k.construct_circumcenter_3_object()(pp1,pp2,pp3);
528 glVertex3f(d2[0],d2[1],d2[2]);
533 const Point& p1 = h->prev()->vertex()->point();
534 const Point& p2 = h->vertex()->point();
535 glVertex3f(p1[0],p1[1],p1[2]);
536 glVertex3f(p2[0],p2[1],p2[2]);
543 template <
class kernel,
class items>
547 for(Point_iterator pPoint = this->points_begin();pPoint != this->points_end();pPoint++)
548 glVertex3f(pPoint->x(),pPoint->y(),pPoint->z());
553 template <
class kernel,
class items>
556 GLUquadricObj* pQuadric = gluNewQuadric();
557 ::glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);
559 for(Vertex_iterator pVertex = this->vertices_begin();pVertex != this->vertices_end(); pVertex++)
562 GEOM_FT radius = average_edge_length_around(pVertex);
563 glTranslatef(pVertex->point().x(),
564 pVertex->point().y(),
565 pVertex->point().z());
566 gluSphere(pQuadric,scale*radius,24,24);
569 gluDeleteQuadric(pQuadric);
573 template <
class kernel,
class items>
576 std::ofstream stream(pFilename);
579 for(Point_iterator pPoint = this->points_begin();pPoint != this->points_end();pPoint++)
580 stream <<
'v' <<
' ' << pPoint->x() <<
' ' <<
581 pPoint->y() <<
' ' <<
582 pPoint->z() << std::endl;
585 this->set_index_vertices();
588 for(Facet_iterator pFacet = this->facets_begin();pFacet != this->facets_end(); pFacet++)
591 Halfedge_around_facet_circulator pHalfedge = pFacet->facet_begin();
593 stream <<
' ' << pHalfedge->vertex()->tag()+incr;
594 while(++pHalfedge != pFacet->facet_begin());
600 template <
class kernel,
class items>
606 glVertex3f(m_bbox.xmin(),m_bbox.ymin(),m_bbox.zmin());
607 glVertex3f(m_bbox.xmax(),m_bbox.ymin(),m_bbox.zmin());
608 glVertex3f(m_bbox.xmin(),m_bbox.ymin(),m_bbox.zmax());
609 glVertex3f(m_bbox.xmax(),m_bbox.ymin(),m_bbox.zmax());
610 glVertex3f(m_bbox.xmin(),m_bbox.ymax(),m_bbox.zmin());
611 glVertex3f(m_bbox.xmax(),m_bbox.ymax(),m_bbox.zmin());
612 glVertex3f(m_bbox.xmin(),m_bbox.ymax(),m_bbox.zmax());
613 glVertex3f(m_bbox.xmax(),m_bbox.ymax(),m_bbox.zmax());
616 glVertex3f(m_bbox.xmin(),m_bbox.ymin(),m_bbox.zmin());
617 glVertex3f(m_bbox.xmin(),m_bbox.ymax(),m_bbox.zmin());
618 glVertex3f(m_bbox.xmin(),m_bbox.ymin(),m_bbox.zmax());
619 glVertex3f(m_bbox.xmin(),m_bbox.ymax(),m_bbox.zmax());
620 glVertex3f(m_bbox.xmax(),m_bbox.ymin(),m_bbox.zmin());
621 glVertex3f(m_bbox.xmax(),m_bbox.ymax(),m_bbox.zmin());
622 glVertex3f(m_bbox.xmax(),m_bbox.ymin(),m_bbox.zmax());
623 glVertex3f(m_bbox.xmax(),m_bbox.ymax(),m_bbox.zmax());
626 glVertex3f(m_bbox.xmin(),m_bbox.ymin(),m_bbox.zmin());
627 glVertex3f(m_bbox.xmin(),m_bbox.ymin(),m_bbox.zmax());
628 glVertex3f(m_bbox.xmin(),m_bbox.ymax(),m_bbox.zmin());
629 glVertex3f(m_bbox.xmin(),m_bbox.ymax(),m_bbox.zmax());
630 glVertex3f(m_bbox.xmax(),m_bbox.ymin(),m_bbox.zmin());
631 glVertex3f(m_bbox.xmax(),m_bbox.ymin(),m_bbox.zmax());
632 glVertex3f(m_bbox.xmax(),m_bbox.ymax(),m_bbox.zmin());
633 glVertex3f(m_bbox.xmax(),m_bbox.ymax(),m_bbox.zmax());
639 template <
class kernel,
class items>
644 for(Halfedge_iterator he = this->halfedges_begin();
645 he != this->halfedges_end();
648 if(he->is_border() && he->tag() == 0)
651 Halfedge_handle curr = he;
663 template <
class kernel,
class items>
668 pSeedFacet->tag(tag_done);
669 std::list<Facet_handle> facets;
670 facets.push_front(pSeedFacet);
671 while(!facets.empty())
673 Facet_handle pFacet = facets.front();
675 pFacet->tag(tag_done);
676 Halfedge_around_facet_circulator pHalfedge = pFacet->facet_begin();
677 Halfedge_around_facet_circulator end = pHalfedge;
678 CGAL_For_all(pHalfedge,end)
680 Facet_handle pNFacet = pHalfedge->opposite()->facet();
681 if(pNFacet !=
nullptr && pNFacet->tag() == tag_free)
683 facets.push_front(pNFacet);
684 pNFacet->tag(tag_done);
691 template <
class kernel,
class items>
696 for(Facet_iterator pFacet = this->facets_begin(); pFacet != this->facets_end(); pFacet++)
698 if(pFacet->tag() == 0)
701 tag_component(pFacet,0,1);
711 template <
class kernel,
class items>
714 const int c = this->nb_components();
715 const int b = this->nb_boundaries();
716 const int v = this->size_of_vertices();
717 const int e = this->size_of_halfedges()/2;
718 const int f = this->size_of_facets();
719 return genus(c,v,f,e,b);
721 template <
class kernel,
class items>
723 {
return (2*c+e-b-f-v)/2; }
728 template <
class Facet>
729 void operator()(Facet& f);
732 template <
class Facet>
733 void Facet_normal::operator()(Facet& f)
735 typename Facet::Normal_3 sum = CGAL::NULL_VECTOR;
736 typename Facet::Halfedge_around_facet_circulator h = f.facet_begin();
739 typename Facet::Normal_3 normal = CGAL::cross_product(
740 h->next()->vertex()->point() - h->vertex()->point(),
741 h->next()->next()->vertex()->point() - h->next()->vertex()->point());
742 GEOM_FT sqnorm = normal * normal;
743 if(sqnorm != 0) normal = normal / sqrt_FT(sqnorm);
746 while(++h != f.facet_begin());
747 float sqnorm = sum * sum;
749 f.normal() = sum / sqrt_FT(sqnorm);
752 f.normal() = CGAL::NULL_VECTOR;
753 std::cerr <<
"degenerate face\n";
761 template <
class Vertex>
762 void operator()(Vertex& v);
765 template <
class Vertex>
766 void Vertex_normal::operator()(Vertex& v)
768 typename Vertex::Normal_3 normal = CGAL::NULL_VECTOR;
769 typename Vertex::Halfedge_around_vertex_const_circulator pHalfedge = v.vertex_begin();
770 typename Vertex::Halfedge_around_vertex_const_circulator begin = pHalfedge;
771 CGAL_For_all(pHalfedge,begin)
772 if(!pHalfedge->is_border()) normal = normal + pHalfedge->facet()->normal();
773 float sqnorm = normal * normal;
775 v.normal() = normal / sqrt_FT(sqnorm);
777 v.normal() = CGAL::NULL_VECTOR;
785 #endif // _POLYGON_MESH_ Definition: enriched_polyhedron.h:174
Definition: enriched_polyhedron.h:133
Definition: enriched_polyhedron.h:137
Definition: enriched_polyhedron.h:726
Definition: enriched_polyhedron.h:161
Definition: enriched_polyhedron.h:43
Definition: enriched_polyhedron.h:759
Definition: enriched_polyhedron.h:98
Definition: enriched_polyhedron.h:71
Definition: enriched_polyhedron.h:149