This post was updated on .
Given two groups of points A and B, I'd like to compute the distance of all the points in B to the convex hull of A. I've done this before, and I know that I can leverage AABB trees for this. I thought I knew everything that was involved in this computation, but I have a feeling that I don't.
Below is a short code of what I'm trying to do typedef CGAL::Simple_cartesian<float> K; typedef K::FT FT; typedef K::Point_3 Point; typedef CGAL::Polyhedron_3<K> Polyhedron; typedef CGAL::AABB_face_graph_triangle_primitive<Polyhedron> Primitive; typedef CGAL::AABB_traits<K, Primitive> Traits; typedef CGAL::AABB_tree<Traits> Tree; typedef Tree::Point_and_primitive_id Point_and_primitive_id; std::vector<Point> cgal_points; for (int i = 0; i < capPoints.size(); i++) cgal_points.push_back(Point(capPoints[i].x(), capPoints[i].y(), capPoints[i].z())); Polyhedron polyhedron; CGAL::convex_hull_3(cgal_points.begin(), cgal_points.end(), polyhedron); Tree tree(faces(polyhedron).first, faces(polyhedron).second, polyhedron); tree.accelerate_distance_queries(); Point_inside inside_tester(tree); for (int i = 0; i < pointCloud.size(); i++) { auto vertex = pointCloud[i]; Point query(vertex.x(), vertex.y(), vertex.z()); auto pnp = tree.closest_point_and_primitive(query); Polyhedron::Face_handle f = pnp.second; float distToFace = CGAL::squared_distance(f->plane(), query); float distToPoint = CGAL::squared_distance(pnp.first, query); // The above values are way dissimilar! } From what I "thought" I knew, I computed the distance of the query point with the closest point of the AABB tree using squared_distance function (stored in distToPoint in the above snippet). But then, I felt the results were off a bit, so I tried computing the query point's distance to the closest face. Again I used squared_distance but this time on the face's plane (basically computing point/plane distance, stored in distToFace above.) If my understanding was correct, the two values had to be equal, but it seems that this is not the case and I am super confused as to why :( Also, I noticed that if I change my kernel from Simple_cartesian<float> to (say) Simple_cartesian<double>, I'd get nan values instead of distances, and again, I have no idea why this is happening. Any helps is greatly appreciated :) |
The planes of the facets of the polyhedron are not initialized.
See [1] for example for how to initialize them. Sebastien. [1] http://doc.cgal.org/latest/Convex_hull_3/Convex_hull_3_2quickhull_3_8cpp-example.html On 11/22/2016 06:45 AM, SirM2X wrote: > Given two groups of points A and B, I'd like to compute the distance of all > the points in B to the convex hull of A. I've done this before, and I know > that I can leverage AABB trees for this. I thought I knew everything that > was involved in this computation, but I have a feeling that I don't. > Below is a short code of what I'm trying to do > > > > From what I "thought" I knew, I computed the distance of the query point > with the closest point of the AABB tree using /squared_distance/ function > (stored in /distToPoint/ in the above snippet). But then, I felt the results > were off a bit, so I tried computing the query point's distance to the > closest face. Again I used /squared_distance/ but this time on the face's > plane (basically computing point/plane distance, stored in /distToFace/ > above.) > > If my understanding was correct, the two values had to be equal, but it > seems that this is not the case and I am super confused as to why :( > > Also, I noticed that if I change my kernel from /Simple_cartesian<float>/ to > (say) /Simple_cartesian<double>/, I'd get nan values instead of distances, > and again, I have no idea why this is happening. > > Any helps is greatly appreciated :) > > > > -- > View this message in context: http://cgal-discuss.949826.n4.nabble.com/Inconsistent-point-convex-hull-distance-computation-values-tp4662388.html > Sent from the cgal-discuss mailing list archive at Nabble.com. > -- You are currently subscribed to cgal-discuss. To unsubscribe or access the archives, go to https://sympa.inria.fr/sympa/info/cgal-discuss |
Thanks a lot Sebastien. That was in fact the issue...
Just to confirm, the closest point that closest_point_and_primitive call gives me is the closest point ON the mesh, right? It's not giving me the closest vertex or anything is it? Thanks again |
On 11/22/2016 07:40 PM, SirM2X wrote:
> Thanks a lot Sebastien. That was in fact the issue... > Just to confirm, the closest point that /closest_point_and_primitive/ call > gives me is the closest point ON the mesh, right? It's not giving me the > closest vertex or anything is it? yes. > > Thanks again > > > > > -- > View this message in context: http://cgal-discuss.949826.n4.nabble.com/Inconsistent-point-convex-hull-distance-computation-values-tp4662388p4662393.html > Sent from the cgal-discuss mailing list archive at Nabble.com. > -- You are currently subscribed to cgal-discuss. To unsubscribe or access the archives, go to https://sympa.inria.fr/sympa/info/cgal-discuss |
Free forum by Nabble | Edit this page |