Subversion Repositories gelsvn

Rev

Rev 595 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
440 jab 1
/*
2
 *  load.cpp
3
 *  GEL
4
 *
5
 *  Created by J. Andreas Bærentzen on 08/03/09.
6
 *  Copyright 2009 __MyCompanyName__. All rights reserved.
7
 *
8
 */
9
 
10
#include "load.h"
11
#include "obj_load.h"
12
#include "ply_load.h"
13
#include "HMesh/x3d_load.h"
14
#include "HMesh/FaceCirculator.h"
15
#include "CGLA/Vec3i.h"
16
 
17
using namespace std;
18
using namespace CGLA;
19
using namespace HMesh;
20
 
21
namespace Geometry
22
{
23
 
24
	void load(const string& fn, TriMesh &mesh)
25
	{
26
		if(fn.substr(fn.length()-4,fn.length())==".obj")
27
		{
28
			obj_load(fn, mesh);
29
		}
30
		else if(fn.substr(fn.length()-4,fn.length())==".ply")
31
		{
32
			ply_load(fn, mesh);
33
		}	
34
		else if(fn.substr(fn.length()-4,fn.length())==".x3d")
35
		{
36
			Manifold m;
37
			x3d_load(fn, m);
38
 
39
			for(VertexIter v=m.vertices_begin(); v != m.vertices_end();++v)
40
				v->touched = mesh.geometry.add_vertex(v->pos);
41
 
42
			for(FaceIter f = m.faces_begin(); f!= m.faces_end(); ++f)
43
			{
44
				Vec3i face;
45
				int i=0;
46
				for(FaceCirculator fc(f); !fc.end(); ++fc,++i)
47
				{
48
					if(i<2)
49
						face[i] = fc.get_vertex()->touched;
50
					else
51
					{
52
						face[2] = fc.get_vertex()->touched;
53
						mesh.geometry.add_face(face);
54
						face[1] = face[2];
55
					}
56
				}	
57
			}
58
		}
59
		else
60
		{
61
			cout << "Either the format was unrecognized or the file did not have the appropriate extension" << endl;
62
			exit(0);
63
		}
64
	}
65
 
66
}
67