function som_show_clear(type, p)

%SOM_SHOW_CLEAR Clear hit marks, labels or trajectories from current figure. 
%
% som_show_clear([type], [p])
% 
%  som_show_clear;
%  som_show_clear('Traj',[1 2]);
% 
% INPUT ARGUMENTS ([]'s are optional) 
%        
%  [type] (string) which markers to delete, 'Hit' or 'Lab' or 'Traj' or 
%          'Comet' or 'all'. (case insenstive). Default: 'all'.
%  [p]    (vector, string) subplot number vector or string 'all'. 
%           If this is not given, the target is the whole current figure 
%           object.
%
% This function removes the objects made by som_show_add from a figure. 
% If no value (or empty matrix) is given for p, the function operates on
% every axis in the current figure. It simply searches for the objects with
% certain 'tags'. It doesn't matter if the figure objects are created by
% SOM Toolbox -functions or not. However, if vector p or string 'all' 
% _is_ given, the figure has to be created by SOM_SHOW.
%  
% Input argument 'type' may be 'Hit' for removing hit marks 
%                              'Lab'              labels 
%                              'Traj'             line trajectories 
%                              'Comet'            comet trajectories 
%
% For more help, try 'type som_show_clear' or check out the helpdesk.
% See also som_show_add, som_show

%%%%%%%%% DEATAILED DESCRIPTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% som_show_clear
%
% PURPOSE
%
% Clear hit marks, labels or trajectories created by som_show_add 
% from the current figure. 
%
% SYNTAX
% 
%  som_show_clear
%  som_show_clear([type],[p])
%
% DESCRIPTION
%
% The function som_show_add creates some markers on the top of
% visualizations made by som_show. These objects may be removed using
% som_show_add even if the object handles are not known. The function
% removes the objects based on certain tags written to the 'Tag' property
% field of the objects.
%
% REQUIRED INPUT ARGUMENTS
%
% - 
% 
% If the function if called without input argument, it searches for every
% object in the cirrent figure that have string 'Hit','Lab','Traj' or 
% 'Comet' in their Tag property field and deletes them. 
%
% OPTIONAL INPUT ARGUMENTS
%
% type  Which type of markers to delete
%
% (string) 'Hit' for removing hit marks    
%          'Lab'              labels 
%          'Traj'             line trajectories 
%          'Comet'            comet trajectories 
%  
% String 'all' removes all types of markers which have these tags.
% Default value is 'all'. Strings are case insensitive.
%
% p     Subplots from which the markers are removed
%
% (vector) specifies the subplots from which the markers are removed. 
%  The valid values are 1...N where N is the number of subplots. 
%  It is required that the figure is created by the som_show function.
%
% FEATURES
%
% If input argument p is not specified, the function does not check that the
% figure is created by function som_show. 
% 
% EXAMPLES 
%          
%   som_show_clear;
%      % deletes all labels, hit marks and trajectories in the figure
%   som_show_clear('hit');
%      % deletes all the hit marks in the current figure
%   som_show_clear('lab',[1 2]);
%      % deletes labels in SOM_SHOW figure subplots 1 and 2. 
%
% SEE ALSO
%
% SOM_SHOW       Basic map visualizations: component planes, u-matrix etc.
% SOM_SHOW_ADD   Show hits, labels and trajectories on SOM_SHOW visualization

% Version 1.0beta  Johan 061197 
% Version 2.0alpha Johan 061099
% Copyright (c) 1997-1999 by the SOM toolbox programming team.
% http://www.cis.hut.fi/projects/somtoolbox/             

%%% Check number of arguments

error(nargchk(0,2, nargin))     % check no. of input args is correct

%%% Initialize & check & action %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

if nargin == 0 | isempty(type) | strcmp(type,'all') % delete everything 
                                                    % in the gcf
  delete(findobj(gcf,'Tag','Hit'));
  delete(findobj(gcf, 'Tag','Lab'));
  delete(findobj(gcf, 'Tag','Traj'));
  delete(findobj(gcf, 'Tag','Comet'));
  return
end

if nargin < 2 | isempty(p)            % check handles
  handle=gcf;                       
else                                  % check subplot handles if p is given
  [handle,msg]=vis_som_show_data(p,gcf);
  if ~isempty(msg)
    error('2nd argument invalid or figure not made by SOM_SHOW: try SOM_SHOW_CLEAR without arguments.');
    end
end

switch lower(type)                    % check type & make proper tag names
case 'hit'  
  tag = 'Hit'; 
case 'lab'
  tag = 'Lab';
case 'traj'
  tag = 'Traj';                     
case 'comet'
  tag = 'Comet';
otherwise                             
  error('Invalid object tag. Must be {lab | hit | traj | comet}');
end

%%% Action %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

for i=1:length(handle),
  h=findobj(handle(i),'Tag',tag);     % find object handles 
  delete(h);                          % delete objects
end				

%%% No output %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

