Subversion Repositories gelsvn

Rev

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

/* ----------------------------------------------------------------------- *
 * This file is part of GEL, www.imm.dtu.dk/GEL
 * Copyright (C) the authors (see AUTHORS.txt) and DTU Informatics
 *
 * Principal authors:
 *  Christian Thode Larsen (thode2d@gmail.com)
 *  J. Andreas Baerentzen (jab@imm.dtu.dk)
 *
 * See LICENSE.txt for licensing information
 * ----------------------------------------------------------------------- */

#include "off_save.h"

#include <fstream>
#include <iostream>
#include <string>
#include <vector>

#include <CGLA/Vec3f.h>

#include "Manifold.h"
#include "AttributeVector.h"

namespace HMesh
{
    using namespace std;
    using namespace CGLA;

    bool off_save(const string& filename, Manifold& m)
    {
        ofstream os(filename.data());
        if(os.bad()){
            return false;
        }

        VertexAttributeVector<IndexType> vmap(m);

        os << "OFF " << "\n";
        os << m.no_vertices() << " " << m.no_faces() << " " << m.no_halfedges()/2 << "\n";

        IndexType k = 0;
        for(VertexIDIterator v = m.vertices_begin(); v != m.vertices_end(); ++v){
            Vec3f p = m.pos(*v);
            os << "v "<< p[0] << " " << p[1] << " " << p[2] << "\n";
            vmap[*v] = k++;
        }

        for(FaceIDIterator f = m.faces_begin(); f != m.faces_end(); ++f){        
            vector<IndexType> verts;
            for(HalfEdgeWalker w = m.halfedgewalker(*f); !w.full_circle(); w = w.circulate_face_cw()){
                IndexType idx = vmap[w.vertex()];                       
                assert(idx < m.no_vertices());
                verts.push_back(idx);
            }
            os << verts.size() << " ";
            for(IndexType i = 1; i < (verts.size()) ; ++i){        
                os << verts[i] << " ";
            }
            os << "\n";
        }
        return true;
    }

}

Generated by GNU Enscript 1.6.6.