halfspace_intersection_3 crash

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

halfspace_intersection_3 crash

LingjieZhu
Hi all,

When I changed the Exact_predicates_inexact_constructions_kernel to Simple_cartesian<double> in halfspace_intersection_3 example, the program may crash in some rare cases.
Here is the code.
-----------------------------------------------
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Convex_hull_3/dual/halfspace_intersection_3.h>
#include <CGAL/point_generators_3.h>
#include <list>
//typedef CGAL::Exact_predicates_inexact_constructions_kernel   K;
typedef CGAL::Simple_cartesian<double>                        K;
typedef K::Plane_3                                            Plane;
typedef K::Point_3                                            Point;
typedef CGAL::Polyhedron_3<K>                                 Polyhedron_3;
// compute the tangent plane of a point
template <typename K>
typename K::Plane_3 tangent_plane (typename K::Point_3 const& p) {
    typename K::Vector_3 v(p.x(), p.y(), p.z());
    v = v / sqrt(v.squared_length());
    typename K::Plane_3 plane(v.x(), v.y(), v.z(), -(p - CGAL::ORIGIN) * v);
    return plane;
}
int main (void) {
    int i = 100000;
   
    while (i--) {
        // number of generated planes
        int N = 200;
        // generates random planes on a sphere
        std::list<Plane> planes;
        CGAL::Random_points_on_sphere_3<Point> g;
        for (int i = 0; i < N; i++) {
            planes.push_back(tangent_plane<K>(*g++));
        }
        // define polyhedron to hold the intersection
        Polyhedron_3 P;
        // compute the intersection
        // if no point inside the intersection is provided, one
        // will be automatically found using linear programming
        CGAL::halfspace_intersection_3(planes.begin(),
            planes.end(),
            P,
            boost::make_optional(Point(0, 0, 0)) );
    }
    std::cout << "Finished." << std::endl;

    return 0;
}
-----------------------------------------------
I was wondering if there is any restriction of the Kernel used in halfspace_intersection_3.
Am I supposed to use exact predicate only when using this function?

Thanks,

Andrew
Reply | Threaded
Open this post in threaded view
|

Re: halfspace_intersection_3 crash

Sebastien Loriot (GeometryFactory)
Exact predicates are needed.

See also:
http://www.cgal.org/FAQ.html#inexact_NT

Sebastien.

On 01/11/2017 10:03 AM, AndrewLiu wrote:

> Hi all,
>
> When I changed the Exact_predicates_inexact_constructions_kernel to
> Simple_cartesian<double> in  halfspace_intersection_3 example
> <http://doc.cgal.org/latest/Convex_hull_3/index.html#Convex_hull_3HalfspaceIntersection>
> , the program may crash in some rare cases.
> Here is the code.
> -----------------------------------------------
> #include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
> #include <CGAL/Convex_hull_3/dual/halfspace_intersection_3.h>
> #include <CGAL/point_generators_3.h>
> #include <list>
> //typedef CGAL::Exact_predicates_inexact_constructions_kernel   K;
> typedef CGAL::Simple_cartesian<double>                        K;
> typedef K::Plane_3                                            Plane;
> typedef K::Point_3                                            Point;
> typedef CGAL::Polyhedron_3<K>                                 Polyhedron_3;
> // compute the tangent plane of a point
> template <typename K>
> typename K::Plane_3 tangent_plane (typename K::Point_3 const& p) {
>     typename K::Vector_3 v(p.x(), p.y(), p.z());
>     v = v / sqrt(v.squared_length());
>     typename K::Plane_3 plane(v.x(), v.y(), v.z(), -(p - CGAL::ORIGIN) * v);
>     return plane;
> }
> int main (void) {
>     int i = 100000;
>
>     while (i--) {
>         // number of generated planes
>         int N = 200;
>         // generates random planes on a sphere
>         std::list<Plane> planes;
>         CGAL::Random_points_on_sphere_3<Point> g;
>         for (int i = 0; i < N; i++) {
>             planes.push_back(tangent_plane<K>(*g++));
>         }
>         // define polyhedron to hold the intersection
>         Polyhedron_3 P;
>         // compute the intersection
>         // if no point inside the intersection is provided, one
>         // will be automatically found using linear programming
>         CGAL::halfspace_intersection_3(planes.begin(),
>             planes.end(),
>             P,
>             boost::make_optional(Point(0, 0, 0)) );
>     }
>     std::cout << "Finished." << std::endl;
>
>     return 0;
> }
> -----------------------------------------------
> I was wondering if there is any restriction of the Kernel used in
> halfspace_intersection_3.
> Am I supposed to use exact predicate only when using this function?
>
> Thanks,
>
> Andrew
>
>
>
> --
> View this message in context: http://cgal-discuss.949826.n4.nabble.com/halfspace-intersection-3-crash-tp4662456.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


Reply | Threaded
Open this post in threaded view
|

Re: halfspace_intersection_3 crash

LingjieZhu

The link is helpful, thanks a lot !