Subversion Repositories gelsvn

Rev

Rev 504 | Rev 512 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

/*
* Written by Christian Thode Larsen 2009-2010
* Contact: thode2d@gmail.com
* Based on original work by J. Andreas Baerentzen
* Inspired by OpenMesh (www.openmesh.org)
*/

#include "off_load.h"

#include <fstream>

#include "Manifold.h"

using namespace std;
using namespace CGLA;
using namespace HMesh;
using namespace Geometry;

namespace HMesh
{
        bool off_load(const std::string& filename, HMesh::Manifold& m)
        {
                ifstream ifs(filename.c_str());
                string str;
        if(ifs.good()){
                        ifs >> str;
        }
        if(str != "OFF") {
                        return false;
        }
                
                IndexType NF, NV, NE;
                
                ifs >> NV >> NF >> NE;
                
                vector<Vec3f> vertices(NV);
        for(IndexType  i= 0; i < NV; ++i){
                        ifs >> vertices[i];
        }
                
                vector<IndexType> faces(NF);
                vector<IndexType> indices;
                for(IndexType i = 0; i < NF; ++i){
                        IndexType verts_in_face;
                        ifs >> verts_in_face;
                        faces[i] = verts_in_face;
                        for(IndexType j = 0; j < verts_in_face; ++j){
                                IndexType idx;
                                ifs >> idx;
                                indices.push_back(idx);
                        }
                }
                m.build(NV, reinterpret_cast<float *>(&vertices[0]), NF, &faces[0], &indices[0]);
                return true;
        }
}