No BSD License  

Highlights from
GeoML

image thumbnail
from GeoML by Gabriele Lombardi
A general morphable template tool for image segmentation.

GeoMLGenerateTree(model,visible)
function tree = GeoMLGenerateTree(model,visible)
% GEOMLGENERATETREE  Generates a tree containing a model.
%
% function tree = GeoMLGenerateTree(model,visible)
%
%  This function generates a tree containing a model hierarchy using
% structs as group containers. Only groups are expanded, other compounds
% like parameters and transformations aren't expanded. This function does
% not convert entities in matlab objects, another function must be used to
% do this. Each structure describes a group and contain a field 'this' that
% contain the group entity that generates the group.
%
%  Params
%  ------
% IN:
%  model    = The GeoML model.
%  visible  = Only visible entities must be inserted? (def=true)
% OUT:
%  tree     = The model tree without groups.
%
%  Pre
%  ---
% -  The model must be a GeoML valid model.
%
%  Post
% -  The tree contains all the model entities except the hidden ones if not
%   required.
% -  The tree order isn't the same of the XML file.

% Check params:
if nargin<1 error('A model must be given!'); end
if nargin<2 visible=true; end

% Check if the model is a group:
if ~isa(model,'com.dsi.libs.geoml.Group')
    % Returning the model itself:
    tree = model;
    return;
end

% Preparing the struct:
tree = struct;

% Iterating on the model parts:
i = model.iterator;
while i.hasNext
    % Getting an entity:
    e = i.next;
    
    % Check if we must insert this entity:
    if e.isVisible || ~visible
        % Checking the type of the component:
        if isa(e,'com.dsi.libs.geoml.Group')
            % This is a group:
            tree = setfield(tree,char(e.getName),GeoMLGenerateTree(e,visible));
        else
            % This is another entity:
            tree = setfield(tree,char(e.getName),e);
        end
    end
end

% Adding this to the tree:
tree = setfield(tree,'this',model);

Contact us at files@mathworks.com