# [FieldTrip] extracting a continuous patch on a mesh

Mon Apr 23 14:48:06 CEST 2018

```Hi All
Is there a Matlab implementation of openMEEG lying around somewhere?
I was wondering, if openMEEG has a pure Matlab or python
implementation.
Pure form.
Many of us (INCLUDING ME) are using code, without really digging deep
into the details.
I would be grateful, if it can be shared.
Many thanks
best regards parham

On 2018-04-23 13:15, Maximilien Chaumon wrote:
> Hi all,
>
> So I coded something that could perhaps be useful to others. It grows
> a patch around a seed up to a certain distance. See below
>
> function [list] = mesh_patch(mesh,seed,dmax)
>
> % [list] = mesh_patch(mesh,seed,d)
> %
> % return the list of connected vertices that are at most d mesh.unit
> away
> % from seed.
> %
> % Maximilien Chaumon 2018
>
> % measure distance to seed
> seedpos = mesh.pos(seed,:);
> distances = sqrt(sum(bsxfun(@minus,mesh.pos,seedpos).^2,2));
>
> % crawl starting from seed
> list = crawl(mesh.tri,distances,dmax,seed);
>
> function final = crawl(tri,d,dmax,vert)
>
> % bookkeeping: the list of vertices
> persistent listi
> st = dbstack;
> level = sum(strcmp({st.name [1]},'crawl'));
> if level == 1
>     listi = [];
> end
> %
>
> listi(end+1) = vert; % append this vertex to the list
>
> conn = tri(any(tri==vert,2),:);% connected vertices
> conn = unique(conn);
> conn(d(conn) > dmax) = []; % remove those that are too far.
> conn(ismember(conn,listi)) = [];%keep only vertices that have not been
> crawled yet
> for i = 1:numel(conn)
>     crawl(tri,d,dmax,conn(i));% move to next
> end
>
> % bookkeeping: return the list at last
> if level == 1
>     final = listi; % return list if it's last call
> end
>
> Le ven. 13 avr. 2018 à 16:16, Maximilien Chaumon
> <maximilien.chaumon at gmail.com> a écrit :
>
>> Dear all,
>>
>> I'm trying to extract a connected patch of vertices at most say 2 cm
>> away from a given seed.
>> Is there an easy way to do this in FieldTrip?
>>
>> Many thanks,
>> Max
>
>
> ------
> [1] http://st.name
>
> _______________________________________________
> fieldtrip mailing list
> fieldtrip at donders.ru.nl
> https://mailman.science.ru.nl/mailman/listinfo/fieldtrip

--
best regards