Subversion Repositories gelsvn

Rev

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

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