Voronoi.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00030
00034
00035
00037
00038
00039
00040 #ifndef __VORONOI_H__
00041 #define __VORONOI_H__
00042
00043 #include <Scan.h>
00044 #include <DraWin.h>
00045
00046 #include <CGAL/basic.h>
00047
00048 #include <CGAL/Simple_cartesian.h>
00049
00050
00051 #include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
00052 #include <CGAL/Delaunay_triangulation_2.h>
00053 #include <CGAL/Voronoi_diagram_2.h>
00054 #include <CGAL/Delaunay_triangulation_adaptation_traits_2.h>
00055 #include <CGAL/Delaunay_triangulation_adaptation_policies_2.h>
00056
00057 #include <CGAL/IO/Geomview_stream.h>
00058 #include <CGAL/IO/Triangulation_geomview_ostream_2.h>
00059
00060 #include <CGAL/intersections.h>
00061 #include <CGAL/centroid.h>
00062 #include <CGAL/Polygon_2.h>
00063
00064 #include <CGAL/Min_circle_2.h>
00065 #include <CGAL/Min_circle_2_traits_2.h>
00066
00067 #include <CGAL/convex_hull_2.h>
00068
00069 using namespace MipResources;
00070
00071 typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
00072 typedef CGAL::Delaunay_triangulation_2<K> Triangulation;
00073 typedef Triangulation::Edge_iterator Edge_iterator;
00074 typedef Triangulation::Point Point;
00075
00076 typedef K::Line_2 Line_2;
00077 typedef K::Ray_2 Ray_2;
00078 typedef K::Segment_2 Segment_2;
00079
00080
00081
00082 typedef CGAL::Delaunay_triangulation_2<K> DT;
00083 typedef CGAL::Delaunay_triangulation_adaptation_traits_2<DT> AT;
00084 typedef CGAL::Delaunay_triangulation_caching_degeneracy_removal_policy_2<DT> AP;
00085 typedef CGAL::Voronoi_diagram_2<DT,AT,AP> VD;
00086
00087
00088 typedef AT::Site_2 Site_2;
00089 typedef AT::Point_2 Point_2;
00090
00091 typedef VD::Locate_result Locate_result;
00092 typedef VD::Vertex_handle Vertex_handle;
00093 typedef VD::Face_handle Face_handle;
00094 typedef VD::Halfedge_handle Halfedge_handle;
00095 typedef VD::Halfedge_iterator Halfedge_iterator;
00096 typedef VD::Ccb_halfedge_circulator Ccb_halfedge_circulator;
00097 typedef VD::Site_iterator Site_iterator;
00098
00099 typedef CGAL::Polygon_2<K> Polygon_2;
00100 typedef Polygon_2::Vertex_circulator Vertex_circulator;
00101 typedef K::Vector_2 Vector_2;
00102 typedef K::Direction_2 Direction_2;
00103
00104 typedef CGAL::Min_circle_2_traits_2<K> Traits;
00105 typedef CGAL::Min_circle_2<Traits> Min_circle;
00106
00107 using CGAL::ORIGIN;
00108
00109
00110 using namespace std;
00111
00112
00119 class VoronoiEdgeSector {
00120
00121 private:
00122
00123 Angle _angMin;
00124 Angle _angMax;
00125 Halfedge_handle _edge;
00126 bool _valid;
00127 Color _dwColor;
00128
00129 public:
00130
00131 VoronoiEdgeSector() {
00132 _valid = false;
00133 }
00134
00135 VoronoiEdgeSector(Angle angMin, Angle angMax, Halfedge_handle edge, Color dwColor) {
00136 _angMin = angMin;
00137 _angMax = angMax;
00138 _edge = edge;
00139 _valid = true;
00140 _dwColor = dwColor;
00141 }
00142
00144 ~VoronoiEdgeSector(){
00145 }
00146
00147 Angle angMin() { return _angMin; }
00148
00149 Angle angMax() { return _angMax; }
00150
00151 Halfedge_handle edge() { return _edge; }
00152
00153 bool valid() { return _valid; }
00154
00155 Color dwColor() { return _dwColor; }
00156
00158 bool isInside(Angle angle) {
00159
00160 if (!_valid) return false;
00161
00162 if (_angMax.dCast2Pi() >= _angMin.dCast2Pi()) {
00163 if (angle.dCast2Pi() >= _angMin.dCast2Pi() && angle.dCast2Pi() <= _angMax.dCast2Pi()) return true;
00164 }
00165 else {
00166 if (angle.dCast2Pi() >= _angMin.dCast2Pi() || angle.dCast2Pi() <= _angMax.dCast2Pi()) return true;
00167 }
00168
00169 return false;
00170 }
00171
00173 string print(){
00174 stringstream s;
00175 s.precision(3);
00176 s.setf(ios::fixed,ios::floatfield);
00177 s << "(angMin: " << _angMin.dCastDeg() << " Deg, angMax: " << _angMax.dCastDeg() << " Deg)" ;
00178 return s.str();
00179 }
00180
00181 };
00182
00183
00192 class Voronoi{
00193 private:
00195 Triangulation T;
00197 VD vd;
00198
00200 vector <Segment_2> scanRays, limitedScanRays, voronoiScanRays;
00202 vector <Point_2> voronoiScanPoints;
00204 vector <Point_2> voronoiSites;
00206 vector <VoronoiEdgeSector> voronoiRegionSectors;
00207
00208
00209 CGAL::Geomview_stream* gv;
00210 bool gvSet;
00211
00212 DraWin* dw;
00213 unsigned int dwList;
00214 bool dwSet;
00215 Pose dwPose;
00216 Decimal dwPointSize;
00217 Decimal dwDiskSize;
00218 Color dwColor;
00219
00224 Face_handle findRegion(Position p);
00225
00232 bool intersectionRayEdge(Segment_2 r, Halfedge_handle e, Point_2 & iPoint);
00233
00239 bool findEdgeSector(Angle bearing, VoronoiEdgeSector & edgeSector);
00240
00245 void findRegionSectors(Position p);
00246
00251 void drawEdge(Halfedge_handle e);
00252
00258 void drawScanRays(vector <Segment_2>& rays, int sampling=1);
00259
00264 Point_2 polygonCentroid(Polygon_2 polyg);
00265
00266 public:
00267
00269 Voronoi(){
00270 gv = 0;
00271 gvSet = false;
00272
00273 dw = 0;
00274 dwList = 0;
00275 dwSet = false;
00276 }
00277
00279 ~Voronoi(){
00280 }
00281
00286 void insert(Position p);
00287
00291 bool valid();
00292
00293
00301 bool scanToFill(Scan& scan, Angle angRangeMin, Angle angRangeMax, Angle angRes);
00302
00309 void fillScan(Scan& scan, Decimal linRangeMax, Angle angRes);
00310
00319 vector <Position> intersectScan(Scan& scan, Position p, Decimal limitedRange, bool limitedRangeOn=true, bool useSectors=true);
00320
00324 Position centroid();
00325
00333 Position weightedNormal(Decimal limitedRange, Decimal limitedRangeEps, Angle angRes, bool limitTarget = true);
00334
00339 Position circumCenter(Decimal &radius);
00340
00344 void clear();
00345
00350 void setGV(CGAL::Geomview_stream* gvs);
00351
00357 void setDW(DraWin* dwp, unsigned int dwpList);
00358
00363 void setDWPose(Pose dwpPose);
00364
00369 void setDWPointSize(Decimal s);
00370
00375 void setDWDiskSize(Decimal s);
00376
00381 void setDWColor(Color c);
00382
00386 void drawDiagram();
00387
00391 void drawSites();
00392
00397 void drawDisk(Position p);
00398
00404 void drawSegment(Position source, Position target);
00405
00412 void drawCircle(Position center, Decimal radius, int sampling=1);
00413
00418 void drawScan(int sampling=1);
00419
00424 void drawLimitedScan(int sampling=1);
00425
00430 void drawVoronoiScan(int sampling=1);
00431
00436 void drawVoronoiScanPoints(int sampling=1);
00437
00438
00439
00440
00445 void drawRegionEdges(Position p);
00446
00453 void drawRegionSectors(Position center, Decimal radius, int sampling=1);
00454
00458 bool clearPlot();
00459
00464 Position pointToPosition(Point_2 point);
00465
00470 Point_2 positionToPoint(Position point);
00471 };
00472
00473
00474 #endif
00475
00476
00477
00478
00479