Now that we have the tag, let's cover the basic data pipeline, which
is implemented using the vtkAlgorithm
class. This class provides input and output ports. Output ports are accessible
via GetOuptutPort member
functions, which return a proxy object ( vtkAlgorithmOutput
*) for an actual output
port.
In Dataflow concepts, vtkAlgorithmOutput
can be made a producer Port
- it corresponds to a single data output point. We support it as such
by defining a PortTraits
type, and associating it with vtkAlgorithmOutput:
namespace boost { namespace dataflow { namespace vtk { // PortTraits for vtkAlgorithmOutput objects, which produce data. // We specify the PortCategory (ports::producer) and Tag (vtk::tag). struct vtk_algorithm_output_producer : public port_traits<ports::producer, vtk::tag> {}; } } } // namespace boost::dataflow::vtk // This macro specializes the traits_of template to the specified // PortTraits, and also verifies that the PortTraits requirements are satisfied. // The traits_of template is used by the Dataflow library to associate // a Port with its PortTraits. DATAFLOW_TRAITS(vtkAlgorithmOutput, vtk::vtk_algorithm_output_producer)
More details about registering PortTraits
for a Port
can be found on the Traits
documentation page.
Now that we have a producer Port,
we need a consumer Port.
vtkAlgorithm
can accept incoming connections using the AddInputConnection
and SetInputConnection
member functions. Since we will make vtkAlgorithm
a Component,
we can't make it a Port
directly - but we can use the port_adapter
class to refer to the Port
functionality of vtkAlgorithm,
so we set up a PortTraits
class to represent this Port
functionality:
namespace boost { namespace dataflow { namespace vtk { struct vtk_algorithm_consumer : public complemented_port_traits<ports::consumer, vtkAlgorithmOutput, vtk::tag> {}; typedef port_adapter<vtkAlgorithm, vtk::vtk_algorithm_consumer, vtk::tag> vtk_algorithm_consumer_adapter; } } } // namespace boost::dataflow::vtk
Note that for the consumer traits, we inherited complemented_port_traits
rather than port_traits.
In doing so, we made vtk_algorithm_consumer
a ComplementedPortTraits.
This basically states that any Port
with vtk_algorithm_consumer
traits is intended for connections with vtkAlgorithmOutput
Ports.
This piece of information can make things easier for the Dataflow library
in certain cases (e.g., the prototype Dataflow.Blueprint
layer currently only knows how to connect two blueprint ports if at least
one of them is a ComplementedPort).