Shinya Kitaoka 810553
#pragma once
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifndef TCG_MESH_BGL_H
Toshihiro Shimizu 890ddd
#define TCG_MESH_BGL_H
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// TCG includes
Toshihiro Shimizu 890ddd
#include "mesh.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// Boost includes
Toshihiro Shimizu 890ddd
#include <boost graph="" graph_traits.hpp=""></boost>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*
Toshihiro Shimizu 890ddd
  \file     tcg_mesh_bgl.h
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
  \brief    This file contains TCG adapters to Boost's Graph Library (BGL).
Toshihiro Shimizu 890ddd
*/
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//************************************************************************************
Toshihiro Shimizu 890ddd
//    boost::graph_traits to tcg::Mesh concept type
Toshihiro Shimizu 890ddd
//************************************************************************************
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
namespace boost
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
template <typename e,="" f="" typename="" v,=""></typename>
Toshihiro Shimizu 890ddd
struct graph_traits<typename e,="" f="" tcg::mesh<v,="">> {</typename>
Toshihiro Shimizu 890ddd
	// Preliminar typedefs
Toshihiro Shimizu 890ddd
	typedef typename tcg::Mesh<v, e,="" f=""> mesh_type;</v,>
Toshihiro Shimizu 890ddd
	typedef typename mesh_type::vertex_type vertex_type;
Toshihiro Shimizu 890ddd
	typedef typename mesh_type::edge_type edge_type;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	typedef typename vertex_type::edges_const_iterator edge_const_iterator;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	// V/E descriptors
Toshihiro Shimizu 890ddd
	typedef int vertex_descriptor;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	struct edge_descriptor // NOTE: Can't use std::pair due to std conflicts
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		int m_e, m_src;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		edge_descriptor() : m_e(-1), m_src(-1) {}
Toshihiro Shimizu 890ddd
		edge_descriptor(int e, int src) : m_e(e), m_src(src) {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		bool operator==(const edge_descriptor &e_d) { return m_e == e_d.m_e; } // Undirected
Toshihiro Shimizu 890ddd
		bool operator!=(const edge_descriptor &e_d) { return !operator==(e_d); }
Toshihiro Shimizu 890ddd
	};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	// Iterators
Toshihiro Shimizu 890ddd
	struct out_edge_iterator : public edge_const_iterator {
Toshihiro Shimizu 890ddd
		int m_src;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		out_edge_iterator() : edge_const_iterator(), m_src(-1) {}
Toshihiro Shimizu 890ddd
		out_edge_iterator(const edge_const_iterator &it, int src)
Toshihiro Shimizu 890ddd
			: edge_const_iterator(it), m_src(src) {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		edge_descriptor operator*() const
Toshihiro Shimizu 890ddd
		{
Toshihiro Shimizu 890ddd
			return edge_descriptor(edge_const_iterator::operator*(), m_src);
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	typedef typename tcg::list<vertex_type>::const_iterator vertex_iterator;</vertex_type>
Toshihiro Shimizu 890ddd
	typedef typename tcg::list<edge_type>::const_iterator edge_iterator;</edge_type>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	// Categories
Toshihiro Shimizu 890ddd
	typedef undirected_tag directed_category;
Toshihiro Shimizu 890ddd
	typedef allow_parallel_edge_tag edge_parallel_category;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	typedef struct our_category : public bidirectional_graph_tag, public vertex_list_graph_tag, public edge_list_graph_tag {
Toshihiro Shimizu 890ddd
	} traversal_category;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	// Sizes
Toshihiro Shimizu 890ddd
	typedef int vertices_size_type;
Toshihiro Shimizu 890ddd
	typedef int edges_size_type;
Toshihiro Shimizu 890ddd
	typedef int degree_size_type;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	// Functions
Toshihiro Shimizu 890ddd
	static inline vertex_descriptor null_vertex() { return -1; }
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
template <typename e,="" f="" typename="" v,=""></typename>
Toshihiro Shimizu 890ddd
struct graph_traits<typename e,="" f="" tcg::trimesh<v,="">></typename>
Toshihiro Shimizu 890ddd
	: public graph_traits<typename e,="" f="" tcg::mesh<v,="">> {</typename>
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
} // namespace boost
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//************************************************************************************
Toshihiro Shimizu 890ddd
//    tcg::bgl  helpers to edge data
Toshihiro Shimizu 890ddd
//************************************************************************************
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
namespace tcg
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
namespace bgl
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
template <typename mesh=""></typename>
Toshihiro Shimizu 890ddd
inline int source(const typename boost::graph_traits<mesh>::edge_descriptor &edge_descr, const Mesh &mesh)</mesh>
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	return edge_descr.m_src;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
template <typename mesh=""></typename>
Toshihiro Shimizu 890ddd
inline int target(const typename boost::graph_traits<mesh>::edge_descriptor &edge_descr, const Mesh &mesh)</mesh>
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	const typename Mesh::edge_type &ed = mesh.edge(edge_descr.m_e);
Toshihiro Shimizu 890ddd
	return (ed.vertex(0) == edge_descr.m_src) ? ed.vertex(1) : ed.vertex(0);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
template <typename mesh=""></typename>
Toshihiro Shimizu 890ddd
inline std::pair<typename boost::graph_traits<mesh="">::out_edge_iterator,</typename>
Toshihiro Shimizu 890ddd
				 typename boost::graph_traits<mesh>::out_edge_iterator></mesh>
Toshihiro Shimizu 890ddd
out_edges(int v, const Mesh &mesh)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	typedef typename boost::graph_traits<mesh>::out_edge_iterator out_edge_iterator;</mesh>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	return make_pair(
Toshihiro Shimizu 890ddd
		out_edge_iterator(mesh.vertex(v).edgesBegin(), v),
Toshihiro Shimizu 890ddd
		out_edge_iterator(mesh.vertex(v).edgesEnd(), v));
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
template <typename mesh=""></typename>
Toshihiro Shimizu 890ddd
inline int out_degree(int v, const Mesh &mesh)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	return mesh.vertex(v).edgesCount();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
} // namespace tcg::bgl
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#endif // TCG_MESH_BGL_H