PageRenderTime 44ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/matlab_tools/Converted/kkblend.m

http://github.com/aludnam/MATLAB
Objective C | 213 lines | 210 code | 3 blank | 0 comment | 58 complexity | 9563297aa79f78a968a5ec9afd9db7ab MD5 | raw file
Possible License(s): BSD-3-Clause
  1. %kkblend 'Output = (Input 1 * Constant) + (Input 2 (1 - Constant))'
  2. % This MatLab function was automatically generated by a converter (KhorosToMatLab) from the Khoros kblend.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. % OutputFile: o 'Output', required: 'resulting output data object'
  8. % InputFile: iratio 'Blending file', optional: 'Input object for providing blending ratios'
  9. %
  10. % Example: o = kkblend({i1, i2, iratio}, {'i1','';'i2','';'o','';'iratio',''})
  11. %
  12. % Khoros helpfile follows below:
  13. %
  14. % PROGRAM
  15. % kblend - Output = (Input 1 * Constant) + (Input 2 (1 - Constant))
  16. %
  17. % DESCRIPTION
  18. % The "Blend" operator (kblend) forms a blend of two objects by
  19. % adding X*(object1)+(1-X)*(object2).
  20. %
  21. % Instead of specifying a constant for the blending ratio, an object can be
  22. % supplied for the blending values. The value segment of the ratio object
  23. % is used to determine the proportion in which the two objects are blended.
  24. % It must take on values between 0 and 1, otherwise an error is generated.
  25. %
  26. %
  27. % "Data Type" 5
  28. % .cI $DATAMANIP/repos/shared/man/sections/value_type_2input
  29. %
  30. % "Map Data" 5
  31. % .cI $DATAMANIP/repos/shared/man/sections/map_2input
  32. %
  33. % "Validity Mask" 5
  34. % If there is a validity mask associated with any of the input objects, the
  35. % resulting output object will have a mask. The output object mask is the
  36. % logical AND of the input object masks. If only one input object has a mask,
  37. % then the other input object's mask is assumed to be "all valid" (mask
  38. % value = 1). If a mask is resized for the operation, the mask padding value
  39. % will be 1.
  40. %
  41. % "Input Objects of Different Sizes" 5
  42. % .cI $DATAMANIP/repos/shared/man/sections/resize_2input
  43. %
  44. % "Explicit Location and Time Data" 5
  45. % .cI $DATAMANIP/repos/shared/man/sections/loc_and_time_2input
  46. %
  47. % "Failure Modes - Two Input Objects"
  48. % .cI $DATAMANIP/repos/shared/man/sections/fail_2input
  49. %
  50. %
  51. %
  52. % EXAMPLES
  53. %
  54. % "SEE ALSO"
  55. %
  56. % RESTRICTIONS
  57. % The blend operator has not been updated to be fully polymorphic.
  58. %
  59. % REFERENCES
  60. %
  61. % COPYRIGHT
  62. % Copyright (C) 1993 - 1997, Khoral Research, Inc. ("KRI") All rights reserved.
  63. %
  64. function varargout = kkblend(varargin)
  65. if nargin ==0
  66. Inputs={};arglist={'',''};
  67. elseif nargin ==1
  68. Inputs=varargin{1};arglist={'',''};
  69. elseif nargin ==2
  70. Inputs=varargin{1}; arglist=varargin{2};
  71. else error('Usage: [out1,..] = kkblend(Inputs,arglist).');
  72. end
  73. if size(arglist,2)~=2
  74. error('arglist must be of form {''ParameterTag1'',value1;''ParameterTag2'',value2}')
  75. end
  76. narglist={'i1', '__input';'i2', '__input';'o', '__output';'iratio', '__input'};
  77. maxval={0,0,0,1};
  78. minval={0,0,0,1};
  79. istoggle=[0,0,0,1];
  80. was_set=istoggle * 0;
  81. paramtype={'InputFile','InputFile','OutputFile','InputFile'};
  82. % identify the input arrays and assign them to the arguments as stated by the user
  83. if ~iscell(Inputs)
  84. Inputs = {Inputs};
  85. end
  86. NumReqOutputs=1; nextinput=1; nextoutput=1;
  87. for ii=1:size(arglist,1)
  88. wasmatched=0;
  89. for jj=1:size(narglist,1)
  90. if strcmp(arglist{ii,1},narglist{jj,1}) % a given argument was matched to the possible arguments
  91. wasmatched = 1;
  92. was_set(jj) = 1;
  93. if strcmp(narglist{jj,2}, '__input')
  94. if (nextinput > length(Inputs))
  95. error(['Input ' narglist{jj,1} ' has no corresponding input!']);
  96. end
  97. narglist{jj,2} = 'OK_in';
  98. nextinput = nextinput + 1;
  99. elseif strcmp(narglist{jj,2}, '__output')
  100. if (nextoutput > nargout)
  101. error(['Output nr. ' narglist{jj,1} ' is not present in the assignment list of outputs !']);
  102. end
  103. if (isempty(arglist{ii,2}))
  104. narglist{jj,2} = 'OK_out';
  105. else
  106. narglist{jj,2} = arglist{ii,2};
  107. end
  108. nextoutput = nextoutput + 1;
  109. if (minval{jj} == 0)
  110. NumReqOutputs = NumReqOutputs - 1;
  111. end
  112. elseif isstr(arglist{ii,2})
  113. narglist{jj,2} = arglist{ii,2};
  114. else
  115. if strcmp(paramtype{jj}, 'Integer') & (round(arglist{ii,2}) ~= arglist{ii,2})
  116. error(['Argument ' arglist{ii,1} ' is of integer type but non-integer number ' arglist{ii,2} ' was supplied']);
  117. end
  118. if (minval{jj} ~= 0 | maxval{jj} ~= 0)
  119. if (minval{jj} == 1 & maxval{jj} == 1 & arglist{ii,2} < 0)
  120. error(['Argument ' arglist{ii,1} ' must be bigger or equal to zero!']);
  121. elseif (minval{jj} == -1 & maxval{jj} == -1 & arglist{ii,2} > 0)
  122. error(['Argument ' arglist{ii,1} ' must be smaller or equal to zero!']);
  123. elseif (minval{jj} == 2 & maxval{jj} == 2 & arglist{ii,2} <= 0)
  124. error(['Argument ' arglist{ii,1} ' must be bigger than zero!']);
  125. elseif (minval{jj} == -2 & maxval{jj} == -2 & arglist{ii,2} >= 0)
  126. error(['Argument ' arglist{ii,1} ' must be smaller than zero!']);
  127. elseif (minval{jj} ~= maxval{jj} & arglist{ii,2} < minval{jj})
  128. error(['Argument ' arglist{ii,1} ' must be bigger than ' num2str(minval{jj})]);
  129. elseif (minval{jj} ~= maxval{jj} & arglist{ii,2} > maxval{jj})
  130. error(['Argument ' arglist{ii,1} ' must be smaller than ' num2str(maxval{jj})]);
  131. end
  132. end
  133. end
  134. if ~strcmp(narglist{jj,2},'OK_out') & ~strcmp(narglist{jj,2},'OK_in')
  135. narglist{jj,2} = arglist{ii,2};
  136. end
  137. end
  138. end
  139. if (wasmatched == 0 & ~strcmp(arglist{ii,1},''))
  140. error(['Argument ' arglist{ii,1} ' is not a valid argument for this function']);
  141. end
  142. end
  143. % match the remaining inputs/outputs to the unused arguments and test for missing required inputs
  144. for jj=1:size(narglist,1)
  145. if strcmp(paramtype{jj}, 'Toggle')
  146. if (narglist{jj,2} ==0)
  147. narglist{jj,1} = '';
  148. end;
  149. narglist{jj,2} = '';
  150. end;
  151. if ~strcmp(narglist{jj,2},'__input') && ~strcmp(narglist{jj,2},'__output') && istoggle(jj) && ~ was_set(jj)
  152. narglist{jj,1} = '';
  153. narglist{jj,2} = '';
  154. end;
  155. if strcmp(narglist{jj,2}, '__input')
  156. if (minval{jj} == 0) % meaning this input is required
  157. if (nextinput > size(Inputs))
  158. error(['Required input ' narglist{jj,1} ' has no corresponding input in the list!']);
  159. else
  160. narglist{jj,2} = 'OK_in';
  161. nextinput = nextinput + 1;
  162. end
  163. else % this is an optional input
  164. if (nextinput <= length(Inputs))
  165. narglist{jj,2} = 'OK_in';
  166. nextinput = nextinput + 1;
  167. else
  168. narglist{jj,1} = '';
  169. narglist{jj,2} = '';
  170. end;
  171. end;
  172. else
  173. if strcmp(narglist{jj,2}, '__output')
  174. if (minval{jj} == 0) % this is a required output
  175. if (nextoutput > nargout & nargout > 1)
  176. error(['Required output ' narglist{jj,1} ' is not stated in the assignment list!']);
  177. else
  178. narglist{jj,2} = 'OK_out';
  179. nextoutput = nextoutput + 1;
  180. NumReqOutputs = NumReqOutputs-1;
  181. end
  182. else % this is an optional output
  183. if (nargout - nextoutput >= NumReqOutputs)
  184. narglist{jj,2} = 'OK_out';
  185. nextoutput = nextoutput + 1;
  186. else
  187. narglist{jj,1} = '';
  188. narglist{jj,2} = '';
  189. end;
  190. end
  191. end
  192. end
  193. end
  194. if nargout
  195. varargout = cell(1,nargout);
  196. else
  197. varargout = cell(1,1);
  198. end
  199. global KhorosRoot
  200. if exist('KhorosRoot') && ~isempty(KhorosRoot)
  201. w=['"' KhorosRoot];
  202. else
  203. if ispc
  204. w='"C:\Program Files\dip\khorosBin\';
  205. else
  206. [s,w] = system('which cantata');
  207. w=['"' w(1:end-8)];
  208. end
  209. end
  210. [varargout{:}]=callKhoros([w 'kblend" '],Inputs,narglist);