<launch>
  <arg name="gui" default="true"/>

  <include file="$(find jsk_perception)/sample/sample_image_publisher.launch">
    <arg name="gui" value="false"/>
  </include>

  <node name="sample_manager"
        pkg="nodelet" type="nodelet"
        args="manager"/>

  <node name="mask_image_generator"
        pkg="nodelet" type="nodelet"
        args="load jsk_perception/MaskImageGenerator /sample_manager">
    <remap from="~input" to="raw_image_rgb/image_color"/>
    <rosparam>
      offset_x: 420
      offset_y: 550
      width: 800
      height: 20
    </rosparam>
  </node>

  <node name="slic_super_pixels"
        pkg="nodelet" type="nodelet"
        args="load jsk_perception/SLICSuperPixels /sample_manager">
    <remap from="image" to="raw_image_rgb/image_color"/>
  </node>

  <node name="hsv_decomposer"
        pkg="nodelet" type="nodelet"
        args="load jsk_perception/HSVDecomposer /sample_manager">
    <remap from="~input" to="raw_image_rgb/image_color"/>
  </node>

  <node name="single_channel_histogram"
        pkg="nodelet" type="nodelet"
        args="load jsk_perception/SingleChannelHistogram /sample_manager"
        respawn="true" >
    <remap from="~input" to="hsv_decomposer/output/saturation"/>
    <remap from="~input/mask" to="mask_image_generator/output"/>
    <rosparam>
      use_mask: true
      hist_size: 100
    </rosparam>
  </node>

  <node name="color_histogram_label_match"
        pkg="nodelet" type="nodelet"
        args="load jsk_perception/ColorHistogramLabelMatch /sample_manager"
        respawn="true" >
    <remap from="~input" to="hsv_decomposer/output/saturation"/>
    <remap from="~input/label" to="slic_super_pixels/output"/>
    <remap from="~input/histogram" to="single_channel_histogram/output"/>
    <rosparam>
      threshold_method: 1
    </rosparam>
  </node>

  <group if="$(arg gui)">
    <node name="label_image_decomposer"
          pkg="jsk_perception" type="label_image_decomposer.py">
      <remap from="~input/label" to="slic_super_pixels/output"/>
      <remap from="~output/label_viz" to="slic_super_pixels/output_viz"/>
      <rosparam>
        only_label: true
        bg_label: 0
      </rosparam>
    </node>

    <node name="image_view_coefficient_image"
          pkg="image_view" type="image_view">
      <remap from="image" to="color_histogram_label_match/output/coefficient_image"/>
      <remap from="~output" to="color_histogram_label_match/output/coefficient_image_viz"/>
      <rosparam>
        gui: false
        do_dynamic_scaling: true
      </rosparam>
    </node>

    <node name="tile_image"
          pkg="jsk_perception" type="tile_image.py">
      <rosparam>
        input_topics:
          - /raw_image_rgb/image_color
          - /mask_image_generator/output
          - /hsv_decomposer/output/saturation
          - /slic_super_pixels/output_viz
          - /color_histogram_label_match/output/coefficient_image_viz
          - /color_histogram_label_match/output/extracted_region
        draw_topic_name: true
        font_scale: 2.0
      </rosparam>
    </node>

    <node name="image_view"
          pkg="image_view" type="image_view">
      <remap from="image" to="tile_image/output"/>
    </node>
  </group>
</launch>
