Rev 489 | Rev 511 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
/*
* off_save.cpp
* GEL
*
* Created by J. Andreas Bærentzen on 17/02/09.
* Copyright 2009 __MyCompanyName__. All rights reserved.
*
*/
#include "off_save.h"
#include <fstream>
#include <iostream>
#include <string>
#include <vector>
#include <CGLA/Vec3f.h>
#include "Manifold.h"
#include "VertexHandle.h"
#include "FaceHandle.h"
#include "FaceCirculator.h"
namespace HMesh
{
using std::string;
using std::ofstream;
using std::vector;
using CGLA::Vec3f;
bool off_save(const string& filename, Manifold& m)
{
ofstream os(filename.data());
if(os.bad()){
return false;
}
//easy way to avoid skipping indice numbers
Manifold m1 = m;
m1.cleanup();
for(VertexHandle v = m1.vertices_begin(); v != m1.vertices_end(); ++v){
Vec3f p = v.get().pos;
os << "v "<< p[0] << " " << p[1] << " " << p[2] << "\n";
}
for(FaceHandle f = m1.faces_begin(); f != m1.faces_end(); ++f){
vector<VertexIndex> verts;
for(FaceCirculator fc(f); !fc.end(); ++fc){
VertexIndex vertex_idx = fc.vertex().get_idx();
assert(vertex_idx < m1.no_vertices());
// adding one to move subscript range from 0..size-1 to 1..size
verts.push_back(vertex_idx);
}
for(IndexType i = 1; i < (verts.size()) ; ++i){
os << "f ";
os << verts[0] << " " << verts[i] << " " << verts[i+1] << "\n";
}
}
return true;
}
}
Generated by GNU Enscript 1.6.6.