BWAPI
SPAR/AIModule/BWTA/vendors/CGAL/CGAL/Triangulation_ds_cell_base_3.h
Go to the documentation of this file.
00001 // Copyright (c) 1999-2005  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_3/include/CGAL/Triangulation_ds_cell_base_3.h $
00015 // $Id: Triangulation_ds_cell_base_3.h 48845 2009-04-21 18:34:14Z spion $
00016 //
00017 // Author(s)     : Monique Teillaud <Monique.Teillaud@sophia.inria.fr>
00018 //                 Sylvain Pion
00019 
00020 // cell of a triangulation data structure of any dimension <=3
00021 
00022 #ifndef CGAL_TRIANGULATION_DS_CELL_BASE_3_H
00023 #define CGAL_TRIANGULATION_DS_CELL_BASE_3_H
00024 
00025 #include <CGAL/basic.h>
00026 #include <CGAL/triangulation_assertions.h>
00027 #include <CGAL/Dummy_tds_3.h>
00028 
00029 CGAL_BEGIN_NAMESPACE
00030 
00031 template < typename TDS = void >
00032 class Triangulation_ds_cell_base_3
00033 {
00034 public:
00035   typedef TDS                          Triangulation_data_structure;
00036   typedef typename TDS::Vertex_handle  Vertex_handle;
00037   typedef typename TDS::Cell_handle    Cell_handle;
00038   typedef typename TDS::Vertex         Vertex;
00039   typedef typename TDS::Cell           Cell;
00040 
00041   template <typename TDS2>
00042   struct Rebind_TDS { typedef Triangulation_ds_cell_base_3<TDS2> Other; };
00043 
00044   Triangulation_ds_cell_base_3()
00045   {
00046     set_vertices();
00047     set_neighbors();
00048     set_in_conflict_flag(0);
00049   }
00050 
00051   Triangulation_ds_cell_base_3(const Vertex_handle& v0, const Vertex_handle& v1,
00052                                const Vertex_handle& v2, const Vertex_handle& v3)
00053   {
00054     set_vertices(v0, v1, v2, v3);
00055     set_neighbors();
00056     set_in_conflict_flag(0);
00057   }
00058 
00059   Triangulation_ds_cell_base_3(const Vertex_handle& v0, const Vertex_handle& v1,
00060                                const Vertex_handle& v2, const Vertex_handle& v3,
00061                                const Cell_handle&   n0, const Cell_handle&   n1,
00062                                const Cell_handle&   n2, const Cell_handle&   n3)
00063   {
00064     set_vertices(v0, v1, v2, v3);
00065     set_neighbors(n0, n1, n2, n3);
00066     set_in_conflict_flag(0);
00067   }
00068 
00069   // ACCESS FUNCTIONS
00070 
00071   const Vertex_handle& vertex(int i) const
00072   {
00073     CGAL_triangulation_precondition( i >= 0 && i <= 3 );
00074     return V[i];
00075   }
00076 
00077   bool has_vertex(const Vertex_handle& v) const
00078   {
00079     return (V[0] == v) || (V[1] == v) || (V[2]== v) || (V[3]== v);
00080   }
00081 
00082   bool has_vertex(const Vertex_handle& v, int & i) const
00083     {
00084       if (v == V[0]) { i = 0; return true; }
00085       if (v == V[1]) { i = 1; return true; }
00086       if (v == V[2]) { i = 2; return true; }
00087       if (v == V[3]) { i = 3; return true; }
00088       return false;
00089     }
00090 
00091   int index(const Vertex_handle& v) const
00092   {
00093     if (v == V[0]) { return 0; }
00094     if (v == V[1]) { return 1; }
00095     if (v == V[2]) { return 2; }
00096     CGAL_triangulation_assertion( v == V[3] );
00097     return 3;
00098   }
00099 
00100   const Cell_handle& neighbor(int i) const
00101   {
00102     CGAL_triangulation_precondition( i >= 0 && i <= 3);
00103     return N[i];
00104   }
00105 
00106   bool has_neighbor(const Cell_handle& n) const
00107   {
00108     return (N[0] == n) || (N[1] == n) || (N[2] == n) || (N[3] == n);
00109   }
00110 
00111   bool has_neighbor(const Cell_handle& n, int & i) const
00112   {
00113     if(n == N[0]){ i = 0; return true; }
00114     if(n == N[1]){ i = 1; return true; }
00115     if(n == N[2]){ i = 2; return true; }
00116     if(n == N[3]){ i = 3; return true; }
00117     return false;
00118   }
00119 
00120   int index(const Cell_handle& n) const
00121   {
00122     if (n == N[0]) return 0;
00123     if (n == N[1]) return 1;
00124     if (n == N[2]) return 2;
00125     CGAL_triangulation_assertion( n == N[3] );
00126     return 3;
00127   }
00128 
00129   // SETTING
00130 
00131   void set_vertex(int i, const Vertex_handle& v)
00132   {
00133     CGAL_triangulation_precondition( i >= 0 && i <= 3);
00134     V[i] = v;
00135   }
00136 
00137   void set_neighbor(int i, const Cell_handle& n)
00138   {
00139     CGAL_triangulation_precondition( i >= 0 && i <= 3);
00140     CGAL_triangulation_precondition( this != &*n );
00141     N[i] = n;
00142   }
00143 
00144   void set_vertices()
00145   {
00146     V[0] = V[1] = V[2] = V[3] = Vertex_handle();
00147   }
00148 
00149   void set_vertices(const Vertex_handle& v0, const Vertex_handle& v1,
00150                     const Vertex_handle& v2, const Vertex_handle& v3)
00151   {
00152     V[0] = v0;
00153     V[1] = v1;
00154     V[2] = v2;
00155     V[3] = v3;
00156   }
00157 
00158   void set_neighbors()
00159   {
00160     N[0] = N[1] = N[2] = N[3] = Cell_handle();
00161   }
00162 
00163   void set_neighbors(const Cell_handle& n0, const Cell_handle& n1,
00164                      const Cell_handle& n2, const Cell_handle& n3)
00165   {
00166     CGAL_triangulation_precondition( this != &*n0 );
00167     CGAL_triangulation_precondition( this != &*n1 );
00168     CGAL_triangulation_precondition( this != &*n2 );
00169     CGAL_triangulation_precondition( this != &*n3 );
00170     N[0] = n0;
00171     N[1] = n1;
00172     N[2] = n2;
00173     N[3] = n3;
00174   }
00175 
00176   // CHECKING
00177 
00178   // the following trivial is_valid allows
00179   // the user of derived cell base classes
00180   // to add their own purpose checking
00181   bool is_valid(bool = false, int = 0) const
00182   { return true; }
00183 
00184   // This is here in the *ds*_cell_base to ease its use as default
00185   // template parameter, so that the .dual() functions of Delaunay_3
00186   // still work.
00187   template < typename Traits >
00188   typename Traits::Point_3
00189   circumcenter(const Traits& gt) const
00190   {
00191     return gt.construct_circumcenter_3_object()(this->vertex(0)->point(),
00192                                                 this->vertex(1)->point(),
00193                                                 this->vertex(2)->point(),
00194                                                 this->vertex(3)->point());
00195   }
00196 
00197   // For use by Compact_container.
00198   void * for_compact_container() const { return N[0].for_compact_container(); }
00199   void * & for_compact_container()     { return N[0].for_compact_container(); }
00200 
00201   // Conflict flag access functions.
00202   // This should become a property map or something at some point.
00203   void set_in_conflict_flag(unsigned char f) { _in_conflict_flag = f; }
00204   unsigned char get_in_conflict_flag() const { return _in_conflict_flag; }
00205 
00206 private:
00207 
00208   Cell_handle   N[4];
00209   Vertex_handle V[4];
00210   unsigned char _in_conflict_flag;
00211 };
00212 
00213 template < class TDS >
00214 inline
00215 std::istream&
00216 operator>>(std::istream &is, Triangulation_ds_cell_base_3<TDS> &)
00217   // non combinatorial information. Default = nothing
00218 {
00219   return is;
00220 }
00221 
00222 template < class TDS >
00223 inline
00224 std::ostream&
00225 operator<<(std::ostream &os, const Triangulation_ds_cell_base_3<TDS> &)
00226   // non combinatorial information. Default = nothing
00227 {
00228   return os;
00229 }
00230 
00231 // Specialization for void.
00232 template <>
00233 class Triangulation_ds_cell_base_3<void>
00234 {
00235 public:
00236   typedef Dummy_tds_3                   Triangulation_data_structure;
00237   typedef Triangulation_data_structure::Vertex_handle   Vertex_handle;
00238   typedef Triangulation_data_structure::Cell_handle     Cell_handle;
00239   template <typename TDS2>
00240   struct Rebind_TDS { typedef Triangulation_ds_cell_base_3<TDS2> Other; };
00241 };
00242 
00243 CGAL_END_NAMESPACE
00244 
00245 #endif // CGAL_TRIANGULATION_DS_CELL_BASE_3_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines