BWAPI
SPAR/AIModule/BWTA/vendors/CGAL/CGAL/Triangulation_ds_face_base_2.h
Go to the documentation of this file.
00001 // Copyright (c) 1997  INRIA Sophia-Antipolis (France).
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/Triangulation_2/include/CGAL/Triangulation_ds_face_base_2.h $
00015 // $Id: Triangulation_ds_face_base_2.h 48844 2009-04-21 18:28:04Z spion $
00016 // 
00017 //
00018 // Author(s)     : Mariette Yvinec
00019 
00020 #ifndef CGAL_TRIANGULATION_DS_FACE_BASE_2_H
00021 #define CGAL_TRIANGULATION_DS_FACE_BASE_2_H
00022 
00023 #include <CGAL/basic.h>
00024 #include <CGAL/triangulation_assertions.h>
00025 #include <CGAL/Triangulation_utils_2.h>
00026 #include <CGAL/Dummy_tds_2.h>
00027 
00028 CGAL_BEGIN_NAMESPACE 
00029 
00030 template < typename TDS = void>
00031 class Triangulation_ds_face_base_2 
00032 {
00033 public:
00034   typedef TDS                          Triangulation_data_structure;
00035   typedef typename TDS::Vertex_handle  Vertex_handle;
00036   typedef typename TDS::Face_handle    Face_handle;
00037 
00038   template <typename TDS2>
00039   struct Rebind_TDS { typedef Triangulation_ds_face_base_2<TDS2> Other; }; 
00040 
00041 private:
00042   Vertex_handle V[3];
00043   Face_handle   N[3];
00044 
00045 public:
00046   Triangulation_ds_face_base_2();
00047   Triangulation_ds_face_base_2(Vertex_handle v0, 
00048                                Vertex_handle v1, 
00049                                Vertex_handle v2);
00050   Triangulation_ds_face_base_2(Vertex_handle v0, 
00051                                Vertex_handle v1, 
00052                                Vertex_handle v2,
00053                                Face_handle n0, 
00054                                Face_handle n1, 
00055                                Face_handle n2);
00056 
00057   Vertex_handle vertex(int i) const;
00058   bool has_vertex(Vertex_handle v) const;
00059   bool has_vertex(Vertex_handle v, int& i) const ;
00060   int index(Vertex_handle v) const ;
00061  
00062   Face_handle neighbor(int i) const ;
00063   bool has_neighbor(Face_handle n) const;
00064   bool has_neighbor(Face_handle n, int& i) const;
00065   int index(Face_handle n) const;
00066 
00067   void set_vertex(int i, Vertex_handle v);
00068   void set_vertices();
00069   void set_vertices(Vertex_handle v0, Vertex_handle v1, Vertex_handle v2);
00070   void set_neighbor(int i, Face_handle n) ;
00071   void set_neighbors();
00072   void set_neighbors(Face_handle n0, Face_handle n1, Face_handle n2);
00073   void reorient();
00074   void ccw_permute();
00075   void cw_permute();
00076   
00077   int dimension() const;
00078   //the following trivial is_valid to allow
00079   // the user of derived face base classes 
00080   // to add their own purpose checking
00081   bool is_valid(bool /* verbose */ = false, int /* level */ = 0) const
00082   {return true;}
00083   
00084    // For use by Compact_container.
00085   void * for_compact_container() const {return N[0].for_compact_container(); }
00086   void * & for_compact_container()     { return N[0].for_compact_container();}
00087 
00088 
00089   static int ccw(int i) {return Triangulation_cw_ccw_2::ccw(i);}
00090   static int  cw(int i) {return Triangulation_cw_ccw_2::cw(i);}
00091 
00092 };
00093 
00094 template <class TDS>
00095 Triangulation_ds_face_base_2<TDS> ::
00096 Triangulation_ds_face_base_2()
00097 {
00098   set_vertices();
00099   set_neighbors();
00100 }
00101 
00102 template <class TDS>
00103 Triangulation_ds_face_base_2<TDS> ::
00104 Triangulation_ds_face_base_2( Vertex_handle v0, 
00105                               Vertex_handle v1, 
00106                               Vertex_handle v2)
00107 {
00108   set_vertices(v0, v1, v2);
00109   set_neighbors();
00110 }
00111 
00112 template <class TDS>
00113 Triangulation_ds_face_base_2<TDS> ::
00114 Triangulation_ds_face_base_2(Vertex_handle v0, 
00115                              Vertex_handle v1, 
00116                              Vertex_handle v2,
00117                              Face_handle n0, 
00118                              Face_handle n1, 
00119                              Face_handle n2)
00120 {
00121   set_vertices(v0, v1, v2);
00122   set_neighbors(n0, n1, n2);
00123 }
00124 
00125 
00126 template <class TDS>
00127 inline 
00128 typename Triangulation_ds_face_base_2<TDS>::Vertex_handle
00129 Triangulation_ds_face_base_2<TDS>::
00130 vertex(int i) const
00131 {
00132   CGAL_triangulation_precondition( i == 0 || i == 1 || i == 2);
00133   return V[i];
00134 } 
00135 
00136 
00137 template <class TDS>
00138 inline bool
00139 Triangulation_ds_face_base_2<TDS> ::
00140 has_vertex(Vertex_handle v) const
00141 {
00142   return (V[0] == v) || (V[1] == v) || (V[2]== v);
00143 }
00144     
00145 template <class TDS>
00146 inline bool
00147 Triangulation_ds_face_base_2<TDS> ::    
00148 has_vertex(Vertex_handle v, int& i) const
00149 {
00150   if (v == V[0]) {
00151     i = 0;
00152     return true;
00153   }
00154   if (v == V[1]) {
00155     i = 1;
00156     return true;
00157   }
00158   if (v == V[2]) {
00159     i = 2;
00160     return true;
00161   }
00162   return false;
00163 }
00164     
00165 template <class TDS>    
00166 inline int
00167 Triangulation_ds_face_base_2<TDS> :: 
00168 index(Vertex_handle v) const
00169 {
00170   if (v == V[0]) return 0;
00171   if (v == V[1]) return 1;
00172   CGAL_triangulation_assertion( v == V[2] );
00173   return 2;
00174 }
00175 
00176 template <class TDS>    
00177 inline 
00178 typename Triangulation_ds_face_base_2<TDS>::Face_handle 
00179 Triangulation_ds_face_base_2<TDS>::
00180 neighbor(int i) const
00181 {
00182   CGAL_triangulation_precondition( i == 0 || i == 1 || i == 2);
00183   return N[i];
00184 }
00185     
00186 template <class TDS>      
00187 inline bool 
00188 Triangulation_ds_face_base_2<TDS> ::
00189 has_neighbor(Face_handle n) const
00190 {
00191   return (N[0] == n) || (N[1] == n) || (N[2] == n);
00192 }
00193     
00194     
00195 template <class TDS>      
00196 inline bool 
00197 Triangulation_ds_face_base_2<TDS> ::
00198 has_neighbor(Face_handle n, int& i) const
00199 {
00200   if(n == N[0]){
00201     i = 0;
00202     return true;
00203   }
00204   if(n == N[1]){
00205     i = 1;
00206     return true;
00207   }
00208   if(n == N[2]){
00209     i = 2;
00210     return true;
00211   }
00212   return false;
00213 }
00214 
00215     
00216     
00217 template <class TDS>      
00218 inline int 
00219 Triangulation_ds_face_base_2<TDS> ::
00220 index(Face_handle n) const
00221 {
00222   if (n == N[0]) return 0;
00223   if (n == N[1]) return 1;
00224   CGAL_triangulation_assertion( n == N[2] );
00225   return 2;
00226 }
00227     
00228 template <class TDS>      
00229 inline void
00230 Triangulation_ds_face_base_2<TDS> :: 
00231 set_vertex(int i, Vertex_handle v)
00232 {
00233   CGAL_triangulation_precondition( i == 0 || i == 1 || i == 2);
00234   V[i] = v;
00235 }
00236     
00237 template <class TDS>      
00238 inline void
00239 Triangulation_ds_face_base_2<TDS> ::     
00240 set_neighbor(int i, Face_handle n)
00241 {
00242   CGAL_triangulation_precondition( i == 0 || i == 1 || i == 2);
00243   CGAL_triangulation_precondition( this != &*n );
00244   N[i] = n;
00245 }
00246 
00247 template <class TDS>      
00248 inline void
00249 Triangulation_ds_face_base_2<TDS> :: 
00250 set_vertices()
00251 {
00252   V[0] = V[1] = V[2] = Vertex_handle();
00253 }
00254     
00255 template <class TDS>      
00256 inline void
00257 Triangulation_ds_face_base_2<TDS> ::     
00258 set_vertices(Vertex_handle v0,  Vertex_handle v1, Vertex_handle v2)
00259 {
00260   V[0] = v0;
00261   V[1] = v1;
00262   V[2] = v2;
00263 }
00264     
00265 template <class TDS>      
00266 inline void
00267 Triangulation_ds_face_base_2<TDS> :: 
00268 set_neighbors()
00269 {
00270   N[0] = N[1] = N[2] = Face_handle();
00271 }
00272     
00273 template <class TDS>      
00274 inline void
00275 Triangulation_ds_face_base_2<TDS> :: 
00276 set_neighbors(Face_handle n0,Face_handle n1, Face_handle n2)
00277 {
00278   CGAL_triangulation_precondition( this != &*n0 );
00279   CGAL_triangulation_precondition( this != &*n1 );
00280   CGAL_triangulation_precondition( this != &*n2 );
00281   N[0] = n0;
00282   N[1] = n1;
00283   N[2] = n2;
00284 }
00285 
00286 template <class TDS>
00287 void
00288 Triangulation_ds_face_base_2<TDS> :: 
00289 reorient()
00290 {
00291   //exchange the vertices 0 and 1
00292   set_vertices (V[1],V[0],V[2]);
00293   set_neighbors(N[1],N[0],N[2]);
00294 }
00295 
00296 template <class TDS>
00297 inline void 
00298 Triangulation_ds_face_base_2<TDS> ::
00299 ccw_permute()
00300 {
00301   set_vertices (V[2],V[0],V[1]);
00302   set_neighbors(N[2],N[0],N[1]);
00303 }
00304 
00305 
00306 template <class TDS>
00307 inline void 
00308 Triangulation_ds_face_base_2<TDS> ::
00309 cw_permute()
00310 {
00311   set_vertices (V[1],V[2],V[0]);
00312   set_neighbors(N[1],N[2],N[0]);
00313 }
00314 
00315 
00316 template < class TDS>
00317 inline  int 
00318 Triangulation_ds_face_base_2<TDS> ::
00319 dimension() const
00320 {
00321   if (V[2] != Vertex_handle()) {return 2;}
00322   else return( V[1] != Vertex_handle() ? 1 : 0);
00323 }
00324 
00325 template < class TDS >
00326 inline
00327 std::istream&
00328 operator>>(std::istream &is, Triangulation_ds_face_base_2<TDS> &)
00329   // non combinatorial information. Default = nothing
00330 {
00331   return is;
00332 }
00333 
00334 template < class TDS >
00335 inline
00336 std::ostream&
00337 operator<<(std::ostream &os, const Triangulation_ds_face_base_2<TDS> &)
00338   // non combinatorial information. Default = nothing
00339 {
00340   return os;
00341 }
00342 
00343 // Specialisation for void.
00344 template <>
00345 class Triangulation_ds_face_base_2<void>
00346 {
00347 public:
00348   typedef Dummy_tds_2                       Triangulation_data_structure;
00349   typedef Triangulation_data_structure::Vertex_handle   Vertex_handle;
00350   typedef Triangulation_data_structure::Face_handle     Face_handle;
00351   template <typename TDS2>
00352   struct Rebind_TDS { typedef Triangulation_ds_face_base_2<TDS2> Other; };
00353 };
00354 
00355 
00356 
00357 CGAL_END_NAMESPACE 
00358 
00359 #endif //CGAL_DS_TRIANGULATION_FACE_BASE_2_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines