Subversion Repositories gelsvn

Rev

Rev 205 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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