# CGAL, convex hull

This topic is 4814 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Im trying to use CGAL to compute a convex hull for to use in occulsion test, the seems to work, but I cant figure out how to get the points/verts. this is what I got so far..

typedef CGAL::Homogeneous<RT>		K;
typedef K::Point_3			Point_3;
typedef CGAL::Convex_hull_traits_3<K>	Traits;
typedef Traits::Polyhedron_3		Polyhedron_3;
typedef std::list<Point_3>		pointlist;

bool CGALTEST(void)
{
pointlist points_in;
points_in.push_back(Point_3(0, 0, 0));
points_in.push_back(Point_3(3, 4, 0));
//and so on....

CGAL::Object ch_object;

CGAL::convex_hull_3(points_in.begin(), points_in.end(), ch_object);

if(ch_object.is_empty())
{
return false;
}

return true;
}


I want to get the points/verts from "ch_object" and put the in a list of my own vertex format, for exampel struct vertex { float x,y,z; } How do I do this? Polyhedron_3 polyhedron; CGAL::assign(polyhedron, ch_object); perhaps, but how do I use the Polyhedron_3? /Luger

##### Share on other sites
Something like this perhaps:
  // Retrieve the triangles  Traits::Point_3 p1, p2, p3;  Traits::Vector_3 normal;  Polyhedron_3::Facet_iterator f;  Polyhedron_3::Halfedge_handle current;  for ( f = polyhedron.facets_begin(); f != polyhedron.facets_end(); f++ )  {  	// Get the three triangle points    current = f->halfedge();    p1 = current->vertex()->point();    p2 = current->next()->vertex()->point();    p3 = current->next()->next()->vertex()->point();    // Compute the face normal    normal = CGAL::cross_product(p1-p2, p1-p3);    // Prepare a triangle    CPoint ptNormal = CPoint( to_double( normal.x() ), to_double( normal.y() ), to_double( normal.z() ) );    CPoint ptA 			= CPoint( to_double( p1.x() ), to_double( p1.y() ), to_double( p1.z() ) );    CPoint ptB 			= CPoint( to_double( p2.x() ), to_double( p2.y() ), to_double( p2.z() ) );    CPoint ptC 			= CPoint( to_double( p3.x() ), to_double( p3.y() ), to_double( p3.z() ) );    // Add a triangle    CTriangle tri;    tri.m_ptVertices[0] = ptA; tri.m_ptNormals[0] = ptNormal;    tri.m_ptVertices[1] = ptB; tri.m_ptNormals[1] = ptNormal;    tri.m_ptVertices[2] = ptC; tri.m_ptNormals[2] = ptNormal;    m_vTriangles.push_back( tri );  }

Greetz,

Illco

##### Share on other sites
That was just what I was looking for, thx Illco!

You saved me alot of time on reading the manual. =)

/Luger

1. 1
Rutin
38
2. 2
3. 3
4. 4
5. 5

• 11
• 9
• 12
• 14
• 9
• ### Forum Statistics

• Total Topics
633350
• Total Posts
3011471
• ### Who's Online (See full list)

There are no registered users currently online

×