BWAPI
SPAR/AIModule/BWTA/vendors/CGAL/CGAL/Nef_2/PM_persistent_PL.h
Go to the documentation of this file.
00001 // Copyright (c) 1997-2000  Max-Planck-Institute Saarbruecken (Germany).
00002 // All rights reserved.
00003 //
00004 // This file is part of CGAL (www.cgal.org); you may redistribute it under
00005 // the terms of the Q Public License version 1.0.
00006 // See the file LICENSE.QPL distributed with CGAL.
00007 //
00008 // Licensees holding a valid commercial license may use this file in
00009 // accordance with the commercial license agreement provided with the software.
00010 //
00011 // This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00012 // WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00013 //
00014 // $URL: svn+ssh://scm.gforge.inria.fr/svn/cgal/branches/CGAL-3.5-branch/Nef_2/include/CGAL/Nef_2/PM_persistent_PL.h $
00015 // $Id: PM_persistent_PL.h 48717 2009-04-08 11:54:51Z spion $
00016 // 
00017 //
00018 // Author(s)     : Michael Seel <seel@mpi-sb.mpg.de>
00019 
00020 #ifndef CGAL_PM_PERSISTENT_PL_H
00021 #define CGAL_PM_PERSISTENT_PL_H
00022 
00023 #include <CGAL/Nef_2/gen_point_location.h>
00024 
00025 template <typename PMPL>
00026 struct PM_persistent_PL_traits 
00027 {
00028   typedef PMPL  Graph;
00029   typedef typename PMPL::Vertex_const_handle   Node;
00030   typedef typename PMPL::Halfedge_const_handle Edge;
00031   typedef typename PMPL::Face_const_handle     Face;
00032   typedef typename PMPL::Object_handle         Object_handle;
00033 
00034   typedef typename PMPL::Geometry  Geometry;
00035   typedef typename PMPL::Point     Point;
00036   typedef typename PMPL::Segment   Segment;
00037   const Geometry* pK;
00038 
00039   typedef typename PMPL::Vertex_const_iterator NodeIterator;
00040   NodeIterator Nodes_begin(const Graph& G) const { return G.vertices_begin(); }
00041   NodeIterator Nodes_end(const Graph& G) const { return G.vertices_end(); }
00042   Node toNode(const NodeIterator& nit) const { return nit; }
00043 
00044   typedef typename PMPL::Halfedge_around_vertex_const_circulator HAVC;
00045   struct IncEdgeIterator {
00046     HAVC _start, _curr;
00047     bool met;
00048     IncEdgeIterator() {}
00049     IncEdgeIterator(HAVC c) : 
00050       _start(c), _curr(c), met(false) {}
00051     IncEdgeIterator& operator++()
00052     { if (_curr==_start)
00053         if (!met)  { met=true; ++_curr; }
00054         else       { _curr=HAVC(); }
00055       else ++_curr;
00056       return *this; 
00057     }
00058     bool operator==(const IncEdgeIterator& it2) const
00059     { return _curr==it2._curr; }
00060     bool operator!=(const IncEdgeIterator& it2) const
00061     { return !(*this==it2); }
00062   };
00063   Edge toEdge(const IncEdgeIterator& eit) const { return eit._curr; }
00064 
00065   IncEdgeIterator IncEdges_begin(const Graph& G, const Node& n) 
00066   { return IncEdgeIterator(HAVC(G.first_out_edge(n))); }
00067   IncEdgeIterator IncEdges_end(const Graph& G, const Node& n)   
00068   { return IncEdgeIterator(); }
00069 
00070   enum EdgeCategory 
00071   { StartingNonVertical, StartingVertical, EndingNonVertical, EndingVertical };
00072 
00073   Node opposite(const Graph& G, const Edge& e, const Node& u)
00074   { if ( G.source(e) == u ) return G.target(e);
00075     else                    return G.source(e); }
00076 
00077   EdgeCategory ClassifyEdge(const Graph& G, const Edge& e, const Node& u)
00078   {
00079     Point p_u = G.point(u);
00080     Point p_v = G.point(opposite(G,e,u));
00081 
00082     int cmpX = pK->compare_x(p_u, p_v);
00083     if ( cmpX < 0 ) return StartingNonVertical;
00084     if ( cmpX > 0 ) return EndingNonVertical;
00085 
00086     int cmpY = pK->compare_y(p_u, p_v); 
00087     CGAL_assertion(cmpY != 0);
00088     if ( cmpY < 0 ) return StartingVertical;
00089     return EndingVertical;
00090   }    
00091 
00092   typedef Point XCoord;
00093   const XCoord getXCoord(const Point& p) const 
00094   { return p; }
00095   const XCoord getXCoord(const Graph& G, const Node& n) const 
00096   { return G.point(n); }
00097 
00098   class PredLessThanX {
00099     const Geometry* pK;
00100   public:
00101     PredLessThanX() : pK(0) {}
00102     PredLessThanX(const Geometry* pKi) : pK(pKi) {}
00103     PredLessThanX(const PredLessThanX& P) : pK(P.pK) 
00104     { CGAL_NEF_TRACEN("copy PredLessThanX"); }
00105     int operator() (const XCoord& x1, const XCoord& x2) const
00106     { return pK->compare_x(x1,x2) < 0; }
00107   };
00108   PredLessThanX getLessThanX() const { return PredLessThanX(pK); }
00109 
00110   // Curve connected functionality:
00111   typedef Segment  Curve;
00112 
00113   Curve makeCurve(const Point& p) const 
00114   { return pK->construct_segment(p,p); }
00115   Curve makeCurve(const Graph& G, const Node& n) const
00116   { return makeCurve(G.point(n)); }
00117   Curve makeCurve(const Graph& G, const Edge& e) const
00118   { Point ps = G.point(G.source(e)), pt = G.point(G.target(e));
00119     Curve res(G.point(G.source(e)),G.point(G.target(e)));
00120     if ( pK->compare_xy(ps,pt) < 0 ) res = pK->construct_segment(ps,pt);
00121     else                             res = pK->construct_segment(pt,ps);
00122     return res; 
00123   }
00124 
00125   struct PredCompareCurves {
00126    const Geometry* pK;
00127    PredCompareCurves() : pK(0) {}
00128    PredCompareCurves(const Geometry* pKi) : pK(pKi) {}
00129    PredCompareCurves(const PredCompareCurves& P) : pK(P.pK) {}
00130 
00131    int cmppntseg(const Point& p, const Curve& s) const
00132    { 
00133      if ( pK->compare_x(pK->source(s),pK->target(s)) != 0 ) // !vertical
00134        return pK->orientation(pK->source(s),pK->target(s), p); 
00135      if ( pK->compare_y(p,pK->source(s)) <= 0 ) return -1;
00136      if ( pK->compare_y(p,pK->target(s)) >= 0 ) return +1;
00137      return 0;
00138    }
00139 
00140    int operator()(const Curve& s1, const Curve& s2) const
00141    { 
00142      Point a = pK->source(s1); 
00143      Point b = pK->target(s1);
00144      Point c = pK->source(s2);
00145      Point d = pK->target(s2);
00146      if ( a==b ) 
00147        if ( c==d ) return pK->compare_y(a,c);
00148        else        return  cmppntseg(a, s2);
00149      if ( c==d )   return -cmppntseg(c, s1);
00150      // now both are non-trivial:
00151      int cmpX = pK->compare_x(a, c);
00152      if ( cmpX < 0 ) 
00153        return - pK->orientation(a,b,c);
00154      if ( cmpX > 0 ) 
00155        return   pK->orientation(c,d,a);
00156 
00157      int cmpY = pK->compare_y(a, c);
00158      if ( cmpY < 0 ) return -1;
00159      if ( cmpY > 0 )  return +1;
00160       
00161      // cmpX == cmpY == 0 => a == c
00162      return pK->orientation(c,d,b);
00163    }
00164   };
00165 
00166   PredCompareCurves getCompareCurves() const
00167   { return PredCompareCurves(pK); }
00168 
00169   typedef GenericLocation<Node, Edge> Location;
00170   typedef Object_handle QueryResult;
00171 
00172   virtual Object_handle 
00173   PostProcess(const Location& L, const Location& L_plus, 
00174     const Point& p) const 
00175   { /* we only get an L_plus (non-nil) if L is ABOVE a vertex
00176        in which case we want to extract the face from the edge
00177        below (p+epsilon) available via L_plus. */
00178     if (!L_plus.is_nil()) { CGAL_assertion(L_plus.is_edge());
00179       return Object_handle(Edge(L_plus));
00180     } else { 
00181       if ( L.is_edge() ) {
00182         return Object_handle(Edge(L));
00183       }
00184       if ( L.is_node() ) {
00185         Node v(L); CGAL_assertion( v != Node() );
00186         return Object_handle(v);
00187       }
00188       return Object_handle();
00189     }
00190   }
00191 
00192   PM_persistent_PL_traits() : pK(0) {}
00193   PM_persistent_PL_traits(const Geometry& k) : pK(&k) {}
00194   virtual ~PM_persistent_PL_traits() {}
00195   virtual void sweep_begin(const Graph&) {}
00196   virtual void sweep_moveto(const XCoord&) {}
00197   virtual void sweep_end() {}
00198   virtual void clear() {}
00199 
00200 };
00201 
00202 
00203 #endif // CGAL_PM_PM_PERSISTENT_PL_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines