Skip to Content.
Sympa Menu

cgal-discuss - Re: [cgal-discuss] Store a polygon into a half edge data structure using CGAL Polyhedron_3 class

Subject: CGAL users discussion list

List archive

Re: [cgal-discuss] Store a polygon into a half edge data structure using CGAL Polyhedron_3 class


Chronological Thread 
  • From: "Sebastien Loriot (GeometryFactory)" <>
  • To:
  • Subject: Re: [cgal-discuss] Store a polygon into a half edge data structure using CGAL Polyhedron_3 class
  • Date: Thu, 18 May 2017 10:06:38 +0200
  • Authentication-results: mail2-smtp-roc.national.inria.fr; spf=None ; spf=Pass ; spf=None
  • Ironport-phdr: 9a23:v8HtSBBdHoSyJpRkPjBhUyQJP3N1i/DPJgcQr6AfoPdwSPTyoMbcNUDSrc9gkEXOFd2CrakV1ayL7OigATVGusfe9ihaMdRlbFwst4Y/p08aPIa9E0r1LfrnPWQRPf9pcxtbxUy9KlVfA83kZlff8TWY5D8WHQjjZ0IufrymUoHdgN6q2O+s5pbdfxtHhCanYbN1MR66sRjdutMYjIZmK6s90BvEr3lVcOhS2W9kOEifkhj468qy5pJv7zhct/c8/MNcTKv2eLg1QrNfADk6KW4549HluwfeRgWV/HscVWsWkhtMAwfb6RzxQ4n8vCjnuOdjwSeWJcL5Q6w6VjSk9KdrVQTniDwbOD4j8WHYkdJ/gaRGqx+8vRN/worUYIaINPpie67WYN0XSXZdUstXSidMBJ63YYkSAOobJetWspfzp1UOoxu5BgeiCu3gxTBKiXDqxqA61vgtHBvc0QA8Ed8DsHLZp8j1OqcIVuC1ybHFwTveYfxIwjjy8pPIcgwgof6SW7J7bMzfyU41FwPEiVWQtZHuMzeU2OsTtGib6vRvVf61i28nqw9+uCSgxtsrionThoMZz17I/jh+zYYuId24T1R7Yd+jEJtMrS2aMo92T9gtQ2Ftoik6y7kGtYSncygNzZQq3hjSYOGJfYiP5xLsTueRITFgiXJjYr2wnA298Uy+xeHmSsa011NKoyxYmdfPrnAAzx7e58edRvdg4Eus2SyD2gPN5u1eIU05m7LXJpwiz7IqiJYevkXOEjXrlEjygqKabEcp9+iu5u/6eLvpvIWcOJVxigzmMqQhhMi/AeMgPwgLRWeb+OC82KTt/E38XLlGl/M2n6nXvZzAKsQboam5AwBR0ok98RqwEzCm0NEAkXkGKlJKZg6HgpDrNlzBOvz0EOmzjlS2nDpo2fzKJL3sD5vVInjGirjhfLJ960BGyAo0yNBS/4lUCrUGIPLpW0/xs8DYAgU8Mwyw2OvnB9B92ZkfWWKLGKOWLKTSsVqQ6uI1P+aMfJMVuCr6K/U9+/HugmU2mVsEcaa03JsXc2y3Hul9I0WCenfsmdcAEWISvgUkVuDqiVuCUSRSZ3moRa486Cs7W8qaCtLISYmpxbCAxyymBYZ+Z2ZcC1nKH227WZ+DXqJGUy+YK9R9kzECHZymUY4myVnumwL9zrd7NPv68yYEsojylZI9s/bXkgsz8iAyCsC13GSETmUylWQNEWxllJtjqFBwnw/QmZNzhOZVQIRe
  • Organization: GeometryFactory

I copy-pasted your point faces in string and wrote the attached program that is working nicely. The nasty part in the file format is that the
first and last point of each face are identical.

Sebastien.

On 05/17/2017 10:44 PM, hossan.nazmul wrote:
Hello Sebastien,
Can you please have a look at my data. CityGML_LoD2_building.gml
<http://cgal-discuss.949826.n4.nabble.com/file/n4662730/CityGML_LoD2_building.gml>

My goal is to store this CityGML building geometry into a CGAL Halfedge Data
Structure so that I can do some geometric operations. According to your
suggestion, I am trying to use CGAL Surface_mesh to store the geometries
according to vertices and faces. I can add vertices but I can not add
vertices into that particular face. I tried with *add_face* function: e.g.
{mesh.add_face(point1, point2, point3);} and
{vertex_range range=mesh.vertices(); face_descriptor
face=mesh.add_face(range);}
but If you see my data, you will see that it has 7 different faces and the
number of points in each face is not always same. I would like to add
exactly those vertices into faces from the dataset. My question is, how can
I add these arbitrary vertices into 7 different faces. or any idea how do I
do that in CGAL?

Thank you so much for your time.

Best,
Nazmul




--
View this message in context:
http://cgal-discuss.949826.n4.nabble.com/Store-a-polygon-into-a-half-edge-data-structure-using-CGAL-Polyhedron-3-class-tp4662587p4662730.html
Sent from the cgal-discuss mailing list archive at Nabble.com.


#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Surface_mesh.h>
#include <fstream>
#include <sstream>
#include <map>

const char* face1="458875.0 5438350.0 112.0 458875.0 5438355.0 112.0 458885.0 5438355.0 112.0 458885.0 5438350.0 112.0 458875.0 5438350.0 112.0";
const char* face2="458885.0 5438355.0 115.0 458875.0 5438355.0 115.0 458875.0 5438352.5 117.0 458885.0 5438352.5 117.0 458885.0 5438355.0 115.0";
const char* face3="458875.0 5438350.0 115.0 458885.0 5438350.0 115.0 458885.0 5438352.5 117.0 458875.0 5438352.5 117.0 458875.0 5438350.0 115.0";
const char* face4="458875.0 5438350.0 112.0 458885.0 5438350.0 112.0 458885.0 5438350.0 115.0 458875.0 5438350.0 115.0 458875.0 5438350.0 112.0";
const char* face5="458885.0 5438355.0 112.0 458875.0 5438355.0 112.0 458875.0 5438355.0 115.0 458885.0 5438355.0 115.0 458885.0 5438355.0 112.0";
const char* face6="458885.0 5438350.0 112.0 458885.0 5438355.0 112.0 458885.0 5438355.0 115.0 458885.0 5438352.5 117.0 458885.0 5438350.0 115.0 458885.0 5438350.0 112.0";
const char* face7="458875.0 5438355.0 112.0 458875.0 5438350.0 112.0 458875.0 5438350.0 115.0 458875.0 5438352.5 117.0 458875.0 5438355.0 115.0 458875.0 5438355.0 112.0";

typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
typedef CGAL::Surface_mesh<K::Point_3> Surface_mesh;

void add_face(const char* face,
              Surface_mesh& sm, 
              std::map<K::Point_3, Surface_mesh::Vertex_index>& point_to_vertex)
{
  std::stringstream ss;
  ss << face;
  std::vector<Surface_mesh::Vertex_index> vertices;
  while (ss)
  {
    K::Point_3 p;
    ss >> p;
    if (!ss) break;
    std::pair<std::map<K::Point_3, Surface_mesh::Vertex_index>::iterator, bool> insert_res
      = point_to_vertex.insert( std::make_pair(p, Surface_mesh::Vertex_index()));
    if (insert_res.second)
      insert_res.first->second = sm.add_vertex(p);
    vertices.push_back( insert_res.first->second );
  }
  if (vertices.front()==vertices.back())
    vertices.pop_back();
  sm.add_face(vertices);
}

void add_face(const char* face,
              std::vector<K::Point_3>& points,
              std::vector< std::vector<std::size_t> >& polygons,
              std::map<K::Point_3, std::size_t>& point_to_vertex)
{
  std::stringstream ss;
  ss << face;
  polygons.resize(polygons.size()+1);
  while (ss)
  {
    K::Point_3 p;
    ss >> p;
    if (!ss) break;
    std::pair<std::map<K::Point_3, std::size_t>::iterator, bool> insert_res
      = point_to_vertex.insert( std::make_pair(p, 0));
    if (insert_res.second)
    {
      insert_res.first->second = points.size();
      points.push_back(p);
    }
    polygons.back().push_back( insert_res.first->second );
  }
  if (polygons.back().front()==polygons.back().back())
    polygons.back().pop_back();
}

int main()
{
  Surface_mesh sm;
  std::map<K::Point_3, Surface_mesh::Vertex_index> point_to_vertex;

  add_face(face1, sm, point_to_vertex);
  add_face(face2, sm, point_to_vertex);
  add_face(face3, sm, point_to_vertex);
  add_face(face4, sm, point_to_vertex);
  add_face(face5, sm, point_to_vertex);
  add_face(face6, sm, point_to_vertex);
  add_face(face7, sm, point_to_vertex);

  
  std::ofstream output("out.off");
  output << sm;
}



Archive powered by MHonArc 2.6.18.

Top of Page