Skip to Content.
Sympa Menu

cgal-discuss - Re: [cgal-discuss] Cannot read Polyhedron from OFF .

Subject: CGAL users discussion list

List archive

Re: [cgal-discuss] Cannot read Polyhedron from OFF .


Chronological Thread 
  • From: Laurent Rineau <>
  • To:
  • Subject: Re: [cgal-discuss] Cannot read Polyhedron from OFF .
  • Date: Thu, 4 Dec 2008 18:41:12 +0100

On Thursday 04 December 2008 17:42:07

wrote:
> Hi,
>
> I am a newbie to CGAL. I was writing a code to access OFF files. I am not
> able to access the properties of mesh. Could some one please point out
> where I am making the mistake.
>
> #include <CGAL/Simple_cartesian.h>
> #include <CGAL/Polyhedron_3.h>
> #include <CGAL/IO/Polyhedron_iostream.h>
>
> #include <iostream>
> #include <istream>
> #include <fstream>
>
> typedef CGAL::Simple_cartesian<double> Kernel;
> typedef CGAL::Polyhedron_3<Kernel> Polyhedron;
>
> int main() {
> std::ifstream stream("test.off");
> Polyhedron P;
> stream >> P;
> std::cout << "\n "<<P.size_of_vertices();
> return 0;
> }

The correct code is that one:

int main() {
std::ifstream stream("test.off");
if(!stream} {
std::cerr << "Cannot open file!\n";
return 1;
}
Polyhedron P;
stream >> P;
if(!stream} {
std::cerr << "test.off is not a polyhedron\n";
return 1;
}
std::cout << "\n "<<P.size_of_vertices();
return 0;
}

That is: you need to test the good() bits of the stream *after* the attempt
to
read a polyhedron from it.

Most probably you OFF file does not correspond to a manifold *and oriented*
mesh (with optional boundaries). You need to orient your off before trying to
read it to a polyhedron.

--
Laurent Rineau, PhD
Engineer at GeometryFactory
http://www.geometryfactory.com/



Archive powered by MHonArc 2.6.16.

Top of Page