CGAL exception while reading CNOFF file

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

CGAL exception while reading CNOFF file

J. Scheurich
Hi,

When i run the following program under Ubuntu 18.04 (X86_64)...

// compile:   g++ -g -O0 readoff_vertexcolor.cpp -lCGAL
// test data:  https://wdune.ourproject.org/examples/test.off

#include <CGAL/Simple_cartesian.h>
typedef CGAL::Simple_cartesian<double> Kernel;
#include <CGAL/Exact_predicates_exact_constructions_kernel.h>
#include <CGAL/Surface_mesh.h>
#include <CGAL/Polygon_mesh_processing/corefinement.h>
#include <CGAL/Polygon_mesh_processing/self_intersections.h>
#include <CGAL/Polygon_mesh_processing/triangulate_faces.h>
#include <CGAL/boost/graph/dijkstra_shortest_paths.h>
#include <CGAL/exceptions.h>
#include <CGAL/IO/Color.h>
#include <boost/graph/prim_minimum_spanning_tree.hpp>
#include <boost/foreach.hpp>
typedef Kernel::Point_3 Point;
typedef CGAL::Surface_mesh<Point> Surface;
typedef CGAL::Surface_mesh<Point> SurfaceMesh;
typedef CGAL::Color Color;
typedef Surface::Vertex_index vertex_index;
typedef boost::graph_traits<Surface>::vertex_descriptor vertex_descriptor;
typedef boost::graph_traits<Surface>::face_descriptor face_descriptor;
typedef boost::graph_traits<Surface>::halfedge_descriptor
halfedge_descriptor;
std::vector<Point> verts;
std::vector<Color> cols;

int main(int argc, char **argv)
{
     const char *filename = "test.off";
     std::ifstream input(filename);
     SurfaceMesh *mesh = new SurfaceMesh();

     if (!input || !(input >> *mesh)) {
         perror(filename);
     }

    SurfaceMesh::Property_map<SurfaceMesh::Vertex_index, CGAL::Color>
vcolors =
         mesh->property_map<SurfaceMesh::Vertex_index, CGAL::Color >
         ("v:color").first;

     bool colorExists = mesh->property_map
         <SurfaceMesh::Vertex_index, CGAL::Color>("v:color").second;

     for (SurfaceMesh::Vertex_index vi : mesh->vertices()) {
         verts.push_back(mesh->point(vi));
         if (colorExists )
             cols.push_back(vcolors[vi]);
     }
}

I get:

$ ./a.out
terminate called after throwing an instance of 'CGAL::Assertion_exception'
   what():  CGAL ERROR: assertion violation!
Expr: n > 2
File: /usr/include/CGAL/boost/graph/Euler_operations.h
Line: 588
Aborted (core dumped)

What is wrong ?

so long
MUFTI



--
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: CGAL exception while reading CNOFF file

Sebastien Loriot (GeometryFactory)
Created this issue to track the pb:

https://github.com/CGAL/cgal/issues/4499

Sebastien.

On 1/31/20 3:52 AM, J. Scheurich wrote:

> Hi,
>
> When i run the following program under Ubuntu 18.04 (X86_64)...
>
> // compile:   g++ -g -O0 readoff_vertexcolor.cpp -lCGAL
> // test data:  https://wdune.ourproject.org/examples/test.off
>
> #include <CGAL/Simple_cartesian.h>
> typedef CGAL::Simple_cartesian<double> Kernel;
> #include <CGAL/Exact_predicates_exact_constructions_kernel.h>
> #include <CGAL/Surface_mesh.h>
> #include <CGAL/Polygon_mesh_processing/corefinement.h>
> #include <CGAL/Polygon_mesh_processing/self_intersections.h>
> #include <CGAL/Polygon_mesh_processing/triangulate_faces.h>
> #include <CGAL/boost/graph/dijkstra_shortest_paths.h>
> #include <CGAL/exceptions.h>
> #include <CGAL/IO/Color.h>
> #include <boost/graph/prim_minimum_spanning_tree.hpp>
> #include <boost/foreach.hpp>
> typedef Kernel::Point_3 Point;
> typedef CGAL::Surface_mesh<Point> Surface;
> typedef CGAL::Surface_mesh<Point> SurfaceMesh;
> typedef CGAL::Color Color;
> typedef Surface::Vertex_index vertex_index;
> typedef boost::graph_traits<Surface>::vertex_descriptor vertex_descriptor;
> typedef boost::graph_traits<Surface>::face_descriptor face_descriptor;
> typedef boost::graph_traits<Surface>::halfedge_descriptor
> halfedge_descriptor;
> std::vector<Point> verts;
> std::vector<Color> cols;
>
> int main(int argc, char **argv)
> {
>      const char *filename = "test.off";
>      std::ifstream input(filename);
>      SurfaceMesh *mesh = new SurfaceMesh();
>
>      if (!input || !(input >> *mesh)) {
>          perror(filename);
>      }
>
>     SurfaceMesh::Property_map<SurfaceMesh::Vertex_index, CGAL::Color>
> vcolors =
>          mesh->property_map<SurfaceMesh::Vertex_index, CGAL::Color >
>          ("v:color").first;
>
>      bool colorExists = mesh->property_map
>          <SurfaceMesh::Vertex_index, CGAL::Color>("v:color").second;
>
>      for (SurfaceMesh::Vertex_index vi : mesh->vertices()) {
>          verts.push_back(mesh->point(vi));
>          if (colorExists )
>              cols.push_back(vcolors[vi]);
>      }
> }
>
> I get:
>
> $ ./a.out
> terminate called after throwing an instance of 'CGAL::Assertion_exception'
>    what():  CGAL ERROR: assertion violation!
> Expr: n > 2
> File: /usr/include/CGAL/boost/graph/Euler_operations.h
> Line: 588
> Aborted (core dumped)
>
> What is wrong ?
>
> so long
> MUFTI
>
>
>

--
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: CGAL exception while reading CNOFF file

Maxime Gimeno
Your input file is not following the standard, that is why it crashes in CGAL. If you use NOFF or CNOFF, normals are expected on the same line as their corresponding vertex, but they are not here. This messes the whole stream. I'm working on a fix to detect if the file is wrong and avoid a crash, but you won't be able to read your input file anywhere.

In CGAL we followed these rules to implement the OFF IO. I think you should have a look.

Le ven. 31 janv. 2020 à 05:00, Sebastien Loriot (GeometryFactory) <[hidden email]> a écrit :
Created this issue to track the pb:

https://github.com/CGAL/cgal/issues/4499

Sebastien.

On 1/31/20 3:52 AM, J. Scheurich wrote:
> Hi,
>
> When i run the following program under Ubuntu 18.04 (X86_64)...
>
> // compile:   g++ -g -O0 readoff_vertexcolor.cpp -lCGAL
> // test data:  https://wdune.ourproject.org/examples/test.off
>
> #include <CGAL/Simple_cartesian.h>
> typedef CGAL::Simple_cartesian<double> Kernel;
> #include <CGAL/Exact_predicates_exact_constructions_kernel.h>
> #include <CGAL/Surface_mesh.h>
> #include <CGAL/Polygon_mesh_processing/corefinement.h>
> #include <CGAL/Polygon_mesh_processing/self_intersections.h>
> #include <CGAL/Polygon_mesh_processing/triangulate_faces.h>
> #include <CGAL/boost/graph/dijkstra_shortest_paths.h>
> #include <CGAL/exceptions.h>
> #include <CGAL/IO/Color.h>
> #include <boost/graph/prim_minimum_spanning_tree.hpp>
> #include <boost/foreach.hpp>
> typedef Kernel::Point_3 Point;
> typedef CGAL::Surface_mesh<Point> Surface;
> typedef CGAL::Surface_mesh<Point> SurfaceMesh;
> typedef CGAL::Color Color;
> typedef Surface::Vertex_index vertex_index;
> typedef boost::graph_traits<Surface>::vertex_descriptor vertex_descriptor;
> typedef boost::graph_traits<Surface>::face_descriptor face_descriptor;
> typedef boost::graph_traits<Surface>::halfedge_descriptor
> halfedge_descriptor;
> std::vector<Point> verts;
> std::vector<Color> cols;
>
> int main(int argc, char **argv)
> {
>      const char *filename = "test.off";
>      std::ifstream input(filename);
>      SurfaceMesh *mesh = new SurfaceMesh();
>
>      if (!input || !(input >> *mesh)) {
>          perror(filename);
>      }
>
>     SurfaceMesh::Property_map<SurfaceMesh::Vertex_index, CGAL::Color>
> vcolors =
>          mesh->property_map<SurfaceMesh::Vertex_index, CGAL::Color >
>          ("v:color").first;
>
>      bool colorExists = mesh->property_map
>          <SurfaceMesh::Vertex_index, CGAL::Color>("v:color").second;
>
>      for (SurfaceMesh::Vertex_index vi : mesh->vertices()) {
>          verts.push_back(mesh->point(vi));
>          if (colorExists )
>              cols.push_back(vcolors[vi]);
>      }
> }
>
> I get:
>
> $ ./a.out
> terminate called after throwing an instance of 'CGAL::Assertion_exception'
>    what():  CGAL ERROR: assertion violation!
> Expr: n > 2
> File: /usr/include/CGAL/boost/graph/Euler_operations.h
> Line: 588
> Aborted (core dumped)
>
> What is wrong ?
>
> so long
> MUFTI
>
>
>

--
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: CGAL exception while reading CNOFF file

J. Scheurich

> Your input file is not following the standard, that is why it crashes
> in CGAL.

I found a COFF file in the internet:

https://people.sc.fsu.edu/~jburkardt/data/off/vertcube.off

This loads in meshlab and shows colors but it fails to be read with CGAL
in the following lines:

>
>     >
>     >      if (!input || !(input >> *mesh)) {
>     >          perror(filename);
>     >      }
>     ....
>     >
>     >      for (SurfaceMesh::Vertex_index vi : mesh->vertices()) {
>     >          verts.push_back(mesh->point(vi));
>     >          if (colorExists )
>     >              cols.push_back(vcolors[vi]);
>     >      }
>

Empty loop (found with  gdb).

so long
MUFTI

--
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: CGAL exception while reading CNOFF file

Maxime Gimeno
Indeed. There is a bug in our reader, if comments are found between the COFF and the 8 6 12, we crash. I'm going to fix that.

Le ven. 31 janv. 2020 à 10:46, J. Scheurich <[hidden email]> a écrit :

> Your input file is not following the standard, that is why it crashes
> in CGAL.

I found a COFF file in the internet:

https://people.sc.fsu.edu/~jburkardt/data/off/vertcube.off

This loads in meshlab and shows colors but it fails to be read with CGAL
in the following lines:
>
>     >
>     >      if (!input || !(input >> *mesh)) {
>     >          perror(filename);
>     >      }
>     ....
>     >
>     >      for (SurfaceMesh::Vertex_index vi : mesh->vertices()) {
>     >          verts.push_back(mesh->point(vi));
>     >          if (colorExists )
>     >              cols.push_back(vcolors[vi]);
>     >      }
>

Empty loop (found with  gdb).

so long
MUFTI

--
You are currently subscribed to cgal-discuss.
To unsubscribe or access the archives, go to
https://sympa.inria.fr/sympa/info/cgal-discuss