Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifndef TCG_FACE_H
Toshihiro Shimizu 890ddd
#define TCG_FACE_H
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// STD includes
Toshihiro Shimizu 890ddd
#include "assert.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
namespace tcg
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
template <typename f=""></typename>
Toshihiro Shimizu 890ddd
struct face_traits {
Toshihiro Shimizu 890ddd
	typedef typename F::edges_const_iterator edges_const_iterator;
Toshihiro Shimizu 890ddd
	typedef typename F::edges_iterator edges_iterator;
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class Face
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
protected:
Toshihiro Shimizu 890ddd
	int m_index;
Toshihiro Shimizu 890ddd
	tcg::list<int> m_edges;</int>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	typedef tcg::list<int>::const_iterator edges_const_iterator;</int>
Toshihiro Shimizu 890ddd
	typedef tcg::list<int>::iterator edges_iterator;</int>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	Face() : m_index(-1) {}
Toshihiro Shimizu 890ddd
	~Face() {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void setIndex(int idx) { m_index = idx; }
Toshihiro Shimizu 890ddd
	int getIndex() const { return m_index; }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	int edge(int e) const { return m_edges[e]; }
Toshihiro Shimizu 890ddd
	int &edge(int e) { return m_edges[e]; }
Toshihiro Shimizu 890ddd
	int edgesCount() const { return (int)m_edges.size(); }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void addEdge(int idx) { m_edges.push_back(idx); }
Toshihiro Shimizu 890ddd
	edges_iterator eraseEdge(const edges_iterator &it) { return m_edges.erase(it); }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	edges_const_iterator edgesBegin() const { return m_edges.begin(); }
Toshihiro Shimizu 890ddd
	edges_const_iterator edgesEnd() const { return m_edges.end(); }
Toshihiro Shimizu 890ddd
	edges_iterator edgesBegin() { return m_edges.begin(); }
Toshihiro Shimizu 890ddd
	edges_iterator edgesEnd() { return m_edges.end(); }
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
template <int n=""></int>
Toshihiro Shimizu 890ddd
class FaceN
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	typedef const int *edges_const_iterator;
Toshihiro Shimizu 890ddd
	typedef int *edges_iterator;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
protected:
Toshihiro Shimizu 890ddd
	int m_e[N], m_count;
Toshihiro Shimizu 890ddd
	int m_index;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	FaceN() : m_index(-1), m_count(0)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		std::fill(m_e, m_e + N, -1);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	FaceN(int(&edges)[N]) : m_index(-1), m_count(0)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		std::copy(edges, edges + N, m_e), m_count = N;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	~FaceN() {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void setIndex(int idx) { m_index = idx; }
Toshihiro Shimizu 890ddd
	int getIndex() const { return m_index; }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	int edge(int e) const
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		assert(e < m_count);
Toshihiro Shimizu 890ddd
		return m_e[e];
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	int &edge(int e)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		assert(e < m_count);
Toshihiro Shimizu 890ddd
		return m_e[e];
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	int edgesCount() const { return m_count; }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void addEdge(int idx)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		assert(m_count < N);
Toshihiro Shimizu 890ddd
		m_e[m_count++] = idx;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	void setEdge(int e, int idx)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		assert(e < m_count);
Toshihiro Shimizu 890ddd
		m_e[e] = idx;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	edges_iterator eraseEdge(const edges_iterator &it)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		std::copy(it + 1, edgesEnd(), it);
Toshihiro Shimizu 890ddd
		m_e[--m_count] = -1;
Toshihiro Shimizu 890ddd
		return it;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	edges_const_iterator edgesBegin() const { return m_e; }
Toshihiro Shimizu 890ddd
	edges_const_iterator edgesEnd() const { return m_e + m_count; }
Toshihiro Shimizu 890ddd
	edges_iterator edgesBegin() { return m_e; }
Toshihiro Shimizu 890ddd
	edges_iterator edgesEnd() { return m_e + m_count; }
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
} // namespace tcg
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#endif // TCG_FACE_H