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