Rev 373 | Blame | Last modification | View Log | RSS feed
#include <iostream>
#include "Util/ArgExtracter.h"
#include "CGLA/Vec3f.h"
#include "HMesh/quadric_simplify.h"
#include "HMesh/x3d_save.h"
#include "HMesh/load.h"
#include "HMesh/obj_save.h"
#include "HMesh/caps_and_needles.h"
#include "HMesh/close_holes.h"
#include "HMesh/triangulate.h"
using namespace std;
using namespace CGLA;
using namespace HMesh;
using namespace Util;
int main(int argc, char** argv)
{
ArgExtracter ae(argc, argv);
float singular_thresh = 0.0001f;
ae.extract("-s", singular_thresh);
float keep_fraction = 0.01f;
ae.extract("-f", keep_fraction);
int choose_optimal_positions = true;
ae.extract("-o", choose_optimal_positions);
Manifold m;
string file;
if(ae.no_remaining_args()>0)
file = ae.get_last_arg();
else
file = "../../data/bunny-little.x3d";
load(file, m);
if(ae.extract("-c"))
{
cout << "Closing holes" << endl;
close_holes(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;
quadric_simplify(m,keep_fraction,singular_thresh,choose_optimal_positions);
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);
}