Subversion Repositories gelsvn

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
107 bj 1
#include <iostream>
2
 
367 jab 3
#include "Util/ArgExtracter.h"
107 bj 4
#include "CGLA/Vec3f.h"
178 bj 5
#include "HMesh/quadric_simplify.h"
6
#include "HMesh/x3d_save.h"
382 jab 7
#include "HMesh/load.h"
336 jab 8
#include "HMesh/obj_save.h"
178 bj 9
#include "HMesh/caps_and_needles.h"
365 jab 10
#include "HMesh/close_holes.h"
305 jab 11
#include "HMesh/triangulate.h"
107 bj 12
 
13
using namespace std;
14
using namespace CGLA;
15
using namespace HMesh;
367 jab 16
using namespace Util;
107 bj 17
 
18
int main(int argc, char** argv)
19
{
367 jab 20
	ArgExtracter ae(argc, argv);
21
 
373 jrf 22
	float singular_thresh = 0.0001f;
367 jab 23
	ae.extract("-s", singular_thresh);
373 jrf 24
	float keep_fraction = 0.01f;
367 jab 25
	ae.extract("-f", keep_fraction);
26
	int choose_optimal_positions = true;
27
	ae.extract("-o", choose_optimal_positions);
28
 
107 bj 29
    Manifold m;
336 jab 30
 
31
    string file;
367 jab 32
    if(ae.no_remaining_args()>0)
33
        file = ae.get_last_arg();
336 jab 34
    else
35
        file = "../../data/bunny-little.x3d";
36
 
382 jab 37
	load(file, m);
38
 
39
	if(ae.extract("-c"))
336 jab 40
	{
382 jab 41
		cout << "Closing holes" << endl;
42
		close_holes(m);
336 jab 43
	}
44
	shortest_edge_triangulate(m);
45
 
382 jab 46
 
47
 
336 jab 48
	Vec3f p0, p7;
49
	m.get_bbox(p0, p7);
50
	Vec3f d = p7-p0;
51
	float s = 1.0/d.max_coord();
52
	cout << p0 << p7 << d << s << endl;
53
	Vec3f pcentre = (p7+p0)/2.0;
54
	for(VertexIter vi = m.vertices_begin(); vi != m.vertices_end(); ++vi)
55
	{
56
		vi->pos = (vi->pos - pcentre) * s;
57
	}
58
 
59
	m.get_bbox(p0, p7);
60
	cout << p0 << p7 << endl;
61
 
62
	float avg_length = 0;
63
	for(HalfEdgeIter h = m.halfedges_begin(); h != m.halfedges_end(); ++h)
64
	{
65
		avg_length += length(h);
66
	}
67
	avg_length /= m.no_halfedges();
68
 
69
	cout << "Perform quadric based simplification ... " << endl;
367 jab 70
	quadric_simplify(m,keep_fraction,singular_thresh,choose_optimal_positions);
336 jab 71
 
72
	cout << "Removing caps and needles ... " << endl;
73
	remove_caps_from_trimesh(m, static_cast<float>(M_PI) * 0.85f);
74
	remove_needles_from_trimesh(m, 0.1 * avg_length);
107 bj 75
 
76
    cout << "Validity: " << m.is_valid() << endl;
77
    cout << "Now saving ... " << endl;
336 jab 78
    obj_save("decimated.obj", m);
107 bj 79
}