00001 #ifndef _COLORING_HPP
00002 #define _COLORING_HPP
00003
00004 #include <assert.h>
00005 #include <vector>
00006 #include <list>
00007 #include <iostream>
00008 #include <CGAL/Triangulation_2.h>
00009 #include <CGAL/Triangulation_face_base_with_info_2.h>
00010 #include <CGAL/Constrained_Delaunay_triangulation_2.h>
00011 #include "global.hpp"
00012 #include "random.hpp"
00013 #include "handle.hpp"
00014 #include "store.hpp"
00015 #include "properties.hpp"
00016 #include "geometry.hpp"
00017 #include "grid.hpp"
00018
00019
00020 #define GRID_EDGE_INDEX
00021
00022
00023 #if defined(TRIANGULATION_EDGE_INDEX) && !defined(EXACT_GEOM_PRED)
00024 #error "The triangulation index requires exact geometric predicates."
00025 #endif
00026
00027 namespace CGAL {
00028 class Qt_widget;
00029 }
00030
00031 namespace Arak {
00032
00033 class QueryPointIndex;
00034
00075 class Coloring {
00076
00077 public:
00078
00079 class Vertex;
00080 class InteriorEdge;
00081 class BoundaryEdge;
00082
00083 typedef PointerHandle<Vertex> VertexHandle;
00084
00085 typedef PointerHandle<InteriorEdge> IntEdgeHandle;
00086
00087 typedef PointerHandle<BoundaryEdge> BdEdgeHandle;
00088
00089 public:
00090
00095 struct FaceColorInfo {
00099 Color color;
00100 };
00101
00107 template <typename FaceInfoType = FaceColorInfo,
00108 typename VertexBaseType = CGAL::Triangulation_vertex_base_2<Geometry::Kernel>
00109 >
00110 struct TriangulationTraits {
00114 typedef typename
00115 CGAL::Triangulation_face_base_with_info_2<FaceInfoType,
00116 Geometry::Kernel>
00117 FaceBaseWithInfo;
00118
00122 typedef typename
00123 CGAL::Constrained_triangulation_face_base_2<Geometry::Kernel,
00124 FaceBaseWithInfo>
00125 TFb;
00126
00131 typedef typename
00132 CGAL::Triangulation_data_structure_2<VertexBaseType, TFb> Tds;
00133
00139 typedef CGAL::No_intersection_tag itag;
00140
00148 typedef typename
00149 CGAL::Constrained_Delaunay_triangulation_2<Geometry::Kernel, Tds, itag>
00150 Triangulation;
00151 };
00152
00153 #ifdef TRIANGULATION_EDGE_INDEX
00154
00155 protected:
00156
00162 template <class Vb = CGAL::Triangulation_vertex_base_2<Geometry::Kernel> >
00163 class TVb : public Vb {
00164 typedef Vb Base;
00165 public:
00166 typedef typename Vb::Vertex_handle Vertex_handle;
00167 typedef typename Vb::Face_handle Face_handle;
00168 typedef typename Vb::Point Point;
00169 typedef std::pair<Face_handle,int> Edge;
00170
00171 template < typename TDS2 >
00172 struct Rebind_TDS {
00173 typedef typename Vb::template Rebind_TDS<TDS2>::Other Vb2;
00174 typedef TVb<Vb2> Other;
00175 };
00176
00180 VertexHandle vertex;
00181
00185 TVb() : Base(), vertex(NULL) {}
00186 TVb(const Point & p) : Base(p), vertex(NULL) {}
00187 TVb(const Point & p, Face_handle f) : Base(f,p), vertex(NULL) {}
00188 TVb(Face_handle f) : Base(f), vertex(NULL) {}
00189 };
00190
00198 typedef TriangulationTraits<FaceColorInfo, TVb<> >::Triangulation
00199 TriangulationIndex;
00200
00204 typedef TriangulationIndex::Face_handle TFaceHandle;
00205
00209 typedef TriangulationIndex::Vertex_handle TVertexHandle;
00210
00214 typedef TriangulationIndex::Edge TEdge;
00215
00220 typedef TriangulationIndex::Line_face_circulator TFaceCirculator;
00221
00226 class Tracer {
00227
00228 protected:
00229
00233 Geometry::Point source;
00234
00239 Geometry::Point target;
00240
00244 const Coloring::TriangulationIndex* tri;
00245
00250 Coloring::TFaceCirculator circ;
00251
00255 Coloring::TEdge edge;
00256
00261 bool forwards;
00262
00266 bool valid;
00267
00272 bool isRay;
00273
00274 public:
00275
00287 Tracer(const Geometry::Point& source,
00288 const Geometry::Point& target,
00289 const Coloring::TriangulationIndex& tri,
00290 bool isRay = false,
00291 const Coloring::TFaceHandle hint =
00292 Coloring::TFaceHandle());
00293
00297 Tracer()
00298 : source(CGAL::ORIGIN),
00299 target(CGAL::ORIGIN),
00300 tri(NULL), circ(),
00301 edge(Coloring::TFaceHandle(), 0),
00302 forwards(true), valid(false), isRay(false) { }
00303
00307 inline bool operator==(const Tracer& other) const
00308 { return ((valid == other.valid) &&
00309 (!valid || (valid && (circ == other.circ)))); }
00310 inline bool operator!=(const Tracer& other) const
00311 { return !(*this == other); }
00312
00316 Tracer operator++(int) {
00317 Tracer tmp(*this);
00318 ++(*this);
00319 return tmp;
00320 }
00321 Tracer& operator++();
00322
00326 const TEdge* operator->() const {return &edge;}
00327 const TEdge& operator*() const { return edge;}
00328
00329 };
00330
00331 #endif // #ifdef TRIANGULATION_EDGE_INDEX
00332
00333 public:
00334
00338 class Vertex : public Geometry::Point {
00339
00340 friend class InteriorEdge;
00341 friend class BoundaryEdge;
00342 friend class Coloring;
00343
00344 public:
00345
00349 enum Type {
00350 INTERIOR,
00352 BOUNDARY,
00354 CORNER,
00356 INVALID,
00358 };
00359
00360 protected:
00361
00362 #ifdef TRIANGULATION_EDGE_INDEX
00363
00366 TVertexHandle tvh;
00367 #endif
00368
00373 Type t;
00374
00380 IntEdgeHandle prevIntEdge;
00381
00387 IntEdgeHandle nextIntEdge;
00388
00394 BdEdgeHandle prevBdEdge;
00395
00401 BdEdgeHandle nextBdEdge;
00402
00411 int index;
00412
00413 public:
00414
00418 Vertex() {
00419 t = INVALID;
00420 index = -1;
00421 }
00422
00428 inline Type type() const { return t; }
00429
00433 const Geometry::Point& point() const { return *this; }
00434
00440 inline bool hasPrevIntEdge() const {
00441 assert(type() != CORNER);
00442 return (prevIntEdge.valid());
00443 }
00444
00451 inline IntEdgeHandle getPrevIntEdge() {
00452 assert(type() != CORNER);
00453 return prevIntEdge;
00454 }
00455 inline const IntEdgeHandle getPrevIntEdge() const {
00456 assert(type() != CORNER);
00457 return prevIntEdge;
00458 }
00459
00465 inline bool hasNextIntEdge() const {
00466 assert(type() != CORNER);
00467 return (nextIntEdge.valid());
00468 }
00469
00476 inline IntEdgeHandle getNextIntEdge() {
00477 assert(type() != CORNER);
00478 return nextIntEdge;
00479 }
00480 inline const IntEdgeHandle getNextIntEdge() const {
00481 assert(type() != CORNER);
00482 return nextIntEdge;
00483 }
00484
00490 inline BdEdgeHandle getPrevBdEdge() {
00491 assert((type() == CORNER) || (type() == BOUNDARY));
00492 return prevBdEdge;
00493 }
00494 inline const BdEdgeHandle getPrevBdEdge() const {
00495 assert((type() == CORNER) || (type() == BOUNDARY));
00496 return prevBdEdge;
00497 }
00498
00504 inline BdEdgeHandle getNextBdEdge() {
00505 assert((type() == CORNER) || (type() == BOUNDARY));
00506 return nextBdEdge;
00507 }
00508 inline const BdEdgeHandle getNextBdEdge() const {
00509 assert((type() == CORNER) || (type() == BOUNDARY));
00510 return nextBdEdge;
00511 }
00512
00517 inline VertexHandle getPrevVertex() {
00518 return getPrevIntEdge()->getPrevVertex();
00519 }
00520 inline const VertexHandle getPrevVertex() const {
00521 return getPrevIntEdge()->getPrevVertex();
00522 }
00523
00528 inline VertexHandle getNextVertex() {
00529 return getNextIntEdge()->getNextVertex();
00530 }
00531 inline const VertexHandle getNextVertex() const {
00532 return getNextIntEdge()->getNextVertex();
00533 }
00534
00540 inline VertexHandle getPrevCornerVertex() {
00541 return getPrevBdEdge()->getPrevCornerVertex();
00542 }
00543 inline const VertexHandle getPrevCornerVertex() const {
00544 return getPrevBdEdge()->getPrevCornerVertex();
00545 }
00546
00552 inline VertexHandle getNextCornerVertex() {
00553 return getNextBdEdge()->getNextCornerVertex();
00554 }
00555 inline const VertexHandle getNextCornerVertex() const {
00556 return getNextBdEdge()->getNextCornerVertex();
00557 }
00558
00570 double logSine();
00571
00572 };
00573
00582 class Edge : public Geometry::Segment {
00583
00584 friend class Vertex;
00585 friend class Coloring;
00586
00587 protected:
00588
00593 VertexHandle prevVertex;
00594
00599 VertexHandle nextVertex;
00600
00608 int index;
00609
00610 public:
00611
00615 Edge() {
00616 index = -1;
00617 }
00618
00622 const Geometry::Segment& segment() const { return *this; }
00623
00628 inline VertexHandle getPrevVertex() { return prevVertex; }
00629 inline const VertexHandle getPrevVertex() const { return prevVertex; }
00630
00635 inline VertexHandle getNextVertex() { return nextVertex; }
00636 inline const VertexHandle getNextVertex() const { return nextVertex; }
00637
00647 Geometry::Point
00648 randomPoint(Arak::Util::Random& random = Arak::Util::default_random) const;
00649
00655 double length() const {
00656 using namespace Arak::Geometry;
00657 return sqrt(CGAL::to_double(squared_length()));
00658 }
00659
00663 bool operator==(const Edge& other) const {
00664 return (this == &other);
00665 }
00666
00671 bool operator!=(const Edge& other) const {
00672 return !this->operator!=(other);
00673 }
00674
00675 };
00676
00681 typedef Grid<IntEdgeHandle> InteriorEdgeIndex;
00682
00689 class InteriorEdge : public Edge {
00690
00691 friend class Vertex;
00692 friend class Coloring;
00693
00694 public:
00695
00699 typedef InteriorEdgeIndex::Cell::Entry CellEntry;
00700
00704 typedef std::list<CellEntry> CellEntryList;
00705
00706 protected:
00707
00711 CellEntryList entries;
00712
00717 CellEntryList unused;
00718
00719 public:
00720
00724 InteriorEdge() : Edge(), entries() { }
00725
00729 ~InteriorEdge() { }
00730
00740 bool crosses(const Geometry::Point& a,
00741 const Geometry::Point& b) const;
00742
00747 const CellEntryList& cellEntries() const { return entries; }
00748
00749 };
00750
00755 class BoundaryEdge : public Edge {
00756
00757 friend class Vertex;
00758 friend class Coloring;
00759
00760 protected:
00761
00766 VertexHandle prevCorner;
00767
00772 VertexHandle nextCorner;
00773
00774 public:
00775
00779 BoundaryEdge() : Edge(), prevCorner(NULL), nextCorner(NULL) { }
00780
00785 inline VertexHandle getPrevCornerVertex() { return prevCorner; }
00786 inline const VertexHandle getPrevCornerVertex() const { return prevCorner; }
00791 inline VertexHandle getNextCornerVertex() { return nextCorner; }
00792 inline const VertexHandle getNextCornerVertex() const { return nextCorner; }
00793
00803 Geometry::Point
00804 randomPoint(Arak::Util::Random& random = Arak::Util::default_random) const;
00805
00806 };
00807
00808 public:
00809
00832 class Listener {
00833
00834 public:
00835
00842 virtual void vertexHasBeenAdded(Coloring::VertexHandle vh) {};
00843
00850 virtual void vertexWillBeRemoved(Coloring::VertexHandle vh) {};
00851
00858 virtual void edgeHasBeenAdded(Coloring::IntEdgeHandle eh) {};
00859
00866 virtual void edgeWillBeRemoved(Coloring::IntEdgeHandle eh) {};
00867
00876 virtual void recolored(const Geometry::Point& a,
00877 const Geometry::Point& b,
00878 const Geometry::Point& c) {};
00879
00892 virtual void recolored(const Geometry::Point& a,
00893 const Geometry::Point& b,
00894 const Geometry::Point& c,
00895 const Geometry::Point& d) {};
00896
00897 };
00898
00899 protected:
00900
00908 Geometry::Rectangle bd;
00909
00913 InteriorEdgeIndex* intEdgeIndex;
00914
00915 #ifdef TRIANGULATION_EDGE_INDEX
00916
00922 TriangulationIndex tri;
00923 #endif
00924
00929 mutable QueryPointIndex* queryPoints;
00930
00934 Store<Vertex> vertexStore;
00935
00940 std::vector<VertexHandle> interiorVertices;
00941
00946 std::vector<VertexHandle> boundaryVertices;
00947
00952 std::vector<VertexHandle> cornerVertices;
00953
00958 Store<InteriorEdge> intEdgeStore;
00959
00966 std::vector<IntEdgeHandle> interiorEdges;
00967
00972 Store<BoundaryEdge> bdEdgeStore;
00973
00978 std::vector<BdEdgeHandle> boundaryEdges;
00979
00983 mutable std::list<Listener*> listeners;
00984
00989 double minEdgeLengthSq;
00990
00998 VertexHandle newVertex(Vertex::Type type, const Geometry::Point& p);
00999
01005 void freeVertex(VertexHandle& v);
01006
01013 void disconnectFromBd(VertexHandle v);
01014
01024 IntEdgeHandle newInteriorEdge(VertexHandle prev, VertexHandle next);
01025
01037 BdEdgeHandle newBoundaryEdge(VertexHandle prev,
01038 VertexHandle next,
01039 VertexHandle prevCorner,
01040 VertexHandle nextCorner);
01041
01047 void freeEdge(IntEdgeHandle& e);
01048
01054 void freeEdge(BdEdgeHandle& e);
01055
01065 void recolored(const Geometry::Point& a,
01066 const Geometry::Point& b,
01067 const Geometry::Point& c);
01068
01081 void recolored(const Geometry::Point& a,
01082 const Geometry::Point& b,
01083 const Geometry::Point& c,
01084 const Geometry::Point& d);
01085
01090 inline void notifyVertexWillBeRemoved(VertexHandle vh) {
01091 for (std::list<Listener*>::iterator it = listeners.begin();
01092 it != listeners.end(); it++)
01093 (*it)->vertexWillBeRemoved(vh);
01094 }
01095
01100 inline void notifyVertexHasBeenAdded(VertexHandle vh) {
01101 for (std::list<Listener*>::iterator it = listeners.begin();
01102 it != listeners.end(); it++)
01103 (*it)->vertexHasBeenAdded(vh);
01104 }
01105
01110 inline void notifyEdgeWillBeRemoved(IntEdgeHandle eh) {
01111 for (std::list<Listener*>::iterator it = listeners.begin();
01112 it != listeners.end(); it++)
01113 (*it)->edgeWillBeRemoved(eh);
01114 }
01115
01120 inline void notifyEdgeHasBeenAdded(IntEdgeHandle eh) {
01121 for (std::list<Listener*>::iterator it = listeners.begin();
01122 it != listeners.end(); it++)
01123 (*it)->edgeHasBeenAdded(eh);
01124 }
01125
01139 void initialize(Geometry::Rectangle &boundary,
01140 int gridRows = 10,
01141 int gridCols = 10,
01142 double minEdgeLength = 0.0);
01143
01147 void clear();
01148
01149 public:
01150
01154 Coloring();
01155
01169 Coloring(Geometry::Rectangle &boundary,
01170 int gridRows = 10,
01171 int gridCols = 10,
01172 double minEdgeLength = 0.0);
01173
01183 Coloring(const Util::PropertyMap& props);
01184
01188 ~Coloring();
01189
01194 void test() const;
01195
01201 const Geometry::Rectangle& boundary() const { return bd; }
01202
01206 const InteriorEdgeIndex& getInteriorEdgeIndex() const {
01207 return *intEdgeIndex;
01208 }
01209
01216 inline int numVertices(Vertex::Type type) const {
01217 switch (type) {
01218 case Vertex::INTERIOR:
01219 return interiorVertices.size();
01220 case Vertex::BOUNDARY:
01221 return boundaryVertices.size();
01222 case Vertex::CORNER:
01223 return cornerVertices.size();
01224 default:
01225 assert(false);
01226 }
01227 }
01228
01237 inline const VertexHandle getVertex(Vertex::Type type, int index) const {
01238 switch (type) {
01239 case Vertex::INTERIOR:
01240 return interiorVertices[index];
01241 case Vertex::BOUNDARY:
01242 return boundaryVertices[index];
01243 case Vertex::CORNER:
01244 return cornerVertices[index];
01245 default:
01246 assert(false);
01247 }
01248 }
01249
01258 inline VertexHandle getVertex(Vertex::Type type, int index) {
01259 switch (type) {
01260 case Vertex::INTERIOR:
01261 return interiorVertices[index];
01262 case Vertex::BOUNDARY:
01263 return boundaryVertices[index];
01264 case Vertex::CORNER:
01265 return cornerVertices[index];
01266 default:
01267 assert(false);
01268 }
01269 }
01270
01276 inline int numInteriorEdges() const {
01277 return interiorEdges.size();
01278 }
01279
01285 inline int numBoundaryEdges() const {
01286 return boundaryEdges.size();
01287 }
01288
01296 inline const IntEdgeHandle getInteriorEdge(int index) const {
01297 return interiorEdges[index];
01298 }
01299 inline IntEdgeHandle getInteriorEdge(int index) {
01300 return interiorEdges[index];
01301 }
01302
01310 inline const BdEdgeHandle getBoundaryEdge(int index) const {
01311 return boundaryEdges[index];
01312 }
01313 inline BdEdgeHandle getBoundaryEdge(int index) {
01314 return boundaryEdges[index];
01315 }
01316
01321 struct TEST_IF_VALID_TAG {};
01322
01328 struct DO_IF_VALID_TAG {};
01329
01340 struct DO_WITHOUT_TEST_TAG {};
01341
01370 bool deleteVertex(VertexHandle v, TEST_IF_VALID_TAG) const;
01371 bool deleteVertex(VertexHandle& v, DO_IF_VALID_TAG);
01372 bool deleteVertex(VertexHandle& v, DO_WITHOUT_TEST_TAG);
01374
01376
01389 bool splitEdge(IntEdgeHandle e,
01390 const Geometry::Point& p,
01391 TEST_IF_VALID_TAG) const;
01392 bool splitEdge(IntEdgeHandle& e,
01393 const Geometry::Point& p,
01394 DO_IF_VALID_TAG);
01395 bool splitEdge(IntEdgeHandle& e,
01396 const Geometry::Point& p,
01397 DO_WITHOUT_TEST_TAG);
01399
01401
01414 bool newInteriorTriangle(const Geometry::Point& x,
01415 const Geometry::Point& y,
01416 const Geometry::Point& z,
01417 TEST_IF_VALID_TAG) const;
01418 VertexHandle newInteriorTriangle(const Geometry::Point& x,
01419 const Geometry::Point& y,
01420 const Geometry::Point& z,
01421 DO_IF_VALID_TAG);
01422 VertexHandle newInteriorTriangle(const Geometry::Point& x,
01423 const Geometry::Point& y,
01424 const Geometry::Point& z,
01425 DO_WITHOUT_TEST_TAG);
01427
01429
01444 bool newBoundaryTriangle(BdEdgeHandle e,
01445 const Geometry::Point& u,
01446 const Geometry::Point& v,
01447 const Geometry::Point& w,
01448 TEST_IF_VALID_TAG) const;
01449 VertexHandle newBoundaryTriangle(BdEdgeHandle e,
01450 const Geometry::Point& u,
01451 const Geometry::Point& v,
01452 const Geometry::Point& w,
01453 DO_IF_VALID_TAG);
01454 VertexHandle newBoundaryTriangle(BdEdgeHandle e,
01455 const Geometry::Point& u,
01456 const Geometry::Point& v,
01457 const Geometry::Point& w,
01458 DO_WITHOUT_TEST_TAG);
01460
01462
01479 bool newCornerTriangle(VertexHandle corner,
01480 const Geometry::Point& u,
01481 const Geometry::Point& v,
01482 TEST_IF_VALID_TAG) const;
01483 VertexHandle newCornerTriangle(VertexHandle corner,
01484 const Geometry::Point& u,
01485 const Geometry::Point& v,
01486 DO_IF_VALID_TAG);
01487 VertexHandle newCornerTriangle(VertexHandle corner,
01488 const Geometry::Point& u,
01489 const Geometry::Point& v,
01490 DO_WITHOUT_TEST_TAG);
01492
01494
01503 bool deleteIntTriangle(VertexHandle vh, TEST_IF_VALID_TAG) const;
01504 bool deleteIntTriangle(VertexHandle& vh, DO_IF_VALID_TAG);
01505 bool deleteIntTriangle(VertexHandle& vh, DO_WITHOUT_TEST_TAG);
01507
01509
01518 bool deleteBdTriangle(VertexHandle vh, TEST_IF_VALID_TAG) const;
01519 bool deleteBdTriangle(VertexHandle& vh, DO_IF_VALID_TAG);
01520 bool deleteBdTriangle(VertexHandle& vh, DO_WITHOUT_TEST_TAG);
01522
01524
01534 bool deleteCornerTriangle(VertexHandle vh, TEST_IF_VALID_TAG) const;
01535 bool deleteCornerTriangle(VertexHandle& vh, DO_IF_VALID_TAG);
01536 bool deleteCornerTriangle(VertexHandle& vh, DO_WITHOUT_TEST_TAG);
01538
01540
01552 bool moveIntVertex(VertexHandle v,
01553 const Geometry::Point& p,
01554 TEST_IF_VALID_TAG) const;
01555 bool moveIntVertex(VertexHandle& v,
01556 const Geometry::Point& p,
01557 DO_IF_VALID_TAG);
01558 bool moveIntVertex(VertexHandle& v,
01559 const Geometry::Point& p,
01560 DO_WITHOUT_TEST_TAG);
01562
01564
01576 bool moveVertexAlongBd(VertexHandle v,
01577 const Geometry::Point& p,
01578 TEST_IF_VALID_TAG) const;
01579 bool moveVertexAlongBd(VertexHandle& v,
01580 const Geometry::Point& p,
01581 DO_IF_VALID_TAG);
01582 bool moveVertexAlongBd(VertexHandle& v,
01583 const Geometry::Point& p,
01584 DO_WITHOUT_TEST_TAG);
01586
01588
01602 bool moveBdVertexPastCorner(BdEdgeHandle e,
01603 const Geometry::Point& p,
01604 TEST_IF_VALID_TAG) const;
01605 bool moveBdVertexPastCorner(BdEdgeHandle& e,
01606 const Geometry::Point& p,
01607 DO_IF_VALID_TAG);
01608 bool moveBdVertexPastCorner(BdEdgeHandle& e,
01609 const Geometry::Point& p,
01610 DO_WITHOUT_TEST_TAG);
01612
01614
01632 bool recolorQuadrilateral(IntEdgeHandle ab,
01633 IntEdgeHandle cd,
01634 bool ac,
01635 TEST_IF_VALID_TAG) const;
01636 bool recolorQuadrilateral(IntEdgeHandle& ab,
01637 IntEdgeHandle& cd,
01638 bool ac,
01639 DO_IF_VALID_TAG);
01640 bool recolorQuadrilateral(IntEdgeHandle& ab,
01641 IntEdgeHandle& cd,
01642 bool ac,
01643 DO_WITHOUT_TEST_TAG);
01645
01646 #ifdef GRID_EDGE_INDEX
01647
01658 bool compatible(const Geometry::Point &xp,
01659 const Geometry::Point &yp) const;
01660 #endif // #ifdef GRID_EDGE_INDEX
01661
01662 #ifdef TRIANGULATION_EDGE_INDEX
01663
01678 bool compatible(const Geometry::Point &xp,
01679 const Geometry::Point &yp,
01680 TFaceHandle fh = TFaceHandle()) const;
01681 #endif // #ifdef TRIANGULATION_EDGE_INDEX
01682
01697 bool trace(const Geometry::Point &xp,
01698 const Geometry::Point &yp,
01699 IntEdgeHandle& edge,
01700 Geometry::Point &ipt,
01701 Geometry::Kernel::FT& sd) const;
01702
01709 bool interior(const Geometry::Point& xp) const {
01710 return bd.has_on_bounded_side(xp);
01711 }
01712
01719 bool boundary(const Geometry::Point& xp) const {
01720 return bd.has_on_boundary(xp);
01721 }
01722
01729 bool outside(const Geometry::Point& xp) const {
01730 return bd.has_on_unbounded_side(xp);
01731 }
01732
01740 Geometry::Point
01741 randomPoint(Arak::Util::Random& random = Arak::Util::default_random) const;
01742
01748 double area() const {
01749 using namespace Arak::Geometry;
01750 return CGAL::to_double(bd.area());
01751 }
01752
01761 inline VertexHandle randomVertex(Vertex::Type type,
01762 Arak::Util::Random& random = Arak::Util::default_random) const {
01763 assert(numVertices(type) > 0);
01764 return getVertex(type, random.uniform(numVertices(type)));
01765 }
01766
01772 void getPointWithColor(Geometry::Point& p, Color& c) const;
01773
01784 Color color(const Geometry::Point& point) const;
01785
01794 bool solid(const Geometry::Polygon& poly, Arak::Color color) const;
01795
01801 void addListener(Listener& listener) const;
01802
01809 void addQueryPoints(const QueryPointIndex& index) const;
01810
01814 const QueryPointIndex& getQueryPoints() const { return *queryPoints; }
01815
01819 QueryPointIndex& getQueryPoints() { return *queryPoints; }
01820
01827 void write(std::ostream& out) const;
01828
01835 void writeBinary(std::ostream& out) const;
01836
01843 void writeXfig(std::ostream& out) const;
01844
01852 bool read(std::istream& in);
01853
01861 bool readBinary(std::istream& in);
01862
01877 template <typename FaceInfoType>
01878 void toTriangulation(CGAL::Constrained_Delaunay_triangulation_2<Geometry::Kernel,
01879 CGAL::Tds2<CGAL::Tvb<Arak::Geometry::Kernel, CGAL::Tdsvb<void> >,
01880 CGAL::Ctfb<Geometry::Kernel,
01881 CGAL::Triangulation_face_base_with_info_2<FaceInfoType,
01882 Geometry::Kernel, CGAL::Tfb<Arak::Geometry::Kernel,
01883 CGAL::Tdsfb<void> > > > >, CGAL::No_intersection_tag>& tri) const;
01884
01888 void visualize(CGAL::Qt_widget& widget,
01889 bool drawEdges = true,
01890 bool drawVertices = true,
01891 bool drawRegions = false,
01892 bool drawQueries = false) const;
01893
01898 bool operator==(const Coloring& other) const {
01899 return (this == &other);
01900 }
01901
01906 bool operator!=(const Coloring& other) const {
01907 return (this != &other);
01908 }
01909 };
01910
01918 inline std::ostream& operator<<(std::ostream& out, const Coloring& c) {
01919 c.write(out);
01920 return out;
01921 }
01922
01930 inline std::istream& operator>>(std::istream& in, Coloring& c) {
01931 if (!c.read(in))
01932 in.setstate(std::ios_base::failbit);
01933 return in;
01934 }
01935
01936 template <typename FaceInfoType>
01937 void Coloring::toTriangulation(CGAL::Constrained_Delaunay_triangulation_2<Geometry::Kernel,
01938 CGAL::Tds2<CGAL::Tvb<Arak::Geometry::Kernel, CGAL::Tdsvb<void> >,
01939 CGAL::Ctfb<Geometry::Kernel,
01940 CGAL::Triangulation_face_base_with_info_2<FaceInfoType,
01941 Geometry::Kernel, CGAL::Tfb<Arak::Geometry::Kernel,
01942 CGAL::Tdsfb<void> > > > >, CGAL::No_intersection_tag>& tri) const {
01943 typedef typename TriangulationTraits<FaceInfoType>::Triangulation
01944 Triangulation;
01945 typedef typename Triangulation::Vertex_handle TVh;
01946 typedef typename Triangulation::Face_handle TFh;
01947
01948 tri.clear();
01949
01950
01951 std::map<VertexHandle, TVh> c2t;
01952
01953 for (int i = 0; i < numVertices(Coloring::Vertex::CORNER); i++) {
01954 Coloring::VertexHandle v =
01955 getVertex(Coloring::Vertex::CORNER, i);
01956 c2t[v] = tri.insert(v->point());
01957 }
01958 for (int i = 0; i < numVertices(Coloring::Vertex::BOUNDARY); i++) {
01959 Coloring::VertexHandle v =
01960 getVertex(Coloring::Vertex::BOUNDARY, i);
01961 c2t[v] = tri.insert(v->point());
01962 }
01963 for (int i = 0; i < numVertices(Coloring::Vertex::INTERIOR); i++) {
01964 Coloring::VertexHandle v =
01965 getVertex(Coloring::Vertex::INTERIOR, i);
01966 c2t[v] = tri.insert(v->point());
01967 }
01968
01969 for (int i = 0; i < numInteriorEdges(); i++) {
01970 const Coloring::IntEdgeHandle e = getInteriorEdge(i);
01971 Coloring::VertexHandle u = e->getPrevVertex();
01972 Coloring::VertexHandle v = e->getNextVertex();
01973 tri.insert_constraint(c2t[u], c2t[v]);
01974 }
01975
01976 typedef typename Triangulation::Finite_faces_iterator FiniteFacesIterator;
01977 FiniteFacesIterator it = tri.finite_faces_begin();
01978 FiniteFacesIterator end = tri.finite_faces_end();
01979 while (it != end) {
01980 it->info().color = INVALID_COLOR;
01981 it++;
01982 }
01983
01984 Geometry::Point p;
01985 Color c;
01986 getPointWithColor(p, c);
01987 TFh fh = tri.locate(p);
01988 assert(!tri.is_infinite(fh));
01989 fh->info().color = c;
01990
01991 std::stack<TFh> unvisited;
01992 unvisited.push(fh);
01993 while (!unvisited.empty()) {
01994 fh = unvisited.top(); unvisited.pop();
01995 assert(fh->info().color != INVALID_COLOR);
01996
01997 for (int i = 0; i < 3; i++) {
01998 TFh nbr = fh->neighbor(i);
01999 if ((nbr->info().color == INVALID_COLOR) &&
02000 (!tri.is_infinite(nbr))) {
02001 if (fh->is_constrained(i))
02002 nbr->info().color = opposite(fh->info().color);
02003 else
02004 nbr->info().color = fh->info().color;
02005 unvisited.push(nbr);
02006 }
02007 }
02008 }
02009 }
02010
02011 }
02012
02013 #endif