Subversion Repositories gelsvn

Rev

Rev 362 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 362 Rev 595
Line -... Line 1...
-
 
1
/* ----------------------------------------------------------------------- *
-
 
2
 * This file is part of GEL, http://www.imm.dtu.dk/GEL
-
 
3
 * Copyright (C) the authors and DTU Informatics
-
 
4
 * For license and list of authors, see ../../doc/intro.pdf
-
 
5
 * ----------------------------------------------------------------------- */
-
 
6
 
-
 
7
#include <fstream>
1
#include "obj_load.h"
8
#include "obj_load.h"
2
#include "Geometry/obj_load.h"
-
 
3
#include "HMesh/Manifold.h"
-
 
4
#include "build_manifold.h"
-
 
5
 
9
 
-
 
10
#include <Geometry/obj_load.h>
-
 
11
#include <Geometry/TriMesh.h>
-
 
12
 
-
 
13
#include "Manifold.h"
6
 
14
 
7
using namespace std;
15
using namespace std;
8
using namespace CGLA;
16
using namespace CGLA;
9
using namespace HMesh;
-
 
10
using namespace Geometry;
-
 
11
 
17
 
12
namespace HMesh
18
namespace HMesh
13
{
19
{
-
 
20
    using std::string;
-
 
21
    using Geometry::TriMesh;
-
 
22
    using Geometry::obj_load;
-
 
23
    
14
		bool obj_load(const std::string& filename, HMesh::Manifold& m)
24
    bool obj_load(const string& filename, Manifold& m)
15
		{
25
    {
-
 
26
        ifstream ifs(filename.data());
-
 
27
        
-
 
28
        if(ifs)
-
 
29
        {
-
 
30
            vector<Vec3f> vertices;
-
 
31
            vector<int> faces;
-
 
32
            vector<int> indices;
-
 
33
            while(ifs.good() && !ifs.eof())
-
 
34
            {
-
 
35
                string tok;
-
 
36
                ifs >> tok;
-
 
37
                if(tok == "v")
-
 
38
                {
-
 
39
                    float x,y,z;
-
 
40
                    ifs >> x >> y >> z;
-
 
41
                    vertices.push_back(Vec3f(x,y,z));
-
 
42
                    char line[1000];
-
 
43
                    ifs.getline(line, 998);
-
 
44
                }
-
 
45
                else if(tok == "f")
-
 
46
                {
-
 
47
                    char line[1000];
-
 
48
                    ifs.getline(line, 998);
-
 
49
                    char* pch = strtok(line, " \t");
-
 
50
                    int ctr = 0;
-
 
51
                    while(pch != 0)
-
 
52
                    {
-
 
53
                        int v;
-
 
54
                        sscanf(pch, "%d", &v);
-
 
55
                        indices.push_back(v-1);
-
 
56
                        pch = strtok(0, " \t");
-
 
57
                        ++ctr;
-
 
58
                    }
-
 
59
                    if(ctr)
-
 
60
                        faces.push_back(ctr);
-
 
61
                }
-
 
62
                else
16
				TriMesh mesh;
63
                {
-
 
64
                    char line[1000];
17
				Geometry::obj_load(filename, mesh);
65
                    ifs.getline(line, 998);
-
 
66
                }
-
 
67
            }
-
 
68
            m.clear();
18
				build_manifold(m, mesh);
69
            m.build(vertices.size(),
-
 
70
                    reinterpret_cast<float*>(&vertices[0]),
-
 
71
                    faces.size(),
-
 
72
                    &faces[0],
-
 
73
                    &indices[0]);
-
 
74
            
19
				return true;
75
            return true;
-
 
76
        }
-
 
77
        return false;
-
 
78
        
20
		}
79
    }
21
}
80
}
22
 
81