Subversion Repositories gelsvn

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
107 bj 1
#include <iostream>
2
 
3
#include "CGLA/Vec3f.h"
178 bj 4
#include "HMesh/quadric_simplify.h"
5
#include "HMesh/x3d_save.h"
6
#include "HMesh/x3d_load.h"
216 jab 7
#include "HMesh/obj_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;
16
 
17
int main(int argc, char** argv)
18
{
19
    Manifold m;
336 jab 20
 
21
    string file;
22
    if(argc>1)
23
        file = argv[1];
24
    else
25
        file = "../../data/bunny-little.x3d";
26
 
27
	if(file.substr(file.length()-4,file.length())==".obj")
28
	{
29
		obj_load(file, m);
30
	}
31
	else
32
		x3d_load(file, m);
33
 
34
	shortest_edge_triangulate(m);
35
 
36
	Vec3f p0, p7;
37
	m.get_bbox(p0, p7);
38
	Vec3f d = p7-p0;
39
	float s = 1.0/d.max_coord();
40
	cout << p0 << p7 << d << s << endl;
41
	Vec3f pcentre = (p7+p0)/2.0;
42
	for(VertexIter vi = m.vertices_begin(); vi != m.vertices_end(); ++vi)
43
	{
44
		vi->pos = (vi->pos - pcentre) * s;
45
	}
46
 
47
	m.get_bbox(p0, p7);
48
	cout << p0 << p7 << endl;
49
 
50
	float avg_length = 0;
51
	for(HalfEdgeIter h = m.halfedges_begin(); h != m.halfedges_end(); ++h)
52
	{
53
		avg_length += length(h);
54
	}
55
	avg_length /= m.no_halfedges();
56
 
57
	cout << "Perform quadric based simplification ... " << endl;
363 jab 58
	quadric_simplify(m,0.1);
59
	quadric_simplify(m,atof(argv[2]));
336 jab 60
 
61
	cout << "Removing caps and needles ... " << endl;
62
	remove_caps_from_trimesh(m, static_cast<float>(M_PI) * 0.85f);
63
	remove_needles_from_trimesh(m, 0.1 * avg_length);
107 bj 64
 
365 jab 65
	cout << "Closing holes" << endl;
66
	close_holes(m);
67
	triangulate(m);
107 bj 68
    cout << "Validity: " << m.is_valid() << endl;
69
    cout << "Now saving ... " << endl;
336 jab 70
    obj_save("decimated.obj", m);
107 bj 71
}