Subversion Repositories gelsvn

Rev

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

#ifndef __HMESH_FACEHANDLE_H__
#define __HMESH_FACEHANDLE_H__

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

namespace CGLA
{
    // forward declaration
    class Vec3f;
}

namespace HMesh
{
    // forward declarations
    class HalfEdgeHandle;

    class FaceHandle
    {
    public:
        FaceHandle();
        FaceHandle(Manifold& _m, FIDX _idx);

        /// Get a const handle to the last halfedge visiting this face
        const HalfEdgeHandle last() const;
        HalfEdgeHandle last();

        const Face& get() const;
        Face& get();

        bool operator==(const FaceHandle& f) const;
        bool operator!=(const FaceHandle& f) const;

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

        /// get face index
        FIDX get_idx() const;
        /// get manifold pointer
        Manifold* get_manifold() const;
    private:
        /// id of face
        FIDX idx;
        /// pointer to manifold storing the face
        Manifold* m;
    };

    inline FaceHandle::FaceHandle(): m(NULL), idx(NULL_FACE_IDX){}
    inline FaceHandle::FaceHandle(Manifold& _m, FIDX _idx): m(&_m), idx(_idx){}

    inline const Face& FaceHandle::get() const{ return m->faces[idx]; }
    inline Face& FaceHandle::get(){ return m->faces[idx]; }

    inline bool FaceHandle::operator==(const FaceHandle& f) const{ return idx == f.get_idx(); }
    inline bool FaceHandle::operator!=(const FaceHandle& f) const{ return idx != f.get_idx(); }
    inline void FaceHandle::operator++(){ do{ ++idx; } while(idx < m->faces.full_size() && !m->faces.in_use(idx)); }
    inline void FaceHandle::operator++(int){ ++(*this); }

    inline FIDX FaceHandle::get_idx() const{ return idx; }
    
#define NULL_FACE_HANDLE FaceHandle()

    /// Compute the number of edges of a face
    size_t no_edges(FaceHandle f);

    /** Compute the normal of a face. If the face is not a triangle,
    the normal is not defined, but computed using the first three
    vertices of the face. */
    CGLA::Vec3f normal(FaceHandle f);

    /// Compute the area of a face. 
    float area(FaceHandle f);

    /// Compute the centre of a face
    CGLA::Vec3f centre(FaceHandle f);
}

#endif __HMESH_FACEHANDLE_H__