Subversion Repositories gelsvn

Rev

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

/*
 *  load.cpp
 *  GEL
 *
 *  Created by J. Andreas Bærentzen on 08/03/09.
 *  Copyright 2009 __MyCompanyName__. All rights reserved.
 *
 */

#include "load.h"
#include "obj_load.h"
#include "ply_load.h"
#include "HMesh/x3d_load.h"
#include "HMesh/FaceCirculator.h"
#include "CGLA/Vec3i.h"

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

namespace Geometry
{
        
        void load(const string& fn, TriMesh &mesh)
        {
                if(fn.substr(fn.length()-4,fn.length())==".obj")
                {
                        obj_load(fn, mesh);
                }
                else if(fn.substr(fn.length()-4,fn.length())==".ply")
                {
                        ply_load(fn, mesh);
                }       
                else if(fn.substr(fn.length()-4,fn.length())==".x3d")
                {
                        Manifold m;
                        x3d_load(fn, m);
                        
                        for(VertexIter v=m.vertices_begin(); v != m.vertices_end();++v)
                                v->touched = mesh.geometry.add_vertex(v->pos);
                        
                        for(FaceIter f = m.faces_begin(); f!= m.faces_end(); ++f)
                        {
                                Vec3i face;
                                int i=0;
                                for(FaceCirculator fc(f); !fc.end(); ++fc,++i)
                                {
                                        if(i<2)
                                                face[i] = fc.get_vertex()->touched;
                                        else
                                        {
                                                face[2] = fc.get_vertex()->touched;
                                                mesh.geometry.add_face(face);
                                                face[1] = face[2];
                                        }
                                }       
                        }
                }
                else
                {
                        cout << "Either the format was unrecognized or the file did not have the appropriate extension" << endl;
                        exit(0);
                }
        }
        
}