BWAPI
SPAR/AIModule/BWTA/vendors/CGAL/CGAL/Nef_polyhedron_S2.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_S2/include/CGAL/Nef_polyhedron_S2.h $
00015 // $Id: Nef_polyhedron_S2.h 44152 2008-07-14 18:57:14Z hachenb $
00016 // 
00017 //
00018 // Author(s)     : Michael Seel       <seel@mpi-sb.mpg.de>
00019 //                 Peter Hachenberger <hachenberger@mpi-sb.mpg.de>
00020 
00021 #ifndef CGAL_NEF_POLYHEDRON_S2_H
00022 #define CGAL_NEF_POLYHEDRON_S2_H
00023 
00024 #if defined(BOOST_MSVC)
00025 #  pragma warning(push)
00026 #  pragma warning(disable:4800) // complaint about performance in std::map where we can't do anything
00027 #endif
00028 
00029 #include <CGAL/basic.h>
00030 #include <CGAL/Handle_for.h>
00031 #include <CGAL/Random.h>
00032 #include <CGAL/Nef_S2/SM_items.h>
00033 #include <CGAL/Nef_S2/Sphere_map.h>
00034 #include <CGAL/Nef_S2/SM_decorator.h>
00035 #include <CGAL/Nef_S2/SM_io_parser.h>
00036 #include <CGAL/Nef_S2/SM_point_locator.h>
00037 #include <CGAL/Nef_S2/SM_overlayer.h>
00038 #include <CGAL/Modifier_base.h>
00039 
00040 #include <vector>
00041 #include <list>
00042 #undef CGAL_NEF_DEBUG
00043 #define CGAL_NEF_DEBUG 53
00044 #include <CGAL/Nef_2/debug.h>
00045 
00046 CGAL_BEGIN_NAMESPACE
00047 
00048 template <typename K, typename I, typename Mk, typename M> class Nef_polyhedron_S2;
00049 template <typename K, typename I, typename Mk, typename M> class Nef_polyhedron_S2_rep;
00050 template <typename K, typename I, typename Mk> class Nef_polyhedron_3;
00051 class SNC_items;
00052 
00053 template <typename K, typename I, typename Mk, typename M>
00054 std::ostream& operator<<(std::ostream&, const Nef_polyhedron_S2<K,I,Mk,M>&); 
00055 template <typename K, typename I, typename Mk, typename M>
00056 std::istream& operator>>(std::istream&, Nef_polyhedron_S2<K,I,Mk,M>&);
00057 
00058 
00059 template <typename K, typename I, typename Mk, typename M>
00060 class Nef_polyhedron_S2_rep { 
00061 
00062   typedef Nef_polyhedron_S2_rep<K,I,Mk,M>        Self;
00063   friend class Nef_polyhedron_S2<K,I,Mk,M>;
00064 
00065  public:
00066   typedef CGAL::Sphere_geometry<K>                     Sphere_kernel;
00067   typedef Mk                                           Mark;
00068   typedef M                                            Sphere_map;
00069   typedef CGAL::SM_const_decorator<Sphere_map>         Const_decorator;
00070   typedef CGAL::SM_decorator<Sphere_map>               Decorator;
00071   typedef CGAL::SM_overlayer<Decorator>                Overlayer;
00072   typedef CGAL::SM_point_locator<Const_decorator>      Locator;
00073 
00074  private:
00075   Sphere_map sm_; 
00076   
00077 public:
00078   Nef_polyhedron_S2_rep() : sm_() {}
00079   Nef_polyhedron_S2_rep(const Self&) : sm_() {}
00080   ~Nef_polyhedron_S2_rep() { sm_.clear(); }
00081 };
00082 
00083 /*{\Moptions print_title=yes }*/ 
00084 /*{\Manpage {Nef_polyhedron_S2}{K}
00085 {Nef Polyhedra in the sphere surface}{N}}*/
00086 
00087 /*{\Mdefinition An instance of data type |\Mname| is a subset of $S_2$
00088 that is the result of forming complements and intersections starting
00089 from a finite set |H| of half-spaces. |\Mtype| is closed under all
00090 binary set operations |intersection|, |union|, |difference|,
00091 |complement| and under the topological operations |boundary|,
00092 |closure|, and |interior|.
00093 
00094 The template parameter |Kernel| is specified via a kernel concept. 
00095 |Kernel| must be a model of the concept |NefSphereKernelTraits_2|.
00096 }*/
00097 
00098 template <typename Kernel_, typename Items_ = SM_items, typename Mark_ = bool,  
00099           typename Map_ = Sphere_map<Sphere_geometry<Kernel_>,Items_, Mark_> >
00100 class Nef_polyhedron_S2 : public Handle_for< Nef_polyhedron_S2_rep<Kernel_,Items_,Mark_,Map_> >, 
00101                           public Nef_polyhedron_S2_rep<Kernel_,Items_,Mark_,Map_>::Const_decorator { 
00102   
00103 public:
00104   /*{\Mtypes 7}*/
00105   typedef Items_                                              Items;
00106   typedef Kernel_                                             Kernel;
00107   typedef Map_                                                Sphere_map;
00108   typedef Mark_                                               Mark;
00109   typedef Nef_polyhedron_S2<Kernel,Items,Mark,Sphere_map>     Self;
00110   typedef Nef_polyhedron_S2_rep<Kernel,Items,Mark,Sphere_map> Rep;
00111   typedef Handle_for< Nef_polyhedron_S2_rep<Kernel,Items,Mark,Sphere_map> >  Base;
00112   typedef typename Rep::Sphere_kernel                         Sphere_kernel;
00113 //  typedef typename Rep::Sphere_map                            Sphere_map;
00114 
00115   typedef typename Sphere_kernel::Sphere_point   Sphere_point;
00116   /*{\Mtypemember points in the sphere surface.}*/
00117 
00118   typedef typename Sphere_kernel::Sphere_segment Sphere_segment;
00119   /*{\Mtypemember segments in the sphere surface.}*/
00120 
00121   typedef typename Sphere_kernel::Sphere_circle  Sphere_circle;
00122   /*{\Mtypemember oriented great circles modeling spherical half-spaces}*/
00123 
00124   typedef typename Sphere_kernel::Sphere_direction Sphere_direction;
00125 
00126 
00127 //  typedef typename Rep::Mark Mark;
00128   /*{\Xtypemember marking set membership or exclusion.}*/
00129 
00130   enum Boundary { EXCLUDED=0, INCLUDED=1 };
00131   /*{\Menum construction selection.}*/
00132 
00133   enum Content { EMPTY=0, COMPLETE=1 };
00134   /*{\Menum construction selection}*/
00135 
00136   const Sphere_map& sphere_map() const { return this->ptr()->sm_; }
00137 protected:
00138   Sphere_map& sphere_map() { return this->ptr()->sm_; } 
00139 
00140   struct AND { bool operator()(const Mark& b1, const Mark& b2)  const { return b1&&b2; }  };
00141   struct OR { bool operator()(const Mark& b1, const Mark& b2)   const { return b1||b2; }  };
00142   struct DIFF { bool operator()(const Mark& b1, const Mark& b2) const { return b1&&!b2; } };
00143   struct XOR { bool operator()(const Mark& b1, const Mark& b2)  const 
00144                { return (b1&&!b2)||(!b1&&b2); } };   
00145 
00146   typedef Nef_polyhedron_S2_rep<Kernel,Items,Mark,Sphere_map>  Nef_rep;
00147   typedef typename Nef_rep::Decorator                     Decorator;
00148 public:
00149   typedef typename Nef_rep::Const_decorator               Const_decorator;
00150 protected:
00151   typedef typename Nef_rep::Overlayer                     Overlayer;
00152   typedef typename Nef_rep::Locator                       Locator;
00153 
00154   friend std::ostream& operator<< <>
00155       (std::ostream& os, const Self& NP);
00156   friend std::istream& operator>> <>
00157       (std::istream& is, Self& NP);
00158 
00159 public:
00160   typedef typename Decorator::SVertex_handle         SVertex_handle;
00161   typedef typename Decorator::SHalfedge_handle       SHalfedge_handle;
00162   typedef typename Decorator::SHalfloop_handle       SHalfloop_handle;
00163   typedef typename Decorator::SFace_handle           SFace_handle;
00164 
00165   typedef typename Sphere_map::SVertex_base          SVertex;
00166   typedef typename Sphere_map::SHalfedge_base        SHalfedge;
00167   typedef typename Sphere_map::SHalfloop             SHalfloop;
00168   typedef typename Sphere_map::SFace_base            SFace;
00169 
00170   typedef typename Decorator::SVertex_const_handle   SVertex_const_handle;
00171   typedef typename Decorator::SHalfedge_const_handle SHalfedge_const_handle;
00172   typedef typename Decorator::SHalfloop_const_handle SHalfloop_const_handle;
00173   typedef typename Decorator::SFace_const_handle     SFace_const_handle;
00174 
00175   typedef typename Decorator::SVertex_iterator       SVertex_iterator;
00176   typedef typename Decorator::SHalfedge_iterator     SHalfedge_iterator;
00177   typedef typename Decorator::SHalfloop_iterator     SHalfloop_iterator;
00178   typedef typename Decorator::SFace_iterator         SFace_iterator;
00179 
00180   typedef typename Const_decorator::SVertex_const_iterator   
00181                                                     SVertex_const_iterator;
00182   typedef typename Const_decorator::SHalfedge_const_iterator 
00183                                                     SHalfedge_const_iterator;
00184   typedef typename Const_decorator::SHalfloop_const_iterator 
00185                                                     SHalfloop_const_iterator;
00186   typedef typename Const_decorator::SFace_const_iterator     
00187                                                     SFace_const_iterator;
00188   typedef typename Const_decorator::Size_type Size_type;
00189   typedef Size_type size_type;
00190   
00191   typedef std::list<Sphere_segment>  SS_list;
00192   typedef typename SS_list::const_iterator SS_iterator;
00193 
00194   friend class Nef_polyhedron_3<Kernel, SNC_items, Mark>;
00195 
00196 public:
00197   /*{\Mcreation 3}*/
00198 
00199   Nef_polyhedron_S2(Content sphere = EMPTY) : Base(Nef_rep())
00200   /*{\Mcreate creates an instance |\Mvar| of type |\Mname|
00201   and initializes it to the empty set if |sphere == EMPTY|
00202   and to the whole sphere if |sphere == COMPLETE|.}*/
00203   {
00204     set_sm(&sphere_map());
00205     Decorator D(&sphere_map());
00206     SFace_handle sf=D.new_sface();
00207     sf->mark() = bool(sphere);
00208   }
00209 
00210 
00211   Nef_polyhedron_S2(const Sphere_circle& c, 
00212                     Boundary circle = INCLUDED) : Base(Nef_rep()) {
00213   /*{\Mcreate creates a Nef polyhedron |\Mvar| containing the half-sphere
00214   left of |c| including |c| if |circle==INCLUDED|, excluding |c| if 
00215   |circle==EXCLUDED|.}*/  
00216     
00217     set_sm(&sphere_map());
00218     CGAL_NEF_TRACEN("Nef_polyhedron_S2(): construction from circle "<<c);
00219     Decorator D(&sphere_map());
00220     Overlayer O(&sphere_map()); 
00221     O.create(c);
00222     SHalfloop_handle h = D.shalfloop();
00223     if ( h->circle() != c ) h = h->twin();
00224     h->incident_sface()->mark() = true;
00225     h->mark() = h->twin()->mark() = bool(circle);
00226   }
00227 
00228 
00229   template <class Forward_iterator>
00230   Nef_polyhedron_S2(Forward_iterator first, Forward_iterator beyond,
00231     Boundary b = INCLUDED) : Base(Nef_rep())
00232   /*{\Mcreate creates a Nef polyhedron |\Mvar| from the set of sphere
00233     segments in the iterator range |[first,beyond)|. If the set of sphere
00234     segments is a simple polygon that separates the sphere surface
00235     into two regions, then the polygonal region that is left of the
00236     segment |*first| is selected. The polygonal region includes its
00237     boundary if |b = INCLUDED| and excludes the boundary
00238     otherwise. |Forward_iterator| has to be an iterator with value
00239     type |Sphere_segment|.}*/
00240   { CGAL_NEF_TRACEN("Nef_polyhedron_S2(): creation from segment range");
00241     CGAL_assertion(first!=beyond);
00242     set_sm(&sphere_map());
00243     Overlayer D(&sphere_map());
00244     Sphere_segment s = *first;
00245     D.create_from_segments(first,beyond);
00246     SHalfedge_iterator e;
00247     CGAL_forall_shalfedges(e,D) {
00248       Sphere_circle c(e->circle());
00249       if ( c == s.sphere_circle() ) break;
00250     }
00251     if ( e != SHalfedge_iterator() ) {
00252       if ( e->circle() != s.sphere_circle() ) e = e->twin();
00253       CGAL_assertion( e->circle() == s.sphere_circle() );
00254       D.set_marks_in_face_cycle(e,bool(b));
00255       if ( D.number_of_sfaces() > 2 ) e->incident_sface()->mark() = true;
00256       else                            e->incident_sface()->mark() = !bool(b);
00257       return;
00258     }
00259     D.simplify();
00260   }
00261 
00262   Nef_polyhedron_S2(const Self& N1) : Base(N1), Const_decorator() {
00263     set_sm(&sphere_map());
00264   }
00265   Nef_polyhedron_S2& operator=(const Self& N1)
00266   { Base::operator=(N1); set_sm(&sphere_map()); return (*this); }
00267   ~Nef_polyhedron_S2() {}
00268 
00269   template <class Forward_iterator>
00270   Nef_polyhedron_S2(Forward_iterator first, Forward_iterator beyond, 
00271     double p) : Base(Nef_rep())
00272   /*{\Xcreate creates a random Nef polyhedron from the arrangement of
00273   the set of circles |S = set[first,beyond)|. The cells of the arrangement
00274   are selected uniformly at random with probability $p$. \precond $0 < p
00275   < 1$.}*/
00276   { CGAL_assertion(0<=p && p<=1);
00277     CGAL_assertion(first!=beyond);
00278     set_sm(&sphere_map());
00279     Overlayer D(&sphere_map());
00280     D.create_from_circles(first, beyond); D.simplify();
00281     SVertex_iterator v; SHalfedge_iterator e; SFace_iterator f;
00282     CGAL_forall_svertices(v,D)
00283       v->mark() = ( default_random.get_double() < p ? true : false );
00284     CGAL_forall_shalfedges(e,D)
00285       e->mark() = ( default_random.get_double() < p ? true : false );
00286     CGAL_forall_sfaces(f,D)
00287       f->mark() = ( default_random.get_double() < p ? true : false );
00288     D.simplify();
00289   }
00290 
00291  void delegate( Modifier_base<Sphere_map>& modifier) {
00292    // calls the `operator()' of the `modifier'. Precondition: The
00293    // `modifier' returns a consistent representation.
00294    modifier(sphere_map());
00295    //   CGAL_expensive_postcondition( is_valid());
00296  }
00297 
00298 //protected:
00299   Nef_polyhedron_S2(const Sphere_map& H, bool clone=true) : Base(Nef_rep()) 
00300   /*{\Xcreate makes |\Mvar| a new object.  If |clone==true| then the
00301   underlying structure of |H| is copied into |\Mvar|.}*/
00302 { 
00303     if(clone)
00304       this->ptr()->sm_ = H; 
00305     set_sm(&sphere_map());
00306   }
00307   
00308   void clone_rep() { *this = Self(sphere_map()); }
00309 
00310   /*{\Moperations 4 3 }*/
00311   public:
00312 
00313   void clear(Content plane = EMPTY)
00314   { *this = Nef_polyhedron_S2(plane); }
00315   /*{\Mop makes |\Mvar| the empty set if |plane == EMPTY| and the
00316   full plane if |plane == COMPLETE|.}*/
00317 
00318   bool is_empty() const
00319   /*{\Mop returns true if |\Mvar| is empty, false otherwise.}*/
00320   { Const_decorator D(&sphere_map());
00321     CGAL_NEF_TRACEN("is_empty()"<<*this);
00322     SFace_const_iterator f = D.sfaces_begin();
00323     return (D.number_of_svertices()==0 &&
00324             D.number_of_sedges()==0 &&
00325             D.number_of_sloops()==0 &&
00326             D.number_of_sfaces()==1 &&
00327             f->mark() == false);
00328   }
00329 
00330   bool is_plane() const
00331   /*{\Mop returns true if |\Mvar| is the whole plane, false otherwise.}*/
00332   { Const_decorator D(&sphere_map());
00333     SFace_const_iterator f = D.sfaces_begin();
00334     return (D.number_of_svertices()==0 &&
00335             D.number_of_sedges()==0 &&
00336             D.number_of_sloops()==0 &&
00337             D.number_of_sfaces()==1 &&
00338             f->mark() == true);
00339   }
00340 
00341   void extract_complement()
00342   { CGAL_NEF_TRACEN("extract complement");
00343     if ( this->is_shared() ) clone_rep();
00344     Overlayer D(&sphere_map());
00345     SVertex_iterator v;
00346     SHalfedge_iterator e;
00347     SFace_iterator f;
00348     CGAL_forall_svertices(v,D) v->mark() = !v->mark();
00349     CGAL_forall_sedges(e,D) e->mark() = !e->mark();
00350     CGAL_forall_sfaces(f,D) f->mark() = !f->mark();
00351     
00352     if ( D.has_shalfloop() )
00353       D.shalfloop()->mark() = 
00354         D.shalfloop()->twin()->mark() = 
00355         !D.shalfloop()->mark();
00356   }
00357 
00358   void extract_interior()
00359   { CGAL_NEF_TRACEN("extract interior");
00360     if ( this->is_shared() ) clone_rep();
00361     Overlayer D(&sphere_map());
00362     SVertex_iterator v;
00363     SHalfedge_iterator e;
00364     CGAL_forall_svertices(v,D) v->mark() = false;
00365     CGAL_forall_sedges(e,D) e->mark() = false;
00366     if ( D.has_sloop() ) D.shalfloop()->mark() = false;
00367     D.simplify();
00368   }
00369 
00370 
00371   void extract_boundary()
00372   { CGAL_NEF_TRACEN("extract boundary");
00373     if ( this->is_shared() ) clone_rep();
00374     Overlayer D(&sphere_map());
00375     SVertex_iterator v;
00376     SHalfedge_iterator e;
00377     SFace_iterator f;
00378     CGAL_forall_svertices(v,D) v->mark() = true;
00379     CGAL_forall_sedges(e,D)    e->mark() = true;
00380     CGAL_forall_sfaces(f,D)    f->mark() = false;
00381     if ( D.has_sloop() )       D.shalfloop()->mark() = D.shalfoop()->twin() = true;
00382     D.simplify();
00383   }
00384 
00385   void extract_closure()
00386   /*{\Xop converts |\Mvar| to its closure. }*/
00387   { CGAL_NEF_TRACEN("extract closure");
00388     extract_complement();
00389     extract_interior();
00390     extract_complement();
00391   }
00392 
00393   void extract_regularization()
00394   /*{\Xop converts |\Mvar| to its regularization. }*/
00395   { CGAL_NEF_TRACEN("extract regularization");
00396     extract_interior();
00397     extract_closure();
00398   }
00399 
00400   /*{\Mtext \headerline{Constructive Operations}}*/
00401 
00402   Self complement() const
00403   /*{\Mop returns the complement of |\Mvar| in the plane.}*/
00404   { Self res = *this;
00405     res.extract_complement();
00406     return res;
00407   }
00408 
00409 
00410   Self interior() const
00411   /*{\Mop returns the interior of |\Mvar|.}*/
00412   { Self res = *this;
00413     res.extract_interior();
00414     return res;
00415   }
00416 
00417   Self closure() const
00418   /*{\Mop returns the closure of |\Mvar|.}*/
00419   { Self res = *this;
00420     res.extract_closure();
00421     return res;
00422   }
00423 
00424   Self boundary() const
00425   /*{\Mop returns the boundary of |\Mvar|.}*/
00426   { Self res = *this;
00427     res.extract_boundary();
00428     return res;
00429   }
00430 
00431   Self regularization() const
00432   /*{\Mop returns the regularized polyhedron (closure of interior).}*/
00433   { Self res = *this;
00434     res.extract_regularization();
00435     return res;
00436   }
00437 
00438 
00439   Self intersection(const Self& N1) const
00440   /*{\Mop returns |\Mvar| $\cap$ |N1|. }*/
00441   { Self res(sphere_map(),false); // empty
00442     Overlayer D(&res.sphere_map());
00443     D.subdivide(&sphere_map(),&N1.sphere_map());
00444     AND _and; D.select(_and); D.simplify();
00445     return res;
00446   }
00447 
00448 
00449   Self join(const Self& N1) const
00450   /*{\Mop returns |\Mvar| $\cup$ |N1|. }*/
00451   { Self res(sphere_map(),false); // empty
00452     Overlayer D(&res.sphere_map());
00453     D.subdivide(&sphere_map(),&N1.sphere_map());
00454     OR _or; D.select(_or); D.simplify();
00455     return res;
00456   }
00457 
00458   Self difference(const Self& N1) const
00459   /*{\Mop returns |\Mvar| $-$ |N1|. }*/
00460   { Self res(sphere_map(),false); // empty
00461     Overlayer D(&res.sphere_map());
00462     D.subdivide(&sphere_map(),&N1.sphere_map());
00463     DIFF _diff; D.select(_diff); D.simplify();
00464     return res;
00465   }    
00466 
00467   Self symmetric_difference(
00468     const Self& N1) const
00469   /*{\Mop returns the symmectric difference |\Mvar - T| $\cup$ 
00470           |T - \Mvar|. }*/
00471   { Self res(sphere_map(),false); // empty
00472     Overlayer D(&res.sphere_map());
00473     D.subdivide(&sphere_map(),&N1.sphere_map());
00474     XOR _xor; D.select(_xor); D.simplify();
00475     return res;
00476   }
00477 
00478   /*{\Mtext Additionally there are operators |*,+,-,^,!| which
00479   implement the binary operations \emph{intersection}, \emph{union},
00480   \emph{difference}, \emph{symmetric difference}, and the unary
00481   operation \emph{complement} respectively. There are also the
00482   corresponding modification operations |*=,+=,-=,^=|.}*/
00483 
00484   Self  operator*(const Self& N1) const
00485   { return intersection(N1); }
00486 
00487   Self  operator+(const Self& N1) const
00488   { return join(N1); }
00489 
00490   Self  operator-(const Self& N1) const
00491   { return difference(N1); }
00492 
00493   Self  operator^(const Self& N1) const
00494   { return symmetric_difference(N1); }
00495 
00496   Self  operator!() const
00497   { return complement(); }
00498    
00499   Self& operator*=(const Self& N1)
00500   { *this = intersection(N1); return *this; }
00501 
00502   Self& operator+=(const Self& N1)
00503   { *this = join(N1); return *this; }
00504 
00505   Self& operator-=(const Self& N1)
00506   { *this = difference(N1); return *this; }
00507 
00508   Self& operator^=(const Self& N1)
00509   { *this = symmetric_difference(N1); return *this; }
00510 
00511   /*{\Mtext There are also comparison operations like |<,<=,>,>=,==,!=|
00512   which implement the relations subset, subset or equal, superset, superset
00513   or equal, equality, inequality, respectively.}*/
00514 
00515   bool operator==(const Self& N1) const
00516   { return symmetric_difference(N1).is_empty(); }
00517 
00518   bool operator!=(const Self& N1) const
00519   { return !operator==(N1); }  
00520 
00521   bool operator<=(const Self& N1) const
00522   { return difference(N1).is_empty(); } 
00523 
00524   bool operator<(const Self& N1) const
00525   { return difference(N1).is_empty() && !N1.difference(*this).is_empty(); } 
00526 
00527   bool operator>=(const Self& N1) const
00528   { return N1.difference(*this).is_empty(); } 
00529 
00530   bool operator>(const Self& N1) const   
00531   { return N1.difference(*this).is_empty() && !difference(N1).is_empty(); } 
00532 
00533 
00534   /*{\Mtext \headerline{Exploration - Point location - Ray shooting}
00535   As Nef polyhedra are the result of forming complements 
00536   and intersections starting from a set |H| of half-spaces that are
00537   defined by oriented lines in the plane, they can be represented by
00538   an attributed plane map $M = (V,E,F)$. For topological queries
00539   within |M| the following types and operations allow exploration
00540   access to this structure.}*/
00541 
00542   /*{\Mtypes 3}*/
00543   typedef Const_decorator Topological_explorer;
00544 
00545   typedef Const_decorator Explorer;
00546   /*{\Mtypemember a decorator to examine the underlying plane map. 
00547   See the manual page of |Explorer|.}*/
00548 
00549   typedef typename Locator::Object_handle Object_handle;
00550   /*{\Mtypemember a generic handle to an object of the underlying
00551   plane map. The kind of object |(vertex, halfedge, face)| can 
00552   be determined and the object can be assigned to a corresponding
00553   handle by the three functions:\\
00554   |bool assign(SVertex_const_handle& h, Object_handle)|\\
00555   |bool assign(SHalfedge_const_handle& h, Object_handle)|\\
00556   |bool assign(SFace_const_handle& h, Object_handle)|\\
00557   where each function returns |true| iff the assignment to
00558   |h| was done.}*/
00559 
00560 
00561   /*{\Moperations 3 1 }*/
00562 
00563   bool contains(Object_handle h) const
00564   /*{\Mop  returns true iff the object |h| is contained in the set
00565   represented by |\Mvar|.}*/
00566   { Locator PL(&sphere_map()); return PL.mark(h); }
00567 
00568   bool contained_in_boundary(Object_handle h) const
00569   /*{\Mop  returns true iff the object |h| is contained in the $1$-skeleton
00570   of |\Mvar|.}*/
00571   { SVertex_const_handle v;
00572     SHalfedge_const_handle e;
00573     return  ( CGAL::assign(v,h) || CGAL::assign(e,h) );
00574   }
00575 
00576 
00577   Object_handle locate(const Sphere_point& p) const
00578   /*{\Mop  returns a generic handle |h| to an object (face, halfedge, vertex) 
00579   of the underlying plane map that contains the point |p| in its relative 
00580   interior. The point |p| is contained in the set represented by |\Mvar| if 
00581   |\Mvar.contains(h)| is true. The location mode flag |m| allows one to choose
00582   between different point location strategies.}*/
00583   { 
00584     Locator PL(&sphere_map());
00585     return PL.locate(p); 
00586   }
00587 
00588   struct INSET {
00589     const Const_decorator& D;
00590     INSET(const Const_decorator& Di) : D(Di) {}
00591     bool operator()(SVertex_const_handle v) const { return v->mark(); }
00592     bool operator()(SHalfedge_const_handle e) const { return e->mark(); }
00593     bool operator()(SHalfloop_const_handle l) const { return l->mark(); }
00594     bool operator()(SFace_const_handle f) const { return f->mark(); }
00595   };
00596 
00597   Object_handle ray_shoot(const Sphere_point& p, 
00598                           const Sphere_direction& d) const
00599   /*{\Mop returns a handle |h| with |\Mvar.contains(h)| that can be
00600   converted to a |SVertex_/SHalfedge_/SFace_const_handle| as described
00601   above. The object returned is intersected by the ray starting in |p|
00602   with direction |d| and has minimal distance to |p|.  The operation
00603   returns the null handle |NULL| if the ray shoot along |d| does not hit
00604   any object |h| of |\Mvar| with |\Mvar.contains(h)|.}*/
00605   { 
00606     Locator PL(&sphere_map());
00607     return PL.ray_shoot(p,d,INSET(PL));
00608   }
00609 
00610   struct INSKEL {
00611     bool operator()(SVertex_const_handle) const { return true; }
00612     bool operator()(SHalfedge_const_handle) const { return true; }
00613     bool operator()(SHalfloop_const_handle) const { return true; }
00614     bool operator()(SFace_const_handle) const { return false; }
00615   };
00616 
00617   Object_handle ray_shoot_to_boundary(const Sphere_point& p, 
00618                                       const Sphere_direction& d) const
00619   /*{\Mop returns a handle |h| that can be converted to a
00620   |SVertex_/SHalfedge_const_handle| as described above. The object
00621   returned is part of the $1$-skeleton of |\Mvar|, intersected by the
00622   ray starting in |p| with direction |d| and has minimal distance to
00623   |p|.  The operation returns the null handle |NULL| if the ray shoot
00624   along |d| does not hit any $1$-skeleton object |h| of |\Mvar|. The
00625   location mode flag |m| allows one to choose between different point
00626   location strategies.}*/
00627   { 
00628     Locator PL(&sphere_map());
00629     return PL.ray_shoot(p,d,INSKEL());
00630   }
00631 
00632 
00633   //  Explorer explorer() const 
00634   /*{\Mop returns a decorator object which allows read-only access of
00635   the underlying plane map. See the manual page |Explorer| for its 
00636   usage.}*/
00637   //  { return Explorer(const_cast<Sphere_map*>(&sphere_map())); }
00638 
00639   /*{\Mtext\headerline{Input and Output}
00640   A Nef polyhedron |\Mvar| can be visualized in an open GL window. The 
00641   output operator is defined in the file 
00642   |CGAL/IO/Nef_\-poly\-hedron_2_\-Win\-dow_\-stream.h|.
00643   }*/
00644 
00645   /*{\Mimplementation Nef polyhedra are implemented on top of a halfedge
00646   data structure and use linear space in the number of vertices, edges
00647   and facets.  Operations like |empty| take constant time. The
00648   operations |clear|, |complement|, |interior|, |closure|, |boundary|,
00649   |regularization|, input and output take linear time. All binary set
00650   operations and comparison operations take time $O(n \log n)$ where $n$
00651   is the size of the output plus the size of the input.
00652 
00653   The point location and ray shooting operations are implemented in
00654   the naive way. The operations run in linear query time without
00655   any preprocessing.}*/
00656 
00657   /*{\Mexample Nef polyhedra are parameterized by a standard CGAL
00658   kernel. 
00659 
00660   \begin{Mverb}
00661   #include <CGAL/Homogeneous.h>
00662   #include <CGAL/leda_integer.h>
00663   #include <CGAL/Nef_polyhedron_S2.h>
00664   #include <CGAL/SM_items.h>
00665 
00666   using namespace CGAL;
00667   typedef  Homogeneous<leda_integer>   Kernel;
00668   typedef  SM_items<Kernel, bool>      SM_items;
00669   typedef  Nef_polyhedron_S2<SM_items> Nef_polyhedron;
00670   typedef  Nef_polyhedron::Sphere_circle Sphere_circle;
00671 
00672   int main()
00673   {
00674     Nef_polyhedron N1(Sphere_circle(1,0,0));
00675     Nef_polyhedron N2(Sphere_circle(0,1,0), Nef_polyhedron::EXCLUDED);
00676     Nef_polyhedron N3 = N1 * N2; // line (*)
00677     return 0;
00678   }
00679   \end{Mverb}
00680   After line (*) |N3| is the intersection of |N1| and |N2|.}*/
00681 
00682 
00683 }; // end of Nef_polyhedron_S2
00684 
00685 template <typename Kernel,typename Items,typename Mark, typename Sphere_map>
00686 std::ostream& operator<<
00687  (std::ostream& os, const Nef_polyhedron_S2<Kernel,Items,Mark,Sphere_map>& NP)
00688 {
00689   os << "Nef_polyhedron_S2\n";
00690   typedef typename Nef_polyhedron_S2<Kernel,Items,Mark,Sphere_map>::Explorer Decorator;
00691   CGAL::SM_io_parser<Decorator> O(os, Decorator(&NP.sphere_map())); 
00692   O.print();
00693   return os;
00694 }
00695 
00696 template <typename Kernel,typename Items, typename Mark, typename Sphere_map>
00697 std::istream& operator>>
00698   (std::istream& is, Nef_polyhedron_S2<Kernel,Items,Mark,Sphere_map>& NP)
00699 {
00700   typedef typename Nef_polyhedron_S2<Kernel,Items,Mark,Sphere_map>::Decorator Decorator;
00701   CGAL::SM_io_parser<Decorator> I(is, Decorator(&NP.sphere_map())); 
00702   //  if ( I.check_sep("Nef_polyhedron_S2") ) 
00703   I.read();
00704   /*
00705   else {
00706     std::cerr << "Nef_polyhedron_S2 input corrupted." << std::endl;
00707     NP = Nef_polyhedron_S2<Kernel,Items,Mark,Sphere_map>();
00708   }
00709   */
00710   /*
00711   typename Nef_polyhedron_S2<Kernel,Items,Mark,Sphere_map>::Topological_explorer D(NP.explorer());
00712   D.check_integrity_and_topological_planarity();
00713   */
00714   return is;
00715 }
00716 
00717 
00718 #if defined(BOOST_MSVC)
00719 #  pragma warning(pop)
00720 #endif
00721 
00722 CGAL_END_NAMESPACE
00723 #endif //CGAL_NEF_POLYHEDRON_S2_H
00724 
00725 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines