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

/matlab_tools/Converted/kkgate.m

http://github.com/aludnam/MATLAB
Objective C | 300 lines | 297 code | 3 blank | 0 comment | 56 complexity | ae10dc7518fa0b0d0472f66447e78edb MD5 | raw file
Possible License(s): BSD-3-Clause
  1. %kkgate 'Based on Gating Input, Output Values Will Be From Input 1 or Input 2'
  2. % This MatLab function was automatically generated by a converter (KhorosToMatLab) from the Khoros kgate.pane file
  3. %
  4. % Parameters:
  5. % InputFile: i1 'Input 1 ', required: 'First input data object'
  6. % InputFile: i2 'Input 2 ', required: 'Second input file object'
  7. % InputFile: igate 'Gating Input', required: 'Gating input data object'
  8. % OutputFile: o 'Output', required: 'Resulting output data object'
  9. %
  10. % Example: o = kkgate({i1, i2, igate}, {'i1','';'i2','';'igate','';'o',''})
  11. %
  12. % Khoros helpfile follows below:
  13. %
  14. % PROGRAM
  15. % kgate - Based on Gating Input, Output Values Will Be From Input 1 or Input 2
  16. %
  17. % DESCRIPTION
  18. % For each point in Input 1 (i1) and Input 2 (i2), "kgate" assigns
  19. % to the Output (o) either the value from Input 1 or Input 2, depending
  20. % on the corresponding value in the Gating Input (igate), the specified
  21. % Gate Value (gval), and the gating logic (logic).
  22. %
  23. % .I kgate
  24. % can be used to gate many operations. The illustration below shows gating
  25. % the addition of of two data objects. The result of the gating is that the
  26. % second input is added to the first only for those pixels defined by the
  27. % gate object. The data objects in the illustration are represented as
  28. % 2x2 matrices. For example, Input 1 is a 2x2 data file with data values
  29. % of 3, shown as
  30. %
  31. % \f(CW
  32. % 3 3
  33. % 3 3
  34. % Input1
  35. % "
  36. %
  37. %
  38. % To perform a gated addition, first add the objects using the Add operator
  39. % (kadd). Next use the first data object as Input 1 (i1) to "kgate",
  40. % and the output of the addition operation as Input 2 (i2) to "kgate".
  41. % The third input to "kgate" is the gating object (igate). Using the
  42. % default logic option (True) and Gate Value (0), the output will get the value
  43. % of Input 2 any time that the value in the gate object is equal to the
  44. % specified Gate Value (0). Otherwise, the output will get the value from
  45. % Input 1.
  46. % .KS
  47. %
  48. % "\fBGated Addition Example:"" 5
  49. %
  50. %
  51. % \f(CW
  52. % +------+
  53. % 3 3 ---+------------------------> |i1 |
  54. % 3 3 | +------+ | out| --- 3 8
  55. % Input1 +--> |i1 | 8 8 ----> |i2 | 8 3
  56. % | out|--- 8 8 | | Result
  57. % 5 5 ------> |i2 | +--> |igate |
  58. % 5 5 +------+ | +------+
  59. % Input2 Add | Gate
  60. % |
  61. % 1 0 ---+
  62. % 0 1
  63. % Gating Input
  64. % "
  65. %
  66. % .KE
  67. %
  68. %
  69. % "Gate Value"
  70. % The Gate Value (gval) is a constant that can be specified by the user.
  71. % "kgate" will compare the elements of the Gate Object against this
  72. % value, and will gate based on whether the values in the Gate Object
  73. % are equal/unequal to the Gate Value. How the gating is applied
  74. % depends on the Gating Logic (logic), described below.
  75. %
  76. % "Gating Logic TRUE"
  77. % When the Gating Logic is set to TRUE (ie. If value in Gating Input equals
  78. % Gate Value, Output = Input 2), Input 1 is predominant, and is only gated when
  79. % the gating condition is met. Therefore the Output will be assigned values
  80. % from Input 1 "unless" the value in the Gating Input equals the specified
  81. % Gate Value, in which case Input 1 is gated and the Output is assigned the
  82. % value from Input 2.
  83. %
  84. % "Gating Logic FALSE"
  85. % When the Gating Logic is set to FALSE (ie. If value in Gating Input equals
  86. % Gate Value, Output = Input 1), Input 2 is predominant, and is only gated when
  87. % the gating condition is met. Therefore the Output will be assigned values
  88. % from Input 2 "unless" the value in the Gating Input equals the specified
  89. % Gate Value, in which case Input 2 is gated and the Output is assigned the
  90. % value from Input 1.
  91. %
  92. % "Subobject Position" 5
  93. % If the Use Subobject Position option (subpos) is set to "Yes", then
  94. % the subobject position of each object will be applied. This includes
  95. % its use in calculating the output object size. See the "Input Objects of
  96. % Different Sizes - Resizing & Padding" section below. The subobject position
  97. % functionality can be disabled by setting this option to "No".
  98. %
  99. % "Data Type" 5
  100. % If the gate object is complex, only the real component will be used.
  101. %
  102. %
  103. % .cI $DATAMANIP/repos/shared/man/sections/value_type_2input
  104. %
  105. % "Map Data" 5
  106. % .cI $DATAMANIP/repos/shared/man/sections/map_2input
  107. %
  108. % "Validity Mask" 5
  109. % If there is a validity mask associated with either source object, the
  110. % destination object mask value will be assigned according to the same
  111. % rules as apply to gating the value data.
  112. %
  113. %
  114. % Important: The Gating object may contain mask data "or" value data,
  115. % but "not" both. If mask data is supplied in the gating object, it
  116. % will be used only as gate values, and will not be propagated as a mask
  117. % to the output object.
  118. %
  119. % "Input Objects of Different Sizes - Resizing & Padding" 5
  120. % .cI $DATAMANIP/repos/shared/man/sections/resize_2input
  121. %
  122. %
  123. % \fBPadding": If Input 1 and/or Input 2 are enlarged, the value and/or map
  124. % data will be zero padded; masks will be padded with ones.
  125. % If the gating object is enlarged, it will be padded with a value "unequal"
  126. % to the gating value. Note that padding, not pixel replication, is performed
  127. % by "kgate". Therefore, if the user wants the gate to be replicated
  128. % along certain dimensions, that operation must be performed before hand using
  129. % the resampling operator (kresample).
  130. %
  131. % "Explicit Location and Time Data" 5
  132. % .cI $DATAMANIP/repos/shared/man/sections/loc_and_time_2input
  133. %
  134. % "Failure Modes" 5
  135. % .cI $DATAMANIP/repos/shared/man/sections/fail_2input
  136. %
  137. %
  138. %
  139. % EXAMPLES
  140. %
  141. % "SEE ALSO"
  142. % DATAMANIP::kblend
  143. %
  144. % RESTRICTIONS
  145. %
  146. % REFERENCES
  147. %
  148. % COPYRIGHT
  149. % Copyright (C) 1993 - 1997, Khoral Research, Inc. ("KRI") All rights reserved.
  150. %
  151. function varargout = kkgate(varargin)
  152. if nargin ==0
  153. Inputs={};arglist={'',''};
  154. elseif nargin ==1
  155. Inputs=varargin{1};arglist={'',''};
  156. elseif nargin ==2
  157. Inputs=varargin{1}; arglist=varargin{2};
  158. else error('Usage: [out1,..] = kkgate(Inputs,arglist).');
  159. end
  160. if size(arglist,2)~=2
  161. error('arglist must be of form {''ParameterTag1'',value1;''ParameterTag2'',value2}')
  162. end
  163. narglist={'i1', '__input';'i2', '__input';'igate', '__input';'o', '__output'};
  164. maxval={0,0,0,0};
  165. minval={0,0,0,0};
  166. istoggle=[0,0,0,0];
  167. was_set=istoggle * 0;
  168. paramtype={'InputFile','InputFile','InputFile','OutputFile'};
  169. % identify the input arrays and assign them to the arguments as stated by the user
  170. if ~iscell(Inputs)
  171. Inputs = {Inputs};
  172. end
  173. NumReqOutputs=1; nextinput=1; nextoutput=1;
  174. for ii=1:size(arglist,1)
  175. wasmatched=0;
  176. for jj=1:size(narglist,1)
  177. if strcmp(arglist{ii,1},narglist{jj,1}) % a given argument was matched to the possible arguments
  178. wasmatched = 1;
  179. was_set(jj) = 1;
  180. if strcmp(narglist{jj,2}, '__input')
  181. if (nextinput > length(Inputs))
  182. error(['Input ' narglist{jj,1} ' has no corresponding input!']);
  183. end
  184. narglist{jj,2} = 'OK_in';
  185. nextinput = nextinput + 1;
  186. elseif strcmp(narglist{jj,2}, '__output')
  187. if (nextoutput > nargout)
  188. error(['Output nr. ' narglist{jj,1} ' is not present in the assignment list of outputs !']);
  189. end
  190. if (isempty(arglist{ii,2}))
  191. narglist{jj,2} = 'OK_out';
  192. else
  193. narglist{jj,2} = arglist{ii,2};
  194. end
  195. nextoutput = nextoutput + 1;
  196. if (minval{jj} == 0)
  197. NumReqOutputs = NumReqOutputs - 1;
  198. end
  199. elseif isstr(arglist{ii,2})
  200. narglist{jj,2} = arglist{ii,2};
  201. else
  202. if strcmp(paramtype{jj}, 'Integer') & (round(arglist{ii,2}) ~= arglist{ii,2})
  203. error(['Argument ' arglist{ii,1} ' is of integer type but non-integer number ' arglist{ii,2} ' was supplied']);
  204. end
  205. if (minval{jj} ~= 0 | maxval{jj} ~= 0)
  206. if (minval{jj} == 1 & maxval{jj} == 1 & arglist{ii,2} < 0)
  207. error(['Argument ' arglist{ii,1} ' must be bigger or equal to zero!']);
  208. elseif (minval{jj} == -1 & maxval{jj} == -1 & arglist{ii,2} > 0)
  209. error(['Argument ' arglist{ii,1} ' must be smaller or equal to zero!']);
  210. elseif (minval{jj} == 2 & maxval{jj} == 2 & arglist{ii,2} <= 0)
  211. error(['Argument ' arglist{ii,1} ' must be bigger than zero!']);
  212. elseif (minval{jj} == -2 & maxval{jj} == -2 & arglist{ii,2} >= 0)
  213. error(['Argument ' arglist{ii,1} ' must be smaller than zero!']);
  214. elseif (minval{jj} ~= maxval{jj} & arglist{ii,2} < minval{jj})
  215. error(['Argument ' arglist{ii,1} ' must be bigger than ' num2str(minval{jj})]);
  216. elseif (minval{jj} ~= maxval{jj} & arglist{ii,2} > maxval{jj})
  217. error(['Argument ' arglist{ii,1} ' must be smaller than ' num2str(maxval{jj})]);
  218. end
  219. end
  220. end
  221. if ~strcmp(narglist{jj,2},'OK_out') & ~strcmp(narglist{jj,2},'OK_in')
  222. narglist{jj,2} = arglist{ii,2};
  223. end
  224. end
  225. end
  226. if (wasmatched == 0 & ~strcmp(arglist{ii,1},''))
  227. error(['Argument ' arglist{ii,1} ' is not a valid argument for this function']);
  228. end
  229. end
  230. % match the remaining inputs/outputs to the unused arguments and test for missing required inputs
  231. for jj=1:size(narglist,1)
  232. if strcmp(paramtype{jj}, 'Toggle')
  233. if (narglist{jj,2} ==0)
  234. narglist{jj,1} = '';
  235. end;
  236. narglist{jj,2} = '';
  237. end;
  238. if ~strcmp(narglist{jj,2},'__input') && ~strcmp(narglist{jj,2},'__output') && istoggle(jj) && ~ was_set(jj)
  239. narglist{jj,1} = '';
  240. narglist{jj,2} = '';
  241. end;
  242. if strcmp(narglist{jj,2}, '__input')
  243. if (minval{jj} == 0) % meaning this input is required
  244. if (nextinput > size(Inputs))
  245. error(['Required input ' narglist{jj,1} ' has no corresponding input in the list!']);
  246. else
  247. narglist{jj,2} = 'OK_in';
  248. nextinput = nextinput + 1;
  249. end
  250. else % this is an optional input
  251. if (nextinput <= length(Inputs))
  252. narglist{jj,2} = 'OK_in';
  253. nextinput = nextinput + 1;
  254. else
  255. narglist{jj,1} = '';
  256. narglist{jj,2} = '';
  257. end;
  258. end;
  259. else
  260. if strcmp(narglist{jj,2}, '__output')
  261. if (minval{jj} == 0) % this is a required output
  262. if (nextoutput > nargout & nargout > 1)
  263. error(['Required output ' narglist{jj,1} ' is not stated in the assignment list!']);
  264. else
  265. narglist{jj,2} = 'OK_out';
  266. nextoutput = nextoutput + 1;
  267. NumReqOutputs = NumReqOutputs-1;
  268. end
  269. else % this is an optional output
  270. if (nargout - nextoutput >= NumReqOutputs)
  271. narglist{jj,2} = 'OK_out';
  272. nextoutput = nextoutput + 1;
  273. else
  274. narglist{jj,1} = '';
  275. narglist{jj,2} = '';
  276. end;
  277. end
  278. end
  279. end
  280. end
  281. if nargout
  282. varargout = cell(1,nargout);
  283. else
  284. varargout = cell(1,1);
  285. end
  286. global KhorosRoot
  287. if exist('KhorosRoot') && ~isempty(KhorosRoot)
  288. w=['"' KhorosRoot];
  289. else
  290. if ispc
  291. w='"C:\Program Files\dip\khorosBin\';
  292. else
  293. [s,w] = system('which cantata');
  294. w=['"' w(1:end-8)];
  295. end
  296. end
  297. [varargout{:}]=callKhoros([w 'kgate" '],Inputs,narglist);