Subversion Repositories gelsvn

Rev

Rev 489 | Blame | Last modification | View Log | RSS feed

#ifndef __HMESH_VERTEXHANDLE_H__
#define __HMESH_VERTEXHANDLE_H__

#include "entities.h"
#include "Manifold.h"

namespace CGLA
{ 
    // Forward declaration
    class Vec3f; 
}

namespace HMesh
{
    // Forward declarations
    class HalfEdgeHandle;

    class VertexHandle
    {
    public:
        VertexHandle();
        VertexHandle(Manifold& _m, VIDX _idx);

        const HalfEdgeHandle out() const;
        HalfEdgeHandle out();

        const Vertex& get() const;
        Vertex& get();

        bool operator==(const VertexHandle& v) const;
        bool operator!=(const VertexHandle& v) const;

        void operator++();
        void operator++(int);

        VIDX get_idx() const;
    private:
        /// Vertex index
        VIDX idx;
        /// Pointer to manifold storing the vertex
        Manifold* m;
    };

    inline VertexHandle::VertexHandle(): m(NULL), idx(NULL_VERTEX_IDX){}
    inline VertexHandle::VertexHandle(Manifold& _m, VIDX _idx): m(&_m), idx(_idx){}

    inline const Vertex& VertexHandle::get() const{ return m->vertices[idx]; }
    inline Vertex& VertexHandle::get(){ return m->vertices[idx]; }

    inline bool VertexHandle::operator==(const VertexHandle& v) const{ return idx == v.get_idx(); }
    inline bool VertexHandle::operator!=(const VertexHandle& v) const{ return idx != v.get_idx(); }

    inline VIDX VertexHandle::get_idx() const { return idx; }

#define NULL_VERTEX_HANDLE VertexHandle()

    /// Returns true if the vertex is a boundary vertex.
    bool is_boundary(VertexHandle v);

    /// Compute valency, i.e. number of incident edges.
    size_t valency(VertexHandle v);

    /// Compute the vertex normal. This function computes the angle weighted sum of incident face normals.
    CGLA::Vec3f normal(VertexHandle v);

    /// Returns true if the two argument vertices are in each other's one-rings.
    bool is_connected(VertexHandle v0, VertexHandle v1);

    /// Check and enforce boundary consistency.
    void check_boundary_consistency(VertexHandle v);
}

#endif __HMESH_VERTEXHANDLE_H__