[cgal];简单示例

问题描述

我一直在学习 Cgal 指南中的三角测量示例。我对一个确切的例子有很大的疑问,simple_example.cpp。代码如下:

#include <Cgal/Exact_predicates_inexact_constructions_kernel.h>
#include <Cgal/Periodic_3_delaunay_triangulation_traits_3.h>
#include <Cgal/Periodic_3_delaunay_triangulation_3.h>
#include <Cgal/periodic_3_triangulation_3_io.h>
#include <iostream>
#include <fstream>
#include <cassert>
#include <list>
#include <vector>
typedef Cgal::Exact_predicates_inexact_constructions_kernel       K;
typedef Cgal::Periodic_3_delaunay_triangulation_traits_3<K>       Gt;
typedef Cgal::Periodic_3_delaunay_triangulation_3<Gt>             P3DT3;
typedef P3DT3::Point             Point;
typedef P3DT3::Iso_cuboid        Iso_cuboid;
typedef P3DT3::Vertex_handle     Vertex_handle;
typedef P3DT3::Cell_handle       Cell_handle;
typedef P3DT3::Locate_type       Locate_type;
int main(int,char**)
{
  Iso_cuboid domain(-1,-1,2,2);  // the fundamental domain
  // construction from a list of points :
  std::list<Point> L;
  L.push_front(Point(0,0));
  L.push_front(Point(1,0));
  L.push_front(Point(0,1,0));
  P3DT3 T(L.begin(),L.end(),domain); // put the domain with the constructor
  P3DT3::size_type n = T.number_of_vertices();
  // insertion from a vector :
  std::vector<Point> V(3);
  V[0] = Point(0,1);
  V[1] = Point(1,1);
  V[2] = Point(-1,-1);
  n = n + T.insert(V.begin(),V.end());
  assert( n == 6 );       // 6 points have been inserted
  assert( T.is_valid() ); // checking validity of T
  Locate_type lt;
  int li,lj;
  Point p(0,0);
  Cell_handle c = T.locate(p,lt,li,lj);
  // p is the vertex of c of index li :
  assert( lt == P3DT3::VERTEX );
  assert( c->vertex(li)->point() == p );
  Vertex_handle v = c->vertex( (li+1)&3 );
  // v is another vertex of c
  Cell_handle nc = c->neighbor(li);
  // nc = neighbor of c opposite to the vertex associated with p
  // nc must have vertex v :
  int nli;
  assert( nc->has_vertex( v,nli ) );
  // nli is the index of v in nc
  // writing file output
  std::ofstream oFileT("output.tri",std::ios::out); // as a .tri file
  oFileT << T;
  std::ofstream to_off("output_regular.off"); // as a .off file
  Cgal::write_triangulation_to_off(to_off,T);
  std::ofstream d_to_off("output_dual.off");
  draw_dual_to_off(d_to_off,T);
  // reading file output
  P3DT3 T1;
  std::ifstream iFileT("output.tri",std::ios::in);
  iFileT >> T1;
  assert( T1.is_valid() );
  assert( T1.number_of_vertices() == T.number_of_vertices() );
  assert( T1.number_of_cells() == T.number_of_cells() );
  return 0;
}

我的疑问是我不确定 P3DT3 T 的输出是什么。输出文件有几行,每一行都有不同的列,但我不确定每一列是什么意思。我一直在互联网和 cgal 指南中搜索,但没有找到任何有趣的东西。有什么帮助吗?

解决方法

输出函数有自己的未公开格式,(引用源代码)是:

the number of vertices
the domain as six coordinates: xmin ymin zmin xmax ymax zmax
the current covering that guarantees the triangulation to be a simplicial complex
the non combinatorial information on vertices (points in case of 1-sheeted
covering,point-offset pairs otherwise)
ALL PERIODIC COPIES OF ONE VERTEX MUST BE STORED CONSECUTIVELY
the number of cells
the cells by the indices of their vertices in the preceding list
of vertices,plus the non combinatorial information on each cell
the neighbors of each cell by their index in the preceding list of cells

为了进一步了解它的作用,我建议直接查看源代码(和注释),位于 https://github.com/CGAL/cgal/blob/master/Periodic_3_triangulation_3/include/CGAL/Periodic_3_triangulation_3.h#L4102