Search code examples
cgal

How do I run the subdivision example in the CGAL user manual


Ok, so I finally installed CGAL and managed to run some of the examples. Now I need to run the code below, which I found in the CGAL SubDivision manual (http://doc.cgal.org/latest/Subdivision_method_3/index.html#Chapter_3D_Surface_Subdivision_Methods):

#include <CGAL/Simple_cartesian.h>
#include <CGAL/Subdivision_method_3.h>
#include <iostream>
#include <CGAL/Polyhedron_3.h>
#include <CGAL/IO/Polyhedron_iostream.h>
typedef CGAL::Simple_cartesian<double> Kernel;
typedef CGAL::Polyhedron_3<Kernel> Polyhedron;
using namespace std;
using namespace CGAL;
int main(int argc, char **argv) {
    if (argc != 2) {
        cout << "Usage: DooSabin_subdivision d < filename" << endl;
        cout << " d: the depth of the subdivision (0 < d < 10)" << endl;
        cout << " filename: the input mesh (.off)" << endl;
        return 0;
}
    int d = argv[1][0] - '0';
    Polyhedron P;
    cin >> P; // read the .off
    Subdivision_method_3::DooSabin_subdivision(P,d);
    cout << P; // write the .off
    return 0;
}

How am I supposed to run this correctly? I can make the executable successfully (using cmake) and I run it with one parameter which is the depth (e.g. >./subd 3).

Then I am supposed to provide a filename for an off file. So I downloaded an example model (airplane_open.off), but when I enter the name it doesn't read from the file, instead it creates a Polyhedron instance with three zero values (default constructor?).

Any suggestions? I am actually interested in the Stanford bunny model and the sqrt3 subdivision algorithm but if the code above runs I can make the necessary modifications to use the bunny.

I am using a mac and the terminal.


Solution

  • As said in the usage output, you must call

    ./subd 3 < airplane_open.off
    

    < to redirect the standart input from a given file.

    Guillaume