Rev 493 | 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 ConstHalfEdgeHandle;
class HalfEdgeHandle;
class ConstFaceHandle;
class FaceHandle;
/************************************
* FaceHandle + functions
*************************************/
class FaceHandle
{
public:
FaceHandle();
FaceHandle(Manifold& _m, FaceIndex _idx);
/// Get a handle to the last halfedge visiting this face
HalfEdgeHandle last();
Face& get();
bool operator==(const FaceHandle& f) const;
bool operator!=(const FaceHandle& f) const;
void operator++();
void operator++(int);
/// get face index
FaceIndex get_idx() const;
/// get manifold pointer
Manifold* get_manifold() const;
private:
friend class ConstFaceHandle;
/// id of face
FaceIndex idx;
/// pointer to manifold storing the face
Manifold* m;
};
inline FaceHandle::FaceHandle()
: m(NULL), idx(NULL_FIDX)
{}
inline FaceHandle::FaceHandle(Manifold& _m, FaceIndex _idx)
: m(&_m), idx(_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 FaceIndex FaceHandle::get_idx() const
{
return idx;
}
#define NULL_FH FaceHandle()
/************************************
* ConstFaceHandle + functions
*************************************/
class ConstFaceHandle
{
public:
ConstFaceHandle();
ConstFaceHandle(const Manifold& _m, FaceIndex _idx);
ConstFaceHandle(const ConstFaceHandle& cfh);
ConstFaceHandle(const FaceHandle& fh);
ConstFaceHandle& operator=(const ConstFaceHandle& cfh);
ConstFaceHandle& operator=(const FaceHandle& fh);
/// Get a handle to the last halfedge visiting this face
ConstHalfEdgeHandle last();
const Face& get() const;
bool operator==(const ConstFaceHandle& f) const;
bool operator!=(const ConstFaceHandle& f) const;
void operator++();
void operator++(int);
/// get face index
FaceIndex get_idx() const;
/// get const manifold pointer
const Manifold* get_manifold() const;
private:
/// const id of face
FaceIndex idx;
/// const pointer to manifold storing the face
const Manifold* m;
};
#define NULL_CFH ConstFaceHandle()
inline ConstFaceHandle::ConstFaceHandle()
: m(NULL), idx(NULL_FIDX)
{}
inline ConstFaceHandle::ConstFaceHandle(const Manifold& _m, FaceIndex _idx)
: m(&_m), idx(_idx)
{}
inline ConstFaceHandle::ConstFaceHandle(const ConstFaceHandle& cfh)
: m(cfh.m), idx(cfh.idx)
{}
inline ConstFaceHandle::ConstFaceHandle(const FaceHandle& fh)
: m(fh.m), idx(fh.idx)
{}
inline ConstFaceHandle& ConstFaceHandle::operator=(const ConstFaceHandle& cfh)
{
m = cfh.m;
idx = cfh.idx;
return *this;
}
inline ConstFaceHandle& ConstFaceHandle::operator=(const FaceHandle& fh)
{
m = fh.m;
idx = fh.idx;
return *this;
}
inline const Face& ConstFaceHandle::get() const
{
return m->faces[idx];
}
inline bool ConstFaceHandle::operator==(const ConstFaceHandle& f) const
{
return idx == f.get_idx();
}
inline bool ConstFaceHandle::operator!=(const ConstFaceHandle& f) const
{
return idx != f.get_idx();
}
inline void ConstFaceHandle::operator++()
{
do{
++idx;
}
while(idx < m->faces.full_size() && !m->faces.in_use(idx));
}
inline void ConstFaceHandle::operator++(int)
{
++(*this);
}
inline FaceIndex ConstFaceHandle::get_idx() const
{
return idx;
}
/// Compute the number of edges of a face
IndexType no_edges(ConstFaceHandle 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(ConstFaceHandle f);
/// Compute the area of a face.
float area(ConstFaceHandle f);
/// Compute the centre of a face
CGLA::Vec3f centre(ConstFaceHandle f);
}
#endif __HMESH_FACEHANDLE_H__