BWAPI
SPAR/AIModule/BWTA/vendors/CGAL/CGAL/Minkowski_sum_3/Gaussian_map_to_nef_3.h
Go to the documentation of this file.
00001 // Copyright (c) 2005-2008 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: 
00015 // $Id: 
00016 // 
00017 //
00018 // Author(s)     :  Peter Hachenberger <hachenberger@mpi-sb.mpg.de>
00019 #ifndef CGAL_MINKOWSKI_GAUSSIAN_MAP_TO_NEF_3_H
00020 #define CGAL_MINKOWSKI_GAUSSIAN_MAP_TO_NEF_3_H
00021 
00022 #include <CGAL/Nef_S2/SM_decorator.h>
00023 #include <CGAL/Minkowski_sum_3/Gaussian_map.h>
00024 #include <CGAL/Modifier_base.h>
00025 
00026 CGAL_BEGIN_NAMESPACE
00027 
00028 template<typename Nef3>
00029   class Gaussian_map_to_nef_3 : public Modifier_base<typename Nef3::SNC_structure > {
00030     
00031   typedef typename Nef3::Kernel                   Kernel;
00032   typedef typename Nef3::SNC_structure            SNC_structure;
00033   typedef typename SNC_structure::Sphere_map      Sphere_map;
00034   typedef CGAL::SM_decorator<Sphere_map>          SM_decorator;
00035   typedef CGAL::Gaussian_map<Kernel, Nef3>        Gaussian_map;
00036 
00037   typedef typename Gaussian_map::SFace_const_iterator       SFace_const_iterator;
00038   typedef typename Gaussian_map::SFace_const_handle         SFace_const_handle;
00039   typedef typename Gaussian_map::SHalfedge_const_iterator   SHalfedge_const_iterator;
00040   typedef typename Gaussian_map::SHalfedge_const_handle     SHalfedge_const_handle;
00041   typedef typename Gaussian_map::SHalfloop_const_handle     SHalfloop_const_handle;
00042   typedef typename Gaussian_map::SVertex_const_iterator     SVertex_const_iterator;
00043   typedef typename Gaussian_map::SVertex_const_handle       SVertex_const_handle;
00044   typedef typename Gaussian_map::SHalfedge_around_sface_const_circulator
00045     SHalfedge_around_sface_const_circulator;
00046 
00047   typedef typename SNC_structure::Vertex_handle            Vertex_handle;
00048   typedef typename SNC_structure::SVertex_handle           SVertex_handle;
00049   typedef typename SNC_structure::SHalfedge_handle         SHalfedge_handle;
00050   typedef typename SNC_structure::SFace_handle             SFace_handle;
00051   
00052   typedef typename SNC_structure::Sphere_circle            Sphere_circle;
00053   typedef typename SNC_structure::Sphere_point             Sphere_point;
00054 
00055   const Gaussian_map& G;
00056 
00057  public:
00058   Gaussian_map_to_nef_3(const Gaussian_map& Gin) : G(Gin) {}
00059     
00060   void create_solid(SNC_structure& snc) {
00061   
00062     CGAL::Unique_hash_map<SHalfedge_const_handle, int> SE2i;
00063     SHalfedge_const_iterator sei;
00064     CGAL_forall_sedges(sei, G) {
00065       SE2i[sei] = Index_generator::get_unique_index();
00066       SE2i[sei->twin()] = SE2i[sei];
00067     }
00068     
00069     CGAL::Unique_hash_map
00070       <SVertex_const_handle, std::pair<int, int> > SV2i;
00071     SVertex_const_iterator svi;
00072     CGAL_forall_svertices(svi, G)
00073       SV2i[svi] = std::pair<int, int>
00074       (Index_generator::get_unique_index(), 
00075        Index_generator::get_unique_index());
00076     
00077     CGAL::Unique_hash_map<SFace_const_handle, Vertex_handle> sface2vertex;
00078     SFace_const_iterator sfi;
00079     for(sfi = G.sfaces_begin(); sfi != G.sfaces_end(); ++sfi) {
00080       sface2vertex[sfi] = snc.new_vertex(sfi->mark().point(), 
00081                                          sfi->mark().boolean());
00082     }
00083 
00084     for(sfi = G.sfaces_begin(); sfi != G.sfaces_end(); ++sfi) {
00085       Vertex_handle v = sface2vertex[sfi];
00086       SM_decorator SM(&*v);
00087 
00088       SHalfedge_const_handle sec = sfi->sface_cycles_begin();
00089       SHalfedge_around_sface_const_circulator sfc(sec), sfcend(sfc);
00090       
00091       SVertex_handle sv, sv_prev, sv_first;
00092       SHalfedge_handle se, se_prev, se_first;
00093       sv_first = 
00094         SM.new_svertex(sface2vertex[sfc->twin()->incident_sface()]->point()-v->point());
00095       sv_first->mark() = sfc->mark().boolean();
00096       sv_first->set_index(SE2i[sfc]);
00097       ++sfc;
00098       sv_prev = sv = 
00099         SM.new_svertex(sface2vertex[sfc->twin()->incident_sface()]->point()-v->point());
00100       sv->mark() = sfc->mark().boolean();
00101       sv->set_index(SE2i[sfc]);
00102       se_first = se_prev = SM.new_shalfedge_pair(sv_first, sv_prev);
00103       se_first->mark() = se_first->twin()->mark() = sfc->source()->mark().boolean();
00104       se_first->set_index(SV2i[sfc->source()].first);
00105       se_first->twin()->set_index(SV2i[sfc->source()].second);
00106       se_first->circle() = Sphere_circle(sv_first->point(), sv->point());
00107       se_first->circle() = normalized(se_first->circle());
00108       se_first->twin()->circle() = se_first->circle().opposite();
00109 
00110       ++sfc;
00111       CGAL_For_all(sfc,sfcend) {
00112         sv = SM.new_svertex(sface2vertex[sfc->twin()->incident_sface()]->point()-v->point());
00113         sv->mark() = sfc->mark().boolean();
00114         sv->set_index(SE2i[sfc]);       
00115         se = SM.new_shalfedge_pair(sv_prev, sv);
00116         se->mark() = se->twin()->mark() = sfc->source()->mark().boolean();
00117         se->set_index(SV2i[sfc->source()].first);
00118         se->twin()->set_index(SV2i[sfc->source()].second);
00119         se->circle() = Sphere_circle(sv_prev->point(), sv->point());
00120         se->circle() = normalized(se->circle());
00121         se->twin()->circle() = se->circle().opposite();
00122         se->sprev() = se_prev;
00123         se_prev->snext() = se;  
00124         sv_prev = sv;
00125         se_prev = se;
00126       }
00127      
00128       se = SM.new_shalfedge_pair(sv_prev, sv_first);
00129       se->mark() = se->twin()->mark() = sfc->source()->mark().boolean();
00130       se->set_index(SV2i[sfc->source()].first);
00131       se->twin()->set_index(SV2i[sfc->source()].second);
00132       se->circle() = Sphere_circle(sv_prev->point(), sv_first->point());
00133       se->circle() = normalized(se->circle());
00134       se->twin()->circle() = se->circle().opposite();
00135       se->sprev() = se_prev;
00136       se_prev->snext() = se;
00137       se_first->sprev() = se;
00138       se->snext() = se_first;
00139 
00140       SFace_handle sf0 = SM.new_sface();
00141       SFace_handle sf1 = SM.new_sface();
00142       sf0->mark() = false;
00143       sf1->mark() = true;
00144       SM.link_as_face_cycle(se,sf0);
00145       SM.link_as_face_cycle(se->twin(),sf1);
00146     }
00147   }
00148 
00149   void create_single_vertex(SNC_structure& snc) {
00150     Vertex_handle v = 
00151       snc.new_vertex(G.sfaces_begin()->mark().point(),
00152                      G.sfaces_begin()->mark().boolean());
00153     SM_decorator SM(&*v);
00154     SFace_handle sf = SM.new_sface();
00155     sf->mark() = false;
00156   }
00157 
00158   void create_single_edge(SNC_structure& snc) {
00159     SHalfloop_const_handle slc = G.shalfloop();
00160     Vertex_handle v0 = 
00161       snc.new_vertex(slc->incident_sface()->mark().point(),
00162                      slc->incident_sface()->mark().boolean());
00163     SM_decorator SM0(&*v0);
00164     SVertex_handle sv0 = SM0.new_svertex();
00165     sv0->point() = slc->circle().orthogonal_vector();
00166     sv0->mark() = true;
00167     SFace_handle sf0 = SM0.new_sface();
00168     sf0->mark() = false;
00169     SM0.link_as_isolated_vertex(sv0, sf0);
00170 
00171     Vertex_handle v1 = 
00172       snc.new_vertex(slc->twin()->incident_sface()->mark().point(),
00173                      slc->twin()->incident_sface()->mark().boolean());
00174     SM_decorator SM1(&*v1);
00175     SVertex_handle sv1 = SM1.new_svertex();
00176     sv1->point() = sv0->point().antipode();
00177     sv1->mark() = true;
00178     SFace_handle sf1 = SM1.new_sface();
00179     sf1->mark() = false;
00180     SM1.link_as_isolated_vertex(sv1, sf1);
00181   }
00182 
00183   void create_single_facet(SNC_structure& snc) {
00184        CGAL::Unique_hash_map<SHalfedge_const_handle, int> SE2i;
00185     SHalfedge_const_iterator sei;
00186     CGAL_forall_sedges(sei, G) {
00187       SE2i[sei] = Index_generator::get_unique_index();
00188       SE2i[sei->twin()] = SE2i[sei];
00189     }
00190     
00191     CGAL::Unique_hash_map
00192       <SVertex_const_handle, std::pair<int, int> > SV2i;
00193     SVertex_const_iterator svi;
00194     CGAL_forall_svertices(svi, G)
00195       SV2i[svi] = std::pair<int, int>
00196       (Index_generator::get_unique_index(), 
00197        Index_generator::get_unique_index());
00198     
00199     CGAL::Unique_hash_map<SFace_const_handle, Vertex_handle> sface2vertex;
00200     SFace_const_iterator sfi;
00201     for(sfi = G.sfaces_begin(); sfi != G.sfaces_end(); ++sfi) {
00202       sface2vertex[sfi] = snc.new_vertex(sfi->mark().point(), 
00203                                          sfi->mark().boolean());
00204     }
00205 
00206     for(sfi = G.sfaces_begin(); sfi != G.sfaces_end(); ++sfi) {
00207       Vertex_handle v = sface2vertex[sfi];
00208       SM_decorator SM(&*v);
00209 
00210       SHalfedge_const_handle sec = sfi->sface_cycles_begin();
00211       SHalfedge_around_sface_const_circulator sfc(sec);
00212       
00213       SVertex_handle sv0 = 
00214         SM.new_svertex(sface2vertex[sfc->twin()->incident_sface()]->point()-v->point());
00215       sv0->mark() = sfc->mark().boolean();
00216       sv0->set_index(SE2i[sfc]);
00217       ++sfc;
00218       SVertex_handle sv1 = 
00219         SM.new_svertex(sface2vertex[sfc->twin()->incident_sface()]->point()-v->point());
00220       sv1->mark() = sfc->mark().boolean();
00221       sv1->set_index(SE2i[sfc]);
00222 
00223       SHalfedge_handle se = SM.new_shalfedge_pair(sv0, sv1);
00224       se->mark() = se->twin()->mark() = sfc->source()->mark().boolean();
00225       se->set_index(SV2i[sfc->source()].first);
00226       se->twin()->set_index(SV2i[sfc->source()].second);
00227       se->circle() = Sphere_circle(sv0->point(), sv1->point());
00228       se->circle() = normalized(se->circle());
00229       se->twin()->circle() = se->circle().opposite();
00230 
00231       SFace_handle sf = SM.new_sface();
00232       sf->mark() = false;
00233       SM.link_as_face_cycle(se, sf);
00234     } 
00235   }
00236 
00237   void operator()(SNC_structure& snc) {
00238     snc.clear();
00239 
00240     if(G.number_of_sfaces() == 1)
00241       create_single_vertex(snc);
00242     else if(G.number_of_sfaces() == 2)
00243       create_single_edge(snc);
00244     else if(G.number_of_svertices() == 2)
00245       create_single_facet(snc);
00246     else
00247       create_solid(snc);
00248   }
00249 
00250 
00251 };
00252 
00253 CGAL_END_NAMESPACE
00254 #endif // CGAL_MS3_GAUSSIAN_MAP_TO_NEF_3_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines