Program Listing for File hgrid3D.hpp
↰ Return to documentation for file (rcppsw/ds/graph/hgrid3D.hpp
)
#pragma once
/*******************************************************************************
* Includes
******************************************************************************/
#include <boost/graph/depth_first_search.hpp>
#include <boost/graph/filtered_graph.hpp>
#include <boost/property_map/dynamic_property_map.hpp>
#include <vector>
#include <utility>
#include "rcppsw/ds/graph/graph.hpp"
#include "rcppsw/math/vector3.hpp"
#include "rcppsw/patterns/decorator/decorator.hpp"
#include "rcppsw/ds/graph/hgrid3D_spec.hpp"
#include "rcppsw/ds/graph/hgrid3D_view.hpp"
#include "rcppsw/ds/graph/hgrid3D_view_filter.hpp"
/*******************************************************************************
* Namespaces/Decls
******************************************************************************/
namespace rcppsw::ds::graph {
/*******************************************************************************
* Class Definitions
******************************************************************************/
template<typename TSpecType>
class hgrid3D : public rpdecorator::decorator<typename TSpecType::bgl_impl_type> {
public:
using spec_type = TSpecType;
using bgl_impl_type = typename spec_type::bgl_impl_type;
using vertex_coord_type = typename spec_type::vertex_coord_type;
using decorator_type = typename rpdecorator::decorator<bgl_impl_type>::decorator_type;
using decoratee_type = typename rpdecorator::decorator<bgl_impl_type>::decoratee_type;
using decorator_type::decoratee;
/* for use in creating graph views */
using view_type = hgrid3D_view<spec_type>;
RCPPSW_DECORATE_DECL(vertex_descriptor);
RCPPSW_DECORATE_DECL(edge_descriptor);
RCPPSW_DECORATE_DECL(directed_category);
RCPPSW_DECORATE_DECL(edge_parallel_category);
RCPPSW_DECORATE_DECL(traversal_category);
RCPPSW_DECORATE_DECL(vertex_iterator);
using vertex_property_type = typename spec_type::vertex_property_type;
using edge_property_type = typename spec_type::edge_property_type;
hgrid3D(void) = default;
hgrid3D(const hgrid3D&) = default;
RCPPSW_DECORATE_DECLDEF(operator[], const);
RCPPSW_DECORATE_DECLDEF_STATIC(rdgraph, find, const);
RCPPSW_DECORATE_DECLDEF_STATIC(rdgraph, contains, const);
RCPPSW_DECORATE_DECLDEF_STATIC(rdgraph, vertices, const);
RCPPSW_DECORATE_DECLDEF_STATIC(rdgraph, adjacent_vertices, const);
RCPPSW_DECORATE_DECLDEF_STATIC(rdgraph, out_edges, const);
RCPPSW_DECORATE_DECLDEF_STATIC(rdgraph, out_degree, const);
RCPPSW_DECORATE_DECLDEF_STATIC(rdgraph, target, const);
RCPPSW_DECORATE_DECLDEF_STATIC(rdgraph, n_vertices, const);
RCPPSW_DECORATE_DECLDEF(operator[]);
RCPPSW_DECORATE_DECLDEF_STATIC(rdgraph, find);
RCPPSW_DECORATE_DECLDEF_STATIC(rdgraph, vertices);
RCPPSW_DECORATE_DECLDEF_STATIC(rdgraph, adjacent_vertices);
RCPPSW_DECORATE_DECLDEF_STATIC(rdgraph, target);
view_type subgraph(const vertex_descriptor& start,
const rtypes::manhattan_dist& max_dist,
boost::optional<rmath::vector3z> axis = boost::none) const {
auto filter_data = detail::hgrid3D_view_filter<spec_type>()(decoratee(),
start,
max_dist,
axis);
/*
* Predicates MUST be default constructible, so we wrap the actual predicate
* functor which takes arguments here.
*/
auto vertex_filter = std::bind(&hgrid3D_view_filter_data<spec_type>::vertex_filter,
filter_data.get(),
std::placeholders::_1);
auto edge_filter = std::bind(&hgrid3D_view_filter_data<spec_type>::edge_filter,
filter_data.get(),
std::placeholders::_1);
using view_impl_type = typename spec_type::template bgl_view_impl_type<
std::function<bool(typename TSpecType::bgl_impl_type::edge_descriptor)>,
std::function<bool(typename TSpecType::bgl_impl_type::vertex_descriptor)>
>;
auto view = view_impl_type(decoratee(), edge_filter, vertex_filter);
return view_type(view, std::move(filter_data));
}
};
} /* namespace rcppsw::ds::graph */