Jump to content
  • Advertisement
Sign in to follow this  
Lugerns

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.

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!