function [verticeslist]=SearchProjectionOnPial(mesh_total,mesh_outer,perim, step)

% step is typically set between 5 and 10. Default is 7, increasing it will
% limit redundancies in the resulting path file.

%% === Original version commented by Yasser Alemán-Gómez (LIM, HGGM, Spain, 23/12/2016) ======== %
% % % % % % verticeslist=[];
% % % % % % for t=1:step:size(perim,2) % Original version
% % % % % %     [nearestIndexMT,nearestValuesMT]=mesh_vertex_nearest(mesh_total.vertices,mesh_outer.vertices(perim(t),:));
% % % % % %     verticeslist= [verticeslist nearestIndexMT];
% % % % % % end
% % % % % % verticeslist=unique(verticeslist);

%% ==== Changed made by Yasser Alemán-Gómez (LIM, HGGM, Spain, 23/12/2016) ==== % 

verticeslist = dsearchn(mesh_total.vertices,mesh_outer.vertices(perim(1:step:length(perim)),:));
nearestValues = mesh_total.vertices(verticeslist,:);
verticeslist = verticeslist(:)';
%% End of changes made by Yasser Alemán-Gómez (LIM, HGGM, Spain, 23/12/2016) ==== % 
