Rev 336 | 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/obj_save.h"
#include "HMesh/caps_and_needles.h"
#include "HMesh/triangulate.h"
using namespace std;
using namespace CGLA;
using namespace HMesh;
int main(int argc, char** argv)
{
Manifold m;
string file;
if(argc>1)
file = argv[1];
else
file = "../../data/bunny-little.x3d";
if(file.substr(file.length()-4,file.length())==".obj")
{
obj_load(file, m);
}
else
x3d_load(file, m);
shortest_edge_triangulate(m);
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;
Vec3f pcentre = (p7+p0)/2.0;
for(VertexIter vi = m.vertices_begin(); vi != m.vertices_end(); ++vi)
{
vi->pos = (vi->pos - pcentre) * s;
}
m.get_bbox(p0, p7);
cout << p0 << p7 << endl;
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]),0.05, true);
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;
obj_save("decimated.obj", m);
}