Subversion Repositories gelsvn

Rev

Rev 205 | Go to most recent revision | Blame | Last modification | View Log | RSS feed

#include <iostream>

#include "CGLA/Vec3f.h"
#include "HMesh/quadric_simplify.h"
#include "HMesh/x3d_save.h"
#include "HMesh/x3d_load.h"
#include "HMesh/obj_load.h"
#include "HMesh/caps_and_needles.h"

using namespace std;
using namespace CGLA;
using namespace HMesh;

int main(int argc, char** argv)
{
    Manifold m;
                if(argc>1)
                {
                                cout << "Loading : " << argv[1] << endl;
                                string file = argv[1];
                                if(file.substr(file.length()-4,file.length())==".obj")
                                {
                                                obj_load(file, m);
                                }
                                else
                                                x3d_load(file, m);
                }
                else
                {
                                cout << "No model" << endl;
                                exit(0);
                }
    
    Vec3f p0, p7;
    m.get_bbox(p0, p7);
    Vec3f d = p7-p0;
    float s = 1.0/d.max_coord();
    cout << p0 << p7 << d << s << endl;
    
    for(VertexIter vi = m.vertices_begin(); vi != m.vertices_end(); ++vi)
    {
                                vi->pos = (vi->pos - p0) * s;
    }

                float avg_length = 0;
    for(HalfEdgeIter h = m.halfedges_begin(); h != m.halfedges_end(); ++h)
    {
                                avg_length += length(h);
    }
                avg_length /= m.no_halfedges();
    
    cout << "Perform quadric based simplification ... " << endl;
    if(argc>2)
                        quadric_simplify(m,atoi(argv[2]));
                else
                        quadric_simplify(m,10000);

                cout << "Removing caps and needles ... " << endl;
                remove_caps_from_trimesh(m, static_cast<float>(M_PI) * 0.85f);
                remove_needles_from_trimesh(m, 0.1 * avg_length);
    
    cout << "Validity: " << m.is_valid() << endl;
    cout << "Now saving ... " << endl;
    x3d_save("decimated.x3d", m);
}