vidzor

FreeBoundary

May 29th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 2.17 KB | None | 0 0
  1. % First of all, working algorithm:
  2. function all_binds = getFreeBoundary( T, V )
  3.     edges = [
  4.         T( :, [1 2] );
  5.         T( :, [1 3] );
  6.         T( :, [2 3] );
  7.     ];
  8.     [B,~] = sort( edges, 2 );
  9.     [edges, ia, ic] = unique( B, 'rows', 'stable' );
  10.     [a,~] = hist( ic, unique(ic) );
  11.     x = find( a == 1 );
  12.     all_binds = edges( x, : );
  13. end
  14.  
  15. % Input to the function is a 3D mesh, output is a line following the path, where the mesh was cut...
  16.  
  17. % My thought proccess for the whole thing:
  18.  
  19. % Ok, a mesh is made up of many polygons (triangles in this case) that connect the vertices in a structured way, so an edge is really  only a vector connecting 2 vertices, like [V1 V2] where V1 and V2 are vertex indices.
  20.  
  21. % Moving on, Cutting a mesh really means duplicating and overlapping some of it's vertices...
  22. % At that point there will be many vertices that are the same, but have different indices, also when a mesh is cut, edges emerge that  are only referenced by a single polygon... And that is what I was supposed to be looking for, in other words: find the unique Vertex pairs.
  23.  
  24. % The idea was simple, sort all the edges, remove the doubles, and pick out those edges that appear only once.
  25.  
  26. % So now I needed to get familiar with the unique() and sort() functions...
  27. % I started small, with a 1D array like: [1 1 1 2 3 4 3 2 11 4 5 5 5] and watched what sort and unique do to it, what they take in and % return back... read some docs etc... Once satisfied I upped to a 2D array like:
  28. % arr = [
  29. %   [1 2];
  30. %   [2 3];
  31. %   [1 2];
  32. %   [3 4];
  33. %   [3 4];
  34. %   [4 3]
  35. % ];
  36. % And did the same... And then I came up with something like this:
  37. function all_binds = getFreeBoundary( T, V )
  38.     edges = [
  39.         T( :, [1 2] );
  40.         T( :, [1 3] );
  41.         T( :, [2 3] );
  42.     ];
  43.     [edges, ind_markers, ~] = unique( sort( edges, 2 ), 'rows' );
  44.    
  45.     occurrences = [];
  46.     for i = 1 : length(ind_markers)-1
  47.         occurrences = [occurrences; ind_markers(i+1)-ind_markers(i) ];
  48.     end
  49.     occurrences = [occurrences; length(edges)-ind_markers(end)+1 ];
  50.    
  51.     all_binds = edges( occurrences == 1 );
  52. end
  53. % Once tested on an actual mesh it gave completelly wrong results...
Add Comment
Please, Sign In to add comment