CGAL:我如何获得凸壳3的所有顶点?

时间:2014-04-18 00:09:57

标签: c++ cgal convex-hull vertices

我有一个关于CGAL中凸包3的基本问题。我创建一个凸包,我想计算这个凸包的中心,然后计算这种三角形的面积:(vertex [i],vertex [I + 1],中心) 但我不知道如何获得顶点......

这是我的代码:

#include <CGAL/Simple_cartesian.h>              
#include <CGAL/linear_least_squares_fitting_3.h> 
#include <CGAL/Polyhedron_3.h>                   
#include <CGAL/convex_hull_3.h>                  
#include <CGAL/Plane_3.h>                        
#include <algorithm>                             
#include <cmath>                                 
#include <cassert>                                                                                              
#include <vector>                                                                                                                                                                                
#include <numeric>                                                                                                                                                                               
#include <functional>                                                                                                                                                                            
#include <fstream>                                                                                                                                                                               
#include <ostream>                                                                                                                                                                               
#include <sstream>                                                                                                                                                                               
#include <string>                                                                                                                                                                                
#include <iostream>                                                                                                                                                                              
#include <boost/iterator/transform_iterator.hpp>                                                                                                                                                 
            typedef CGAL::Simple_cartesian<double>  K;                                                                                                                                           
            typedef CGAL::Polyhedron_3<K>               Polyhedron_3;                                                                                                                           
            typedef K::Plane_3                  Plane;                                                                                                                                           
            typedef K::Point_3                  Point;                                                                                                                                           
            typedef Polyhedron_3::Vertex_iterator Vertex_iterator; 
            typedef Polyhedron_3::Vertex_handle Vertex_handle;


            struct CxhullVertices
            {
                //template <class Facet>
                Polyhedron_3::Point_3 operator()(Polyhedron_3::Facet& f)
                {
                    Polyhedron_3::Halfedge_handle h = f.halfedge();
                    return Polyhedron_3::Point_3(h->vertex()->point(),
                                                 h->next()->vertex()->point(),
                                                 h->next()->next()->vertex()->point());
                }
            };
            int main()                                                                                                                                                                           
            {                                                                                                                                                                                    

                std::vector<double> alldata;                                                                                                                                                     
                std::ifstream infile;                                                                                                                                                            
                infile.open("V1L3.txt");                                                                                                                                       
                double temp;                                                                                                                                                                     
                if(!infile) return 0.0;                                                                                                                                                          
                while(!infile.eof())                                                                                                                                                             
                {                                                                                                                                                                                
                    infile>>temp;                                                                                                                                                                
                    alldata.push_back(temp);                                                                                                                                                     
                }                                                                                                                                                                                
                infile.close();                                                                                                                                                                  
                std::vector<Point> points1;                                                                                                                                                      
                for(int i2=0;i2<alldata.size()/3;i2++)                                                                                                                                           
                {                                                                                                                                                                                
                    double a1 = alldata[3*i2+0];                                                                       
                    double a2 = alldata[3*i2+1];                                                                     
                    double a3 = alldata[3*i2+2];                                                                                   
                    points1.push_back(Point(a1,a2,a3));                                                                                                                                          
                }                                                                                                                                                                                
                Polyhedron_3 poly;                                                                                                                                                               
                CGAL::convex_hull_3(points1.begin(),points1.end(),poly);
                 std::transform( poly.facets_begin(), poly.facets_end(), poly.planes_begin(),CxhullVertices());
                CGAL::set_ascii_mode( std::cout);
                std::copy(poly.vertices_begin(),poly.vertices_end(),std::ostream_iterator<Point>( std::cout, "\n"));

                return 0;                                                                                                                                                                        
            }   

我知道我的代码一定有问题,但我不知道该怎么办,请帮帮我,谢谢

0 个答案:

没有答案