PageRenderTime 42ms CodeModel.GetById 13ms RepoModel.GetById 1ms app.codeStats 0ms

/matlab_tools/Converted/kkinset.m

http://github.com/aludnam/MATLAB
Objective C | 268 lines | 265 code | 3 blank | 0 comment | 63 complexity | 78f2ef7ab69a9255c274fae703ad7d27 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. %kkinset 'Inset Object 2 into Object 1'
  2. % This MatLab function was automatically generated by a converter (KhorosToMatLab) from the Khoros kinset.pane file
  3. %
  4. % Parameters:
  5. % InputFile: i1 'Input 1', required: 'Base input image'
  6. % InputFile: i2 'Input 2', required: 'Second (inset) input image'
  7. % OutputFile: o 'Output', required: 'Resulting output object'
  8. % Toggle: attr 'Use Input 2 Sub-Object Position (unless overridden below)', default: 0: 'Insert at i2 subobject position (attribute) - w,h,d,t,e will override if specified'
  9. % Integer: woff 'Width Coordinate ', default: 0: 'Insert region beginning at this width coordinate'
  10. % Integer: hoff 'Height Coordinate ', default: 0: 'Insert region beginning at this height coordinate'
  11. % Integer: doff 'Depth Coordinate ', default: 0: 'Insert region beginning at this depth coordinate'
  12. % Integer: toff 'Time Coordinate ', default: 0: 'Insert region beginning at this time coordinate'
  13. % Integer: eoff 'Element Coordinate', default: 0: 'Insert region beginning at this element coordinate'
  14. %
  15. % Example: o = kkinset({i1, i2}, {'i1','';'i2','';'o','';'attr',0;'woff',0;'hoff',0;'doff',0;'toff',0;'eoff',0})
  16. %
  17. % Khoros helpfile follows below:
  18. %
  19. % PROGRAM
  20. % kinset - Inset Object 2 into Object 1
  21. %
  22. % DESCRIPTION
  23. % The Inset operator, kinset, insets data from "Input 2" (i2) into
  24. % "Input 1" (i1) at the specified position, replacing the data in
  25. % "Input 1". The resulting \fIOutput\fP object (o) size will be at
  26. % least the size of Input 1, and may be larger, depending on the specified
  27. % position values and the size of Input 2.
  28. %
  29. % If Input 2 has a mask, an "Only Inset VALID Data" (insetvalid)
  30. % parameter can be set to define whether only data from Input 2
  31. % that is marked as valid by the validity mask is inset into Input 1.
  32. % If this parameter is set to FALSE (-insetvalid 0), all value
  33. % data and the mask from Input 2 are inset into Input 1. If the
  34. % parameter is TRUE (-insetvalid 1), for each point in Input 2,
  35. % the mask is checked, and only valid points are inset into
  36. % Input 1. In this case, the mask from Input 2 is not propagated
  37. % to the output.
  38. %
  39. % The inset operation is based on implicit indexing. This means
  40. % that if location or time data exist, the inset
  41. % operation is not done in terms an interpretation of
  42. % the location/time data values, but in terms of the
  43. % implicit indexing of these data (which is specified
  44. % by the Width, Height, Depth, Time, Elements indices
  45. % of the polymorphic data model).
  46. %
  47. % The position in Input 1 where the origin of Input 2 will be placed
  48. % can be determined from the Sub-Object Position attribute
  49. % that is stored in Input 2, or it can be specified explicitly
  50. % by providing Width, Height, Depth, Time and Element Coordinates (w,h,d,t,e).
  51. % The subobject position attribute is automatically set by programs
  52. % such as the Extract operator (kextract).
  53. % It is legal to specify a subset of coordinates, and let the subobject
  54. % position attribute define the rest of the coordinates.
  55. %
  56. % In some instances, padding is necessary to
  57. % maintain the integrity of the polymorphic data model -
  58. % for example when the final size of the Output
  59. % object is larger than that of Input 1. The Real
  60. % and Imaginary Pad Values (real, imag) define the values that
  61. % will be used when padding.
  62. %
  63. % If padding occurs, and the option to "Identify padded data added
  64. % by this program as Valid" is selected (valid TRUE), all padded data
  65. % is considered valid and, if either input object contains a validity mask,
  66. % the output object will have a mask, and the mask value for the padded
  67. % data will be 1. The output object will not contain a mask if
  68. % neither input object has a mask. If padded data is to
  69. % be identified as Invalid (valid FALSE), the padded data will be
  70. % masked as invalid (0). In this case, even if neither input object has
  71. % a validity mask, the output object will have one.
  72. %
  73. % "Map Data" 5
  74. % When either of the input objects has map data, the treatment of the
  75. % maps, and how the data is represented in the output object, depends on
  76. % the mapping option (mapping) specified by the user. Possible mapping
  77. % options are: (0) Map Data Thru Maps and (1) Use First Map Only. If
  78. % neither input object has a map, the mapping option is ignored. If
  79. % there are doubts about which mapping option to use, the safest bet
  80. % is to map the data thru the maps.
  81. %
  82. %
  83. % "Map Data Thru Maps:" 5
  84. % All data will be mapped before the data objects are combined. The
  85. % output object will not have a map.
  86. %
  87. % "Use First Map Only:" 5
  88. % In this case, the map data and color attributes of the
  89. % first input object that has a map are directly transferred
  90. % to the output object. Note that by selecting this
  91. % mapping option, you are assuming that the value segments
  92. % of both objects have valid indices into that map.
  93. %
  94. %
  95. % "Data Type" 5
  96. % .cI $DATAMANIP/repos/shared/man/sections/value_type_2input
  97. %
  98. % "Location & Time Data" 5
  99. % .cI $DATAMANIP/repos/shared/man/sections/loc_and_time_2input
  100. %
  101. % "Failure Modes" 5
  102. % This program will fail if either input object lacks value data.
  103. %
  104. %
  105. %
  106. % EXAMPLES
  107. %
  108. % "SEE ALSO"
  109. % DATAMANIP::kappend
  110. % DATAMANIP::kextract
  111. %
  112. % RESTRICTIONS
  113. %
  114. % REFERENCES
  115. %
  116. % COPYRIGHT
  117. % Copyright (C) 1993 - 1997, Khoral Research, Inc. ("KRI") All rights reserved.
  118. %
  119. function varargout = kkinset(varargin)
  120. if nargin ==0
  121. Inputs={};arglist={'',''};
  122. elseif nargin ==1
  123. Inputs=varargin{1};arglist={'',''};
  124. elseif nargin ==2
  125. Inputs=varargin{1}; arglist=varargin{2};
  126. else error('Usage: [out1,..] = kkinset(Inputs,arglist).');
  127. end
  128. if size(arglist,2)~=2
  129. error('arglist must be of form {''ParameterTag1'',value1;''ParameterTag2'',value2}')
  130. end
  131. narglist={'i1', '__input';'i2', '__input';'o', '__output';'attr', 0;'woff', 0;'hoff', 0;'doff', 0;'toff', 0;'eoff', 0};
  132. maxval={0,0,0,0,0,0,0,0,0};
  133. minval={0,0,0,0,0,0,0,0,0};
  134. istoggle=[0,0,0,1,1,1,1,1,1];
  135. was_set=istoggle * 0;
  136. paramtype={'InputFile','InputFile','OutputFile','Toggle','Integer','Integer','Integer','Integer','Integer'};
  137. % identify the input arrays and assign them to the arguments as stated by the user
  138. if ~iscell(Inputs)
  139. Inputs = {Inputs};
  140. end
  141. NumReqOutputs=1; nextinput=1; nextoutput=1;
  142. for ii=1:size(arglist,1)
  143. wasmatched=0;
  144. for jj=1:size(narglist,1)
  145. if strcmp(arglist{ii,1},narglist{jj,1}) % a given argument was matched to the possible arguments
  146. wasmatched = 1;
  147. was_set(jj) = 1;
  148. if strcmp(narglist{jj,2}, '__input')
  149. if (nextinput > length(Inputs))
  150. error(['Input ' narglist{jj,1} ' has no corresponding input!']);
  151. end
  152. narglist{jj,2} = 'OK_in';
  153. nextinput = nextinput + 1;
  154. elseif strcmp(narglist{jj,2}, '__output')
  155. if (nextoutput > nargout)
  156. error(['Output nr. ' narglist{jj,1} ' is not present in the assignment list of outputs !']);
  157. end
  158. if (isempty(arglist{ii,2}))
  159. narglist{jj,2} = 'OK_out';
  160. else
  161. narglist{jj,2} = arglist{ii,2};
  162. end
  163. nextoutput = nextoutput + 1;
  164. if (minval{jj} == 0)
  165. NumReqOutputs = NumReqOutputs - 1;
  166. end
  167. elseif isstr(arglist{ii,2})
  168. narglist{jj,2} = arglist{ii,2};
  169. else
  170. if strcmp(paramtype{jj}, 'Integer') & (round(arglist{ii,2}) ~= arglist{ii,2})
  171. error(['Argument ' arglist{ii,1} ' is of integer type but non-integer number ' arglist{ii,2} ' was supplied']);
  172. end
  173. if (minval{jj} ~= 0 | maxval{jj} ~= 0)
  174. if (minval{jj} == 1 & maxval{jj} == 1 & arglist{ii,2} < 0)
  175. error(['Argument ' arglist{ii,1} ' must be bigger or equal to zero!']);
  176. elseif (minval{jj} == -1 & maxval{jj} == -1 & arglist{ii,2} > 0)
  177. error(['Argument ' arglist{ii,1} ' must be smaller or equal to zero!']);
  178. elseif (minval{jj} == 2 & maxval{jj} == 2 & arglist{ii,2} <= 0)
  179. error(['Argument ' arglist{ii,1} ' must be bigger than zero!']);
  180. elseif (minval{jj} == -2 & maxval{jj} == -2 & arglist{ii,2} >= 0)
  181. error(['Argument ' arglist{ii,1} ' must be smaller than zero!']);
  182. elseif (minval{jj} ~= maxval{jj} & arglist{ii,2} < minval{jj})
  183. error(['Argument ' arglist{ii,1} ' must be bigger than ' num2str(minval{jj})]);
  184. elseif (minval{jj} ~= maxval{jj} & arglist{ii,2} > maxval{jj})
  185. error(['Argument ' arglist{ii,1} ' must be smaller than ' num2str(maxval{jj})]);
  186. end
  187. end
  188. end
  189. if ~strcmp(narglist{jj,2},'OK_out') & ~strcmp(narglist{jj,2},'OK_in')
  190. narglist{jj,2} = arglist{ii,2};
  191. end
  192. end
  193. end
  194. if (wasmatched == 0 & ~strcmp(arglist{ii,1},''))
  195. error(['Argument ' arglist{ii,1} ' is not a valid argument for this function']);
  196. end
  197. end
  198. % match the remaining inputs/outputs to the unused arguments and test for missing required inputs
  199. for jj=1:size(narglist,1)
  200. if strcmp(paramtype{jj}, 'Toggle')
  201. if (narglist{jj,2} ==0)
  202. narglist{jj,1} = '';
  203. end;
  204. narglist{jj,2} = '';
  205. end;
  206. if ~strcmp(narglist{jj,2},'__input') && ~strcmp(narglist{jj,2},'__output') && istoggle(jj) && ~ was_set(jj)
  207. narglist{jj,1} = '';
  208. narglist{jj,2} = '';
  209. end;
  210. if strcmp(narglist{jj,2}, '__input')
  211. if (minval{jj} == 0) % meaning this input is required
  212. if (nextinput > size(Inputs))
  213. error(['Required input ' narglist{jj,1} ' has no corresponding input in the list!']);
  214. else
  215. narglist{jj,2} = 'OK_in';
  216. nextinput = nextinput + 1;
  217. end
  218. else % this is an optional input
  219. if (nextinput <= length(Inputs))
  220. narglist{jj,2} = 'OK_in';
  221. nextinput = nextinput + 1;
  222. else
  223. narglist{jj,1} = '';
  224. narglist{jj,2} = '';
  225. end;
  226. end;
  227. else
  228. if strcmp(narglist{jj,2}, '__output')
  229. if (minval{jj} == 0) % this is a required output
  230. if (nextoutput > nargout & nargout > 1)
  231. error(['Required output ' narglist{jj,1} ' is not stated in the assignment list!']);
  232. else
  233. narglist{jj,2} = 'OK_out';
  234. nextoutput = nextoutput + 1;
  235. NumReqOutputs = NumReqOutputs-1;
  236. end
  237. else % this is an optional output
  238. if (nargout - nextoutput >= NumReqOutputs)
  239. narglist{jj,2} = 'OK_out';
  240. nextoutput = nextoutput + 1;
  241. else
  242. narglist{jj,1} = '';
  243. narglist{jj,2} = '';
  244. end;
  245. end
  246. end
  247. end
  248. end
  249. if nargout
  250. varargout = cell(1,nargout);
  251. else
  252. varargout = cell(1,1);
  253. end
  254. global KhorosRoot
  255. if exist('KhorosRoot') && ~isempty(KhorosRoot)
  256. w=['"' KhorosRoot];
  257. else
  258. if ispc
  259. w='"C:\Program Files\dip\khorosBin\';
  260. else
  261. [s,w] = system('which cantata');
  262. w=['"' w(1:end-8)];
  263. end
  264. end
  265. [varargout{:}]=callKhoros([w 'kinset" '],Inputs,narglist);