Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- % First of all, working algorithm:
- function all_binds = getFreeBoundary( T, V )
- edges = [
- T( :, [1 2] );
- T( :, [1 3] );
- T( :, [2 3] );
- ];
- [B,~] = sort( edges, 2 );
- [edges, ia, ic] = unique( B, 'rows', 'stable' );
- [a,~] = hist( ic, unique(ic) );
- x = find( a == 1 );
- all_binds = edges( x, : );
- end
- % Input to the function is a 3D mesh, output is a line following the path, where the mesh was cut...
- % My thought proccess for the whole thing:
- % 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.
- % Moving on, Cutting a mesh really means duplicating and overlapping some of it's vertices...
- % 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.
- % The idea was simple, sort all the edges, remove the doubles, and pick out those edges that appear only once.
- % So now I needed to get familiar with the unique() and sort() functions...
- % 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:
- % arr = [
- % [1 2];
- % [2 3];
- % [1 2];
- % [3 4];
- % [3 4];
- % [4 3]
- % ];
- % And did the same... And then I came up with something like this:
- function all_binds = getFreeBoundary( T, V )
- edges = [
- T( :, [1 2] );
- T( :, [1 3] );
- T( :, [2 3] );
- ];
- [edges, ind_markers, ~] = unique( sort( edges, 2 ), 'rows' );
- occurrences = [];
- for i = 1 : length(ind_markers)-1
- occurrences = [occurrences; ind_markers(i+1)-ind_markers(i) ];
- end
- occurrences = [occurrences; length(edges)-ind_markers(end)+1 ];
- all_binds = edges( occurrences == 1 );
- end
- % Once tested on an actual mesh it gave completelly wrong results...
Add Comment
Please, Sign In to add comment