Subversion Repositories gelsvn

Rev

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

/* ----------------------------------------------------------------------- *
 * This file is part of GEL, http://www.imm.dtu.dk/GEL
 * Copyright (C) the authors and DTU Informatics
 * For license and list of authors, see ../../doc/intro.pdf
 * ----------------------------------------------------------------------- */

#ifndef __HMESH_CONNECTIVITY_KERNEL_H__
#define __HMESH_CONNECTIVITY_KERNEL_H__

#include <vector>
#include <map>
#include "ItemVector.h"
#include "ItemID.h"

namespace HMesh
{
    typedef std::map<VertexID, VertexID> VertexIDRemap;
    typedef std::map<FaceID, FaceID> FaceIDRemap;
    typedef std::map<HalfEdgeID, HalfEdgeID> HalfEdgeIDRemap;

    struct IDRemap
    {
        VertexIDRemap vmap;
        FaceIDRemap fmap;
        HalfEdgeIDRemap hmap;
    };

    struct Vertex
    { 
        HalfEdgeID out; 
    };

    struct Face
    { 
        HalfEdgeID last; 
    };

    struct HalfEdge
    {
        HalfEdgeID next;
        HalfEdgeID prev;
        HalfEdgeID opp;
        VertexID vert;
        FaceID face;
    };

    class ConnectivityKernel
    {
    public:
        /// add vertex to kernel
        VertexID add_vertex();
        /// add face to kernel
        FaceID add_face();
        /// add halfedge to kernel
        HalfEdgeID add_halfedge();

        /// remove vertex from kernel, given by ID
        void remove_vertex(VertexID id);
        /// remove face from kernel, given by ID
        void remove_face(FaceID id);
        /// remove halfedge from kernel, given by ID
        void remove_halfedge(HalfEdgeID id);

        /// resize kernel vertices container to size
        void resize_vertices(size_t size);
        /// resize kernel faces container to size
        void resize_faces(size_t size);
        /// resize kernel halfedges container to size
        void resize_halfedges(size_t size);

        /// get the ID of next halfedge, given by current halfedge ID
        HalfEdgeID next(HalfEdgeID current) const;
        /// get the ID of previous halfedge, given by current halfedge ID
        HalfEdgeID prev(HalfEdgeID current) const;
        /// get the ID of opposite halfedge, given by current halfedge ID
        HalfEdgeID opp(HalfEdgeID current) const;
        /// get the ID of outgoing halfedge, given by current vertex ID
        HalfEdgeID out(VertexID current) const;
        /// get the ID of last halfedge of current face ID
        HalfEdgeID last(FaceID current) const;
        /// get the ID of vertex pointed to by current halfedge ID
        VertexID vert(HalfEdgeID id) const;
        /// get the ID of face owning current halfedge ID
        FaceID face(HalfEdgeID id) const;

        /// set the ID of next halfedge of current halfedge to next
        void set_next(HalfEdgeID current, HalfEdgeID next);
        /// set the ID of previous halfedge of current halfedge to prev
        void set_prev(HalfEdgeID current, HalfEdgeID prev);
        /// set the ID of opposite halfedge of current halfedge to opp
        void set_opp(HalfEdgeID current, HalfEdgeID opp);
        /// set the ID of outgoing halfedge of current vertex to out
        void set_out(VertexID current, HalfEdgeID out);
        /// set the ID of last halfedge of current face to last
        void set_last(FaceID current, HalfEdgeID last);
        /// set the ID of vertex pointed to by current halfedge to vert
        void set_vert(HalfEdgeID current, VertexID vert);
        /// set the ID of face owning current halfedge to face
        void set_face(HalfEdgeID current, FaceID face);

        /// number of active vertices in kernel
        size_t active_vertices() const;
        /// number of active faces in kernel
        size_t active_faces() const;
        /// number of active halfedges in kernel
        size_t active_halfedges() const;

        /// number of total vertices in kernel
        size_t total_vertices() const;
        /// number of total faces in kernel
        size_t total_faces() const;
        /// number of total halfedges in kernel
        size_t total_halfedges() const;

        /// check if ID of vertex is in use
        bool in_use(VertexID id) const;
        /// check if ID of face is in use
        bool in_use(FaceID id) const;
        /// check if ID of halfedge is in use
        bool in_use(HalfEdgeID id) const;

        /// get the ID of next vertex in container (default: skip unused IDs)
        VertexID vertices_next(VertexID id, bool skip = true) const;
        /// get the ID of next face in container (default: skip unused IDs)
        HalfEdgeID halfedges_next(HalfEdgeID id, bool skip = true) const;
        /// get the ID of next halfedge in container (default: skip unused IDs)
        FaceID faces_next(FaceID id, bool skip = true) const;

        /// get the ID of previous vertex in container (default: skip unused IDs)
        VertexID vertices_prev(VertexID id, bool skip = true) const;
        /// get the ID of previous face in container (default: skip unused IDs)
        HalfEdgeID halfedges_prev(HalfEdgeID id, bool skip = true) const;
        /// get the ID of previous halfedge in container (default: skip unused IDs)
        FaceID faces_prev(FaceID id, bool skip = true) const;

        /// get the ID of first vertex in container (default: skip unused IDs)
        VertexID vertices_begin(bool skip = true) const;
        /// get the ID of first vertex in container (default: skip unused IDs)
        HalfEdgeID halfedges_begin(bool skip = true) const;
        /// get the ID of first vertex in container (default: skip unused IDs)
        FaceID faces_begin(bool skip = true) const;

        /// get the ID of one past the end vertex in container
        VertexID vertices_end() const;
        /// get the ID of one past the end face in container 
        HalfEdgeID halfedges_end() const;
        /// get the ID of one past the end halfedge in container
        FaceID faces_end() const;

        /// Clean up unused space in vectors - WARNING! Invalidates existing handles!
        void cleanup(IDRemap& map);

        /// clear the kernel
        void clear();

    private:
        ItemVector<Vertex> vertices;
        ItemVector<Face> faces;
        ItemVector<HalfEdge> halfedges;
    };

    inline VertexID ConnectivityKernel::add_vertex()
    {
        vertices.add(Vertex());
        return VertexID(vertices.total_size() - 1);
    }

    inline FaceID ConnectivityKernel::add_face()
    {
        faces.add(Face());
        return FaceID(faces.total_size() - 1);
    }

    inline HalfEdgeID ConnectivityKernel::add_halfedge()
    {
        halfedges.add(HalfEdge());
        return HalfEdgeID(halfedges.total_size() - 1);
    }




    inline void ConnectivityKernel::remove_vertex(VertexID id)
    { vertices.remove(id.index); }

    inline void ConnectivityKernel::remove_face(FaceID id)
    { faces.remove(id.index); }

    inline void ConnectivityKernel::remove_halfedge(HalfEdgeID id)
    { halfedges.remove(id.index); }



    inline void ConnectivityKernel::resize_vertices(size_t size)
    {  vertices.resize(size); }

    inline void ConnectivityKernel::resize_faces(size_t size)
    {  faces.resize(size); }

    inline void ConnectivityKernel::resize_halfedges(size_t size)
    {  halfedges.resize(size); }


    inline HalfEdgeID ConnectivityKernel::next(HalfEdgeID id) const
    { return HalfEdgeID(halfedges[id.index].next); }

    inline HalfEdgeID ConnectivityKernel::prev(HalfEdgeID id) const
    { return HalfEdgeID(halfedges[id.index].prev); }

    inline HalfEdgeID ConnectivityKernel::opp(HalfEdgeID id) const
    { return HalfEdgeID(halfedges[id.index].opp); }

    inline HalfEdgeID ConnectivityKernel::out(VertexID id) const
    { return HalfEdgeID(vertices[id.index].out); }

    inline HalfEdgeID ConnectivityKernel::last(FaceID id) const
    { return HalfEdgeID(faces[id.index].last); }

    inline VertexID ConnectivityKernel::vert(HalfEdgeID id) const
    { return VertexID(halfedges[id.index].vert); }

    inline FaceID ConnectivityKernel::face(HalfEdgeID id) const
    { return FaceID(halfedges[id.index].face); }

    inline void ConnectivityKernel::set_next(HalfEdgeID id, HalfEdgeID next)
    { halfedges[id.index].next = next; }

    inline void ConnectivityKernel::set_prev(HalfEdgeID id, HalfEdgeID prev)
    { halfedges[id.index].prev = prev; }

    inline void ConnectivityKernel::set_opp(HalfEdgeID id, HalfEdgeID opp)
    {halfedges[id.index].opp = opp; }

    inline void ConnectivityKernel::set_out(VertexID id, HalfEdgeID out)
    { vertices[id.index].out = out; }

    inline void ConnectivityKernel::set_last(FaceID id, HalfEdgeID last)
    { faces[id.index].last = last; }

    inline void ConnectivityKernel::set_vert(HalfEdgeID id, VertexID vert)
    { halfedges[id.index].vert = vert; }

    inline void ConnectivityKernel::set_face(HalfEdgeID id, FaceID face)
    { halfedges[id.index].face = face; }



    inline size_t ConnectivityKernel::active_vertices() const
    { return vertices.active_size(); }

    inline size_t ConnectivityKernel::active_faces() const
    { return faces.active_size(); }

    inline size_t ConnectivityKernel::active_halfedges() const
    { return halfedges.active_size(); }



    inline size_t ConnectivityKernel::total_vertices() const
    { return vertices.total_size(); }

    inline size_t ConnectivityKernel::total_faces() const
    { return faces.total_size(); }

    inline size_t ConnectivityKernel::total_halfedges() const
    { return halfedges.total_size(); }



    inline bool ConnectivityKernel::in_use(VertexID id) const
    { return vertices.in_use(id.index); }

    inline bool ConnectivityKernel::in_use(FaceID id) const
    { return faces.in_use(id.index); }

    inline bool ConnectivityKernel::in_use(HalfEdgeID id) const
    { return halfedges.in_use(id.index); }



    inline VertexID ConnectivityKernel::vertices_next(VertexID id, bool skip) const
    { return vertices.index_next(id.index, skip); }

    inline HalfEdgeID ConnectivityKernel::halfedges_next(HalfEdgeID id, bool skip) const
    { return halfedges.index_next(id.index, skip); }

    inline FaceID ConnectivityKernel::faces_next(FaceID id, bool skip) const
    { return faces.index_next(id.index, skip); }

    inline VertexID ConnectivityKernel::vertices_prev(VertexID id, bool skip) const
    { return vertices.index_prev(id.index, skip); }

    inline HalfEdgeID ConnectivityKernel::halfedges_prev(HalfEdgeID id, bool skip) const
    { return halfedges.index_prev(id.index, skip); }

    inline FaceID ConnectivityKernel::faces_prev(FaceID id, bool skip) const
    { return faces.index_prev(id.index, skip); }

    inline VertexID ConnectivityKernel::vertices_begin(bool skip) const
    { return vertices.index_begin(skip); }

    inline HalfEdgeID ConnectivityKernel::halfedges_begin(bool skip) const
    { return halfedges.index_begin(skip); }

    inline FaceID ConnectivityKernel::faces_begin(bool skip) const
    { return faces.index_begin(skip); }

    inline VertexID ConnectivityKernel::vertices_end() const
    { return vertices.index_end(); }

    inline HalfEdgeID ConnectivityKernel::halfedges_end() const
    { return halfedges.index_end(); }

    inline FaceID ConnectivityKernel::faces_end() const
    { return faces.index_end(); }

    inline void ConnectivityKernel::clear()
    {
        vertices.clear();
        faces.clear();
        halfedges.clear();
    }
}

#endif

Generated by GNU Enscript 1.6.6.