PageRenderTime 40ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

/matlab_tools/Converted/kkvsnorm.m

http://github.com/aludnam/MATLAB
Objective C | 224 lines | 221 code | 3 blank | 0 comment | 56 complexity | 7128cd2937c05e4fd2a02f46c1126f14 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. %kkvsnorm 'Compute surface normal vectors in voxel/object space (volume) '
  2. % This MatLab function was automatically generated by a converter (KhorosToMatLab) from the Khoros kvsnorm.pane file
  3. %
  4. % Parameters:
  5. % InputFile: i1 '3D Data', required: 'Input scene (gray or binary scene)'
  6. % InputFile: i2 'Coordinates', required: 'Coordinates at z-buffer distance (surface)'
  7. % OutputFile: o 'Normal Vectors', required: 'Surface normal vectors in voxel/object space'
  8. %
  9. % Example: o = kkvsnorm({i1, i2}, {'i1','';'i2','';'o',''})
  10. %
  11. % Khoros helpfile follows below:
  12. %
  13. % PROGRAM
  14. % kvsnorm - Compute voxel space normals
  15. %
  16. % DESCRIPTION
  17. % The "kvsnorm" operator computes voxel space normal vectors based on the
  18. % object voxel values
  19. % at the neighborhood of given coordinates.
  20. % The coordinate input file is an image w x h x 1 x 1 x 3 containing the
  21. % coordinates x,y and
  22. % z, and can be generated optionally by the routine kzbuff. The scene input file
  23. % is an image ws x hs x ds x ts x 1.
  24. %
  25. % The output is an image w x h x 1 x 1 x 3 of data storage type KFLOAT, where
  26. % w and h are the same as in the coordinate input file. For each pixel in the
  27. % z-buffer, a normal
  28. % vector is computed and its components in x,y,z directions are stored with
  29. % inverted signals, as expected by the operator kshad.
  30. %
  31. % N(u,v) = (Nx, Ny, Nz)
  32. % Nx = [f(x+1,y,z)-f(x-1,y,z)]/2
  33. % Ny = [f(x,y-1,z)-f(x,y+1,z)]/2
  34. % Nz = [f(x,y,z-1)-f(x,y,z+1)]/2
  35. % where
  36. % f is the density in the scene input object and the coordinates x,y and z
  37. % are taken from the coordinate input object at position (u,v).
  38. %
  39. % Negative values in the coordinate file are interpreted as points which are
  40. % out of the object, and null vectors are generated in these cases.
  41. %
  42. %
  43. %
  44. % EXAMPLES
  45. % kvsnorm -i1 scene.viff -i2 coord.viff -o normal.viff
  46. %
  47. % computes the
  48. % normal vectors for each pixel in "coord.viff", according to the neighborhood
  49. % of the voxel addressed by the coordinate in the scene.
  50. %
  51. % "SEE ALSO"
  52. % kzbuff, kisnorm, kvsnorm, ktextu, kvoxext
  53. %
  54. % RESTRICTIONS
  55. % The input objects must have only the value segment.
  56. %
  57. % The input object scene can not have dimention e > 1. The input object
  58. % coordinate must have dimention e=3.
  59. %
  60. % The input object scene can not be of data type KCOMPLEX.
  61. % The input object coordinate can not be of data types KBIT, KFLOAT, KDOUBLE
  62. % and KCOMPLEX.
  63. %
  64. % In case of t > 1 in the input objects, the operator will be applied to the time
  65. % t=0 only.
  66. %
  67. % None of the input and output objects are referenced, therefore some attributes
  68. % may change, as the VALUE_POSITION, for example.
  69. %
  70. % REFERENCES
  71. %
  72. % COPYRIGHT
  73. % Copyright (C) 1993, 1994, 1995 UNICAMP, R A Lotufo, All rights reserved.
  74. %
  75. function varargout = kkvsnorm(varargin)
  76. if nargin ==0
  77. Inputs={};arglist={'',''};
  78. elseif nargin ==1
  79. Inputs=varargin{1};arglist={'',''};
  80. elseif nargin ==2
  81. Inputs=varargin{1}; arglist=varargin{2};
  82. else error('Usage: [out1,..] = kkvsnorm(Inputs,arglist).');
  83. end
  84. if size(arglist,2)~=2
  85. error('arglist must be of form {''ParameterTag1'',value1;''ParameterTag2'',value2}')
  86. end
  87. narglist={'i1', '__input';'i2', '__input';'o', '__output'};
  88. maxval={0,0,0};
  89. minval={0,0,0};
  90. istoggle=[0,0,0];
  91. was_set=istoggle * 0;
  92. paramtype={'InputFile','InputFile','OutputFile'};
  93. % identify the input arrays and assign them to the arguments as stated by the user
  94. if ~iscell(Inputs)
  95. Inputs = {Inputs};
  96. end
  97. NumReqOutputs=1; nextinput=1; nextoutput=1;
  98. for ii=1:size(arglist,1)
  99. wasmatched=0;
  100. for jj=1:size(narglist,1)
  101. if strcmp(arglist{ii,1},narglist{jj,1}) % a given argument was matched to the possible arguments
  102. wasmatched = 1;
  103. was_set(jj) = 1;
  104. if strcmp(narglist{jj,2}, '__input')
  105. if (nextinput > length(Inputs))
  106. error(['Input ' narglist{jj,1} ' has no corresponding input!']);
  107. end
  108. narglist{jj,2} = 'OK_in';
  109. nextinput = nextinput + 1;
  110. elseif strcmp(narglist{jj,2}, '__output')
  111. if (nextoutput > nargout)
  112. error(['Output nr. ' narglist{jj,1} ' is not present in the assignment list of outputs !']);
  113. end
  114. if (isempty(arglist{ii,2}))
  115. narglist{jj,2} = 'OK_out';
  116. else
  117. narglist{jj,2} = arglist{ii,2};
  118. end
  119. nextoutput = nextoutput + 1;
  120. if (minval{jj} == 0)
  121. NumReqOutputs = NumReqOutputs - 1;
  122. end
  123. elseif isstr(arglist{ii,2})
  124. narglist{jj,2} = arglist{ii,2};
  125. else
  126. if strcmp(paramtype{jj}, 'Integer') & (round(arglist{ii,2}) ~= arglist{ii,2})
  127. error(['Argument ' arglist{ii,1} ' is of integer type but non-integer number ' arglist{ii,2} ' was supplied']);
  128. end
  129. if (minval{jj} ~= 0 | maxval{jj} ~= 0)
  130. if (minval{jj} == 1 & maxval{jj} == 1 & arglist{ii,2} < 0)
  131. error(['Argument ' arglist{ii,1} ' must be bigger or equal to zero!']);
  132. elseif (minval{jj} == -1 & maxval{jj} == -1 & arglist{ii,2} > 0)
  133. error(['Argument ' arglist{ii,1} ' must be smaller or equal to zero!']);
  134. elseif (minval{jj} == 2 & maxval{jj} == 2 & arglist{ii,2} <= 0)
  135. error(['Argument ' arglist{ii,1} ' must be bigger than zero!']);
  136. elseif (minval{jj} == -2 & maxval{jj} == -2 & arglist{ii,2} >= 0)
  137. error(['Argument ' arglist{ii,1} ' must be smaller than zero!']);
  138. elseif (minval{jj} ~= maxval{jj} & arglist{ii,2} < minval{jj})
  139. error(['Argument ' arglist{ii,1} ' must be bigger than ' num2str(minval{jj})]);
  140. elseif (minval{jj} ~= maxval{jj} & arglist{ii,2} > maxval{jj})
  141. error(['Argument ' arglist{ii,1} ' must be smaller than ' num2str(maxval{jj})]);
  142. end
  143. end
  144. end
  145. if ~strcmp(narglist{jj,2},'OK_out') & ~strcmp(narglist{jj,2},'OK_in')
  146. narglist{jj,2} = arglist{ii,2};
  147. end
  148. end
  149. end
  150. if (wasmatched == 0 & ~strcmp(arglist{ii,1},''))
  151. error(['Argument ' arglist{ii,1} ' is not a valid argument for this function']);
  152. end
  153. end
  154. % match the remaining inputs/outputs to the unused arguments and test for missing required inputs
  155. for jj=1:size(narglist,1)
  156. if strcmp(paramtype{jj}, 'Toggle')
  157. if (narglist{jj,2} ==0)
  158. narglist{jj,1} = '';
  159. end;
  160. narglist{jj,2} = '';
  161. end;
  162. if ~strcmp(narglist{jj,2},'__input') && ~strcmp(narglist{jj,2},'__output') && istoggle(jj) && ~ was_set(jj)
  163. narglist{jj,1} = '';
  164. narglist{jj,2} = '';
  165. end;
  166. if strcmp(narglist{jj,2}, '__input')
  167. if (minval{jj} == 0) % meaning this input is required
  168. if (nextinput > size(Inputs))
  169. error(['Required input ' narglist{jj,1} ' has no corresponding input in the list!']);
  170. else
  171. narglist{jj,2} = 'OK_in';
  172. nextinput = nextinput + 1;
  173. end
  174. else % this is an optional input
  175. if (nextinput <= length(Inputs))
  176. narglist{jj,2} = 'OK_in';
  177. nextinput = nextinput + 1;
  178. else
  179. narglist{jj,1} = '';
  180. narglist{jj,2} = '';
  181. end;
  182. end;
  183. else
  184. if strcmp(narglist{jj,2}, '__output')
  185. if (minval{jj} == 0) % this is a required output
  186. if (nextoutput > nargout & nargout > 1)
  187. error(['Required output ' narglist{jj,1} ' is not stated in the assignment list!']);
  188. else
  189. narglist{jj,2} = 'OK_out';
  190. nextoutput = nextoutput + 1;
  191. NumReqOutputs = NumReqOutputs-1;
  192. end
  193. else % this is an optional output
  194. if (nargout - nextoutput >= NumReqOutputs)
  195. narglist{jj,2} = 'OK_out';
  196. nextoutput = nextoutput + 1;
  197. else
  198. narglist{jj,1} = '';
  199. narglist{jj,2} = '';
  200. end;
  201. end
  202. end
  203. end
  204. end
  205. if nargout
  206. varargout = cell(1,nargout);
  207. else
  208. varargout = cell(1,1);
  209. end
  210. global KhorosRoot
  211. if exist('KhorosRoot') && ~isempty(KhorosRoot)
  212. w=['"' KhorosRoot];
  213. else
  214. if ispc
  215. w='"C:\Program Files\dip\khorosBin\';
  216. else
  217. [s,w] = system('which cantata');
  218. w=['"' w(1:end-8)];
  219. end
  220. end
  221. [varargout{:}]=callKhoros([w 'kvsnorm" '],Inputs,narglist);