00001
00006 #ifndef REGION_H
00007 #define REGION_H
00008
00009 #include <assert.h>
00010 #include <vector>
00011
00012
00013 #include <CGAL/Filtered_kernel.h>
00014 #include <CGAL/Intersections.h>
00015
00016
00017 #include "lib/enriched_polyhedron.h"
00018 #include "lib/enriched_kernel.h"
00019 #include "lib/enriched_items.h"
00020
00021
00027 class Region
00028 {
00029 public:
00030 typedef Enriched_polyhedron<Enriched_kernel,Enriched_items> Polyhedron ;
00031 typedef Polyhedron::Vertex Vertex;
00032 typedef Polyhedron::Vertex_handle Vertex_handle;
00033 typedef Polyhedron::Vector Vector;
00034 typedef Polyhedron::Point Point;
00035 typedef Polyhedron::Facet_handle Facet_handle;
00036 typedef Polyhedron::Halfedge_handle Halfedge_handle;
00037 typedef Polyhedron::Halfedge Halfedge;
00038
00040 typedef Polyhedron::Vertex_iterator Vertex_iterator;
00041
00043 typedef Polyhedron::Edge_iterator Edge_iterator;
00044
00046 typedef Polyhedron::Halfedge_iterator Halfedge_iterator;
00047
00049 typedef Polyhedron::Facet_iterator Facet_iterator;
00050
00052 typedef Polyhedron::Halfedge_around_vertex_circulator Halfedge_around_vertex_circulator;
00053 typedef Polyhedron::Halfedge_around_vertex_const_circulator Halfedge_around_vertex_const_circulator;
00054
00056 typedef Polyhedron::Halfedge_around_facet_circulator Halfedge_around_facet_circulator;
00057
00058
00059
00060
00061
00062 typedef CGAL::Line_2<Enriched_kernel> Line_2 ;
00063 typedef CGAL::Point_2<Enriched_kernel> Point_2 ;
00064
00065 private:
00066 Polyhedron _mesh3D;
00067
00068 bool _is_valid;
00069
00071 Polyhedron _mesh2D;
00072
00073 bool _is_valid2;
00074
00075 public:
00076
00077
00079 Region() :_mesh3D(), _is_valid(false) {};
00080
00082 Region(Polyhedron _mesh) :
00083 _mesh3D(_mesh),
00084 _is_valid(!_mesh3D.is_closed()),
00085 _mesh2D(_mesh),
00086 _is_valid2(!_mesh2D.is_closed())
00087 {} ;
00088
00090 ~Region(){ }
00091
00092
00093 bool valide3D() { return _is_valid; }
00094
00095 bool valide2D() { return _is_valid2; }
00096
00098 Polyhedron* mesh3D () { return &_mesh3D ; }
00099
00101 Polyhedron* mesh2D () { return &_mesh2D ; }
00102
00103
00104 bool Un_Sommet_de_la_mesh2D(Vertex_handle pV)
00105 {
00106 for(Vertex_iterator pVertex = _mesh2D.vertices_begin(); pVertex != _mesh2D.vertices_end(); pVertex++)
00107 {
00108 if (pV == pVertex ) return true;
00109 }
00110
00111 return false;
00112 }
00113
00114
00115 bool Un_Sommet_de_la_mesh3D(Vertex_handle pV)
00116 {
00117 for(Vertex_iterator pVertex = _mesh3D.vertices_begin(); pVertex != _mesh3D.vertices_end(); pVertex++)
00118 {
00119 if (pV == pVertex ) return true;
00120 }
00121
00122 return false;
00123 }
00124
00125
00126 private:
00127
00133 double Compute_nrj_sommet_sur_mesh (Vertex_handle pV);
00134
00135
00136
00144 double Compute_nrj_sommet (Vertex_handle pV) ;
00145
00146
00147 public:
00148
00151 double Nrj_sommet (Vertex_handle pV)
00152 {
00153 if (Un_Sommet_de_la_mesh2D(pV))
00154 return Compute_nrj_sommet_sur_mesh (pV);
00155 else
00156 return Compute_nrj_sommet(pV);
00157
00158 }
00159
00160
00163 void Compute_Parameterization() ;
00164
00175 bool isEdge(int i, int j) ;
00176
00185 bool isBorderVertex(Vertex_handle vh) ;
00186
00192 void Trace2file(char* filename) ;
00193
00194
00195
00196 void vh2Dfrom3D (Vertex_handle& vh) ;
00197
00198
00199
00200 void vh3Dfrom2D(Vertex_handle& vh) ;
00201
00202 bool Appartient_facet(Facet_handle pF, Point p)
00203 {
00204 Point_2 pp=Point_2(p[0], p[1]) ;
00205
00206 Halfedge_around_facet_circulator h = pF->facet_begin();
00207
00208 if (CGAL::circulator_size(h)!=3) { std::cout << "ERROR in Compute_nrj_sommet: facet must be triangle" << std::endl; exit(-1); }
00209
00210 Point p1=h->vertex()->point();
00211 Point_2 pp1(p1[0], p1[1]) ;
00212 h++;
00213 Point p2=h->vertex()->point();
00214 Point_2 pp2(p2[0], p2[1]) ;
00215 h++;
00216 Point p3=h->vertex()->point();
00217 Point_2 pp3(p3[0], p3[1]) ;
00218
00219 Point_2 ipoint ;
00220 Line_2 iline ;
00221 CGAL::Object result = intersection(Line_2(pp1,pp),Line_2(pp2,pp3)) ;
00222 if (CGAL::assign(ipoint, result))
00223 {
00224 if( are_ordered_along_line( pp2 , ipoint , pp3) )
00225 return true;
00226 } else
00227 if (CGAL::assign(iline, result))
00228 {
00229 std::cout << "result ligne" << std::endl ;
00230 return false;
00231 } else
00232 {
00233 std::cout << "result pas d inters" << std::endl ;
00234 return false;
00235 }
00236
00237 return false;
00238
00239 }
00240
00241
00242
00243 void Point3D_from_2D(Point& p);
00244
00245 };
00246
00247 #endif