简体   繁体   English

在CGAL中创建3D Alpha形状和可视化

[英]Creating 3D Alpha Shapes in CGAL and the visualization

I am a new CGAL user with basic C++ experience, trying to find the 3D Alpha shapes of a set of points. 我是具有基本C ++经验的CGAL新用户,试图查找一组点的3D Alpha形状。 I am using the ex_alpha_shapes_3 example code, and then using the instructions in saving CGAL alpha shape surface mesh for visualization of the results. 我正在使用ex_alpha_shapes_3示例代码,然后使用说明保存CGAL alpha形状表面网格以可视化结果。 Everything seems to work properly, but when I try to change the value of alpha by replacing 一切似乎都能正常工作,但是当我尝试通过替换来更改alpha值时

    Alpha_shape_3 as(lp.begin(),lp.end());

with

    Alpha_shape_3 as(lp.begin(),lp.end(),1, Alpha_shape_3::GENERAL);

assuming the third variable is the value of alpha (= 1) and change this value each time, no change in the results is obtained. 假设第三个变量是alpha的值(= 1),并且每次更改此值,结果都不会改变。

More specifically, in my set of particles, some are detached from the majority and I would like to represent them with separate volumes (similar to the Figure 41.1 ) using the concave hull or alpha shapes. 更具体地说,在我的一组粒子中,有些粒子与多数粒子分离,我想使用凹壳或alpha形状用单独的体积(类似于图41.1 )表示它们。 Currently what I get (using the Tecplot for visualization) is: 目前,我得到的(使用Tecplot进行可视化处理)是: 在此处输入图片说明 and as you can see, the detached particles are connected to the other particles. 如您所见,分离的粒子与其他粒子相连。 I am also attaching my code, at the end. 最后,我还将附加我的代码。 I would appreciate any help on this matter. 对此,我将不胜感激。

    #include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
    #include <CGAL/Delaunay_triangulation_3.h>
    #include <CGAL/Alpha_shape_3.h>

    #include <iostream>
    #include <fstream>
    #include <list>
    #include <cassert>

    typedef CGAL::Exact_predicates_inexact_constructions_kernel Gt;

    typedef CGAL::Alpha_shape_vertex_base_3<Gt>          Vb;
    typedef CGAL::Alpha_shape_cell_base_3<Gt>            Fb;
    typedef CGAL::Triangulation_data_structure_3<Vb,Fb>  Tds;
    typedef CGAL::Delaunay_triangulation_3<Gt,Tds>       Triangulation_3;
    typedef CGAL::Alpha_shape_3<Triangulation_3>         Alpha_shape_3;

    typedef Gt::Point_3                                  Point;
    typedef Alpha_shape_3::Alpha_iterator               Alpha_iterator;

    using namespace std;

    int main()
    {
      std::list<Point> lp;

      //read input
      std::ifstream is("./data/finalwater4.dat");
      int n;
      is >> n;
      std::cout << "Reading " << n << " points " << std::endl;
      Point p;
      for( ; n>0 ; n--)    {
        is >> p;
        lp.push_back(p);
      }

      // compute alpha shape
    //  Alpha_shape_3 as(lp.begin(),lp.end());
      Alpha_shape_3 as(lp.begin(),lp.end(),0.001, Alpha_shape_3::GENERAL);

      // find optimal alpha value
      Alpha_iterator opt = as.find_optimal_alpha(1);
      std::cout << "Optimal alpha value to get one connected component is "
            <<  *opt    << std::endl;
      as.set_alpha(*opt);
      assert(as.number_of_solid_components() == 1);

      /// the rest of the code, prepares the output to be written into a file

      /// collect all regular facets (fetch regular facets from as and inserts in facets)
      std::vector<Alpha_shape_3::Facet> facets;
      as.get_alpha_shape_facets(std::back_inserter(facets), Alpha_shape_3::REGULAR);

      std::stringstream pts;
      std::stringstream ind;

      std::size_t nbf=facets.size();
      for (std::size_t i=0;i<nbf;++i)
      { 
        //To have a consistent orientation of the facet, always consider an exterior cell
        if ( as.classify( facets[i].first )!=Alpha_shape_3::EXTERIOR )
          facets[i]=as.mirror_facet( facets[i] );
        CGAL_assertion(  as.classify( facets[i].first )==Alpha_shape_3::EXTERIOR  );

        int indices[3]={
          (facets[i].second+1)%4,
          (facets[i].second+2)%4,
          (facets[i].second+3)%4,
        };

        /// according to the encoding of vertex indices, this is needed to get
        /// a consistent orienation
        if ( facets[i].second%2==0 ) std::swap(indices[0], indices[1]);


        pts << 
        facets[i].first->vertex(indices[0])->point() << "\n" <<
        facets[i].first->vertex(indices[1])->point() << "\n" <<
        facets[i].first->vertex(indices[2])->point() << "\n"; 
        ind << 3*i+1 << " " << 3*i+2 << " " << 3*i+3 << "\n";
      }

      ofstream myfile;
      myfile.open ("output.dat");
      myfile << "variables = x, y, z\n";
      myfile << "zone n="<< 3*nbf << " , e=" << nbf << " , f=fepoint, et=triangle\n";
      myfile << pts.str();
      myfile << ind.str();
      myfile.close();

      return 0;
    }

If you want to filter things out, you need to take a alpha shape with value less than the one returned by as.find_optimal_alpha(1). 如果要过滤掉内容,则需要采用alpha形状,其值小于as.find_optimal_alpha(1)返回的值。 I suggest to run the alpha-shape demo which feature a slider that will display what the alpha-shape looks like depending on the value of alpha. 我建议运行带有滑块的alpha形状演示,该滑块将显示取决于alpha值的alpha形状。 Input file should be with a .pts extension and must contains the number of points, followed by the coordinates of the points. 输入文件的扩展名应为.pts,并且必须包含点数,后跟点的坐标。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM