diff --git a/src/@deproj/deproj.m b/src/@deproj/deproj.m index 36c371c109becae7fc765aa673f74359ca857f0e..ca7d9feada60f18b5adc3379a5d4848684dcf5e4 100644 --- a/src/@deproj/deproj.m +++ b/src/@deproj/deproj.m @@ -26,6 +26,11 @@ classdef deproj % Exports results to a spreadsheet file. to_file( obj, file_name, include_header ) + %% Conversion between MATLAB objects. + + % Returns the faces and vertices of a deproj collection. + [ V, F ] = to_vertices_and_faces( obj ) + %% Generate figures. % Figure with the local plan orientation for a collection of epicells. diff --git a/src/@deproj/to_vertices_and_faces.m b/src/@deproj/to_vertices_and_faces.m new file mode 100644 index 0000000000000000000000000000000000000000..ed709104663a9ae362d1fa74425e41fa068bc1e1 --- /dev/null +++ b/src/@deproj/to_vertices_and_faces.m @@ -0,0 +1,29 @@ +function [ V, F ] = to_vertices_and_faces( obj ) +%TO_FACES Returns the faces and vertices of a deproj collection. +% The vertices are made of the junction centroid coordinates. +% Each face is one epicell, enclosed by the junctions around it. + + % Collect vertices. + g = obj.junction_graph; + V = g.Nodes.Centroid; + + % Collected junction ids. + ids = { obj.epicells.junction_ids }'; + n_vertices = cellfun(@numel, ids ); + max_n_vertices = max( n_vertices ); + n_obj = numel( obj.epicells ); + + % Write into the face matrix. + F = NaN( n_obj, max_n_vertices ); + for i = 1 : n_obj + + jids = ids{ i }; + P = V( jids, : ); + + % Sort the points so that we don't have intersecting polygons. + [ ~, I ] = deproj.sort_polygon( P ); + F( i, 1 : n_vertices(i) ) = jids( I ); + end + +end +