Subversion Repositories gelsvn

Rev

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