Subversion Repositories gelsvn

Rev

Rev 572 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
512 s042372 1
/* ----------------------------------------------------------------------- *
572 jab 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
512 s042372 5
 * ----------------------------------------------------------------------- */
511 s042372 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
{
512 s042372 20
    bool off_load(const std::string& filename, HMesh::Manifold& m)
21
    {
22
        ifstream ifs(filename.c_str());
23
        string str;
511 s042372 24
        if(ifs.good()){
512 s042372 25
            ifs >> str;
511 s042372 26
        }
584 jab 27
        else return false;
511 s042372 28
        if(str != "OFF") {
512 s042372 29
            return false;
511 s042372 30
        }
512 s042372 31
 
518 s042372 32
        size_t NF, NV, NE;
512 s042372 33
 
34
        ifs >> NV >> NF >> NE;
35
 
36
        vector<Vec3f> vertices(NV);
518 s042372 37
        for(size_t i = 0; i < NV; ++i){
512 s042372 38
            ifs >> vertices[i];
511 s042372 39
        }
512 s042372 40
 
518 s042372 41
        vector<int> faces(NF);
42
        vector<int> indices;
43
        for(size_t i = 0; i < NF; ++i){
44
            int verts_in_face;
512 s042372 45
            ifs >> verts_in_face;
46
            faces[i] = verts_in_face;
518 s042372 47
            for(int j = 0; j < verts_in_face; ++j){
48
                int idx;
512 s042372 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
    }
511 s042372 56
}
57