PageRenderTime 48ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/matlab_tools/Converted/kktextu.m

http://github.com/aludnam/MATLAB
Objective C | 297 lines | 294 code | 3 blank | 0 comment | 62 complexity | 4b67a45a51f3d7ebec5a98ec0c93a808 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. %kktextu 'Compute "texture" extracted from the surface surroundings '
  2. % This MatLab function was automatically generated by a converter (KhorosToMatLab) from the Khoros ktextu.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 '"Texture"', required: '"Texture" information which can be incorporated on shading'
  8. % Double: step 'increment step', default: 1: 'Increment step during "texture" computation'
  9. % Toggle: ave_type 'average value', default: 0: 'Meaning of "texture" is the average of voxel values'
  10. % Toggle: wei_type 'weighted average value', default: 0: 'Meaning of "texture" is the weighted average of voxel values'
  11. % Toggle: max_type 'maximum value', default: 0: 'Meaning of "texture" is the maximum voxel value'
  12. % Toggle: min_type 'minimum value', default: 0: 'Meaning of "texture" is the minimum voxel value'
  13. % Toggle: thi_type 'thickness (specify threshold)', default: 0: 'Meaning of "texture" is the length traced while below threshold'
  14. % Toggle: norm_dir 'normal direction', default: 0: 'Follows the normal direction to extract "texture" information'
  15. % InputFile: i3 'Normal Vectors', optional: 'Surface normal vectors'
  16. % Toggle: view_dir 'view direction', default: 0: 'follows the viewer (projection) direction to extract "texture" information'
  17. % Double: alpha 'alpha', default: 0: 'View plane rotation angle around Z axis'
  18. % Double: beta 'beta ', default: 0: 'View plane rotation angle around X axis'
  19. % Double: out_range 'outside surface', default: 0: 'Length of the region outside the surface where to compute "texture"'
  20. % Double: in_range 'inside surface ', default: 10: 'Length of the region inside the surface where to compute "texture"'
  21. % Double: thres_range 'threshold >=', default: 0: 'Threshold value which determines the region inside the surface where to compute "texture"'
  22. %
  23. % Example: o = kktextu({i1, i2, i3}, {'i1','';'i2','';'o','';'step',1;'ave_type',0;'wei_type',0;'max_type',0;'min_type',0;'thi_type',0;'norm_dir',0;'i3','';'view_dir',0;'alpha',0;'beta',0;'out_range',0;'in_range',10;'thres_range',0})
  24. %
  25. % Khoros helpfile follows below:
  26. %
  27. % PROGRAM
  28. % ktextu - Compute texture information for each point lying on the visible surface
  29. %
  30. % DESCRIPTION
  31. %
  32. % creates an image file based on volumetric information of a 3D object. This
  33. % information can be of several types and is called here TEXTURE. It can can be
  34. % obtained specifying the walk direction, the range of walking around the object
  35. % surface and the type of texture. The output image is of type KFLOAT.
  36. %
  37. % This operator requires as inputs the volume (3D object) file, and the
  38. % coordinate file, which is an object w x h x 1 x 1 x 3
  39. % that can be generated optionally by the operator kzbuff, containing the
  40. % coordinates X, Y and Z of each point of the object surface.
  41. %
  42. % The "ktextu" simulates that, for each point of the object's surface,
  43. % there is a
  44. % ray going inside the object in the specified direction. Then it walks (visits
  45. % voxels) in that ray in the given range and gets the information according
  46. % to the texture type.
  47. %
  48. % There are two options for the direction of "texture" extraction: Normal
  49. % direction, which
  50. % corresponds to the directions of the normal vectors to the object's surface,
  51. % and View direction, which corresponds to the view direction of the z-buffer.
  52. % The first option requires the input file of normal vectors, which is an
  53. % object w x h x 1 x 1 x 3 that can be generated optionally by the operators
  54. % kvsnorm or kisnorm,
  55. % containing the X, Y and Z components of the vectors, stored with inverted
  56. % signals (vectors pointing to inside the object). The second option requires
  57. % the angles alpha and beta, used to obtain the z-buffer.
  58. %
  59. % There are two options for the range of "texture" extraction: along a region
  60. % around the
  61. % surface, specified as how many steps to walk backwards (outside the object)
  62. % and forwards (inside the object); and
  63. % along the thickness, which is determined by the specified threshold. The
  64. % later option requires the direction of "texture" extraction to be the normal
  65. % direction.
  66. %
  67. % The increment step can be specified and represents the sampling step while
  68. % extracting the "texture". An increment step equal to 1 visits the voxels one
  69. % by one.
  70. %
  71. % There are five types of texture: 1) the voxels' average value, 2) the voxels'
  72. % weighted average value, 3) the voxels' maximal value, 4) the voxels' minimal
  73. % value and 5) the thickness.
  74. %
  75. % The first option calculates the average value of all the visited voxels. The
  76. % second option is still not implemented. The third option calculates the
  77. % maximal voxel value of all the visited voxels. The forth option calculates
  78. % the minimal voxel value of all the visited voxels. Finally, the last option
  79. % estimate the thickness of the surface based on the length of the ray within
  80. % the object. This last option requires the direction of extraction to be the
  81. % normal direction and the range of extraction to be given by the threshold.
  82. %
  83. % The images generated by "ktextu" are useful for analysis by themselves,
  84. % or can be used as input to the operator
  85. % kshad, to compose a shaded image based not only on the object surface form,
  86. % but also on its volumetric structure information.
  87. %
  88. %
  89. %
  90. % EXAMPLES
  91. % ktextu -i1 volume.viff -i2 coord.viff -o texture.viff -step 1.0 -norm_dir
  92. % -i3 normal.viff -out_range 10.0 -in_range 10.0 -max_type
  93. %
  94. % This example will create a texture file texture.viff from the volume file
  95. % volume.viff and the coordinate file coord.viff by walking 10 steps
  96. % backwards (outside the object) and 10 steps forwards (inside the object)
  97. % around the surface, in the normal direction
  98. % (which is defined by the normal vector file normal.viff), with a sampling
  99. % step
  100. % equal to 1. The specified texture type is the voxels' maximal value.
  101. %
  102. % ktextu -i1 volume.viff -i2 coord.viff -o texture.viff -step 2.0 -view_dir
  103. % -alpha 90.0 -beta 15.0 -out_range 10.0 -in_range 10.0 -ave_type
  104. %
  105. % This example will create a texture file texture.viff from the volume file
  106. % volume.viff and the coodinate file coord.viff by walking 10 steps
  107. % backwards and 10 steps forwards around the surface, in the view direction
  108. % (which is a plane rotated 90 degrees in alpha and 15 degrees in beta), with a
  109. % sampling step equal to 2. The specified texture type is the voxels' average
  110. % value.
  111. %
  112. % ktextu -i1 volume.viff -i2 coord.viff -o texture.viff -step 1.0 -norm_dir
  113. % -i3 normal.viff -thres 70 -thi_type
  114. %
  115. % This example will create a texture file texture.viff from the volume file
  116. % volume.viff and the coodinate file coord.viff by walking
  117. % in the normal direction (which is defined by the normal vector
  118. % file normal.viff), with a sampling step equal to 1. The specified texture type is the thickness, while the threshold is less than 70.
  119. %
  120. % "SEE ALSO"
  121. % kzbuff, kshad, kisnorm, kvsnorm, kvoxext
  122. %
  123. % RESTRICTIONS
  124. % The input objects must have only the value segment.
  125. %
  126. % The
  127. % input object scene can not have dimention e > 1. The input objects coord and
  128. % norm must have dimention e=3.
  129. %
  130. % The input object scene can not be of data types KCOMPLEX and KDCOMPLEX. The
  131. % input object coord can not be of data types KBIT, KFLOAT, KDOUBLE, KCOMPLEX
  132. % and KDCOMPLEX. The input object scene can not be of data types KBIT, KCOMPLEX
  133. % and KDCOMPLEX.
  134. %
  135. % The input objects coord and norm must match in their dimentions w and h.
  136. %
  137. % In case of t > 1 in the input objects, the operator will be applied to the time
  138. % t=0 only.
  139. %
  140. % None of the input and output objects are referenced, therefore some attributes
  141. % may change, as the VALUE_POSITION, for example.
  142. %
  143. % REFERENCES
  144. %
  145. % COPYRIGHT
  146. % Copyright (C) 1993, 1994, 1995 UNICAMP, R A Lotufo, All rights reserved.
  147. %
  148. function varargout = kktextu(varargin)
  149. if nargin ==0
  150. Inputs={};arglist={'',''};
  151. elseif nargin ==1
  152. Inputs=varargin{1};arglist={'',''};
  153. elseif nargin ==2
  154. Inputs=varargin{1}; arglist=varargin{2};
  155. else error('Usage: [out1,..] = kktextu(Inputs,arglist).');
  156. end
  157. if size(arglist,2)~=2
  158. error('arglist must be of form {''ParameterTag1'',value1;''ParameterTag2'',value2}')
  159. end
  160. narglist={'i1', '__input';'i2', '__input';'o', '__output';'step', 1;'ave_type', 0;'wei_type', 0;'max_type', 0;'min_type', 0;'thi_type', 0;'norm_dir', 0;'i3', '__input';'view_dir', 0;'alpha', 0;'beta', 0;'out_range', 0;'in_range', 10;'thres_range', 0};
  161. maxval={0,0,0,2,0,0,0,0,0,0,1,0,0,0,1,1,0};
  162. minval={0,0,0,2,0,0,0,0,0,0,1,0,0,0,1,1,0};
  163. istoggle=[0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1];
  164. was_set=istoggle * 0;
  165. paramtype={'InputFile','InputFile','OutputFile','Double','Toggle','Toggle','Toggle','Toggle','Toggle','Toggle','InputFile','Toggle','Double','Double','Double','Double','Double'};
  166. % identify the input arrays and assign them to the arguments as stated by the user
  167. if ~iscell(Inputs)
  168. Inputs = {Inputs};
  169. end
  170. NumReqOutputs=1; nextinput=1; nextoutput=1;
  171. for ii=1:size(arglist,1)
  172. wasmatched=0;
  173. for jj=1:size(narglist,1)
  174. if strcmp(arglist{ii,1},narglist{jj,1}) % a given argument was matched to the possible arguments
  175. wasmatched = 1;
  176. was_set(jj) = 1;
  177. if strcmp(narglist{jj,2}, '__input')
  178. if (nextinput > length(Inputs))
  179. error(['Input ' narglist{jj,1} ' has no corresponding input!']);
  180. end
  181. narglist{jj,2} = 'OK_in';
  182. nextinput = nextinput + 1;
  183. elseif strcmp(narglist{jj,2}, '__output')
  184. if (nextoutput > nargout)
  185. error(['Output nr. ' narglist{jj,1} ' is not present in the assignment list of outputs !']);
  186. end
  187. if (isempty(arglist{ii,2}))
  188. narglist{jj,2} = 'OK_out';
  189. else
  190. narglist{jj,2} = arglist{ii,2};
  191. end
  192. nextoutput = nextoutput + 1;
  193. if (minval{jj} == 0)
  194. NumReqOutputs = NumReqOutputs - 1;
  195. end
  196. elseif isstr(arglist{ii,2})
  197. narglist{jj,2} = arglist{ii,2};
  198. else
  199. if strcmp(paramtype{jj}, 'Integer') & (round(arglist{ii,2}) ~= arglist{ii,2})
  200. error(['Argument ' arglist{ii,1} ' is of integer type but non-integer number ' arglist{ii,2} ' was supplied']);
  201. end
  202. if (minval{jj} ~= 0 | maxval{jj} ~= 0)
  203. if (minval{jj} == 1 & maxval{jj} == 1 & arglist{ii,2} < 0)
  204. error(['Argument ' arglist{ii,1} ' must be bigger or equal to zero!']);
  205. elseif (minval{jj} == -1 & maxval{jj} == -1 & arglist{ii,2} > 0)
  206. error(['Argument ' arglist{ii,1} ' must be smaller or equal to zero!']);
  207. elseif (minval{jj} == 2 & maxval{jj} == 2 & arglist{ii,2} <= 0)
  208. error(['Argument ' arglist{ii,1} ' must be bigger than zero!']);
  209. elseif (minval{jj} == -2 & maxval{jj} == -2 & arglist{ii,2} >= 0)
  210. error(['Argument ' arglist{ii,1} ' must be smaller than zero!']);
  211. elseif (minval{jj} ~= maxval{jj} & arglist{ii,2} < minval{jj})
  212. error(['Argument ' arglist{ii,1} ' must be bigger than ' num2str(minval{jj})]);
  213. elseif (minval{jj} ~= maxval{jj} & arglist{ii,2} > maxval{jj})
  214. error(['Argument ' arglist{ii,1} ' must be smaller than ' num2str(maxval{jj})]);
  215. end
  216. end
  217. end
  218. if ~strcmp(narglist{jj,2},'OK_out') & ~strcmp(narglist{jj,2},'OK_in')
  219. narglist{jj,2} = arglist{ii,2};
  220. end
  221. end
  222. end
  223. if (wasmatched == 0 & ~strcmp(arglist{ii,1},''))
  224. error(['Argument ' arglist{ii,1} ' is not a valid argument for this function']);
  225. end
  226. end
  227. % match the remaining inputs/outputs to the unused arguments and test for missing required inputs
  228. for jj=1:size(narglist,1)
  229. if strcmp(paramtype{jj}, 'Toggle')
  230. if (narglist{jj,2} ==0)
  231. narglist{jj,1} = '';
  232. end;
  233. narglist{jj,2} = '';
  234. end;
  235. if ~strcmp(narglist{jj,2},'__input') && ~strcmp(narglist{jj,2},'__output') && istoggle(jj) && ~ was_set(jj)
  236. narglist{jj,1} = '';
  237. narglist{jj,2} = '';
  238. end;
  239. if strcmp(narglist{jj,2}, '__input')
  240. if (minval{jj} == 0) % meaning this input is required
  241. if (nextinput > size(Inputs))
  242. error(['Required input ' narglist{jj,1} ' has no corresponding input in the list!']);
  243. else
  244. narglist{jj,2} = 'OK_in';
  245. nextinput = nextinput + 1;
  246. end
  247. else % this is an optional input
  248. if (nextinput <= length(Inputs))
  249. narglist{jj,2} = 'OK_in';
  250. nextinput = nextinput + 1;
  251. else
  252. narglist{jj,1} = '';
  253. narglist{jj,2} = '';
  254. end;
  255. end;
  256. else
  257. if strcmp(narglist{jj,2}, '__output')
  258. if (minval{jj} == 0) % this is a required output
  259. if (nextoutput > nargout & nargout > 1)
  260. error(['Required output ' narglist{jj,1} ' is not stated in the assignment list!']);
  261. else
  262. narglist{jj,2} = 'OK_out';
  263. nextoutput = nextoutput + 1;
  264. NumReqOutputs = NumReqOutputs-1;
  265. end
  266. else % this is an optional output
  267. if (nargout - nextoutput >= NumReqOutputs)
  268. narglist{jj,2} = 'OK_out';
  269. nextoutput = nextoutput + 1;
  270. else
  271. narglist{jj,1} = '';
  272. narglist{jj,2} = '';
  273. end;
  274. end
  275. end
  276. end
  277. end
  278. if nargout
  279. varargout = cell(1,nargout);
  280. else
  281. varargout = cell(1,1);
  282. end
  283. global KhorosRoot
  284. if exist('KhorosRoot') && ~isempty(KhorosRoot)
  285. w=['"' KhorosRoot];
  286. else
  287. if ispc
  288. w='"C:\Program Files\dip\khorosBin\';
  289. else
  290. [s,w] = system('which cantata');
  291. w=['"' w(1:end-8)];
  292. end
  293. end
  294. [varargout{:}]=callKhoros([w 'ktextu" '],Inputs,narglist);