PageRenderTime 52ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/matlab_tools/Converted/kkappend.m

http://github.com/aludnam/MATLAB
Objective C | 282 lines | 279 code | 3 blank | 0 comment | 57 complexity | f661deadfba909b2d61cdb9ae7b30188 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. %kkappend 'Append (or Prepend) Input Objects to Base Object'
  2. % This MatLab function was automatically generated by a converter (KhorosToMatLab) from the Khoros kappend.pane file
  3. %
  4. % Parameters:
  5. % InputFile: i1 'Input 1 (Base)', required: 'Base Input data object (input 1)'
  6. % InputFile: i2 'Input 2', optional: 'input file 2'
  7. % InputFile: i3 'Input 3', optional: 'input file 3'
  8. % InputFile: i4 'Input 4', optional: 'input file 4'
  9. % InputFile: i5 'Input 5', optional: 'input file 5'
  10. % InputFile: i6 'Input 6', optional: 'input file 6'
  11. % InputFile: i7 'Input 7', optional: 'input file 7'
  12. % InputFile: i8 'Input 8', optional: 'input file 8'
  13. % InputFile: i9 'Input 9', optional: 'input file 9'
  14. % InputFile: i10 'Input 10', optional: 'input file 10'
  15. % OutputFile: o 'Output', required: 'Resulting output data object'
  16. % Toggle: w 'Width', default: 0: 'Stack objects along width dimension'
  17. % Toggle: h 'Height', default: 0: 'Stack objects along height dimension'
  18. % Toggle: d 'Depth', default: 0: 'Stack objects along depth dimension'
  19. % Toggle: t 'Time', default: 0: 'Stack objects along time dimension'
  20. % Toggle: e 'Elements', default: 0: 'Stack objects along elements dimension'
  21. %
  22. % Example: o = kkappend({i1, i2, i3, i4, i5, i6, i7, i8, i9, i10}, {'i1','';'i2','';'i3','';'i4','';'i5','';'i6','';'i7','';'i8','';'i9','';'i10','';'o','';'w',0;'h',0;'d',0;'t',0;'e',0})
  23. %
  24. % Khoros helpfile follows below:
  25. %
  26. % PROGRAM
  27. % kappend - Append (or Prepend) Input Objects to Base Object
  28. %
  29. % DESCRIPTION
  30. % The "Append" operator (kappend) combines all input data objects
  31. % (i1 to i10) into a single output object (o).
  32. % The objects are combined in order from Input 1 to Input 10. If the
  33. % user specifies placement as "Prepend Objects to Base Object" (-append 0),
  34. % then the first input will be the last appended to the output object.
  35. % The dimension flags Width (w_flag), Height (h_flag), Depth (d_flag),
  36. % Time (t_flag), and Elements (e_flag), specify which dimension the objects
  37. % will be stacked along. For example, stacking two images along width
  38. % would produce an output with the images side by side. One and only one
  39. % of the dimension flags can be true.
  40. %
  41. % "Value Data" 5
  42. % All input objects must have value data. The value size of each input
  43. % object will be zero-padded to the maximum of all sizes, except in the
  44. % stacking dimension. The output size in the stacking dimension will
  45. % be the sum of that dimension across all input objects. The output object
  46. % data type will be the highest data type of the input data objects.
  47. %
  48. % "Map Data" 5
  49. % When some or all of the input objects have map data, the treatment of the
  50. % maps, and how the data is represented in the output object, depends on the
  51. % mapping option (mapping) specified by the user.
  52. % Possible mapping options are: (0) Map Data Thru Maps, (1) Use First Map Only,
  53. % and (2) Create a Map for Each Input.
  54. % If no input objects have maps, the mapping option is ignored.
  55. % If there are doubts about which
  56. % mapping option to use, the safest bet is to map the data thru the maps.
  57. %
  58. %
  59. % "Map Data Thru Maps:" 5
  60. % All data will be mapped before the data objects are combined. The output
  61. % object will not have a map.
  62. %
  63. % "Use First Map Only:" 5
  64. % In this case, the map data and color attributes of the first input
  65. % object that has a map are directly transferred to the output object.
  66. % The depth, time, and elements dimensions of that map must be 1, otherwise
  67. % this mapping option will fail. Note that by selecting this mapping
  68. % option, you are assuming that the value segments of all objects being
  69. % appended have valid indices into that map.
  70. %
  71. % "Create a Map for Each Input:" 5
  72. % (All input objects may have maps.)
  73. % For each input object that does not have a map, one will be created for it.
  74. % The the output object color attributes will be copied from the first
  75. % input object that has a map. New map values will be assigned using the
  76. % autocolor attribute.
  77. %
  78. %
  79. % The map dimension corresponding to the stacking dimension (Depth, Time,
  80. % or Elements) will reflect the new size of the value data in that dimension,
  81. % and the maps from each object will be appended accordingly.
  82. % The maximum width and height of all maps will be propagated to the output,
  83. % with zero-padding being applied where necessary.
  84. % Padding in the other map dimensions may occur as well.
  85. % For example, if objects with the following map and value
  86. % Depth sizes are being stacked along the Depth dimension,
  87. %
  88. % obj1 DEP=3 MAP_DEP = 3
  89. % obj2 DEP=4 MAP_DEP = 1
  90. % obj2 DEP=2 MAP_DEP = 2
  91. %
  92. % the resulting value data will have a depth of 9, so the map depth will be 9
  93. % too. In this example, the second object's map will be zero-padded to have
  94. % a map depth of four.
  95. %
  96. %
  97. % If the objects are being combined along the width or
  98. % height dimensions, this mapping option will fail.
  99. %
  100. %
  101. %
  102. % The output object map data type will be the highest of the input object map
  103. % data types.
  104. %
  105. % "Mask Data" 5
  106. % If any input object has mask data, then the output
  107. % object will also have mask data. The mask data will be resized
  108. % in the same manner as value data is resized. The mask will be padded
  109. % as valid (1). The highest
  110. % data type of input masks will be propagated to the output mask.
  111. %
  112. % "Location and Time Data" 5
  113. % In all cases, the time and location data and/or attributes
  114. % of the first input object will transferred to the output
  115. % object. If location or time data is propagated, data values
  116. % along the stacking dimension will not be changed, and
  117. % therefore, the location or time data may become invalid.
  118. %
  119. %
  120. %
  121. % EXAMPLES
  122. %
  123. % "SEE ALSO"
  124. % DATAMANIP::kinset
  125. %
  126. % RESTRICTIONS
  127. %
  128. % REFERENCES
  129. %
  130. % COPYRIGHT
  131. % Copyright (C) 1993 - 1997, Khoral Research, Inc. ("KRI") All rights reserved.
  132. %
  133. function varargout = kkappend(varargin)
  134. if nargin ==0
  135. Inputs={};arglist={'',''};
  136. elseif nargin ==1
  137. Inputs=varargin{1};arglist={'',''};
  138. elseif nargin ==2
  139. Inputs=varargin{1}; arglist=varargin{2};
  140. else error('Usage: [out1,..] = kkappend(Inputs,arglist).');
  141. end
  142. if size(arglist,2)~=2
  143. error('arglist must be of form {''ParameterTag1'',value1;''ParameterTag2'',value2}')
  144. end
  145. narglist={'i1', '__input';'i2', '__input';'i3', '__input';'i4', '__input';'i5', '__input';'i6', '__input';'i7', '__input';'i8', '__input';'i9', '__input';'i10', '__input';'o', '__output';'w', 0;'h', 0;'d', 0;'t', 0;'e', 0};
  146. maxval={0,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0};
  147. minval={0,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0};
  148. istoggle=[0,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1];
  149. was_set=istoggle * 0;
  150. paramtype={'InputFile','InputFile','InputFile','InputFile','InputFile','InputFile','InputFile','InputFile','InputFile','InputFile','OutputFile','Toggle','Toggle','Toggle','Toggle','Toggle'};
  151. % identify the input arrays and assign them to the arguments as stated by the user
  152. if ~iscell(Inputs)
  153. Inputs = {Inputs};
  154. end
  155. NumReqOutputs=1; nextinput=1; nextoutput=1;
  156. for ii=1:size(arglist,1)
  157. wasmatched=0;
  158. for jj=1:size(narglist,1)
  159. if strcmp(arglist{ii,1},narglist{jj,1}) % a given argument was matched to the possible arguments
  160. wasmatched = 1;
  161. was_set(jj) = 1;
  162. if strcmp(narglist{jj,2}, '__input')
  163. if (nextinput > length(Inputs))
  164. error(['Input ' narglist{jj,1} ' has no corresponding input!']);
  165. end
  166. narglist{jj,2} = 'OK_in';
  167. nextinput = nextinput + 1;
  168. elseif strcmp(narglist{jj,2}, '__output')
  169. if (nextoutput > nargout)
  170. error(['Output nr. ' narglist{jj,1} ' is not present in the assignment list of outputs !']);
  171. end
  172. if (isempty(arglist{ii,2}))
  173. narglist{jj,2} = 'OK_out';
  174. else
  175. narglist{jj,2} = arglist{ii,2};
  176. end
  177. nextoutput = nextoutput + 1;
  178. if (minval{jj} == 0)
  179. NumReqOutputs = NumReqOutputs - 1;
  180. end
  181. elseif isstr(arglist{ii,2})
  182. narglist{jj,2} = arglist{ii,2};
  183. else
  184. if strcmp(paramtype{jj}, 'Integer') & (round(arglist{ii,2}) ~= arglist{ii,2})
  185. error(['Argument ' arglist{ii,1} ' is of integer type but non-integer number ' arglist{ii,2} ' was supplied']);
  186. end
  187. if (minval{jj} ~= 0 | maxval{jj} ~= 0)
  188. if (minval{jj} == 1 & maxval{jj} == 1 & arglist{ii,2} < 0)
  189. error(['Argument ' arglist{ii,1} ' must be bigger or equal to zero!']);
  190. elseif (minval{jj} == -1 & maxval{jj} == -1 & arglist{ii,2} > 0)
  191. error(['Argument ' arglist{ii,1} ' must be smaller or equal to zero!']);
  192. elseif (minval{jj} == 2 & maxval{jj} == 2 & arglist{ii,2} <= 0)
  193. error(['Argument ' arglist{ii,1} ' must be bigger than zero!']);
  194. elseif (minval{jj} == -2 & maxval{jj} == -2 & arglist{ii,2} >= 0)
  195. error(['Argument ' arglist{ii,1} ' must be smaller than zero!']);
  196. elseif (minval{jj} ~= maxval{jj} & arglist{ii,2} < minval{jj})
  197. error(['Argument ' arglist{ii,1} ' must be bigger than ' num2str(minval{jj})]);
  198. elseif (minval{jj} ~= maxval{jj} & arglist{ii,2} > maxval{jj})
  199. error(['Argument ' arglist{ii,1} ' must be smaller than ' num2str(maxval{jj})]);
  200. end
  201. end
  202. end
  203. if ~strcmp(narglist{jj,2},'OK_out') & ~strcmp(narglist{jj,2},'OK_in')
  204. narglist{jj,2} = arglist{ii,2};
  205. end
  206. end
  207. end
  208. if (wasmatched == 0 & ~strcmp(arglist{ii,1},''))
  209. error(['Argument ' arglist{ii,1} ' is not a valid argument for this function']);
  210. end
  211. end
  212. % match the remaining inputs/outputs to the unused arguments and test for missing required inputs
  213. for jj=1:size(narglist,1)
  214. if strcmp(paramtype{jj}, 'Toggle')
  215. if (narglist{jj,2} ==0)
  216. narglist{jj,1} = '';
  217. end;
  218. narglist{jj,2} = '';
  219. end;
  220. if ~strcmp(narglist{jj,2},'__input') && ~strcmp(narglist{jj,2},'__output') && istoggle(jj) && ~ was_set(jj)
  221. narglist{jj,1} = '';
  222. narglist{jj,2} = '';
  223. end;
  224. if strcmp(narglist{jj,2}, '__input')
  225. if (minval{jj} == 0) % meaning this input is required
  226. if (nextinput > size(Inputs))
  227. error(['Required input ' narglist{jj,1} ' has no corresponding input in the list!']);
  228. else
  229. narglist{jj,2} = 'OK_in';
  230. nextinput = nextinput + 1;
  231. end
  232. else % this is an optional input
  233. if (nextinput <= length(Inputs))
  234. narglist{jj,2} = 'OK_in';
  235. nextinput = nextinput + 1;
  236. else
  237. narglist{jj,1} = '';
  238. narglist{jj,2} = '';
  239. end;
  240. end;
  241. else
  242. if strcmp(narglist{jj,2}, '__output')
  243. if (minval{jj} == 0) % this is a required output
  244. if (nextoutput > nargout & nargout > 1)
  245. error(['Required output ' narglist{jj,1} ' is not stated in the assignment list!']);
  246. else
  247. narglist{jj,2} = 'OK_out';
  248. nextoutput = nextoutput + 1;
  249. NumReqOutputs = NumReqOutputs-1;
  250. end
  251. else % this is an optional output
  252. if (nargout - nextoutput >= NumReqOutputs)
  253. narglist{jj,2} = 'OK_out';
  254. nextoutput = nextoutput + 1;
  255. else
  256. narglist{jj,1} = '';
  257. narglist{jj,2} = '';
  258. end;
  259. end
  260. end
  261. end
  262. end
  263. if nargout
  264. varargout = cell(1,nargout);
  265. else
  266. varargout = cell(1,1);
  267. end
  268. global KhorosRoot
  269. if exist('KhorosRoot') && ~isempty(KhorosRoot)
  270. w=['"' KhorosRoot];
  271. else
  272. if ispc
  273. w='"C:\Program Files\dip\khorosBin\';
  274. else
  275. [s,w] = system('which cantata');
  276. w=['"' w(1:end-8)];
  277. end
  278. end
  279. [varargout{:}]=callKhoros([w 'kappend" '],Inputs,narglist);