PageRenderTime 57ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/matlab_tools/Converted/krotate.m

http://github.com/aludnam/MATLAB
Objective C | 200 lines | 197 code | 3 blank | 0 comment | 54 complexity | 899f828743e5c249eb6b11334fc8a9d3 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. %krotate 'rotates a 3D Image in space '
  2. % This MatLab function was automatically generated by a converter (KhorosToMatLab) from the Khoros rotate.pane file
  3. %
  4. % Parameters:
  5. % InputFile: i 'Input ', required: 'First Input data object'
  6. % InputFile: v 'Vector file', optional: 'File with ascii coordinates of three matching points'
  7. % Toggle: center 'but use center', default: 0: 'if given : determine only the angles from vectorfile and use center given below'
  8. % InputFile: icorrel 'correlation input', optional: 'determine exact angle and center from this input, use given angles as starting point'
  9. % Double: phase 'PhaseFac', default: 1: 'rotation angle (deg) about X-axis'
  10. % InputFile: tangle 'turning angle input', optional: 'KDF File with AngleX, AngleY, AngleZ in X-direction in it'
  11. % Double: width 'Start Width', default: 10: 'starting width to find best position'
  12. % OutputFile: rangle 'Angle Output', optional: 'Writes a KDF File with calculated angles in it. Only when correlation file is used'
  13. % Toggle: op 'only about Z', default: 0: 'if selected rotational alignment will only be about Z axis'
  14. % Toggle: successive 'Successive Alignment', default: 0: 'if activated, each ELEMENT will be allilgned with the previous one.'
  15. % Double: aX 'Angle about X', default: 0: 'rotation angle (deg) about X-axis'
  16. % Double: aY 'Y', default: 0: 'rotation angle (deg) about Y-axis'
  17. % Double: aZ 'Z', default: 0: 'rotation angle (deg) about Z-axis'
  18. % Toggle: xstretch 'Scale X', default: 0: 'if activated, the X-Scaling will be optimized'
  19. % Double: cX 'Center X', default: 0: 'center of rotation coordinates'
  20. % Double: cY 'Y', default: 0: 'center of rotation coordinates'
  21. % Double: cZ 'Z', default: 0: 'center of rotation coordinates'
  22. % Toggle: ystretch 'Scale Y', default: 0: 'if activated, the Y-Scaling will be optimized'
  23. % Double: sX 'Scale X', default: 1: 'scaling X'
  24. % Double: sY 'Y', default: 1: 'scaling Y'
  25. % Double: sZ 'Z', default: 1: 'scaling Z'
  26. % Toggle: zstretch 'Scale Z', default: 0: 'if activated, the Z-Scaling will be optimized'
  27. % OutputFile: o 'Output', required: 'Resulting output data object'
  28. %
  29. % Example: [rangle, o] = krotate({i, v, icorrel, tangle}, {'i','';'v','';'center',0;'icorrel','';'phase',1;'tangle','';'width',10;'rangle','';'op',0;'successive',0;'aX',0;'aY',0;'aZ',0;'xstretch',0;'cX',0;'cY',0;'cZ',0;'ystretch',0;'sX',1;'sY',1;'sZ',1;'zstretch',0;'o',''})
  30. %
  31. % Khoros helpfile follows below:
  32. %
  33. % PROGRAM
  34. % rotate - rotates a 3D Image in space
  35. %
  36. % DESCRIPTION
  37. %
  38. %
  39. %
  40. % EXAMPLES
  41. %
  42. % "SEE ALSO"
  43. %
  44. % RESTRICTIONS
  45. %
  46. % REFERENCES
  47. %
  48. % COPYRIGHT
  49. % Copyright (C) 1996-2003, Rainer Heintzmann, All rights reserved.
  50. %
  51. function varargout = krotate(varargin)
  52. if nargin ==0
  53. Inputs={};arglist={'',''};
  54. elseif nargin ==1
  55. Inputs=varargin{1};arglist={'',''};
  56. elseif nargin ==2
  57. Inputs=varargin{1}; arglist=varargin{2};
  58. else error('Usage: [out1,..] = krotate(Inputs,arglist).');
  59. end
  60. if size(arglist,2)~=2
  61. error('arglist must be of form {''ParameterTag1'',value1;''ParameterTag2'',value2}')
  62. end
  63. narglist={'i', '__input';'v', '__input';'center', 0;'icorrel', '__input';'phase', 1;'tangle', '__input';'width', 10;'rangle', '__output';'op', 0;'successive', 0;'aX', 0;'aY', 0;'aZ', 0;'xstretch', 0;'cX', 0;'cY', 0;'cZ', 0;'ystretch', 0;'sX', 1;'sY', 1;'sZ', 1;'zstretch', 0;'o', '__output'};
  64. maxval={0,1,0,1,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
  65. minval={0,1,0,1,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
  66. istoggle=[0,1,1,1,0,1,0,1,1,1,0,0,0,1,1,1,1,1,1,1,1,1,0];
  67. was_set=istoggle * 0;
  68. paramtype={'InputFile','InputFile','Toggle','InputFile','Double','InputFile','Double','OutputFile','Toggle','Toggle','Double','Double','Double','Toggle','Double','Double','Double','Toggle','Double','Double','Double','Toggle','OutputFile'};
  69. % identify the input arrays and assign them to the arguments as stated by the user
  70. if ~iscell(Inputs)
  71. Inputs = {Inputs};
  72. end
  73. NumReqOutputs=1; nextinput=1; nextoutput=1;
  74. for ii=1:size(arglist,1)
  75. wasmatched=0;
  76. for jj=1:size(narglist,1)
  77. if strcmp(arglist{ii,1},narglist{jj,1}) % a given argument was matched to the possible arguments
  78. wasmatched = 1;
  79. was_set(jj) = 1;
  80. if strcmp(narglist{jj,2}, '__input')
  81. if (nextinput > length(Inputs))
  82. error(['Input ' narglist{jj,1} ' has no corresponding input!']);
  83. end
  84. narglist{jj,2} = 'OK_in';
  85. nextinput = nextinput + 1;
  86. elseif strcmp(narglist{jj,2}, '__output')
  87. if (nextoutput > nargout)
  88. error(['Output nr. ' narglist{jj,1} ' is not present in the assignment list of outputs !']);
  89. end
  90. if (isempty(arglist{ii,2}))
  91. narglist{jj,2} = 'OK_out';
  92. else
  93. narglist{jj,2} = arglist{ii,2};
  94. end
  95. nextoutput = nextoutput + 1;
  96. if (minval{jj} == 0)
  97. NumReqOutputs = NumReqOutputs - 1;
  98. end
  99. elseif isstr(arglist{ii,2})
  100. narglist{jj,2} = arglist{ii,2};
  101. else
  102. if strcmp(paramtype{jj}, 'Integer') & (round(arglist{ii,2}) ~= arglist{ii,2})
  103. error(['Argument ' arglist{ii,1} ' is of integer type but non-integer number ' arglist{ii,2} ' was supplied']);
  104. end
  105. if (minval{jj} ~= 0 | maxval{jj} ~= 0)
  106. if (minval{jj} == 1 & maxval{jj} == 1 & arglist{ii,2} < 0)
  107. error(['Argument ' arglist{ii,1} ' must be bigger or equal to zero!']);
  108. elseif (minval{jj} == -1 & maxval{jj} == -1 & arglist{ii,2} > 0)
  109. error(['Argument ' arglist{ii,1} ' must be smaller or equal to zero!']);
  110. elseif (minval{jj} == 2 & maxval{jj} == 2 & arglist{ii,2} <= 0)
  111. error(['Argument ' arglist{ii,1} ' must be bigger than zero!']);
  112. elseif (minval{jj} == -2 & maxval{jj} == -2 & arglist{ii,2} >= 0)
  113. error(['Argument ' arglist{ii,1} ' must be smaller than zero!']);
  114. elseif (minval{jj} ~= maxval{jj} & arglist{ii,2} < minval{jj})
  115. error(['Argument ' arglist{ii,1} ' must be bigger than ' num2str(minval{jj})]);
  116. elseif (minval{jj} ~= maxval{jj} & arglist{ii,2} > maxval{jj})
  117. error(['Argument ' arglist{ii,1} ' must be smaller than ' num2str(maxval{jj})]);
  118. end
  119. end
  120. end
  121. if ~strcmp(narglist{jj,2},'OK_out') & ~strcmp(narglist{jj,2},'OK_in')
  122. narglist{jj,2} = arglist{ii,2};
  123. end
  124. end
  125. end
  126. if (wasmatched == 0 & ~strcmp(arglist{ii,1},''))
  127. error(['Argument ' arglist{ii,1} ' is not a valid argument for this function']);
  128. end
  129. end
  130. % match the remaining inputs/outputs to the unused arguments and test for missing required inputs
  131. for jj=1:size(narglist,1)
  132. if strcmp(paramtype{jj}, 'Toggle')
  133. if (narglist{jj,2} ==0)
  134. narglist{jj,1} = '';
  135. end;
  136. narglist{jj,2} = '';
  137. end;
  138. if ~strcmp(narglist{jj,2},'__input') && ~strcmp(narglist{jj,2},'__output') && istoggle(jj) && ~ was_set(jj)
  139. narglist{jj,1} = '';
  140. narglist{jj,2} = '';
  141. end;
  142. if strcmp(narglist{jj,2}, '__input')
  143. if (minval{jj} == 0) % meaning this input is required
  144. if (nextinput > size(Inputs))
  145. error(['Required input ' narglist{jj,1} ' has no corresponding input in the list!']);
  146. else
  147. narglist{jj,2} = 'OK_in';
  148. nextinput = nextinput + 1;
  149. end
  150. else % this is an optional input
  151. if (nextinput <= length(Inputs))
  152. narglist{jj,2} = 'OK_in';
  153. nextinput = nextinput + 1;
  154. else
  155. narglist{jj,1} = '';
  156. narglist{jj,2} = '';
  157. end;
  158. end;
  159. else
  160. if strcmp(narglist{jj,2}, '__output')
  161. if (minval{jj} == 0) % this is a required output
  162. if (nextoutput > nargout & nargout > 1)
  163. error(['Required output ' narglist{jj,1} ' is not stated in the assignment list!']);
  164. else
  165. narglist{jj,2} = 'OK_out';
  166. nextoutput = nextoutput + 1;
  167. NumReqOutputs = NumReqOutputs-1;
  168. end
  169. else % this is an optional output
  170. if (nargout - nextoutput >= NumReqOutputs)
  171. narglist{jj,2} = 'OK_out';
  172. nextoutput = nextoutput + 1;
  173. else
  174. narglist{jj,1} = '';
  175. narglist{jj,2} = '';
  176. end;
  177. end
  178. end
  179. end
  180. end
  181. if nargout
  182. varargout = cell(1,nargout);
  183. else
  184. varargout = cell(1,1);
  185. end
  186. global KhorosRoot
  187. if exist('KhorosRoot') && ~isempty(KhorosRoot)
  188. w=['"' KhorosRoot];
  189. else
  190. if ispc
  191. w='"C:\Program Files\dip\khorosBin\';
  192. else
  193. [s,w] = system('which cantata');
  194. w=['"' w(1:end-8)];
  195. end
  196. end
  197. [varargout{:}]=callKhoros([w 'rotate" -k'],Inputs,narglist);