In the VTK example above, both vtkConeSource
and vtkPolyDataMapper
inherit vtkAlgorithm.
We've set up Ports
that we can get to, and connect. However, we would like to be able to
connect the two components directly, with something like connect(*cone, *coneMapper).
To do that, we need to make vtkAlgorithm
a Component,
which allows us to designate default ports to be used when, e.g., connecting:
namespace boost { namespace dataflow { namespace vtk { namespace detail { typedef mpl::map< mpl::pair<dataflow::default_port_selector <dataflow::args::left>, mpl::int_<0> >, mpl::pair<dataflow::default_port_selector <dataflow::args::right>, mpl::int_<1> > >::type default_map; typedef mpl::map< mpl::pair<dataflow::default_port_selector <dataflow::args::right>, mpl::int_<0> > >::type consumer_only_map; } // First we need a ComponentTraits type template<typename T> struct vtk_algorithm_component_traits : public dataflow::fusion_component_traits< fusion::vector< vtkAlgorithmOutput &, vtk_algorithm_consumer_adapter>, detail::default_map, tag> { template<typename Component> static typename vtk_algorithm_component_traits::fusion_ports get_ports(Component &c) { return typename vtk_algorithm_component_traits::fusion_ports(*c.GetOutputPort(), c); } }; } } } // namespace boost::dataflow::vtk // Then we associate all descendants of vtkAlgorithm with the ComponentTraits. // vtkMapper is a descendant of vtkAlgorithm, but we want to exclude it's // descendants from this registration because they will be treated differently. DATAFLOW_TRAITS_ENABLE_IF( T, mpl::and_< boost::is_base_of<vtkAlgorithm BOOST_PP_COMMA() T> BOOST_PP_COMMA() mpl::not_<boost::is_base_of<vtkMapper BOOST_PP_COMMA() T> > >, vtk::vtk_algorithm_component_traits<T>)
Now, vtkAlgorithm
is a producer Port.
What we can do with what we have so far
connect(*cone, *coneMapper)