#include "Behaviors/StateMachine.h"

using namespace DualCoding;

$nodeclass DstBehavior : VisualRoutinesStateNode : doStart {
  camSkS.clear();
  NEW_SKETCH(camFrame, uchar, sketchFromSeg());

  NEW_SKETCH(blue_stuff, bool, visops::colormask(camFrame,"blue"));
  NEW_SKETCH(b_cc, uint, visops::labelcc(blue_stuff));
  NEW_SKETCH(b_area, uint, visops::areacc(b_cc));
  NEW_SKETCH(b_max, bool, b_area == b_area->max());

  NEW_SKETCH(b_dist, uint, visops::edist(b_max));

  NEW_SKETCH(orange_stuff, bool, visops::colormask(camFrame,"orange"));
  NEW_SKETCH(o_cc, uint, visops::labelcc(orange_stuff));
  NEW_SKETCH(o_area, uint, visops::areacc(o_cc));
  NEW_SKETCH(o_blobs, bool, o_area > 10);

  NEW_SKETCH(bo_dist, uint, b_dist*o_blobs);
  int const min_index = bo_dist->findMinPlus();
  int const min_label = o_cc[min_index];
  NEW_SKETCH(bo_win, bool, o_cc == min_label);
  NEW_SKETCH(rawY, uchar, sketchFromRawY());
}

REGISTER_BEHAVIOR(DstBehavior);
