Rev 507 | 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 "subdivision.h"
#include <vector>
#include <CGLA/Vec3f.h>
#include "Manifold.h"
#include "AttributeVector.h"
namespace HMesh
{
using namespace std;
using namespace CGLA;
void cc_split(Manifold& m_in, Manifold& m_out)
{
vector<Vec3f> new_points(m_in.no_vertices());
VertexAttributeVector<IndexType> vtouched(m_in);
HalfEdgeAttributeVector<IndexType> htouched(m_in, NULL_INDEX);
IndexType npsize = 0;
for(VertexIDIterator v = m_in.vertices_begin(); v != m_in.vertices_end(); ++v, ++npsize){
vtouched[*v] = npsize;
new_points[npsize] = m_in.pos(*v);
}
for(HalfEdgeIDIterator h = m_in.halfedges_begin(); h != m_in.halfedges_end(); ++h, ++npsize)
if(htouched[*h] == NULL_INDEX){
HalfEdgeWalker w = m_in.halfedgewalker(*h);
htouched[*h] = htouched[w.opp().halfedge()] = npsize;
new_points.push_back(m_in.pos(w.vertex()) + m_in.pos(w.opp().vertex()) * 0.5f);
}
vector<IndexType> indices;
vector<IndexType> faces;
for(FaceIDIterator f = m_in.faces_begin(); f != m_in.faces_end(); ++f, ++npsize){
for(HalfEdgeWalker w = m_in.halfedgewalker(*f); !w.full_circle(); w = w.circulate_face_cw()){
indices.push_back(npsize);
indices.push_back(htouched[w.halfedge()]);
indices.push_back(vtouched[w.vertex()]);
indices.push_back(htouched[w.next().halfedge()]);
faces.push_back(4);
}
new_points.push_back(centre(m_in, *f));
}
m_out.clear();
m_out.build(npsize, reinterpret_cast<float*>(&new_points[0]), faces.size(), &faces[0], &indices[0]);
}
}