Skip to Content.
Sympa Menu

cgal-discuss - [cgal-discuss] how to construct a 2d Triangulation explicitly

Subject: CGAL users discussion list

List archive

[cgal-discuss] how to construct a 2d Triangulation explicitly


Chronological Thread 
  • From: 魏华祎 <>
  • To:
  • Subject: [cgal-discuss] how to construct a 2d Triangulation explicitly
  • Date: Sun, 22 May 2011 18:00:28 -0700
  • Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:date:message-id:subject:from:to:content-type; b=ci8/6DTkesInLaZLmA1z03FP7YF9lYpN6ugcxIFR3OxPxdm38+KRYEx05pLhxtOQua AR6msnm5v7P/U/lkcJITri/f2/TmOI4GzNYQ/yijepgEs9l39CMduczzVEGLcj/4RIo7 OyIBwyJe3Y6dWTMYiTSTdnCfTfs8ttCJ9ugZw=


  Hi, everyone,
      
     I have a 2d simple triangulation with four vertices: p1 = (0,0),  p2 = (1,0), p3  = (1,1), p4 = ( 0,1),  and two triangles: (p2, p3, p1) and (p4,p1,p3). And I want to construct a object of Triangulation_2 class, explicitly ( not write these information into files, then use >> read them). The following is my code. But at last, I got five finite vertices and three finite faces. I am confused,  can anyone give me some suggestions about it?  Thanks very much! 


    By the way, I follow the code of  the "file_input" member function in Triangulation_data_structure_2.h to write my own code. 




#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/IO/Color.h>
#include <CGAL/Triangulation_2.h>

#include <CGAL/Triangulation_face_base_2.h>
#include <CGAL/Triangulation_vertex_base_2.h>

typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
typedef CGAL::Triangulation_vertex_base_2<K> Vb;
typedef CGAL::Triangulation_face_base_2<K> Fb;
typedef CGAL::Triangulation_data_structure_2<Vb,Fb> Tds;
typedef CGAL::Triangulation_2<K,Tds> Triangulation;

typedef Triangulation::Face_handle Face_handle;
typedef Triangulation::Vertex_handle Vertex_handle;
typedef Triangulation::Point Point;

typedef Triangulation::Finite_vertices_iterator Fvi;

int main(){


  int n = 4, m = 2, d = 2;
  std::vector<Point> P(4);
  P[0] = Point(0,0);
  P[1] = Point(1,0);
  P[2] = Point(1,1);
  P[3] = Point(0,1);

  std::vector<Vertex_handle> V(n+1);
  std::vector<Face_handle> F(m);

  Triangulation tri;
  tri.tds().set_dimension(d);
 // if I comment the following two lines, there will four finite vertices, but still three faces
  V[0] = tri.tds().create_vertex(); 
  tri.set_infinite_vertex(V[0]); // set the infinite vertex of tri

 // create the vertex_handles
  for(int i = 1; i< 5;i++){
    V[i] = tri.tds().create_vertex();
    V[i]->set_point(P[i-1]);
  }

 //create the first face and set its vertices
  F[0] = tri.create_face();
  F[0]->set_vertex(0,V[2]);
  V[2]->set_face(F[0]);

  F[0]->set_vertex(1,V[3]);
  V[3]->set_face(F[0]);

  F[0]->set_vertex(2,V[1]);
  V[1]->set_face(F[0]);

  // create the second face and set its vertices
  F[1] = tri.create_face();
  F[1]->set_vertex(0,V[4]);
  V[4]->set_face(F[1]);

  F[1]->set_vertex(1,V[1]);
  V[1]->set_face(F[1]);
  
  F[1]->set_vertex(2,V[3]);
  V[3]->set_face(F[1]);

  // set neighbor information
  F[0]->set_neighbor(0,F[1]);
  F[1]->set_neighbor(0,F[0]);

  std::cout<<tri.number_of_vertices()<<std::endl<<tri.number_of_faces()<<std::endl;

  return 0;
}




Archive powered by MHonArc 2.6.16.

Top of Page