Skip to Content.
Sympa Menu

cgal-discuss - [cgal-discuss] Problems with calculating a convex hull in 3d

Subject: CGAL users discussion list

List archive

[cgal-discuss] Problems with calculating a convex hull in 3d


Chronological Thread 
  • From: Christoph Weber <>
  • To: cgal-liste <>
  • Subject: [cgal-discuss] Problems with calculating a convex hull in 3d
  • Date: Thu, 09 Apr 2009 18:01:50 +0200

Hi,

I got a problem in some situation, when i want to estimate a convex
hull for a given point set in 3d. Sometimes my program hangs, but I
don't understand why. Maybe it's a bug. I wrote a bug report program,
which reproduces my error and put it in the apendix. Can somebody help
me?

regards, Christoph
#include <CGAL/Simple_cartesian.h>
#include <CGAL/Homogeneous.h>
#include <CGAL/point_generators_3.h>
#include <CGAL/copy_n.h>
#include <CGAL/Convex_hull_traits_3.h>
#include <CGAL/convex_hull_3.h>
#include <vector>
#include <string>
#include <sstream>
#include <iostream>
#include <fstream>
#include <CGAL/basic.h>



  typedef CGAL::Simple_cartesian<double>          K;


  typedef CGAL::Convex_hull_traits_3<K>      Traits;
  typedef Traits::Polyhedron_3               Polyhedron;
  typedef K::Segment_3                       Segment;
  typedef K::Point_3                         Point;
  typedef CGAL::Object                       Object;

  typedef std::vector<Point>::iterator       Iterator;


//  getting the convex hull
Polyhedron cvx_hull_of_pointset(std::vector<Point> *list, Iterator start, Iterator end)
{
  Object object;
  Polyhedron ret;
  CGAL::convex_hull_3(start, end, object);

  if ( CGAL::assign(ret, object) )       return ret ;
  else
  {
    ret.clear();
    return ret;
  }

};


// print convex hull to std out
void  hull_points(Polyhedron Pcvx)
{

 Polyhedron::Vertex_iterator     vi;
 std::vector<Point> ret;


  if (!Pcvx.empty())
  {
    vi = Pcvx.vertices_begin();

    std::cerr<< "Points of the convex hull are:" <<std::endl;
    for (; vi!= Pcvx.vertices_end(); vi++)
    {
      Polyhedron::Vertex v = *vi;
      ret.push_back(v.point());
      std::cerr<< v.point() << std::endl;
    }
  }
};

// print used point set to std out
void print_plist(std::vector<Point> *plist, Iterator start, Iterator end)
{
  std::cerr<< "points" << std::endl;
  do
  {
    std::cerr<< *start <<std::endl;
    start++;
  } while(start!=end);
 
}
int main()
{
  std::vector<Point> *plist = new std::vector<Point>();
  Polyhedron P_ret;

  plist->push_back(Point(2.3, 4.1, 0.6));
  plist->push_back(Point(4.2, 1.4, 4.7));
  plist->push_back(Point(5.0, 3.0, 2.6));
  plist->push_back(Point(3.0, 2.0, 1.0));
  plist->push_back(Point(4.1, 4.1, 1.9));

  // adding this point will corrupt the convex hull generation,
  // try another valeu for 4.7, and it will work again..
  plist->push_back(Point(3.4, 4.7, 3.5));

  Polyhedron P;

  std::cerr<<"\n\n";
  print_plist(plist, plist->begin(), plist->begin()+3);  	// print used point set to std out
  P=cvx_hull_of_pointset(plist, plist->begin(), plist->begin()+3);  // get the convex hull of the actual point set
  hull_points(P);							// print convex hull points to std out
  std::cerr<<"\n\n";


  // do the same with another points set
  print_plist(plist, plist->begin(), plist->begin()+4);
  P=cvx_hull_of_pointset(plist, plist->begin(), plist->begin()+4);
  hull_points(P);


  // ...again..
  std::cerr<<"\n\n";
  print_plist(plist, plist->begin(), plist->begin()+5);
  cvx_hull_of_pointset(plist, plist->begin(), plist->begin()+5);
  hull_points(P);

  // again ... but
  // this won't work
  std::cerr<<"\n\n";
  print_plist(plist, plist->begin(), plist->begin()+6);
  cvx_hull_of_pointset(plist, plist->begin(), plist->begin()+6);
  hull_points(P);

  delete plist;
};



Archive powered by MHonArc 2.6.16.

Top of Page