Subversion Repositories gelsvn

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
667 khor 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 "off_load.h"
8
 
9
#include <fstream>
10
 
11
#include "Manifold.h"
12
 
13
using namespace std;
14
using namespace CGLA;
15
using namespace HMesh;
16
using namespace Geometry;
17
 
18
namespace HMesh
19
{
20
    bool off_load(const std::string& filename, HMesh::Manifold& m)
21
    {
22
        ifstream ifs(filename.c_str());
23
        string str;
24
        if(ifs.good()){
25
            ifs >> str;
26
        }
27
        else return false;
28
        if(str != "OFF") {
29
            return false;
30
        }
31
 
32
        size_t NF, NV, NE;
33
 
34
        ifs >> NV >> NF >> NE;
35
 
36
        vector<Vec3f> vertices(NV);
37
        for(size_t i = 0; i < NV; ++i){
38
            ifs >> vertices[i];
39
        }
40
 
41
        vector<int> faces(NF);
42
        vector<int> indices;
43
        for(size_t i = 0; i < NF; ++i){
44
            int verts_in_face;
45
            ifs >> verts_in_face;
46
            faces[i] = verts_in_face;
47
            for(int j = 0; j < verts_in_face; ++j){
48
                int idx;
49
                ifs >> idx;
50
                indices.push_back(idx);
51
            }
52
        }
53
        m.build(NV, reinterpret_cast<float *>(&vertices[0]), NF, &faces[0], &indices[0]);
54
        return true;
55
    }
56
}
57