Subject: CGAL users discussion list
List archive
- From: Jatin Relan <>
- To:
- Subject: [cgal-discuss] Questions about interpolation
- Date: Mon, 20 Dec 2010 13:36:31 +0100 (CET)
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h> #include <CGAL/Polyhedron_incremental_builder_3.h> #include <CGAL/Polyhedron_3.h> #include <CGAL/IO/Polyhedron_iostream.h> #include <CGAL/Delaunay_triangulation_3.h> #include <fstream> // A modifier creating a triangle with the incremental builder. template <class HDS,class Triangulation> class Build_convex_hull_from_triangulation_3 : public CGAL::Modifier_base<HDS> { typedef std::map<typename Triangulation::Vertex_handle,unsigned> Vertex_map; const Triangulation& t; template <class Builder> static unsigned get_vertex_index( Vertex_map& vertex_map, typename Triangulation::Vertex_handle vh, Builder& builder, unsigned& vindex) { std::pair<typename Vertex_map::iterator,bool> res=vertex_map.insert(std::make_pair(vh,vindex)); if (res.second){ builder.add_vertex(vh->point()); ++vindex; } return res.first->second; } public: Build_convex_hull_from_triangulation_3(const Triangulation& t_):t(t_) { CGAL_assertion(t.dimension()==3); } void operator()( HDS& hds) { // Postcondition: `hds' is a valid polyhedral surface. typedef typename HDS::Vertex Vertex; typedef typename Vertex::Point Point; CGAL::Polyhedron_incremental_builder_3<HDS> B( hds, true); std::vector<typename Triangulation::Cell_handle> ch_facets; Vertex_map vertex_map; t.incident_cells(t.infinite_vertex(),std::back_inserter(ch_facets)); std::size_t nb_facets=ch_facets.size(); //start the surface B.begin_surface( nb_facets, nb_facets); unsigned vindex=0; for (typename std::vector<typename Triangulation::Cell_handle>::const_iterator it= ch_facets.begin();it!=ch_facets.end();++it) { unsigned ifv_index= (*it)->index(t.infinite_vertex()); bool is_odd=ifv_index%2==0; unsigned i0=get_vertex_index(vertex_map,(*it)->vertex((ifv_index + (is_odd?3:1) )%4),B,vindex); unsigned i1=get_vertex_index(vertex_map,(*it)->vertex((ifv_index + 2 )%4),B,vindex); unsigned i2=get_vertex_index(vertex_map,(*it)->vertex((ifv_index + (is_odd?1:3) )%4),B,vindex); B.begin_facet(); B.add_vertex_to_facet( i0 ); B.add_vertex_to_facet( i1 ); B.add_vertex_to_facet( i2 ); B.end_facet(); } B.end_surface(); } }; template <class PointIterator,class Polyhedron> void make_convex_hull_3(PointIterator begin,PointIterator end,Polyhedron& P) { typedef typename CGAL::Kernel_traits< typename std::iterator_traits<PointIterator>::value_type >::Kernel Kernel; typedef typename Polyhedron::HalfedgeDS HalfedgeDS; typedef typename CGAL::Delaunay_triangulation_3<Kernel> Triangulation; Triangulation dt3(begin,end); Build_convex_hull_from_triangulation_3<HalfedgeDS,Triangulation> get_chull(dt3); P.delegate( get_chull ); CGAL_assertion( P.is_pure_triangle() ); } typedef CGAL::Exact_predicates_inexact_constructions_kernel Kernel; typedef CGAL::Polyhedron_3<Kernel> Polyhedron; int main() { std::ifstream iFile; iFile.open("1.off"); if (!iFile.is_open()) { std::cerr<<"Error opening file\n"; exit(EXIT_FAILURE); } Polyhedron P_tmp; iFile >> P_tmp; iFile.close(); Polyhedron chull; make_convex_hull_3(P_tmp.points_begin(),P_tmp.points_end(),chull); std::ofstream out("out.off"); out << chull; return 0; }
- [cgal-discuss] Convex hull errors, johnzjq, 12/08/2010
- Re: [cgal-discuss] Convex hull errors, Sebastien Loriot (GeometryFactory), 12/09/2010
- [cgal-discuss] Re: Convex hull errors, johnzjq, 12/09/2010
- Re: [cgal-discuss] Re: Convex hull errors, Sebastien Loriot (GeometryFactory), 12/09/2010
- [cgal-discuss] Re: Convex hull errors, johnzjq, 12/10/2010
- [cgal-discuss] Re: Convex hull errors, johnzjq, 12/10/2010
- Re: [cgal-discuss] Re: Convex hull errors, Sebastien Loriot (GeometryFactory), 12/20/2010
- [cgal-discuss] 答复: Convex hull errors, johnzjq, 12/20/2010
- Re: [cgal-discuss] 答复: Convex hull errors, Sebastien Loriot (GeometryFactory), 12/20/2010
- [cgal-discuss] Questions about interpolation, Jatin Relan, 12/20/2010
- Re: [cgal-discuss] Questions about interpolation, Sebastien Loriot (GeometryFactory), 12/27/2010
- Re: [cgal-discuss] Questions about interpolation, Jatin Relan, 12/29/2010
- Re: [cgal-discuss] Questions about interpolation, Sebastien Loriot (GeometryFactory), 12/29/2010
- [cgal-discuss] 答复: Convex hull errors, johnzjq, 12/20/2010
- [cgal-discuss] Re: re: Convex hull errors, johnzjq, 12/20/2010
- [cgal-discuss] Re: Convex hull errors, johnzjq, 12/10/2010
- Re: [cgal-discuss] Re: Convex hull errors, Sebastien Loriot (GeometryFactory), 12/09/2010
- [cgal-discuss] Re: Convex hull errors, johnzjq, 12/09/2010
- Re: [cgal-discuss] Convex hull errors, Sebastien Loriot (GeometryFactory), 12/09/2010
Archive powered by MHonArc 2.6.16.