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