Subversion Repositories gelsvn

Rev

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

Rev Author Line No. Line
595 jab 1
/* ----------------------------------------------------------------------- *
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
5
 * ----------------------------------------------------------------------- */
6
 
7
#include "off_save.h"
8
 
9
#include <fstream>
10
#include <iostream>
11
#include <string>
12
#include <vector>
13
 
14
#include <CGLA/Vec3f.h>
15
 
16
#include "Manifold.h"
17
#include "AttributeVector.h"
18
 
19
namespace HMesh
20
{
21
    using namespace std;
22
    using namespace CGLA;
23
 
24
    bool off_save(const string& filename, Manifold& m)
25
    {
26
        ofstream os(filename.data());
27
        if(os.bad()){
28
            return false;
29
        }
30
 
31
        VertexAttributeVector<int> vmap(m.allocated_vertices());
32
 
33
        os << "OFF" << "\n";
34
        os << m.no_vertices() << " " << m.no_faces() << " " << m.no_halfedges()/2 << "\n";
35
 
36
        int k = 0;
37
        for(VertexIDIterator v = m.vertices_begin(); v != m.vertices_end(); ++v){
38
            Vec3d p = m.pos(*v);
39
            os << "v "<< p[0] << " " << p[1] << " " << p[2] << "\n";
40
            vmap[*v] = k++;
41
        }
42
 
43
        for(FaceIDIterator f = m.faces_begin(); f != m.faces_end(); ++f){        
44
            vector<int> verts;
45
            for(Walker w = m.walker(*f); !w.full_circle(); w = w.circulate_face_ccw()){
46
                int idx = vmap[w.vertex()];			
47
                assert(static_cast<size_t>(idx) < m.no_vertices());
48
                verts.push_back(idx);
49
            }
50
            os << verts.size() << " ";
51
            for(size_t i = 0; i < verts.size() ; ++i){	   
52
                os << verts[i] << " ";
53
            }
54
            os << "\n";
55
        }
56
        return true;
57
    }
58
 
59
}