BWAPI
SPAR/AIModule/BWTA/vendors/CGAL/CGAL/IO/Complex_2_in_triangulation_3_polyhedron_builder.h
Go to the documentation of this file.
00001 // Copyright (c) 2003-2007  INRIA Sophia-Antipolis (France).
00002 // Copyright (c) 2008       GeometryFactory (France)
00003 // All rights reserved.
00004 //
00005 // This file is part of CGAL (www.cgal.org); you may redistribute it under
00006 // the terms of the Q Public License version 1.0.
00007 // See the file LICENSE.QPL distributed with CGAL.
00008 //
00009 // Licensees holding a valid commercial license may use this file in
00010 // accordance with the commercial license agreement provided with the software.
00011 //
00012 // This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00013 // WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00014 //
00015 // $URL: svn+ssh://scm.gforge.inria.fr/svn/cgal/branches/CGAL-3.5-branch/Surface_mesher/include/CGAL/IO/Complex_2_in_triangulation_3_polyhedron_builder.h $
00016 // $Id: Complex_2_in_triangulation_3_polyhedron_builder.h 48774 2009-04-14 15:24:57Z lsaboret $
00017 //
00018 //
00019 // Author(s)     : Laurent Rineau
00020 
00021 #ifndef CGAL_IO_COMPLEX_2_IN_TRIANGULATION_3_POLYHEDRON_BUILDER_H
00022 #define CGAL_IO_COMPLEX_2_IN_TRIANGULATION_3_POLYHEDRON_BUILDER_H
00023 
00024 #include <CGAL/Modifier_base.h>
00025 #include <CGAL/Polyhedron_incremental_builder_3.h>
00026 
00027 namespace CGAL {
00028 
00029 template <class C2T3, class Polyhedron_>
00030 class Complex_2_in_triangulation_3_polyhedron_builder
00031   : public CGAL::Modifier_base<typename Polyhedron_::HalfedgeDS>
00032 {
00033 public:
00034   typedef C2T3 C2t3;
00035   typedef Polyhedron_ Polyhedron;
00036   typedef typename Polyhedron::HalfedgeDS HDS;
00037 
00038 private:
00039   typedef typename C2T3::Triangulation Tr;
00040 
00041   const C2t3& c2t3;
00042   typedef CGAL::Modifier_base<typename Polyhedron::HalfedgeDS> Base;
00043 
00044 public:
00045   Complex_2_in_triangulation_3_polyhedron_builder(const C2t3& c2t3)
00046     : Base(), c2t3(c2t3)
00047   {
00048   }
00049 
00050   void operator()(HDS& hds) {
00051     typedef typename Tr::Vertex_handle Vertex_handle;
00052     typedef typename Tr::Point Point;
00053     typedef typename Tr::Edge Edge;
00054     typedef typename Tr::Facet Facet;
00055     typedef typename Tr::Finite_vertices_iterator Finite_vertices_iterator;
00056     typedef typename Tr::Finite_facets_iterator Finite_facets_iterator;
00057 
00058     const Tr& tr = c2t3.triangulation();
00059     CGAL::Polyhedron_incremental_builder_3<HDS> builder(hds, true);
00060     const typename Tr::size_type number_of_facets = c2t3.number_of_facets();
00061     builder.begin_surface(tr.number_of_vertices(),
00062                           number_of_facets);
00063     {
00064       // Finite vertices coordinates.
00065       std::map<Vertex_handle, int> V;
00066       int inum = 0;
00067       for(Finite_vertices_iterator vit = tr.finite_vertices_begin();
00068           vit != tr.finite_vertices_end();
00069           ++vit)
00070       {
00071         V[vit] = inum++;
00072         Point p = static_cast<Point>(vit->point());
00073         builder.add_vertex(p);
00074       }
00075       Finite_facets_iterator fit = tr.finite_facets_begin();
00076       std::set<Facet> oriented_set;
00077       std::stack<Facet> stack;
00078 
00079       CGAL_assertion_code(typename Tr::size_type nb_facets = 0; )
00080 
00081         while (oriented_set.size() != number_of_facets) {
00082           while ( fit->first->is_facet_on_surface(fit->second) == false ||
00083                   oriented_set.find(*fit) != oriented_set.end() ||
00084 
00085                   oriented_set.find(c2t3.opposite_facet(*fit)) !=
00086                   oriented_set.end() ) {
00087             ++fit;
00088           }
00089           oriented_set.insert(*fit);
00090           stack.push(*fit);
00091           while(! stack.empty() ) {
00092             Facet f = stack.top();
00093             stack.pop();
00094             for(int ih = 0 ; ih < 3 ; ++ih) {
00095               const int i1  = tr.vertex_triple_index(f.second, tr. cw(ih));
00096               const int i2  = tr.vertex_triple_index(f.second, tr.ccw(ih));
00097               if( c2t3.face_status(Edge(f.first, i1, i2)) == C2t3::REGULAR ) {
00098                 Facet fn = c2t3.neighbor(f, ih);
00099                 if (oriented_set.find(fn) == oriented_set.end() &&
00100                     oriented_set.find(c2t3.opposite_facet(fn)) == oriented_set.end())
00101                 {
00102                   oriented_set.insert(fn);
00103                   stack.push(fn);
00104                 }
00105               } // end "if the edge is regular"
00106             } // end "for each neighbor of f"
00107           } // end "stack non empty"
00108         } // end "oriented_set not full"
00109 
00110       for(typename std::set<Facet>::const_iterator fit =
00111             oriented_set.begin();
00112           fit != oriented_set.end();
00113           ++fit)
00114       {
00115         int indices[3];
00116         int index = 0;
00117         for (int i=0; i<3; i++)
00118           indices[index++] =
00119             V[fit->first->vertex(tr.vertex_triple_index(fit->second, i))];
00120         builder.add_facet(indices+0, indices+3);
00121         CGAL_assertion_code(++nb_facets);
00122       }
00123       CGAL_assertion(nb_facets == number_of_facets);
00124       //        for( Finite_facets_iterator fit = tr.finite_facets_begin();
00125       //             fit != tr.finite_facets_end(); ++fit)
00126       //          if ((*fit).first->is_facet_on_surface((*fit).second)==true)
00127       //          {
00128       //            int indices[3];
00129       //            int index = 0;
00130       //            for (int i=0; i<3; i++)
00131       //              std::cerr << ( indices[index++] = V[(*fit).first->vertex(tr.vertex_triple_index(fit->second, i))] ) << ", ";
00132       //            std::cerr << "\n";
00133       //            if( builder.test_facet(indices+0, indices+3) )
00134       //              builder.add_facet(indices+0, indices+3);
00135       //            else
00136       //            {
00137       //              builder.begin_facet();
00138       //              builder.add_vertex_to_facet(indices[2]);
00139       //              builder.add_vertex_to_facet(indices[1]);
00140       //              builder.add_vertex_to_facet(indices[0]);
00141       //              builder.end_facet();
00142       //            }
00143       //            CGAL_assertion_code(++nb_facets);
00144       //          }
00145     }
00146     builder.end_surface();
00147   } // end operator()
00148 }; // end Complex_2_in_triangulation_3_polyhedron_builder
00149 
00150 } // end namespace CGAL
00151 
00152 #endif  // CGAL_IO_COMPLEX_2_IN_TRIANGULATION_3_POLYHEDRON_BUILDER_H
00153 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines