Home > cellorganizer > syn2blender.m

syn2blender

PURPOSE ^

SYN2BLENDER Exports a generated instance from CellOrganizer to a format

SYNOPSIS ^

function answer = syn2blender( imgfolder, outputfolder, param )

DESCRIPTION ^

SYN2BLENDER Exports a generated instance from CellOrganizer to a format
that can be read by Blender.

 Inputs       Description
 ------       -----------
 imgfolder    a folder with a 3d image you wish to obtain the mesh for
 outputfolder the path where you wish to save the generated files

 Parameter structure description
 Parameter   Description
 ---------   -----------
 downsample  (optional) downsample scale. default is 1.
 verbose     (optional) verbose flag that displays progress
 debug       (optional) flag that displays debugging messages. default is false
 
 Outputs
 -------
 answer      true if it saves object file that can be loaded into blender 
             specified by savefile to disk, false otherwise

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function answer = syn2blender( imgfolder, outputfolder, param )
0002 %SYN2BLENDER Exports a generated instance from CellOrganizer to a format
0003 %that can be read by Blender.
0004 %
0005 % Inputs       Description
0006 % ------       -----------
0007 % imgfolder    a folder with a 3d image you wish to obtain the mesh for
0008 % outputfolder the path where you wish to save the generated files
0009 %
0010 % Parameter structure description
0011 % Parameter   Description
0012 % ---------   -----------
0013 % downsample  (optional) downsample scale. default is 1.
0014 % verbose     (optional) verbose flag that displays progress
0015 % debug       (optional) flag that displays debugging messages. default is false
0016 %
0017 % Outputs
0018 % -------
0019 % answer      true if it saves object file that can be loaded into blender
0020 %             specified by savefile to disk, false otherwise
0021 
0022 % Author: Ivan E. Cao-Berg
0023 % Edited:
0024 % April 21, 2013 D. Sullivan Allowed for the output directory to be created
0025 %                            instead of crashing. Removed warning message.
0026 %
0027 % Copyright (C) 2012 Murphy Lab
0028 % Lane Center for Computational Biology
0029 % School of Computer Science
0030 % Carnegie Mellon University
0031 %
0032 % This program is free software; you can redistribute it and/or modify
0033 % it under the terms of the GNU General Public License as published
0034 % by the Free Software Foundation; either version 2 of the License,
0035 % or (at your option) any later version.
0036 %
0037 % This program is distributed in the hope that it will be useful, but
0038 % WITHOUT ANY WARRANTY; without even the implied warranty of
0039 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0040 % General Public License for more details.
0041 %
0042 % You should have received a copy of the GNU General Public License
0043 % along with this program; if not, write to the Free Software
0044 % Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
0045 % 02110-1301, USA.
0046 %
0047 % For additional information visit http://murphylab.web.cmu.edu or
0048 % send email to murphy@cmu.edu
0049 
0050 
0051 %icaoberg june 19, 2012
0052 %step 0: check input arguments
0053 answer = false;
0054 
0055 if nargin > 3
0056     error('Wrong number of input arguments');
0057 end
0058 
0059 if nargin == 2
0060    param = struct([]);
0061 end
0062 
0063 try
0064    verbose = param.verbose;
0065    if ~islogical( verbose )
0066      verbose = false;
0067    end
0068 catch
0069    verbose = false;
0070 end
0071 
0072 try
0073    debug = param.debug;
0074    if ~islogical( debug )
0075       debug = false;
0076    end
0077 catch
0078    debug = false;
0079 end
0080 
0081 try
0082    downsample = param.downsample;
0083    if ~isnumeric( downsample )
0084       downsample = 1;
0085    end
0086 catch
0087    downsample = 1;
0088 end
0089 
0090 if isempty( imgfolder )
0091     if debug
0092        warning('Input argument imgfolder cannot be empty')
0093     end
0094     return
0095 end
0096 
0097 if ~exist( imgfolder )
0098     if debug
0099        warning('Input argument imgfolder does not exist');
0100     end
0101     return
0102 end
0103 
0104 if isempty( outputfolder )
0105     if debug
0106         warning('Input argument savefile cannot be empty');
0107     end
0108     return
0109 end
0110 
0111 if ~exist( outputfolder )
0112    %D. Sullivan 4/22/13 allowed for the output directory to be created
0113    %instead of crashing. Removed warning message
0114     mkdir(outputfolder)
0115 %     if debug
0116 %         warning('Input argument outputfolder does not exist')
0117 %     end
0118 %     return
0119 end
0120 
0121 %step 1: find all the generated tiff file in imgfolder
0122 files = ml_dir( [ imgfolder filesep '*.tif' ] );
0123 
0124 %step 2: make object files
0125 
0126 for index=1:1:length(files)
0127    file = files{index};
0128    img = tif2img( [imgfolder filesep file] );
0129    if index == 1
0130        %R. Arepally 6/5/13 added shiftvector parameter for im2blender
0131        %function. Used to center objects at origin.
0132        shiftvector = [];
0133    end
0134    savefile = [ outputfolder filesep file(1:end-3) 'obj' ];
0135    if verbose
0136      disp( [ 'Exporting ' file ' to ' savefile ] );
0137    end
0138    try
0139        if length(downsample)==1
0140        
0141            if isfield(param,'patchsample')
0142                if length(param.patchsample) == 1
0143                    im2blender( img, savefile, downsample,param.patchsample, [], shiftvector );
0144                elseif length(param.patchsample)==length(files)
0145                    im2blender( img, savefile, downsample,param.patchsample(index),[], shiftvector);
0146                else
0147                    warning('Unable to generate blender files, invalid patchsample vector specified.');
0148                    return;
0149                end
0150            else
0151                im2blender( img, savefile, downsample, [], shiftvector);
0152            end
0153        elseif length(downsample)>1
0154            if isfield(param,'patchsample')
0155                if length(param.patchsample) ==1
0156                    im2blender( img, savefile, downsample(index),param.patchsample);
0157                elseif length(param.patchsample)==length(files)
0158                    im2blender( img, savefile, downsample(index),param.patchsample(index));
0159                else
0160                    warning('Unable to generate blender files, invalid patchsample vector specified.');
0161                    return;
0162                end
0163            else
0164                im2blender( img, savefile, downsample(index));
0165            end
0166        else
0167            warning('Unable to generate blender files, invalid downsampling vector specified.');
0168            return;
0169        end
0170    catch
0171        disp(['Unable to make ' savefile ]);
0172    end
0173 end
0174 
0175 answer = true;

Generated on Sun 29-Sep-2013 18:44:06 by m2html © 2005