c - How to find row indices of large row matrix with n common elements in matlab? -


i trying find pairs of rows index matrix 2 common elements. have triangulation of 3d object , want filter triangles angle of neighboring triangles. so, have find triangles share edge. in order this, must find rows of .tri file have 2 common points.

i have 350ish .tri files each of them have 7000x3 in dim. have found resource: mathworks link accepted answer takes mac air 15 mins, , matt figs answer takes 8 mins per .tri file (i have 350!).

how can complete process? have been told try , code part in c ( have never used c). have considered trying install matlab on linux server , run there ( have never done either). advice on how either write program in c or use aws server?

3d files located here: 3d files here code run: (any suggestions clean appreciated)

addpath('/users/len/desktop/javaplex/nonrigid3d') files1 = dir('/users/len/desktop/javaplex/nonrigid3d/*.tri');     files2 = dir('/users/len/desktop/javaplex/nonrigid3d/*.vert');  time=cputime; k =1:length(files1)         x=load(files1(k).name);     pt=load(files2(k).name);      %define sparse matrix holding angles between 2-simplices     w=sparse(length(x),length(x));      % find common vertices: try c     xs = sort(x,2);     s = size(x,1);     l = s*(s+1)/2;     f = sparse(l,l);     cnt = 0;     ntoshare = 2;     ii = 1:s         jj = ii+1:s             cnt = cnt + 1;             if sum(ismembc(xs(ii,:),xs(jj,:)))==ntoshare                 f(jj,ii) = 1;             end         end      end  [i,j] = find(f); % pairs of rows have 2 common vertices. cmn=[i,j];  % calculate angle , store in sparse matrix. row , col reference triangles i=1:length(cmn)     normal1=cross(pt(x(cmn(i,1),1),:)-pt(x(cmn(i,1),2),:) ,pt(x(cmn(i,1),1),:)-pt(x(cmn(i,1),3),:));      normal2=cross(pt(x(cmn(i,2),1),:)-pt(x(cmn(i,2),2),:), pt(x(cmn(i,2),1),:)-pt(x(cmn(i,2),3),:));      theta = acos((dot(normal1,normal2)/(norm(normal1)*norm(normal2))));      w(cmn(i,1),cmn(i,2))=theta; end     % save w txt file nameofimage.txt in current directory [i,j,val]=find(w); data_dump=[i,j,val]; l=files1(k).name; filename = strrep(l, '.tri','.txt'); dlmwrite(filename, data_dump, 'delimiter',' '); 

there lots of built-in methods doing computations on triangle-meshes. have @ triangulation class. following lines compute angles between non-boundary triangles code does.

%%// generate triangulation data structure tri = triangulation(x, pt); %%// find neighboring triangles edgeattachments = tri.edgeattachments(tri.edges); neighbors = cell2mat(edgeattachments(cellfun(@numel, edgeattachments)==2)); %%// compute angles normals1 = tri.facenormal(neighbors(:,1)); normals2 = tri.facenormal(neighbors(:,2)); angles = acos(dot(normals1, normals2, 2)); %// facenormals normalized %%// generate output looking data_dump = [neighbors, angles]; 

Popular posts from this blog