Fix crash in halfspaces_intersection_3

This commit is contained in:
Jocelyn MEYRON 2014-07-17 16:11:52 +02:00
parent 3ee7070476
commit cb18c331b2
2 changed files with 45 additions and 11 deletions

View File

@ -8,7 +8,6 @@
#include <CGAL/convex_hull_3.h>
#include <CGAL/intersections.h>
#include <CGAL/assertions.h>
#include <CGAL/Point_inside_polyhedron_3.h>
namespace CGAL
{
@ -107,9 +106,10 @@ namespace CGAL
// To do this, for each dual vertex, we circulate around this vertex
// and we add an edge between each facet we encounter
for (Vertex_const_iterator it = _dual.vertices_begin();
it != _dual.vertices_end(); ++it, ++n) {
it != _dual.vertices_end(); ++it) {
typename Polyhedron_dual::Halfedge_around_vertex_const_circulator
h0 = it->vertex_begin(), hf = h0;
B.begin_facet();
do {
B.add_vertex_to_facet(primal_vertices[hf->facet()]);
@ -120,6 +120,43 @@ namespace CGAL
B.end_surface();
}
};
// Functor used during the computation of the equations
// of the facets of a convex polyhedron
template <class Facet>
struct Plane_equation_convex_polyhedron {
typename Facet::Plane_3 operator()(Facet& f) {
typename Facet::Halfedge_handle h = f.halfedge();
typedef typename Facet::Plane_3 Plane;
return Plane(h->vertex()->point(),
h->next()->vertex()->point(),
h->next()->next()->vertex()->point());
}
};
// Test if a point is inside a convex polyhedron
template <class Polyhedron>
bool point_inside_convex_polyhedron (Polyhedron &P,
typename Polyhedron::Traits::Point_3 const& p) {
// Compute the equations of the facets of the polyhedron
typedef typename Polyhedron::Traits::Kernel K;
typedef typename Polyhedron::Plane_iterator Plane_iterator;
typedef typename Polyhedron::Facet Facet;
std::transform(P.facets_begin(), P.facets_end(), P.planes_begin(),
Plane_equation_convex_polyhedron<Facet>());
// Check if the point is inside the polyhdreon
for (Plane_iterator pit = P.planes_begin();
pit != P.planes_end();
++pit) {
if (! pit->has_on_negative_side(p)) {
return false;
}
}
return true;
}
} // namespace internal
} // namespace Convex_hull_3
@ -140,10 +177,9 @@ namespace CGAL
Builder build_primal(dual_convex_hull, origin);
P.delegate(build_primal);
// Posterior check for the origin inside the cmputed polyhedron
Point_inside_polyhedron_3<Polyhedron, K> is_inside(P);
CGAL_assertion_msg(is_inside(origin) == CGAL::ON_BOUNDED_SIDE,
"halfspaces_intersection_3: origin not in the polyhedron");
// Posterior check if the origin is inside the computed polyhedron
Polyhedron Q(P);
CGAL_assertion_msg(!Convex_hull_3::internal::point_inside_convex_polyhedron(Q, origin), "halfspaces_intersection_3: origin not in the polyhedron");
}
} // namespace CGAL

View File

@ -2,12 +2,14 @@
#define CGAL_VCM_ESTIMATE_NORMALS_H
#include <CGAL/property_map.h>
#include <CGAL/assertions.h>
#include <CGAL/Delaunay_triangulation_3.h>
#include <CGAL/voronoi_covariance_3.h>
#include <CGAL/vcm_utilities.h>
#include <CGAL/Kd_tree.h>
#include <CGAL/Search_traits_3.h>
#include <CGAL/Orthogonal_k_neighbor_search.h>
#include <CGAL/Fuzzy_sphere.h>
#include <Eigen/Dense>
@ -284,11 +286,7 @@ vcm_estimate_normals (ForwardIterator first, ///< iterator over the first input
for (ForwardIterator it = first; it != beyond; ++it) {
Eigen::Vector3f enormal;
Eigen::Vector3f dir;
if (! internal::extract_greater_eigenvector(cov[i], enormal)) {
std::cerr << "Error during extraction of normal: " <<
"the covariance matrix is not diagonalizable!\n";
exit(1);
}
internal::extract_greater_eigenvector(cov[i], enormal);
CGAL::Vector_3<Kernel> normal(enormal[0],
enormal[1],