Skip to Content.
Sympa Menu

cgal-discuss - Re: [cgal-discuss] scan_OFF result operator(): input error: file format is not in OFF.

Subject: CGAL users discussion list

List archive

Re: [cgal-discuss] scan_OFF result operator(): input error: file format is not in OFF.


Chronological Thread 
  • From: sergio campo <>
  • To:
  • Subject: Re: [cgal-discuss] scan_OFF result operator(): input error: file format is not in OFF.
  • Date: Tue, 29 May 2018 16:20:42 +0200
  • Authentication-results: mail2-smtp-roc.national.inria.fr; spf=None ; spf=Pass ; spf=None
  • Ironport-phdr: 9a23:nqdWHxfzNy0m5Otrzp3RGXIzlGMj4u6mDksu8pMizoh2WeGdxcuzYR7h7PlgxGXEQZ/co6odzbaO6Oa4ASQp2tWoiDg6aptCVhsI2409vjcLJ4q7M3D9N+PgdCcgHc5PBxdP9nC/NlVJSo6lPwWB6nK94iQPFRrhKAF7Ovr6GpLIj8Swyuu+54Dfbx9HiTahb75+Ngm6oRnMvcQKnIVuLbo8xAHUqXVSYeRWwm1oJVOXnxni48q74YBu/SdNtf8/7sBMSar1cbg2QrxeFzQmLns65Nb3uhnZTAuA/WUTX2MLmRdVGQfF7RX6XpDssivms+d2xSeXMdHqQb0yRD+v6bpgRh31hycdLzM28m/XhMx+gqxYvRyvuQBwzpXOb42JLvdzZL/Rcc8YSGdHQ81fVzZBAoS5b4YXFOoOI/xYr4b8p1sJsBCxGROjBOb3yj9Pm3T72rM63P49HgHH2gwgENwOsHPOrNXyL6oSXuW1w7PJzTXHdf9ZxTD96I3Rfx0nvPqCU7Vwcc/LxkkuEQPIllOQppb+MDyO0uQCrXKX4PZnVeKqk2Iotw5xrSKrxss2jYnJnI0VxkjL9Spnx4Y1IMO3SFJhYd+kHptfrT2VN5dxQsM4Q2Bkojo1yroDuZO9YSMEy4wnygbdZvGIaYSE/wzvWeaLLTp7mn5pYrKyihi0/EO90OPzTNO030xPriddktnDqHQN1xvL58iCUPR9/0Oh1S+B1gDW9u1IOE40mKrVJpI7zb4wkZ0TsUvHHiDogkn5kKiWdkA89uip7eTofKnmq4eeOoJ7kA3yL7oil8ylDek7LAQCRWiW9Oqk2L3m50L5QbFKjvMskqnetZDXPdobqbSlDA9U1IYj5Bi/DzC80NQfhnQHI1dFdwiGj4jtIV3BPPf4DfKnj1S2jDhr3+zGPqHmApjVMnfDn63ufbJk50FByQoz1sxQ549PCrEaO//zQU/wtNnADhAjKQC0wuDnCM981owEQ26PDLWZY+vutgqD6esrZuWNf4QIoy3VKv4/5veog2Vqt0UaePyy0IEYaXfwFf1jO0LRNWTlidYHHmkNpA0WQ+njiVnEWjlWMSXhF5kg7y02Xdr1RbzIQZqg1eTYjXWLW6ZOb2UDMWiiVHLhdoGKQfAJMXvALcpokzhCXr+kGdZ4iUOe8TTiwr8iFdL6vzUCvMu6htdw7uzX0xo18G4sVpnP4yS2V2hx21gwaXo20aR4+xEvz16C1e1nhqQdG4EIofxOVQg+ONjXyOkoU90=

Ok it works! this is the results(Thank you):

#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Surface_mesh.h>
#include <CGAL/Polygon_mesh_processing/self_intersections.h>

// ----------------------------------------------------------------------------
// CGAL::Polygon_mesh_processing::is_outward_oriented
// ----------------------------------------------------------------------------

#include <CGAL/Polygon_mesh_processing/orientation.h>

// ----------------------------------------------------------------------------
// scan_OFF
// ----------------------------------------------------------------------------
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Polyhedron_3.h>

// ----------------------------------------------------------------------------
// isOutwardOriented
// ----------------------------------------------------------------------
#include <CGAL/IO/OFF_reader.h>
#include <CGAL/Polygon_mesh_processing/polygon_soup_to_polygon_mesh.h>


#include <fstream>





// ----------------------------------------------------------------------------
// Types
// ----------------------------------------------------------------------------
typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
typedef CGAL::Surface_mesh<K::Point_3>             Mesh;
typedef boost::graph_traits<Mesh>::face_descriptor face_descriptor;

namespace PMP = CGAL::Polygon_mesh_processing;

// polyhedron
typedef CGAL::Polyhedron_3<K> Polyhedron;

bool getMeshFromPolygonSoup(const char* filename, Polyhedron &mesh)
{
std::ifstream input(filename);
if (!input)
{
std::cerr << "Cannot open file " << std::endl;
return false;
}
std::vector<K::Point_3> points;
std::vector< std::vector<std::size_t> > polygons;
if (!CGAL::read_OFF(input, points, polygons))
{
std::cerr << "Error parsing the OFF file " << std::endl;
return false;
}
CGAL::Polygon_mesh_processing::orient_polygon_soup(points, polygons);
CGAL::Polygon_mesh_processing::polygon_soup_to_polygon_mesh(points, polygons, mesh);
return true;
}

bool isOutwardOriented(const char* filename)
{
Polyhedron mesh;

if (!getMeshFromPolygonSoup(filename, mesh))
{
std::cerr << "isOutwardOriented: Cannot open file " << std::endl;
return false;
}

if (CGAL::is_closed(mesh) && (!CGAL::Polygon_mesh_processing::is_outward_oriented(mesh)))
{
std::cerr << "isOutwardOriented: it not outward oriented" << std::endl;
return false;
}
return true;
}

int main(int argc, char* argv[])
{
  const char* filename = argv[1];

  bool is_outward_oriented_mesh = isOutwardOriented(filename);
  if (!is_outward_oriented_mesh)
  {
  std::cerr << "Not a outward oriented mesh" << std::endl;
  }
  
  std::ifstream input(filename);
  if (!input)
  {
  std::cerr << "Cannot open file " << std::endl;
  }

  Polyhedron M;     // a typical definition of a Polyhedron (see other examples)
  scan_OFF(input, M, true);                   // read OFF file in verbose mode
  assert(input);                       // input fails iff mesh is not manifold
    
  return 0;
}

Thanks and Best regards,

Sergio

On Tue, May 29, 2018 at 12:07 PM, Andreas Fabri <> wrote:

Have a look at this example

https://doc.cgal.org/latest/Polygon_mesh_processing/Polygon_mesh_processing_2polygon_soup_example_8cpp-example.html#a3


On 5/29/2018 11:54 AM, sergio campo wrote:
Thanks for your answer. But how It can be detected before corret it?
Sergio

On Tue, May 29, 2018 at 11:03 AM, Andreas Fabri <> wrote:


The orientation of the triangles is not coherent.

You have for examples 2 triangles with an edge going from vertex 0 to vertex 1

You should read a polygon soup and call the function if it can be oriented


andreas


On 5/29/2018 10:56 AM, sergio wrote:
I'm implementing algorithms to detect(Only detection of error, not
correction) if mesh has errors like self-intersection, wrong oriented
normals, etc.
Using scan_OFF with a *.off file it always has result "operator(): input
error: file format is not in OFF."
Why 

// kernel
typedef CGAL::Exact_predicates_inexact_constructions_kernel Kernel;

// polyhedron
typedef CGAL::Polyhedron_3<Kernel> Polyhedron;

int main(int argc, char* argv[])
{
  const char* filename = (argc > 1) ? argv[1] : "tetrahedron-piramide.off";
  std::ifstream input(filename);
  
  Mesh mesh;
  if (!input || !(input >> mesh) || !CGAL::is_triangle_mesh(mesh))
  {
    std::cerr << "Not a valid input file." << std::endl;
    return 1;
  }
  
  Polyhedron M;     // a typical definition of a Polyhedron (see other
examples)
  scan_OFF(input, M, true);                   // read OFF file in verbose
mode
  assert(input);                       // input fails iff mesh is not
manifold
  return 0;
}

This is a simple mesh and I think it does not have errors. Added file 
tetrahedron-piramide.off
<http://cgal-discuss.949826.n4.nabble.com/file/t375958/tetrahedron-piramide.off> 
.

Thanks in advance



--
Sent from: http://cgal-discuss.949826.n4.nabble.com/


-- 
Andreas Fabri, PhD
Chief Officer, GeometryFactory
Editor, The CGAL Project

phone: +33.492.954.912    skype: andreas.fabri


-- 
Andreas Fabri, PhD
Chief Officer, GeometryFactory
Editor, The CGAL Project

phone: +33.492.954.912    skype: andreas.fabri




Archive powered by MHonArc 2.6.18.

Top of Page