Subversion Repositories gelsvn

Rev

Rev 518 | Rev 556 | 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 "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)
    {
        const int Invalid = -1;

        vector<Vec3f> new_points;
        new_points.reserve(m_in.active_vertices());

        VertexAttributeVector<int> vtouched(m_in.total_vertices(), Invalid);
        HalfEdgeAttributeVector<int> htouched(m_in.total_halfedges(), Invalid);

        int npsize = 0;
        for(VertexIDIterator v = m_in.vertices_begin(); v != m_in.vertices_end(); ++v){       
            vtouched[*v] = npsize;
            new_points.push_back(m_in.pos(*v));
            ++npsize;
        }

        for(HalfEdgeIDIterator h = m_in.halfedges_begin(); h != m_in.halfedges_end(); ++h)
            if(htouched[*h] == Invalid){
                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);
                ++npsize;
            }

            vector<int> indices;
            vector<int> faces;

            for(FaceIDIterator f = m_in.faces_begin(); f != m_in.faces_end(); ++f){           
                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));
                 ++npsize;
            }

            m_out.clear();
            m_out.build(npsize, reinterpret_cast<float*>(&new_points[0]), faces.size(), &faces[0], &indices[0]);
    }

}