scan_OFF result operator(): input error: file format is not in OFF.

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

scan_OFF result operator(): input error: file format is not in OFF.

sergio
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/

--
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: scan_OFF result operator(): input error: file format is not in OFF.

andreas.fabri

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 <[hidden email]> 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
Reply | Threaded
Open this post in threaded view
|

Re: scan_OFF result operator(): input error: file format is not in OFF.

sergio
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 <[hidden email]> 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 <[hidden email]> 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