function hPlot = videocellplots(option,varargin)
%VIDEOCELLHELPER Helper function for plotting in videocellcounting demo

%   Copyright 2004-2009 The MathWorks, Inc.
%   $Revision: 1.1.6.1 $  $Date: 2010/08/30 02:59:25 $

persistent firstTime;

switch option  
  case 'setup'    
    hFig = figure('Name', 'Cell Division Rate', ...
      'Color', 'white','visible','off');
    set(hFig, 'Position', [59 394 610 330]);    
    hPlot = plot(0, NaN, 'r', 'LineWidth', 2);
    hold  on; grid on;
    axis([1 30 0 1000]);
    xlabel('Frame number');
    ylabel('Cell count');
    firstTime = true;
    
  case 'plot'
    hPlot = varargin{1};
    numBlobs = varargin{2};
    if isempty(firstTime)
      firstTime = true;
    end    
    if firstTime
      set(get(hPlot,'Parent'),'Visible','on');
      firstTime = false;      
    end
    ydata = [get(hPlot, 'YData') numBlobs];
    set(hPlot, 'YData', ydata, 'XData', 1:length(ydata));
    drawnow;
    
  otherwise
    error('vipblks:system:videocellcounting:invalidOption',...
      'Invalid first argument to videocellplots.');
end