Skip to Content.
Sympa Menu

cgal-discuss - [cgal-discuss] cannot read Polygon_2 from std::istream (with CGAL::Gps_circle_segment_traits_2)

Subject: CGAL users discussion list

List archive

[cgal-discuss] cannot read Polygon_2 from std::istream (with CGAL::Gps_circle_segment_traits_2)


Chronological Thread 
  • From: Forest Darling <>
  • To:
  • Subject: [cgal-discuss] cannot read Polygon_2 from std::istream (with CGAL::Gps_circle_segment_traits_2)
  • Date: Thu, 13 Aug 2020 14:54:23 -0500
  • Authentication-results: mail3-smtp-sop.national.inria.fr; spf=None ; spf=Pass ; spf=None
  • Ironport-phdr: 9a23:tNxysxZXfcbRszFwuBCEdQH/LSx+4OfEezUN459isYplN5qZr8+/bnLW6fgltlLVR4KTs6sC17OI9fG9EjVZv96oizMrSNR0TRgLiMEbzUQLIfWuLgnFFsPsdDEwB89YVVVorDmROElRH9viNRWJ+iXhpTEdFQ/iOgVrO+/7BpDdj9it1+C15pbffxhEiCCybL9vLRi6twHcu8kZjYd/N6o8ywbCr2dVdehR2W5mP0+YkQzm5se38p5j8iBQtOwk+sVdT6j0fLk2QKJBAjg+PG87+MPktR/YTQuS/XQcSXkZkgBJAwfe8h73WIr6vzbguep83CmaOtD2TawxVD+/4apnVAPkhSEaPDM/7WrZiNF/jLhDrR2upxJxzY3abpyLOvViZa7deM8WSHBbU8pNSyBMAIWxZJYPAeobOuZYqpHwqVsJrRukGwasH//vwSJGiHDsx6061+UhEQfJ3Ac9GN8Ovmnbo8/vNKcWUOC1yqbIwC7Mb/NTwzj96YzIfgo9rvGLWLJ9aMzcwlQgGA3ZlFufs5DlPy+L2eQXtWiW9/ZtWP+thmMntg18oDaiytkwhoTGhI8bxEzJ+CR2zYg7J9C1TEx2bN+qHZZTqy2UN5d6Tt4gTm9ouSs0xaMLtIK9cSMXxponwBvfZOaGc4iO+h/jW+eRISt4hHJ4Y72znQq98U+lyuD6S8K6005KozJbntXQsn0BzR/e58idRvdg4Eus2iyD2g/R5+xCPEs6j7DUK4Q7zb41jpcTsVrMHivxmEjuia+ZbEQk+uyx5+XpZ7Xqu4aQN4F7hwz8KKgulcu/AeM3MggKQWeX4/iz1Lrm/UHhQbVKiOM5krXBvZzEOcgWorS1DgxV34o59hqzETSr3M4XkHQFNF5FfQiIj4ntO1HAOvD4CvK/jkyikDh23f/GJLnhApTLLnjMi7rhcrN95FRdyAo319xQ+5VUCrQZLPLpRkDxrMDYDgM+MwGs3+nnB89y1ocHVW2SA6+ZK7/dsUKT5uI0OOSMf48UuDPlK/c//fLujHk5mUUcfaazx5cXZmq4TbxaJBCSbnPox9sACmwXpREWTerwiVTEXyQASWy1WvcS4Ss2E57uIY7ZQoGrj/TV0iuyBJlXYG9uBVWFEHOufIKBDaRfIBmOK9Nsx2RXHYOqTJUsgEn36V3KjoF/J++RwRU28JLu0N8vur/WnBA2sCNxVoGTjz7LQGZzkWcFATQx2fIn+BAv+hK4yaF9xsdgO5lL/foQC1U1MJfdy6pxDNWgAluQLOfMc06vR5CdOR90S9swx9EUZEMkQoetixnC22yhBLpHzrE=

Hello,

I have a "CGAL::Gps_circle_segment_traits_2" Polygon_2  that I generate and manipulate in CGAL. When trying to take the orientation of the polygon (one of the first operations I do), CGAL fails a precondition assertion. This only happens if I use the "CGAL::Simple_cartesian<double>" kernel, it works with the "CGAL::Exact_predicates_exact_constructions_kernel" kernel.

It's a very basic shape, so I was trying to investigate the issue by creating a minimal C++ example to demonstrate the problem. However, I ran into another problem: while I can export the Polygon_2 as binary, I cannot import it!

It seems to be that while General_polygon_2 has the ability to read from an istream:
https://github.com/CGAL/releases/blob/bca0a8035cc3dafaba6f5c0888559c67f372223f/include/CGAL/General_polygon_2.h#L163

The "Traits::X_monotone_curve_2" which resolves to "_X_monotone_circle_segment_2" in the case of "CGAL::Gps_circle_segment_traits_2" only supports exporting to an ostream, not importing from an istream:

https://github.com/CGAL/releases/blob/bca0a8035cc3dafaba6f5c0888559c67f372223f/include/CGAL/Arr_geometry_traits/Circle_segment_2.h#L2477

Is this an oversight? Is it by design? Or am I missing something here? I attached a main.cpp file that will give the compilation error when trying to deserialize the Polygon_2.

I'd appreciate any help!

Thanks,

--Forest
#include <iostream>

// #define USE_EXACT_MATH

#ifdef USE_EXACT_MATH
#include <CGAL/Exact_predicates_exact_constructions_kernel.h>
#else // !defined(USE_EXACT_MATH)
#include <CGAL/Simple_cartesian.h>
#endif // USE_EXACT_MATH

#include <CGAL/Gps_circle_segment_traits_2.h>
#include <CGAL/General_polygon_set_2.h>
#include <CGAL/General_polygon_2.h>

#ifdef USE_EXACT_MATH
typedef CGAL::Exact_predicates_exact_constructions_kernel Kernel;
#else // !defined(USE_EXACT_MATH)
typedef CGAL::Simple_cartesian<double> Kernel;
#endif // USE_EXACT_MATH

typedef Kernel::Point_2                                   Point_2;
typedef Kernel::Circle_2                                  Circle_2;
typedef Kernel::Line_2                                    Line_2;
typedef CGAL::Gps_circle_segment_traits_2<Kernel>         Traits_2;
typedef CGAL::General_polygon_set_2<Traits_2>             Polygon_set_2;
typedef Traits_2::Polygon_2                               Polygon_2;
typedef Traits_2::Polygon_with_holes_2                    Polygon_with_holes_2;
typedef Traits_2::Curve_2                                 Curve_2;
typedef Traits_2::X_monotone_curve_2                      X_monotone_curve_2;

int main(int argc, char **argv)
{
    Polygon_2 poly;
    
    // read Polygon_2 from binary file
    {
        std::ifstream f("bad.bin");
        CGAL::set_binary_mode(f);
        f >> poly;
    }

    std::cout << "poly = " << poly << std::endl;
    const int orient = poly.orientation();
    std::cout << "poly.orientation() = " << orient << std::endl;

    return 0;
}

Attachment: bad.bin
Description: Binary data



  • [cgal-discuss] cannot read Polygon_2 from std::istream (with CGAL::Gps_circle_segment_traits_2), Forest Darling, 08/13/2020

Archive powered by MHonArc 2.6.19+.

Top of Page