From 744748ea9e96384910549e01ef8fc6ff9355330c Mon Sep 17 00:00:00 2001 From: Jean-Yves TINEVEZ <tinevez@pasteur.fr> Date: Sun, 26 Jul 2020 14:13:48 +0200 Subject: [PATCH] Convert to junction graph to vertices and faces. The goal is to be able to plot the tissue with one face per cell, to have a simplified representation of the cells on the tissue with e.g.: >> patch( 'Faces', F, 'Vertices', V, 'FaceColor', 'g' ) --- src/@deproj/deproj.m | 5 +++++ src/@deproj/to_vertices_and_faces.m | 29 +++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 src/@deproj/to_vertices_and_faces.m diff --git a/src/@deproj/deproj.m b/src/@deproj/deproj.m index 36c371c..ca7d9fe 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 0000000..ed70910 --- /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 + -- GitLab