Skip to Content.
Sympa Menu

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

Subject: CGAL users discussion list

List archive

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


Chronological Thread 
  • From: "Laurent Rineau (GeometryFactory)" <>
  • To:
  • Subject: Re: [cgal-discuss] how to construct a 2d Triangulation explicitly
  • Date: Mon, 23 May 2011 11:16:32 +0200
  • Organization: GeometryFactory

On lundi 23 mai 2011 03:00:28 魏华祎 wrote:
> 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]);
> }

Forget those low level functions! You do not know what they do. Just use the
insert() function:

// [... skipped the #include and typedef, please recopy them...]

int main(){
int n = 4;
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);
Triangulation tri;
for(int i = 1; i< 4;i++){
tri.insert(P[i]);
}

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

Then after 'tri' is filled, you can navigate into it using the query
functions. See
http://www.cgal.org/Manual/latest/doc_html/cgal_manual/Triangulation_2_ref/Class_Triangulation_2.html

--
Laurent Rineau, PhD
R&D Engineer at GeometryFactory http://www.geometryfactory.com/
Release Manager of the CGAL Project http://www.cgal.org/



Archive powered by MHonArc 2.6.16.

Top of Page