function [labeledComponents,sizeOfLabeledComponents,barycenterOfLabeledComponents,nb_labeled_comp]=getConnectedComponentLabeledMesh(Nodes,AdjMatrix, NodesLabel,labelRegion)

% Nodes=vertices';
% NodesLabel=labels;
% labelRegion=labelInsula;
         
%@SD .   
[indR]=find(NodesLabel==labelRegion);

Region={};
i=0;
while(~isempty(indR))
    i=i+1;
    Region{i}=indR(1);
    [~,indV]=find(AdjMatrix(indR(1),:)>0);
    indV=unique(indV');
    indR(1)=[];
    [indPL]=find(NodesLabel(indV)==labelRegion);
    indVL=indV(indPL);
    indToR=find(ismember(indR,indVL));
    indR(indToR)=[];

    while(~isempty(indVL))        
        reg=unique(Region{i});
        indVL=reshape(indVL,max(size(indVL)),1);
        Region{i}=[reg;indVL];
        
        [~,indV]=find(AdjMatrix(indVL,:)~=0);
        indV=unique(indV);
        [indPL]=find(NodesLabel(indV)==labelRegion);
        indVL=indV(indPL);
        indInR=find(ismember(Region{i},indVL));
         indInVL=find(ismember(indVL,Region{i}(indInR)));
        indVL(indInVL)=[];
        indToR=find(ismember(indR,indVL));
        indR(indToR)=[];
%         size(indR)
    end    
end
    
labeledComponents=Region;
for i=1:size(labeledComponents,2)
  barycenterOfLabeledComponents{i}=mean(Nodes(labeledComponents{i},:),1);
   sizeOfLabeledComponents{i}=max(size(Region{i}));
end   

 nb_labeled_comp=size(labeledComponents,2);   
end

function[neighb]=isNeighborOf(indNodeRef, indNodeTgt,AdjMatrix)
neighb=AdjMatrix(indNodeRef,indNodeTgt);
end