diff --git a/Linear_cell_complex/doc/Linear_cell_complex/CGAL/Linear_cell_complex_constructors.h b/Linear_cell_complex/doc/Linear_cell_complex/CGAL/Linear_cell_complex_constructors.h index faabfd7a207..9323e47193c 100644 --- a/Linear_cell_complex/doc/Linear_cell_complex/CGAL/Linear_cell_complex_constructors.h +++ b/Linear_cell_complex/doc/Linear_cell_complex/CGAL/Linear_cell_complex_constructors.h @@ -41,38 +41,6 @@ template typename LCC::Dart_handle import_from_plane_graph(LCC& lcc, std::istream& ais); -/*! -\ingroup PkgLinearCellComplexConstructions - -Imports `apoly` (a `Polyhedron_3`) into `lcc`. Objects are added in `lcc`, -existing darts are not modified. -Returns a dart created during the import. -\pre \ref CombinatorialMap::dimension "LCC::dimension"\f$ \geq\f$ 2 and - \ref Linear_cell_complex::ambient_dimension "LCC::ambient_dimension"==3. - -\sa `CGAL::import_from_plane_graph` -\sa `CGAL::import_from_triangulation_3` -*/ -template -typename LCC::Dart_handle import_from_polyhedron_3(LCC& lcc, -const Polyhedron &apoly); - - -/*! -\ingroup PkgLinearCellComplexConstructions - -Imports `atr` (a `Triangulation_3`) into `lcc`. -Objects are added in `lcc`, existing darts are not modified. -Returns a dart created during the import. -\pre \ref CombinatorialMap::dimension "LCC::dimension"\f$ \geq\f$ 3 and - \ref Linear_cell_complex::ambient_dimension "LCC::ambient_dimension"==3. - -\sa `CGAL::import_from_plane_graph` -\sa `CGAL::import_from_polyhedron_3` -*/ -template -typename LCC::Dart_handle import_from_triangulation_3(LCC& lcc, -const Triangulation_&atr); } /* namespace CGAL */ diff --git a/Linear_cell_complex/doc/Linear_cell_complex/CGAL/import_from_polyhedron_3.h b/Linear_cell_complex/doc/Linear_cell_complex/CGAL/import_from_polyhedron_3.h new file mode 100644 index 00000000000..dcbc5d72824 --- /dev/null +++ b/Linear_cell_complex/doc/Linear_cell_complex/CGAL/import_from_polyhedron_3.h @@ -0,0 +1,16 @@ + +/*! +\ingroup PkgLinearCellComplexConstructions + +Imports `apoly` (a `Polyhedron_3`) into `lcc`. Objects are added in `lcc`, +existing darts are not modified. +Returns a dart created during the import. +\pre \ref CombinatorialMap::dimension "LCC::dimension"\f$ \geq\f$ 2 and + \ref Linear_cell_complex::ambient_dimension "LCC::ambient_dimension"==3. + +\sa `CGAL::import_from_plane_graph` +\sa `CGAL::import_from_triangulation_3` +*/ +template +typename LCC::Dart_handle import_from_polyhedron_3(LCC& lcc, +const Polyhedron &apoly); diff --git a/Linear_cell_complex/doc/Linear_cell_complex/CGAL/import_from_triangulation_3.h b/Linear_cell_complex/doc/Linear_cell_complex/CGAL/import_from_triangulation_3.h new file mode 100644 index 00000000000..819bff15367 --- /dev/null +++ b/Linear_cell_complex/doc/Linear_cell_complex/CGAL/import_from_triangulation_3.h @@ -0,0 +1,17 @@ + + +/*! +\ingroup PkgLinearCellComplexConstructions + +Imports `atr` (a `Triangulation_3`) into `lcc`. +Objects are added in `lcc`, existing darts are not modified. +Returns a dart created during the import. +\pre \ref CombinatorialMap::dimension "LCC::dimension"\f$ \geq\f$ 3 and + \ref Linear_cell_complex::ambient_dimension "LCC::ambient_dimension"==3. + +\sa `CGAL::import_from_plane_graph` +\sa `CGAL::import_from_polyhedron_3` +*/ +template +typename LCC::Dart_handle import_from_triangulation_3(LCC& lcc, +const Triangulation_&atr); diff --git a/Linear_cell_complex/examples/Linear_cell_complex/voronoi_2.cpp b/Linear_cell_complex/examples/Linear_cell_complex/voronoi_2.cpp index 8668f5e5ee6..de4fea27565 100644 --- a/Linear_cell_complex/examples/Linear_cell_complex/voronoi_2.cpp +++ b/Linear_cell_complex/examples/Linear_cell_complex/voronoi_2.cpp @@ -2,6 +2,8 @@ #include #include #include +#include + #include #include diff --git a/Linear_cell_complex/examples/Linear_cell_complex/voronoi_3.cpp b/Linear_cell_complex/examples/Linear_cell_complex/voronoi_3.cpp index df4780d4d21..e96daa22884 100644 --- a/Linear_cell_complex/examples/Linear_cell_complex/voronoi_3.cpp +++ b/Linear_cell_complex/examples/Linear_cell_complex/voronoi_3.cpp @@ -2,6 +2,8 @@ #include #include #include +#include + #include #include diff --git a/Linear_cell_complex/include/CGAL/Linear_cell_complex_constructors.h b/Linear_cell_complex/include/CGAL/Linear_cell_complex_constructors.h index aa292442063..0ac56d156c3 100644 --- a/Linear_cell_complex/include/CGAL/Linear_cell_complex_constructors.h +++ b/Linear_cell_complex/include/CGAL/Linear_cell_complex_constructors.h @@ -22,8 +22,7 @@ #include #include -#include -#include + #include #include #include @@ -166,284 +165,6 @@ namespace CGAL { return first; } - /** Convert a given Triangulation_2 into a 2D linear cell complex. - * @param alcc the used linear cell complex. - * @param atr the Triangulation_2. - * @param aface_to_dart a pointer to a std::map associating to each - * triangle of atr a corresponding dart in alcc. Not used if NULL. - * @return A dart incident to the infinite vertex. - */ - template < class LCC, class Triangulation > - typename LCC::Dart_handle import_from_triangulation_2 - (LCC& alcc, const Triangulation &atr, - std::map* aface_to_dart=NULL) - { - CGAL_static_assertion( LCC::dimension>=2 && LCC::ambient_dimension==2 ); - - // Case of empty triangulations. - if (atr.number_of_vertices() == 0) return LCC::null_handle; - - // Check the dimension. - if (atr.dimension() != 2) return LCC::null_handle; - CGAL_assertion(atr.is_valid()); - - typedef typename Triangulation::Vertex_handle TVertex_handle; - typedef typename Triangulation::All_vertices_iterator TVertex_iterator; - typedef typename Triangulation::All_faces_iterator TFace_iterator; - typedef typename std::map - < TFace_iterator, typename LCC::Dart_handle >::iterator itmap_tcell; - - // Create vertices in the map and associate in a map - // TVertex_handle and vertices in the map. - std::map< TVertex_handle, typename LCC::Vertex_attribute_handle > TV; - for (TVertex_iterator itv = atr.all_vertices_begin(); - itv != atr.all_vertices_end(); ++itv) - { - TV[itv] = alcc.create_vertex_attribute(itv->point()); - } - - // Create the triangles and create a map to link Cell_iterator - // and triangles. - TFace_iterator it; - - std::map TC; - std::map* - mytc = (aface_to_dart==NULL?&TC:aface_to_dart); - - itmap_tcell maptcell_it; - - typename LCC::Dart_handle res=LCC::null_handle, dart=LCC::null_handle; - typename LCC::Dart_handle cur=LCC::null_handle, neighbor=LCC::null_handle; - - for (it = atr.all_faces_begin(); it != atr.all_faces_end(); ++it) - { - /* if (it->vertex(0) != atr.infinite_vertex() && - it->vertex(1) != atr.infinite_vertex() && - it->vertex(2) != atr.infinite_vertex() && - it->vertex(3) != atr.infinite_vertex()) - */ - { - res = alcc.make_triangle(TV[it->vertex(0)], - TV[it->vertex(1)], - TV[it->vertex(2)]); - - if ( dart==LCC::null_handle ) - { - if ( it->vertex(0) == atr.infinite_vertex() ) - dart = res; - else if ( it->vertex(1) == atr.infinite_vertex() ) - dart = alcc.beta(res,1); - else if ( it->vertex(2) == atr.infinite_vertex() ) - dart = alcc.beta(res,0); - } - - for (unsigned int i=0; i<3; ++i) - { - switch (i) - { - case 0: cur = alcc.beta(res,1); break; - case 1: cur = alcc.beta(res,0); break; - case 2: cur = res; break; - } - - maptcell_it = mytc->find(it->neighbor(i)); - if (maptcell_it != mytc->end()) - { - switch (atr.mirror_index(it,i) ) - { - case 0: neighbor = alcc.beta(maptcell_it->second,1); - break; - case 1: neighbor = alcc.beta(maptcell_it->second,0); - break; - case 2: neighbor = maptcell_it->second; break; - } - alcc.template topo_sew<2>(cur, neighbor); - } - } - (*mytc)[it] = res; - } - } - - CGAL_assertion(dart!=LCC::null_handle); - return dart; - } - - /** Convert a given Triangulation_3 into a 3D linear cell complex. - * @param alcc the used linear cell complex. - * @param atr the Triangulation_3. - * @param avol_to_dart a pointer to a std::map associating to each - * tetrahedron of atr a corresponding dart in alcc. Not used if NULL. - * @return A dart incident to the infinite vertex. - */ - template < class LCC, class Triangulation > - typename LCC::Dart_handle import_from_triangulation_3 - (LCC& alcc, const Triangulation &atr, - std::map* avol_to_dart=NULL) - { - CGAL_static_assertion( LCC::dimension>=3 && LCC::ambient_dimension==3 ); - - // Case of empty triangulations. - if (atr.number_of_vertices() == 0) return LCC::null_handle; - - // Check the dimension. - if (atr.dimension() != 3) return LCC::null_handle; - CGAL_assertion(atr.is_valid()); - - typedef typename Triangulation::Vertex_handle TVertex_handle; - typedef typename Triangulation::Vertex_iterator TVertex_iterator; - typedef typename Triangulation::Cell_iterator TCell_iterator; - typedef typename std::map - < TCell_iterator, typename LCC::Dart_handle >::iterator itmap_tcell; - - // Create vertices in the map and associate in a map - // TVertex_handle and vertices in the map. - std::map< TVertex_handle, typename LCC::Vertex_attribute_handle > TV; - for (TVertex_iterator itv = atr.vertices_begin(); - itv != atr.vertices_end(); ++itv) - { - TV[itv] = alcc.create_vertex_attribute(itv->point()); - } - - // Create the tetrahedron and create a map to link Cell_iterator - // and tetrahedron. - TCell_iterator it; - - std::map TC; - std::map* - mytc = (avol_to_dart==NULL?&TC:avol_to_dart); - - itmap_tcell maptcell_it; - - typename LCC::Dart_handle res=LCC::null_handle, dart=LCC::null_handle; - typename LCC::Dart_handle cur=LCC::null_handle, neighbor=LCC::null_handle; - - for (it = atr.cells_begin(); it != atr.cells_end(); ++it) - { - /* if (it->vertex(0) != atr.infinite_vertex() && - it->vertex(1) != atr.infinite_vertex() && - it->vertex(2) != atr.infinite_vertex() && - it->vertex(3) != atr.infinite_vertex()) - */ - { - res = alcc.make_tetrahedron(TV[it->vertex(0)], - TV[it->vertex(1)], - TV[it->vertex(2)], - TV[it->vertex(3)]); - - if ( dart==LCC::null_handle ) - { - if ( it->vertex(0) == atr.infinite_vertex() ) - dart = res; - else if ( it->vertex(1) == atr.infinite_vertex() ) - dart = alcc.beta(res, 1); - else if ( it->vertex(2) == atr.infinite_vertex() ) - dart = alcc.beta(res, 1, 1); - else if ( it->vertex(3) == atr.infinite_vertex() ) - dart = alcc.beta(res, 2, 0); - } - - for (unsigned int i = 0; i < 4; ++i) - { - switch (i) - { - case 0: cur = alcc.beta(res, 1, 2); break; - case 1: cur = alcc.beta(res, 0, 2); break; - case 2: cur = alcc.beta(res, 2); break; - case 3: cur = res; break; - } - - maptcell_it = mytc->find(it->neighbor(i)); - if (maptcell_it != mytc->end()) - { - switch (atr.mirror_index(it,i) ) - { - case 0: neighbor = alcc.beta(maptcell_it->second, 1, 2); - break; - case 1: neighbor = alcc.beta(maptcell_it->second, 0, 2); - break; - case 2: neighbor = alcc.beta(maptcell_it->second, 2); break; - case 3: neighbor = maptcell_it->second; break; - } - while (alcc.temp_vertex_attribute(neighbor) != - alcc.temp_vertex_attribute(alcc.other_extremity(cur)) ) - neighbor = alcc.beta(neighbor,1); - alcc.template topo_sew<3>(cur, neighbor); - } - } - (*mytc)[it] = res; - } - } - CGAL_assertion(dart!=LCC::null_handle); - return dart; - } - - /** Import a given Polyhedron_3 into a Linear_cell_complex. - * @param alcc the linear cell complex where Polyhedron_3 will be converted. - * @param apoly the Polyhedron. - * @return A dart created during the convertion. - */ - template< class LCC, class Polyhedron > - typename LCC::Dart_handle import_from_polyhedron_3(LCC& alcc, - const Polyhedron &apoly) - { - CGAL_static_assertion( LCC::dimension>=2 && LCC::ambient_dimension==3 ); - - typedef typename Polyhedron::Halfedge_const_handle Halfedge_handle; - typedef typename Polyhedron::Facet_const_iterator Facet_iterator; - typedef typename Polyhedron::Halfedge_around_facet_const_circulator - HF_circulator; - - typedef std::map < Halfedge_handle, typename LCC::Dart_handle> - Halfedge_handle_map; - typedef typename Halfedge_handle_map::iterator itmap_hds; - Halfedge_handle_map TC; - - itmap_hds it; - typename LCC::Dart_handle d = LCC::null_handle, prev = LCC::null_handle; - typename LCC::Dart_handle firstFacet = LCC::null_handle, firstAll = LCC::null_handle; - - // First traversal to build the darts and link them. - for (Facet_iterator i = apoly.facets_begin(); i != apoly.facets_end(); ++i) - { - HF_circulator j = i->facet_begin(); - prev = LCC::null_handle; - do - { - d = alcc.create_dart(); - TC[j] = d; - - if (prev != LCC::null_handle) alcc.template link_beta<1>(prev, d); - else firstFacet = d; - it = TC.find(j->opposite()); - if (it != TC.end()) - alcc.template link_beta<2>(d, it->second); - prev = d; - } - while (++j != i->facet_begin()); - alcc.template link_beta<1>(prev, firstFacet); - if (firstAll == LCC::null_handle) firstAll = firstFacet; - } - - // Second traversal to update the geometry. - // We run one again through the facets of the HDS. - for (Facet_iterator i = apoly.facets_begin(); i != apoly.facets_end(); ++i) - { - HF_circulator j = i->facet_begin(); - do - { - d = TC[j]; // Get the dart associated to the Halfedge - if (alcc.temp_vertex_attribute(d) == LCC::null_handle) - { - alcc.set_vertex_attribute - (d, alcc.create_vertex_attribute(j->opposite()->vertex()->point())); - } - } - while (++j != i->facet_begin()); - } - return firstAll; - } template < class LCC > void load_off(LCC& alcc, std::istream& in) @@ -525,25 +246,7 @@ namespace CGAL { B.end_surface(); } - /** Convert a Polyhedron_3 read into a flux into 3D linear cell complex. - * @param alcc the linear cell complex where Polyhedron_3 will be converted. - * @param ais the istream where read the Polyhedron_3. - * @return A dart created during the convertion. - */ - template < class LCC > - typename LCC::Dart_handle - import_from_polyhedron_3_flux(LCC& alcc, std::istream& ais) - { - if (!ais.good()) - { - std::cout << "Error reading flux." << std::endl; - return LCC::null_handle; - } - CGAL::Polyhedron_3 P; - ais >> P; - return import_from_polyhedron_3 > (alcc, P); - } + /** Export the alcc in off file format. If dimension>2, export all faces but only once. */ diff --git a/Linear_cell_complex/test/Linear_cell_complex/Linear_cell_complex_3_test.h b/Linear_cell_complex/test/Linear_cell_complex/Linear_cell_complex_3_test.h index 5a365cbed1a..e95a72891ea 100644 --- a/Linear_cell_complex/test/Linear_cell_complex/Linear_cell_complex_3_test.h +++ b/Linear_cell_complex/test/Linear_cell_complex/Linear_cell_complex_3_test.h @@ -25,6 +25,8 @@ #include #include #include +#include +#include #include "Linear_cell_complex_2_test.h" #include diff --git a/Polyhedron/include/CGAL/import_from_polyhedron_3.h b/Polyhedron/include/CGAL/import_from_polyhedron_3.h new file mode 100644 index 00000000000..4410f857108 --- /dev/null +++ b/Polyhedron/include/CGAL/import_from_polyhedron_3.h @@ -0,0 +1,119 @@ +// Copyright (c) 2011 CNRS and LIRIS' Establishments (France). +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org); you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public License as +// published by the Free Software Foundation; either version 3 of the License, +// or (at your option) any later version. +// +// Licensees holding a valid commercial license may use this file in +// accordance with the commercial license agreement provided with the software. +// +// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +// +// $URL$ +// $Id$ +// +// Author(s) : Guillaume Damiand +// + +#ifndef CGAL_IMPORT_FROM_POLYHEDRON_3_H +#define CGAL_IMPORT_FROM_POLYHEDRON_3_H + +#include +#include +#include + +namespace CGAL { + + /** Import a given Polyhedron_3 into a Linear_cell_complex. + * @param alcc the linear cell complex where Polyhedron_3 will be converted. + * @param apoly the Polyhedron. + * @return A dart created during the convertion. + */ + template< class LCC, class Polyhedron > + typename LCC::Dart_handle import_from_polyhedron_3(LCC& alcc, + const Polyhedron &apoly) + { + CGAL_static_assertion( LCC::dimension>=2 && LCC::ambient_dimension==3 ); + + typedef typename Polyhedron::Halfedge_const_handle Halfedge_handle; + typedef typename Polyhedron::Facet_const_iterator Facet_iterator; + typedef typename Polyhedron::Halfedge_around_facet_const_circulator + HF_circulator; + + typedef std::map < Halfedge_handle, typename LCC::Dart_handle> + Halfedge_handle_map; + typedef typename Halfedge_handle_map::iterator itmap_hds; + Halfedge_handle_map TC; + + itmap_hds it; + typename LCC::Dart_handle d = LCC::null_handle, prev = LCC::null_handle; + typename LCC::Dart_handle firstFacet = LCC::null_handle, firstAll = LCC::null_handle; + + // First traversal to build the darts and link them. + for (Facet_iterator i = apoly.facets_begin(); i != apoly.facets_end(); ++i) + { + HF_circulator j = i->facet_begin(); + prev = LCC::null_handle; + do + { + d = alcc.create_dart(); + TC[j] = d; + + if (prev != LCC::null_handle) alcc.template link_beta<1>(prev, d); + else firstFacet = d; + it = TC.find(j->opposite()); + if (it != TC.end()) + alcc.template link_beta<2>(d, it->second); + prev = d; + } + while (++j != i->facet_begin()); + alcc.template link_beta<1>(prev, firstFacet); + if (firstAll == LCC::null_handle) firstAll = firstFacet; + } + + // Second traversal to update the geometry. + // We run one again through the facets of the HDS. + for (Facet_iterator i = apoly.facets_begin(); i != apoly.facets_end(); ++i) + { + HF_circulator j = i->facet_begin(); + do + { + d = TC[j]; // Get the dart associated to the Halfedge + if (alcc.temp_vertex_attribute(d) == LCC::null_handle) + { + alcc.set_vertex_attribute + (d, alcc.create_vertex_attribute(j->opposite()->vertex()->point())); + } + } + while (++j != i->facet_begin()); + } + return firstAll; + } + + + /** Convert a Polyhedron_3 read into a flux into 3D linear cell complex. + * @param alcc the linear cell complex where Polyhedron_3 will be converted. + * @param ais the istream where read the Polyhedron_3. + * @return A dart created during the convertion. + */ + template < class LCC > + typename LCC::Dart_handle + import_from_polyhedron_3_flux(LCC& alcc, std::istream& ais) + { + if (!ais.good()) + { + std::cout << "Error reading flux." << std::endl; + return LCC::null_handle; + } + CGAL::Polyhedron_3 P; + ais >> P; + return import_from_polyhedron_3 > (alcc, P); + } + +} // namespace CGAL + +#endif // CGAL_IMPORT_FROM_POLYHEDRON_3_H diff --git a/Triangulation_2/include/CGAL/import_from_triangulation_2.h b/Triangulation_2/include/CGAL/import_from_triangulation_2.h new file mode 100644 index 00000000000..07c2fba34f6 --- /dev/null +++ b/Triangulation_2/include/CGAL/import_from_triangulation_2.h @@ -0,0 +1,136 @@ +// Copyright (c) 2011 CNRS and LIRIS' Establishments (France). +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org); you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public License as +// published by the Free Software Foundation; either version 3 of the License, +// or (at your option) any later version. +// +// Licensees holding a valid commercial license may use this file in +// accordance with the commercial license agreement provided with the software. +// +// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +// +// $URL$ +// $Id$ +// +// Author(s) : Guillaume Damiand +// + +#ifndef CGAL_IMPORT_FROM_TRIANGULATION_2_H +#define CGAL_IMPORT_FROM_TRIANGULATION_2_H + +#include +#include + +#include + +namespace CGAL { + + /** Convert a given Triangulation_2 into a 2D linear cell complex. + * @param alcc the used linear cell complex. + * @param atr the Triangulation_2. + * @param aface_to_dart a pointer to a std::map associating to each + * triangle of atr a corresponding dart in alcc. Not used if NULL. + * @return A dart incident to the infinite vertex. + */ + template < class LCC, class Triangulation > + typename LCC::Dart_handle import_from_triangulation_2 + (LCC& alcc, const Triangulation &atr, + std::map* aface_to_dart=NULL) + { + CGAL_static_assertion( LCC::dimension>=2 && LCC::ambient_dimension==2 ); + + // Case of empty triangulations. + if (atr.number_of_vertices() == 0) return LCC::null_handle; + + // Check the dimension. + if (atr.dimension() != 2) return LCC::null_handle; + CGAL_assertion(atr.is_valid()); + + typedef typename Triangulation::Vertex_handle TVertex_handle; + typedef typename Triangulation::All_vertices_iterator TVertex_iterator; + typedef typename Triangulation::All_faces_iterator TFace_iterator; + typedef typename std::map + < TFace_iterator, typename LCC::Dart_handle >::iterator itmap_tcell; + + // Create vertices in the map and associate in a map + // TVertex_handle and vertices in the map. + std::map< TVertex_handle, typename LCC::Vertex_attribute_handle > TV; + for (TVertex_iterator itv = atr.all_vertices_begin(); + itv != atr.all_vertices_end(); ++itv) + { + TV[itv] = alcc.create_vertex_attribute(itv->point()); + } + + // Create the triangles and create a map to link Cell_iterator + // and triangles. + TFace_iterator it; + + std::map TC; + std::map* + mytc = (aface_to_dart==NULL?&TC:aface_to_dart); + + itmap_tcell maptcell_it; + + typename LCC::Dart_handle res=LCC::null_handle, dart=LCC::null_handle; + typename LCC::Dart_handle cur=LCC::null_handle, neighbor=LCC::null_handle; + + for (it = atr.all_faces_begin(); it != atr.all_faces_end(); ++it) + { + /* if (it->vertex(0) != atr.infinite_vertex() && + it->vertex(1) != atr.infinite_vertex() && + it->vertex(2) != atr.infinite_vertex() && + it->vertex(3) != atr.infinite_vertex()) + */ + { + res = alcc.make_triangle(TV[it->vertex(0)], + TV[it->vertex(1)], + TV[it->vertex(2)]); + + if ( dart==LCC::null_handle ) + { + if ( it->vertex(0) == atr.infinite_vertex() ) + dart = res; + else if ( it->vertex(1) == atr.infinite_vertex() ) + dart = alcc.beta(res,1); + else if ( it->vertex(2) == atr.infinite_vertex() ) + dart = alcc.beta(res,0); + } + + for (unsigned int i=0; i<3; ++i) + { + switch (i) + { + case 0: cur = alcc.beta(res,1); break; + case 1: cur = alcc.beta(res,0); break; + case 2: cur = res; break; + } + + maptcell_it = mytc->find(it->neighbor(i)); + if (maptcell_it != mytc->end()) + { + switch (atr.mirror_index(it,i) ) + { + case 0: neighbor = alcc.beta(maptcell_it->second,1); + break; + case 1: neighbor = alcc.beta(maptcell_it->second,0); + break; + case 2: neighbor = maptcell_it->second; break; + } + alcc.template topo_sew<2>(cur, neighbor); + } + } + (*mytc)[it] = res; + } + } + + CGAL_assertion(dart!=LCC::null_handle); + return dart; + } + +} // namespace CGAL + +#endif // CGAL_IMPORT_FROM_TRIANGULATION_2_H diff --git a/Triangulation_3/include/CGAL/import_from_triangulation_3.h b/Triangulation_3/include/CGAL/import_from_triangulation_3.h new file mode 100644 index 00000000000..35b05235f16 --- /dev/null +++ b/Triangulation_3/include/CGAL/import_from_triangulation_3.h @@ -0,0 +1,141 @@ +// Copyright (c) 2011 CNRS and LIRIS' Establishments (France). +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org); you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public License as +// published by the Free Software Foundation; either version 3 of the License, +// or (at your option) any later version. +// +// Licensees holding a valid commercial license may use this file in +// accordance with the commercial license agreement provided with the software. +// +// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +// +// $URL$ +// $Id$ +// +// Author(s) : Guillaume Damiand +// + +#ifndef CGAL_IMPORT_FROM_TRIANGULATION_3_H +#define CGAL_IMPORT_FROM_TRIANGULATION_3_H + +#include +#include + +namespace CGAL { + + /** Convert a given Triangulation_3 into a 3D linear cell complex. + * @param alcc the used linear cell complex. + * @param atr the Triangulation_3. + * @param avol_to_dart a pointer to a std::map associating to each + * tetrahedron of atr a corresponding dart in alcc. Not used if NULL. + * @return A dart incident to the infinite vertex. + */ + template < class LCC, class Triangulation > + typename LCC::Dart_handle import_from_triangulation_3 + (LCC& alcc, const Triangulation &atr, + std::map* avol_to_dart=NULL) + { + CGAL_static_assertion( LCC::dimension>=3 && LCC::ambient_dimension==3 ); + + // Case of empty triangulations. + if (atr.number_of_vertices() == 0) return LCC::null_handle; + + // Check the dimension. + if (atr.dimension() != 3) return LCC::null_handle; + CGAL_assertion(atr.is_valid()); + + typedef typename Triangulation::Vertex_handle TVertex_handle; + typedef typename Triangulation::Vertex_iterator TVertex_iterator; + typedef typename Triangulation::Cell_iterator TCell_iterator; + typedef typename std::map + < TCell_iterator, typename LCC::Dart_handle >::iterator itmap_tcell; + + // Create vertices in the map and associate in a map + // TVertex_handle and vertices in the map. + std::map< TVertex_handle, typename LCC::Vertex_attribute_handle > TV; + for (TVertex_iterator itv = atr.vertices_begin(); + itv != atr.vertices_end(); ++itv) + { + TV[itv] = alcc.create_vertex_attribute(itv->point()); + } + + // Create the tetrahedron and create a map to link Cell_iterator + // and tetrahedron. + TCell_iterator it; + + std::map TC; + std::map* + mytc = (avol_to_dart==NULL?&TC:avol_to_dart); + + itmap_tcell maptcell_it; + + typename LCC::Dart_handle res=LCC::null_handle, dart=LCC::null_handle; + typename LCC::Dart_handle cur=LCC::null_handle, neighbor=LCC::null_handle; + + for (it = atr.cells_begin(); it != atr.cells_end(); ++it) + { + /* if (it->vertex(0) != atr.infinite_vertex() && + it->vertex(1) != atr.infinite_vertex() && + it->vertex(2) != atr.infinite_vertex() && + it->vertex(3) != atr.infinite_vertex()) + */ + { + res = alcc.make_tetrahedron(TV[it->vertex(0)], + TV[it->vertex(1)], + TV[it->vertex(2)], + TV[it->vertex(3)]); + + if ( dart==LCC::null_handle ) + { + if ( it->vertex(0) == atr.infinite_vertex() ) + dart = res; + else if ( it->vertex(1) == atr.infinite_vertex() ) + dart = alcc.beta(res, 1); + else if ( it->vertex(2) == atr.infinite_vertex() ) + dart = alcc.beta(res, 1, 1); + else if ( it->vertex(3) == atr.infinite_vertex() ) + dart = alcc.beta(res, 2, 0); + } + + for (unsigned int i = 0; i < 4; ++i) + { + switch (i) + { + case 0: cur = alcc.beta(res, 1, 2); break; + case 1: cur = alcc.beta(res, 0, 2); break; + case 2: cur = alcc.beta(res, 2); break; + case 3: cur = res; break; + } + + maptcell_it = mytc->find(it->neighbor(i)); + if (maptcell_it != mytc->end()) + { + switch (atr.mirror_index(it,i) ) + { + case 0: neighbor = alcc.beta(maptcell_it->second, 1, 2); + break; + case 1: neighbor = alcc.beta(maptcell_it->second, 0, 2); + break; + case 2: neighbor = alcc.beta(maptcell_it->second, 2); break; + case 3: neighbor = maptcell_it->second; break; + } + while (alcc.temp_vertex_attribute(neighbor) != + alcc.temp_vertex_attribute(alcc.other_extremity(cur)) ) + neighbor = alcc.beta(neighbor,1); + alcc.template topo_sew<3>(cur, neighbor); + } + } + (*mytc)[it] = res; + } + } + CGAL_assertion(dart!=LCC::null_handle); + return dart; + } + +} // namespace CGAL + +#endif CGAL_IMPORT_FROM_TRIANGULATION_3_H