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

/matlab_tools/Converted/kvtoggle.m

http://github.com/aludnam/MATLAB
Objective C | 198 lines | 195 code | 3 blank | 0 comment | 56 complexity | a4b508c1c865b2af683e1a1ab826b6dc MD5 | raw file
Possible License(s): BSD-3-Clause
  1. %kvtoggle 'Toggle of Two Images'
  2. % This MatLab function was automatically generated by a converter (KhorosToMatLab) from the Khoros vtoggle.pane file
  3. %
  4. % Parameters:
  5. % InputFile: i1 'Input Image #1', required: 'first input image'
  6. % InputFile: i2 'Input Image #2', required: 'second input image'
  7. % InputFile: i3 'Input Image #3', required: 'third input image'
  8. % OutputFile: o 'Output Image ', required: 'resulting output image'
  9. %
  10. % Example: o = kvtoggle({i1, i2, i3}, {'i1','';'i2','';'i3','';'o',''})
  11. %
  12. % Khoros helpfile follows below:
  13. %
  14. % PROGRAM
  15. % vtoggle - Toggle of Two Images
  16. %
  17. % DESCRIPTION
  18. % .I vtoggle
  19. % will do the toggle between two input images pixel by pixel.
  20. %
  21. % The two input images must be of the same size and have the same
  22. % number of data bands. The input
  23. % images may be of the same or different data types. If the input
  24. % images are of different data types, then all input images will be
  25. % upcast to the highest input image data type. The output
  26. % image data type will be the same as that of the highest data type
  27. % of the input images.
  28. %
  29. %
  30. %
  31. % EXAMPLES
  32. % vtoggle -i1 feath.xv -i2 openfeath.xv -i3 closefeath.xv -o outimage.xv
  33. %
  34. % Will do the toggle between image 2 "openfeath.xv" and image 2 "closefeath.xv"
  35. % with the resulting image written to "outimage.xv".
  36. %
  37. % "SEE ALSO"
  38. % vcast1(1)
  39. %
  40. % RESTRICTIONS
  41. % .I vtoggle
  42. % can be defined for all data types supported by Khoros (except bit), but at the moment it has been implemented just for unsigned char type.
  43. %
  44. % REFERENCES
  45. %
  46. % COPYRIGHT
  47. % Copyright (C) 1993-1997 Junior Barrera, Roberto Lotufo. All rights reserved.
  48. %
  49. function varargout = kvtoggle(varargin)
  50. if nargin ==0
  51. Inputs={};arglist={'',''};
  52. elseif nargin ==1
  53. Inputs=varargin{1};arglist={'',''};
  54. elseif nargin ==2
  55. Inputs=varargin{1}; arglist=varargin{2};
  56. else error('Usage: [out1,..] = kvtoggle(Inputs,arglist).');
  57. end
  58. if size(arglist,2)~=2
  59. error('arglist must be of form {''ParameterTag1'',value1;''ParameterTag2'',value2}')
  60. end
  61. narglist={'i1', '__input';'i2', '__input';'i3', '__input';'o', '__output'};
  62. maxval={0,0,0,0};
  63. minval={0,0,0,0};
  64. istoggle=[0,0,0,0];
  65. was_set=istoggle * 0;
  66. paramtype={'InputFile','InputFile','InputFile','OutputFile'};
  67. % identify the input arrays and assign them to the arguments as stated by the user
  68. if ~iscell(Inputs)
  69. Inputs = {Inputs};
  70. end
  71. NumReqOutputs=1; nextinput=1; nextoutput=1;
  72. for ii=1:size(arglist,1)
  73. wasmatched=0;
  74. for jj=1:size(narglist,1)
  75. if strcmp(arglist{ii,1},narglist{jj,1}) % a given argument was matched to the possible arguments
  76. wasmatched = 1;
  77. was_set(jj) = 1;
  78. if strcmp(narglist{jj,2}, '__input')
  79. if (nextinput > length(Inputs))
  80. error(['Input ' narglist{jj,1} ' has no corresponding input!']);
  81. end
  82. narglist{jj,2} = 'OK_in';
  83. nextinput = nextinput + 1;
  84. elseif strcmp(narglist{jj,2}, '__output')
  85. if (nextoutput > nargout)
  86. error(['Output nr. ' narglist{jj,1} ' is not present in the assignment list of outputs !']);
  87. end
  88. if (isempty(arglist{ii,2}))
  89. narglist{jj,2} = 'OK_out';
  90. else
  91. narglist{jj,2} = arglist{ii,2};
  92. end
  93. nextoutput = nextoutput + 1;
  94. if (minval{jj} == 0)
  95. NumReqOutputs = NumReqOutputs - 1;
  96. end
  97. elseif isstr(arglist{ii,2})
  98. narglist{jj,2} = arglist{ii,2};
  99. else
  100. if strcmp(paramtype{jj}, 'Integer') & (round(arglist{ii,2}) ~= arglist{ii,2})
  101. error(['Argument ' arglist{ii,1} ' is of integer type but non-integer number ' arglist{ii,2} ' was supplied']);
  102. end
  103. if (minval{jj} ~= 0 | maxval{jj} ~= 0)
  104. if (minval{jj} == 1 & maxval{jj} == 1 & arglist{ii,2} < 0)
  105. error(['Argument ' arglist{ii,1} ' must be bigger or equal to zero!']);
  106. elseif (minval{jj} == -1 & maxval{jj} == -1 & arglist{ii,2} > 0)
  107. error(['Argument ' arglist{ii,1} ' must be smaller or equal to zero!']);
  108. elseif (minval{jj} == 2 & maxval{jj} == 2 & arglist{ii,2} <= 0)
  109. error(['Argument ' arglist{ii,1} ' must be bigger than zero!']);
  110. elseif (minval{jj} == -2 & maxval{jj} == -2 & arglist{ii,2} >= 0)
  111. error(['Argument ' arglist{ii,1} ' must be smaller than zero!']);
  112. elseif (minval{jj} ~= maxval{jj} & arglist{ii,2} < minval{jj})
  113. error(['Argument ' arglist{ii,1} ' must be bigger than ' num2str(minval{jj})]);
  114. elseif (minval{jj} ~= maxval{jj} & arglist{ii,2} > maxval{jj})
  115. error(['Argument ' arglist{ii,1} ' must be smaller than ' num2str(maxval{jj})]);
  116. end
  117. end
  118. end
  119. if ~strcmp(narglist{jj,2},'OK_out') & ~strcmp(narglist{jj,2},'OK_in')
  120. narglist{jj,2} = arglist{ii,2};
  121. end
  122. end
  123. end
  124. if (wasmatched == 0 & ~strcmp(arglist{ii,1},''))
  125. error(['Argument ' arglist{ii,1} ' is not a valid argument for this function']);
  126. end
  127. end
  128. % match the remaining inputs/outputs to the unused arguments and test for missing required inputs
  129. for jj=1:size(narglist,1)
  130. if strcmp(paramtype{jj}, 'Toggle')
  131. if (narglist{jj,2} ==0)
  132. narglist{jj,1} = '';
  133. end;
  134. narglist{jj,2} = '';
  135. end;
  136. if ~strcmp(narglist{jj,2},'__input') && ~strcmp(narglist{jj,2},'__output') && istoggle(jj) && ~ was_set(jj)
  137. narglist{jj,1} = '';
  138. narglist{jj,2} = '';
  139. end;
  140. if strcmp(narglist{jj,2}, '__input')
  141. if (minval{jj} == 0) % meaning this input is required
  142. if (nextinput > size(Inputs))
  143. error(['Required input ' narglist{jj,1} ' has no corresponding input in the list!']);
  144. else
  145. narglist{jj,2} = 'OK_in';
  146. nextinput = nextinput + 1;
  147. end
  148. else % this is an optional input
  149. if (nextinput <= length(Inputs))
  150. narglist{jj,2} = 'OK_in';
  151. nextinput = nextinput + 1;
  152. else
  153. narglist{jj,1} = '';
  154. narglist{jj,2} = '';
  155. end;
  156. end;
  157. else
  158. if strcmp(narglist{jj,2}, '__output')
  159. if (minval{jj} == 0) % this is a required output
  160. if (nextoutput > nargout & nargout > 1)
  161. error(['Required output ' narglist{jj,1} ' is not stated in the assignment list!']);
  162. else
  163. narglist{jj,2} = 'OK_out';
  164. nextoutput = nextoutput + 1;
  165. NumReqOutputs = NumReqOutputs-1;
  166. end
  167. else % this is an optional output
  168. if (nargout - nextoutput >= NumReqOutputs)
  169. narglist{jj,2} = 'OK_out';
  170. nextoutput = nextoutput + 1;
  171. else
  172. narglist{jj,1} = '';
  173. narglist{jj,2} = '';
  174. end;
  175. end
  176. end
  177. end
  178. end
  179. if nargout
  180. varargout = cell(1,nargout);
  181. else
  182. varargout = cell(1,1);
  183. end
  184. global KhorosRoot
  185. if exist('KhorosRoot') && ~isempty(KhorosRoot)
  186. w=['"' KhorosRoot];
  187. else
  188. if ispc
  189. w='"C:\Program Files\dip\khorosBin\';
  190. else
  191. [s,w] = system('which cantata');
  192. w=['"' w(1:end-8)];
  193. end
  194. end
  195. [varargout{:}]=callKhoros([w 'vtoggle" '],Inputs,narglist);