PageRenderTime 51ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/matlab_tools/Converted/kmtransform.m

http://github.com/aludnam/MATLAB
Objective C | 228 lines | 225 code | 3 blank | 0 comment | 55 complexity | 355f286294659f9f3e42d7bbc85fac98 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. %kmtransform 'Transform all vectors in an object using a single matrix'
  2. % This MatLab function was automatically generated by a converter (KhorosToMatLab) from the Khoros mtransform.pane file
  3. %
  4. % Parameters:
  5. % InputFile: i1 'Input matrix', required: 'matrix to be used to transform the vectors'
  6. % InputFile: i2 'Vector object', required: 'object of vectors (down E) to be transformed'
  7. % OutputFile: o 'Output vector object', required: 'Object of transformed E vectors'
  8. %
  9. % Example: o = kmtransform({i1, i2}, {'i1','';'i2','';'o',''})
  10. %
  11. % Khoros helpfile follows below:
  12. %
  13. % PROGRAM
  14. % mtransform - Transform all vectors in an object using a single matrix
  15. %
  16. % DESCRIPTION
  17. % .I mtransform
  18. % multiplies a given matrix onto each of the WxHxDxT vectors down E in
  19. % a data object. The matrix is assumed to be provided as a single WxH plane,
  20. % thus the W dimension of the matrix must match the E dimension of the
  21. % vectors. The result is to transform each vector down W from the input
  22. % vector object into a vector down the E axis of the output vector object, with
  23. % the E size of the output object being the same as the H dimension of the matrix.
  24. %
  25. % This operation is represented schematically as:
  26. % .begin code
  27. %
  28. % [ ] [ ] [ ]
  29. % [ ] [ ] [ ]
  30. % [ ] [ ] -> [ ]
  31. % [ ] [ ] [ ]
  32. % [ ] [ ] E x1
  33. % W x H E x1 o
  34. % m m i
  35. %
  36. % ^ ^ ^
  37. % | | |
  38. % | | +--- output vector, E =H
  39. % | | o m
  40. % | +--- input vector
  41. % |
  42. % +--- input matrix
  43. %
  44. % .end code
  45. % The output data type is controlled by the -type argument.
  46. % If -type is 0 ("Propagate input type") then output data type will be the same
  47. % as the input data type (look out for wraparound). If a different data type is
  48. % specified, the output data is cast to that type after the transformation is
  49. % computed.
  50. %
  51. %
  52. %
  53. % EXAMPLES
  54. % The following will scale the first band of a 3-band image by 1.0, the second
  55. % band by 2.0, and the third band by 3.0:
  56. %
  57. %
  58. % % cat > matrix <<EOF
  59. % 1 0 0
  60. % 0 2 0
  61. % 0 0 3
  62. % EOF
  63. %
  64. % % mtransform -i1 matrix -i2 3-band-image -o output
  65. %
  66. %
  67. % "SEE ALSO"
  68. % mcovar(1)
  69. %
  70. % RESTRICTIONS
  71. % This routine really should be able to operate on vectors along ANY direction,
  72. % not just E.
  73. %
  74. % REFERENCES
  75. %
  76. % COPYRIGHT
  77. % Copyright (C) 1993 - 1997, Khoral Research, Inc. ("KRI") All rights reserved.
  78. %
  79. function varargout = kmtransform(varargin)
  80. if nargin ==0
  81. Inputs={};arglist={'',''};
  82. elseif nargin ==1
  83. Inputs=varargin{1};arglist={'',''};
  84. elseif nargin ==2
  85. Inputs=varargin{1}; arglist=varargin{2};
  86. else error('Usage: [out1,..] = kmtransform(Inputs,arglist).');
  87. end
  88. if size(arglist,2)~=2
  89. error('arglist must be of form {''ParameterTag1'',value1;''ParameterTag2'',value2}')
  90. end
  91. narglist={'i1', '__input';'i2', '__input';'o', '__output'};
  92. maxval={0,0,0};
  93. minval={0,0,0};
  94. istoggle=[0,0,0];
  95. was_set=istoggle * 0;
  96. paramtype={'InputFile','InputFile','OutputFile'};
  97. % identify the input arrays and assign them to the arguments as stated by the user
  98. if ~iscell(Inputs)
  99. Inputs = {Inputs};
  100. end
  101. NumReqOutputs=1; nextinput=1; nextoutput=1;
  102. for ii=1:size(arglist,1)
  103. wasmatched=0;
  104. for jj=1:size(narglist,1)
  105. if strcmp(arglist{ii,1},narglist{jj,1}) % a given argument was matched to the possible arguments
  106. wasmatched = 1;
  107. was_set(jj) = 1;
  108. if strcmp(narglist{jj,2}, '__input')
  109. if (nextinput > length(Inputs))
  110. error(['Input ' narglist{jj,1} ' has no corresponding input!']);
  111. end
  112. narglist{jj,2} = 'OK_in';
  113. nextinput = nextinput + 1;
  114. elseif strcmp(narglist{jj,2}, '__output')
  115. if (nextoutput > nargout)
  116. error(['Output nr. ' narglist{jj,1} ' is not present in the assignment list of outputs !']);
  117. end
  118. if (isempty(arglist{ii,2}))
  119. narglist{jj,2} = 'OK_out';
  120. else
  121. narglist{jj,2} = arglist{ii,2};
  122. end
  123. nextoutput = nextoutput + 1;
  124. if (minval{jj} == 0)
  125. NumReqOutputs = NumReqOutputs - 1;
  126. end
  127. elseif isstr(arglist{ii,2})
  128. narglist{jj,2} = arglist{ii,2};
  129. else
  130. if strcmp(paramtype{jj}, 'Integer') & (round(arglist{ii,2}) ~= arglist{ii,2})
  131. error(['Argument ' arglist{ii,1} ' is of integer type but non-integer number ' arglist{ii,2} ' was supplied']);
  132. end
  133. if (minval{jj} ~= 0 | maxval{jj} ~= 0)
  134. if (minval{jj} == 1 & maxval{jj} == 1 & arglist{ii,2} < 0)
  135. error(['Argument ' arglist{ii,1} ' must be bigger or equal to zero!']);
  136. elseif (minval{jj} == -1 & maxval{jj} == -1 & arglist{ii,2} > 0)
  137. error(['Argument ' arglist{ii,1} ' must be smaller or equal to zero!']);
  138. elseif (minval{jj} == 2 & maxval{jj} == 2 & arglist{ii,2} <= 0)
  139. error(['Argument ' arglist{ii,1} ' must be bigger than zero!']);
  140. elseif (minval{jj} == -2 & maxval{jj} == -2 & arglist{ii,2} >= 0)
  141. error(['Argument ' arglist{ii,1} ' must be smaller than zero!']);
  142. elseif (minval{jj} ~= maxval{jj} & arglist{ii,2} < minval{jj})
  143. error(['Argument ' arglist{ii,1} ' must be bigger than ' num2str(minval{jj})]);
  144. elseif (minval{jj} ~= maxval{jj} & arglist{ii,2} > maxval{jj})
  145. error(['Argument ' arglist{ii,1} ' must be smaller than ' num2str(maxval{jj})]);
  146. end
  147. end
  148. end
  149. if ~strcmp(narglist{jj,2},'OK_out') & ~strcmp(narglist{jj,2},'OK_in')
  150. narglist{jj,2} = arglist{ii,2};
  151. end
  152. end
  153. end
  154. if (wasmatched == 0 & ~strcmp(arglist{ii,1},''))
  155. error(['Argument ' arglist{ii,1} ' is not a valid argument for this function']);
  156. end
  157. end
  158. % match the remaining inputs/outputs to the unused arguments and test for missing required inputs
  159. for jj=1:size(narglist,1)
  160. if strcmp(paramtype{jj}, 'Toggle')
  161. if (narglist{jj,2} ==0)
  162. narglist{jj,1} = '';
  163. end;
  164. narglist{jj,2} = '';
  165. end;
  166. if ~strcmp(narglist{jj,2},'__input') && ~strcmp(narglist{jj,2},'__output') && istoggle(jj) && ~ was_set(jj)
  167. narglist{jj,1} = '';
  168. narglist{jj,2} = '';
  169. end;
  170. if strcmp(narglist{jj,2}, '__input')
  171. if (minval{jj} == 0) % meaning this input is required
  172. if (nextinput > size(Inputs))
  173. error(['Required input ' narglist{jj,1} ' has no corresponding input in the list!']);
  174. else
  175. narglist{jj,2} = 'OK_in';
  176. nextinput = nextinput + 1;
  177. end
  178. else % this is an optional input
  179. if (nextinput <= length(Inputs))
  180. narglist{jj,2} = 'OK_in';
  181. nextinput = nextinput + 1;
  182. else
  183. narglist{jj,1} = '';
  184. narglist{jj,2} = '';
  185. end;
  186. end;
  187. else
  188. if strcmp(narglist{jj,2}, '__output')
  189. if (minval{jj} == 0) % this is a required output
  190. if (nextoutput > nargout & nargout > 1)
  191. error(['Required output ' narglist{jj,1} ' is not stated in the assignment list!']);
  192. else
  193. narglist{jj,2} = 'OK_out';
  194. nextoutput = nextoutput + 1;
  195. NumReqOutputs = NumReqOutputs-1;
  196. end
  197. else % this is an optional output
  198. if (nargout - nextoutput >= NumReqOutputs)
  199. narglist{jj,2} = 'OK_out';
  200. nextoutput = nextoutput + 1;
  201. else
  202. narglist{jj,1} = '';
  203. narglist{jj,2} = '';
  204. end;
  205. end
  206. end
  207. end
  208. end
  209. if nargout
  210. varargout = cell(1,nargout);
  211. else
  212. varargout = cell(1,1);
  213. end
  214. global KhorosRoot
  215. if exist('KhorosRoot') && ~isempty(KhorosRoot)
  216. w=['"' KhorosRoot];
  217. else
  218. if ispc
  219. w='"C:\Program Files\dip\khorosBin\';
  220. else
  221. [s,w] = system('which cantata');
  222. w=['"' w(1:end-8)];
  223. end
  224. end
  225. [varargout{:}]=callKhoros([w 'mtransform" '],Inputs,narglist);