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