Subversion Repositories gelsvn

Rev

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

Rev 433 Rev 595
Line 1... Line -...
1
/*
-
 
-
 
1
/* ----------------------------------------------------------------------- *
2
 *  off_load.cpp
2
 * This file is part of GEL, http://www.imm.dtu.dk/GEL
3
 *  GEL
-
 
4
 *
-
 
5
 *  Created by J. Andreas Bærentzen on 16/02/09.
3
 * Copyright (C) the authors and DTU Informatics
6
 *  Copyright 2009 __MyCompanyName__. All rights reserved.
4
 * For license and list of authors, see ../../doc/intro.pdf
-
 
5
 * ----------------------------------------------------------------------- */
7
 *
6
 
8
 */
-
 
9
#include <fstream>
-
 
10
#include "off_load.h"
7
#include "off_load.h"
-
 
8
 
11
#include "HMesh/Manifold.h"
9
#include <fstream>
12
#include "build_manifold.h"
-
 
13
 
10
 
-
 
11
#include "Manifold.h"
14
 
12
 
15
using namespace std;
13
using namespace std;
16
using namespace CGLA;
14
using namespace CGLA;
17
using namespace HMesh;
15
using namespace HMesh;
18
using namespace Geometry;
16
using namespace Geometry;
19
 
17
 
20
namespace HMesh
18
namespace HMesh
21
{
19
{
22
	bool off_load(const std::string& filename, HMesh::Manifold& m)
20
    bool off_load(const std::string& filename, HMesh::Manifold& m)
23
	{
21
    {
24
		ifstream ifs(filename.c_str());
22
        ifstream ifs(filename.c_str());
25
		string str;
23
        string str;
26
		if(ifs.good())
24
        if(ifs.good()){
27
			ifs >> str;
25
            ifs >> str;
-
 
26
        }
-
 
27
        else return false;
28
		if(str != "OFF") 
28
        if(str != "OFF") {
29
			return false;
29
            return false;
-
 
30
        }
30
		
31
 
31
		int NF, NV, NE;
32
        size_t NF, NV, NE;
32
		
33
 
33
		ifs >> NV >> NF >> NE;
34
        ifs >> NV >> NF >> NE;
34
		
35
 
35
		vector<Vec3f> vertices(NV);
36
        vector<Vec3f> vertices(NV);
36
		for(int i=0;i<NV;++i)
37
        for(size_t i = 0; i < NV; ++i){
37
			ifs >> vertices[i];
38
            ifs >> vertices[i];
-
 
39
        }
38
		
40
 
39
		vector<int> faces(NF);
41
        vector<int> faces(NF);
40
		vector<int> indices;
42
        vector<int> indices;
41
		for(int i=0;i<NF;++i)
43
        for(size_t i = 0; i < NF; ++i){
42
		{
-
 
43
			int	verts_in_face;
44
            int verts_in_face;
44
			ifs >> verts_in_face;
45
            ifs >> verts_in_face;
45
			faces[i]=verts_in_face;
46
            faces[i] = verts_in_face;
46
			for(int j=0;j<verts_in_face;++j)
47
            for(int j = 0; j < verts_in_face; ++j){
47
			{
-
 
48
				int idx;
48
                int idx;
49
				ifs >> idx;
49
                ifs >> idx;
50
				indices.push_back(idx);
50
                indices.push_back(idx);
51
			}
51
            }
52
		}
52
        }
53
		build_manifold(m, NV, &vertices[0], NF, &faces[0], &indices[0]);
53
        m.build(NV, reinterpret_cast<float *>(&vertices[0]), NF, &faces[0], &indices[0]);
54
		return true;
54
        return true;
55
	}
55
    }
56
}
56
}
57
 
57