function ClassifyByDiffusion( cPoints, cTrainLabels, cDiffuser, cDiffuserExtraParam, cClassifier, cClassifierExtraParam )

%
% function ClassifyByDiffusion( cPoints, cTrainLabels, cDiffuser, cDiffuserExtraParam, cClassifier, cClassifierExtraParam )
%
% IN:
%   cPoints                 : M by N matrix of M points in R^N
%   cTrainLabels            : training label function on cPoints, as a M row vector
%   cDiffuser               : pointer to a diffuser function complying to Diffuse_Template.m
%   cDiffuserExtraParam     : extra parameters for the diffuser function
%   cClassifier             : pointer to a classifier function complying to Classifier_Template.m
%   cClassifierExtraParam   : extra parameters for the classifier function
%
% OUT:
%
% USES:
%   cDiffuser, cClassifier
%
% SOURCE CONTROL
%   MM, 3/1/04
%

global gDiffuseObj
global gClassifierObj

%plot(cPoints(:,1),cPoints(:,2),'b.');drawnow;pause(0.1);hold on;

% Let cDiffuser create the diffusion object
feval(cDiffuser,'create',cPoints,cDiffuserExtraParam);
% Let cClassifier create the classifier object
feval(cClassifier,'create',cPoints,cTrainLabels,cClassifierExtraParam);
cClassifierExtraParam.Diffuser = cDiffuser;

% Now let's start diffusion
lTime = 1;
for lk = 1:50
    % Diffuse one step
    feval(cDiffuser,'diffuse',cPoints,cDiffuserExtraParam);
    % Classify after diffusion 
    feval(cClassifier,'classify',cPoints,cTrainLabels,cClassifierExtraParam);   
    
    % Plot some stuff    
    %lIdxs = find(gDiffuseObj.Heat>0);
    %plot(cPoints(lIdxs,1),cPoints(lIdxs,2),'r.');drawnow;pause(0.1);        
    figure(1);hold off;scatter(cPoints(:,1),cPoints(:,2),15,'b.','filled');hold on;
    if length(gClassifierObj.Growth)>1
        scatter(cPoints(gClassifierObj.BdryIdxs,1),cPoints(gClassifierObj.BdryIdxs,2),15,gClassifierObj.Growth,'filled');colorbar;
    else
        if lk > 1,
            break;
        end;
    end;
    title(sprintf('Time %d',lTime));drawnow;
    
    lTime = lTime + 1;
end;

%figure(3);plot(cPoints(:,1),cPoints(:,2),'b.');drawnow;pause(0.1);hold on;
%lIdxs=find(gDiffuseObj.Heat>0);hold on;plot(cPoints(lIdxs,1),cPoints(lIdxs,2),'r.');

return;