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

/matlab_tools/Converted/krender.m

http://github.com/aludnam/MATLAB
Objective C | 570 lines | 570 code | 0 blank | 0 comment | 16 complexity | 5ddd4dbf96a9df7ba7c6feb41637c3e8 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. %krender 'Interactive Geometry Visualization'
  2. % This MatLab function was automatically generated by a converter (KhorosToMatLab) from the Khoros render.pane file
  3. %
  4. % Parameters:
  5. % InputFile: i1 'Input 1', optional: 'Input file 1'
  6. % InputFile: i2 'Input 2', optional: 'Input file 2'
  7. % InputFile: i3 'Input 3', optional: 'Input file 3'
  8. % InputFile: i4 'Input 4', optional: 'Input file 4'
  9. % InputFile: i5 'Input 5', optional: 'Input file 5'
  10. % InputFile: i6 'Input 6', optional: 'Input file 6'
  11. % InputFile: i7 'Input 7', optional: 'Input file 7'
  12. % InputFile: iscene 'Scene File', optional: 'Specificatio of a so-called scene file.'
  13. % Integer: wsize 'Image Width ', default: 256: 'width of rendered image'
  14. % Integer: hsize 'Image Height', default: 256: 'height of rendered image'
  15. % Double: eye_x 'X', default: 0: 'x component of eye position.'
  16. % Double: up_x 'X', default: 0: 'x component of up vector.'
  17. % Double: at_x 'X', default: 0: 'x component of initial look-at point.'
  18. % Double: eye_y 'Y', default: 10: 'y component of eye position.'
  19. % Double: up_y 'Y', default: 1: 'y component of up vector.'
  20. % Double: at_y 'Y', default: 0: 'y component of initial look-at point.'
  21. % Double: eye_z 'Z', default: 50: 'z component of eye position.'
  22. % Double: up_z 'Z', default: 0: 'z component of up vector.'
  23. % Double: at_z 'Z', default: 0: 'z component of initial look-at point.'
  24. % Double: hither 'Front', default: 0.05: 'Location of front clip plane. (1 is look-at point, 0 is view point)'
  25. % Double: yon 'Back ', default: 2: 'Location of back clip plane. (0 is look-at point, 1 is view point)'
  26. % OutputFile: o 'Output', optional: 'Output rendered image'
  27. % OutputFile: oxfrm 'Output Transformation Matrices', optional: 'Data object which holds view transformation matrix, and transformation matrix for the top level object.'
  28. % OutputFile: oscene 'Output Scene File Name', optional: 'output scene file'
  29. %
  30. % Example: [o, oxfrm, oscene] = krender({i1, i2, i3, i4, i5, i6, i7, iscene}, {'i1','';'i2','';'i3','';'i4','';'i5','';'i6','';'i7','';'iscene','';'wsize',256;'hsize',256;'eye_x',0;'up_x',0;'at_x',0;'eye_y',10;'up_y',1;'at_y',0;'eye_z',50;'up_z',0;'at_z',0;'hither',0.05;'yon',2;'o','';'oxfrm','';'oscene',''})
  31. %
  32. % Khoros helpfile follows below:
  33. %
  34. % PROGRAM
  35. % render - Interactive Geometry Visualization
  36. %
  37. % DESCRIPTION
  38. % Render is the Khoros geometry renderer. Implemented
  39. % as an Xvroutine, it may be included as part of a Cantata workspace or
  40. % run from the command line.
  41. %
  42. % Render accepts input in the form of geometry created by the
  43. % visualization modules in the Geometry Toolbox, and produces
  44. % images, possibly displaying them. A GUI is provided which permits
  45. % interaction between the user and the renderer.
  46. %
  47. % To use Render, first compute some geometry with one of the
  48. % modules which produce geometry (extents_box, isosurface, etc). The
  49. % input parameters to Render should use the name of a transport
  50. % (stream, shared memory, etc.) that contains geometry data.
  51. % When Render comes
  52. % up, it will pop up two windows. One window is the control panel for
  53. % the Render, the second is the image display window (unless
  54. % image display has been supressed). If certain default values are
  55. % used (such as the "autonormalize view" option), your geometry objects
  56. % should be visible when both of the display and menu windows appear on
  57. % your screen.
  58. %
  59. % The default position for the camera is roughly (0,10,50) looking in the
  60. % -Z direction towards the XY plane (unless this position is overridden
  61. % by command-line arguments).
  62. %
  63. % Direct interaction with the rendered image is available with the mouse.
  64. % Pressing different mouse buttons on the image and moving
  65. % the mouse will perform different transformations. When a
  66. % transformation is initiated by pressing on a mouse button, you will
  67. % see a bounding box representing the extents of the geometry. Moving
  68. % the mouse will transform this bounding box. When the desired
  69. % transformation has been performed, releasing the mouse button will
  70. % initiate a rendering at the new transformation.
  71. %
  72. % The middle button controls rotations. Shift+middle button will produce
  73. % an isometric scaling of the object. The right mouse button will translate
  74. % the object parallel to the x-y image plane. Shift+right will move the object
  75. % along the z-axis of the image plane.
  76. %
  77. % On the keyboard, the up and down arrow keys control rotations about
  78. % the X-axis; the left and right arrow keys control rotations about the
  79. % Y-axis; the Page_up and Page_down keys control rotations about the
  80. % Z-axis. There seems to be a bug on non-solaris machines which
  81. % prevents actions from being defined on the arrow keys. If the arrow
  82. % keys do not work for your display, the (x-X,y-Y,z-Z) keys may be used
  83. % as alternatives.
  84. %
  85. %
  86. % \fBRotations"
  87. % Pressing the middle mouse button on the rendered image and moving the
  88. % mouse will allow you to rotate the geometry. When you press down on
  89. % the middle mouse button, you will see a circle drawn on the image.
  90. % Moving the mouse up and down within this circle will perform an X
  91. % rotation. Moving the mouse left and right within this circle will
  92. % perform a Y rotation. Moving the mouse around the outside of the
  93. % circle will perform a Z rotation.
  94. %
  95. % \fBScaling"
  96. % Pressing the middle mouse button while holding down the shift key on
  97. % the rendered image and moving the mouse will allow you to scale the
  98. % geometry. Moving the mouse to the left will scale downward and moving
  99. % the mouse up and to the left will scale upward.
  100. %
  101. % \fBTranslation"
  102. % Pressing the right mouse button the rendered image and moving the
  103. % mouse will allow you to translate the geometry in the X and Y
  104. % directions. Translations in the Z direction is accomplished by
  105. % pressing the right mouse button and the shift key.
  106. %
  107. %
  108. % \fBRender Control Panes"
  109. %
  110. % A number of different control panes are present on the interface for
  111. % Render. These are described below.
  112. %
  113. %
  114. % "\fBObjects Pane""
  115. % The Objects pane provides for control over different
  116. % object-level properties; selecting an object from the pulldown gives
  117. % you control over that particular object. Selecting the root object
  118. % implies that property changes apply globally to all objects.
  119. % Different object shaders are selected from the pull-down menu here.
  120. % Note that selecting objects here also indicates which object you wish
  121. % to transform. You can directly control object transformations, either
  122. % from the Transformations Pane or directly from the image.
  123. %
  124. % The "reset object transformation matrix" will change the matrix of
  125. % the currently selected object to the identity matrix.
  126. %
  127. %
  128. % "\fBCameras Pane""
  129. % The Cameras pane provides control over the camera parameters,
  130. % such as the eye point, the look-at point, the up vector, the frustrum
  131. % of vision (which defines the angle frustrum in degrees), as well
  132. % as the front and back clipping planes.
  133. %
  134. % The viewer's position is located at (Eye_X, Eye_Y, Eye_Z) in world
  135. % space coordinate, looking at the point (At_X, At_Y, At_Z), also in
  136. % world space coordinates. The vector specified by (Up_X,Up_Y,Up_Z)
  137. % is a reference vector indicating which was is "up" from the viewer's
  138. % point of view. The field-of-view parameter defines the window
  139. % size through which the viewer is looking. The entire contents of
  140. % this window is mapped to the display image. The aspect ratio is
  141. % always 1:1, although this will be changed in future releases. Thus,
  142. % when mapping a square window (defined by the 1:1 aspect ratio) into
  143. % a non-square display window, the objects may appear squished or stretched,
  144. % depending upon the degree of "non-squaredness" of the display window.
  145. %
  146. % The clipping planes are specified as follows: A floating point value
  147. % between 0 and 1.0 for the front clip plane indicates a point along the
  148. % vector between the eyepoint and the look-at point at which the front
  149. % clip plane will be positioned. A value of 1.0 puts the front clip plane
  150. % at the look-at point. A value of 0.5 puts the front clip plane halfway
  151. % between the viewer and the look-at point. A value of 0.0 (although this
  152. % is not allowed) would put the front clip plane at the view point. Front
  153. % plane clipping is always enabled.
  154. %
  155. % A similar scheme is used for the back clip plane, although the directions
  156. % are reversed. A value of 0.0 puts the back clip plane at the look-at point.
  157. % A value of 1.0 puts the back clip plane "one unit" away from the look-at
  158. % point, where "one unit" is defined as the distance between the viewer and
  159. % the look-at point. Increasing the value for the back clip plane moves it
  160. % further and further away from the look-at point along the view/look-at
  161. % vector. There is no upper bound on this value. Back plane clipping may
  162. % be turned on or off using the toggle on the cameras menu.
  163. %
  164. % The "startup defaults" button will reset the view parameters to those
  165. % used at startup time (either from the command line, if specified, or
  166. % from values internal to the code used if no command line arguments
  167. % are present.
  168. %
  169. % The "normalize view" button will attempt to set the view parameters
  170. % to those in which the displayed object appears centered in the display
  171. % and sized such that they fill "Most" of the display. This operation
  172. % works pretty well most of the time, although there are conditions in
  173. % which it fails.
  174. %
  175. %
  176. % "\fBLights Pane""
  177. % The Lights pane provides control to the array of lights which are
  178. % provided for use in illuminating the scene. Within the light array,
  179. % the user is free to set the light type be directional, bidirectional
  180. % or point-light. There is one global ambient light which is separate
  181. % from this array of lights. The initial configuration of the 3-element
  182. % light array is 3 directional light sources, only one of which is
  183. % turned on.
  184. %
  185. % BUG: only Light1 works reliably. Multiple light sources are not
  186. % fully functional yet (April 1995).
  187. %
  188. %
  189. % "\fBImaging Pane""
  190. % The Imaging pane contains controls for changing the image size,
  191. % the image display, and the background color, and the way in which the
  192. % computed image is presented to the user.
  193. %
  194. % The background color sliders are used to set the RGB value of the
  195. % image background.
  196. %
  197. % The image display mode parameter will allow you to choose how the
  198. % image will be displayed to you. The choices available are: "3-3-2
  199. % truecolor" (an 8-bit display mode that is fast but doesn't look that
  200. % great); "24bit truecolor" (best visually, but only works on 24bit
  201. % displays); color quantized (an 8-bit display mode that works pretty
  202. % well, but is kind of slow) and a "dithered" mode (also an 8-bit
  203. % display mode that works pretty well and is a bit faster than color
  204. % quantizing).
  205. %
  206. % On SGI machines, an additional "24-Bit RGB OpenGL" mode is available
  207. % for hardware assisted rendering. This mode will utilize the SGI
  208. % graphics hardware to allow rendering at interactive speeds. In this
  209. % mode, the Renderer Invocation can be turned to "Immediate". In
  210. % Immediate mode rendering, interactive transformations will apply
  211. % immediately to the rendered view, rather than being deferred until the
  212. % mouse button is released.
  213. %
  214. % The controls for texture mapping are also here. Texture maps can
  215. % either be Point-Sampled or Bilinear as they are rendered. Bilinear
  216. % produces a "better" image than Point-Sampled, at the cost of slower
  217. % rendering time. The texture mapping can also be disabled if not
  218. % needed. (Khoros 2.1 - only point-sampled texture mapping is supported.)
  219. %
  220. % The image width and height sliders will allow you specify a new width
  221. % and/or height for the image. You can use these sliders, or you can just
  222. % resize the display window with the mouse via your window manager.
  223. %
  224. % Whenever you resize the image or select a new display mode, you'll have
  225. % to press the "render" button to get the objects rerendered and displayed
  226. % to you.
  227. %
  228. %
  229. % "\fBTransformations Pane""
  230. % The primary purpose of the transformations pane is to provide some
  231. % degree of control over how relative transformations are performed, as
  232. % well as give some informational data about the objects, etc. being
  233. % viewed. The user can set the amount of relative rotation along either
  234. % of the X-Axis, Y-Axis or Z-axis. Effecting relative rotation is done
  235. % by using the following keys on the keyboard (with the cursor positioned
  236. % within the image display window): up and down buttons (X-axis relative
  237. % rotation); left and right buttons (Y-axis relative rotation); page-up
  238. % and page-down buttons (Z-axis relative rotation).
  239. %
  240. %
  241. % The balance of the items on the transformations pane are either not
  242. % currently implemented (isometric scaling) or are informational only
  243. % (object center point, translate vector).
  244. %
  245. %
  246. % Future plans include interactive transformation of lights and viewer
  247. % position, but for now (April, 1995) only objects may be moved around
  248. % interactively.
  249. %
  250. % "\fBInput Pane""
  251. % The Input pane contains four input lines. these can be used to specify
  252. % files containing geometry data to be rendered. If input files were
  253. % specified on startup, the files specified here will replace them.
  254. %
  255. % "\fBOutput Pane""
  256. % The Output pane contains a selection for saving the currently displayed
  257. % image. This feature is currently unimplemented.
  258. %
  259. %
  260. % \fBShaders Available"
  261. %
  262. % A number of different shaders are supported in the Render. Typical
  263. % surface shaders are no-light (where the color of the surface doesn't
  264. % depend upon interactions with the lights in the scene), flat (where
  265. % the polygons are assumed to be of a constant shade), gouroud (where
  266. % colors are interpolated between vertices across the face of the
  267. % polygon) and phong (where the surface normal is interpolated across
  268. % the face of the polygon). At present, only no-light, flat and gouroud
  269. % shaders are supported.
  270. %
  271. % For volume rendering, three shader types are supported; these are
  272. % "voxel-dot" (where a single point, possibly transparent, is produced
  273. % for each voxel), "splat homogeneous" (where the 2d voxel footprint is
  274. % approximated with a rectangle of constant shade and opacity) and
  275. % "splat homogeneous gauss" (where the 2d voxel footprint is
  276. % approximated with a rectangle of constant shade, but the opacity in
  277. % the rectangle is approximated with a 2D gaussian function.
  278. %
  279. % One note about triangle shading : Most shading models assume
  280. % per-vertex normals, and all shading calculations are performed at each
  281. % vertex, with the triangle's shade interpolated across the face of the
  282. % triangle. Geometry Services, in contrast, provides a wide range of
  283. % combinations of per-vertex/per-facet data; color and normals may be
  284. % specified either per-vertex or per-facet. By necessity, some of the
  285. % potential speed increases are lost when per-face normals or colors are
  286. % used as these specifications imply that shared vertices must have
  287. % shading calculations performed on a per-facet basis. The portions of
  288. % the rendering which is shared, regardless of the per-facet or
  289. % per-vertex specification, is the geometric transformation (this
  290. % calculation is less expensive than the cost of shading a vertex).
  291. %
  292. %
  293. % \fBSupported Geometry"
  294. %
  295. % There are a number of primitives which can be rendered directly by the
  296. % Render.
  297. %
  298. %
  299. % "Disjoint Triangles"
  300. % Disjoint triangles, where every triangle is represented by three
  301. % vertices, can be rendered by Render. Triangles with no colors,
  302. % per-vertex colors, and per-face colors are supported. If no colors
  303. % are provided, the global object color is used. If no normals are
  304. % provided, then normals are generated on input. Texture mapping is
  305. % not yet implemented for disjoint triangles.
  306. %
  307. %
  308. % "Connected Triangles"
  309. % Connected triangles, also known as triangle strips or triangle meshes,
  310. % have the benefit of reducing vertex redundancy, achieving up to a
  311. % threefold reduction in space over disjoint triangles by employing
  312. % vertices which are shared between adjacent triangles. Up to a
  313. % threefold performance increase may be realized due to the fact that
  314. % three times fewer per-vertex operations are performed.
  315. %
  316. % Triangle strips may be rendered with 1. per-vertex colors and
  317. % normals; 2. per-vertex colors and NO normals (they will be computed
  318. % per-face on object read-in); 3. per-face colors and NO normals (they
  319. % will be computed per-face on object read-in); 4. per-face colors and
  320. % per-face normals or 5. no colors or normals.
  321. %
  322. % Texture mapping onto triangle strips is not yet supported.
  323. %
  324. %
  325. % Spheres
  326. % Spheres, where each sphere is represented by a vertex are supported.
  327. % The spheres are actually tesselated into triangles for rendering. If
  328. % the provided spheres data has no colors or radii, the global object
  329. % color and a default radius will be used.
  330. %
  331. %
  332. % "Disjoint and Connected Lines"
  333. % Both disjoint and connected lines are understood by Render.
  334. %
  335. %
  336. % "Text"
  337. % Text primitives are supported by Render.
  338. %
  339. %
  340. % Quadmeshes
  341. % Quadmeshes are supported. Currently, provided colors must be
  342. % per-vertex and consist of RGBA vectors. If no normals are provided,
  343. % then normals are generated on input.
  344. %
  345. %
  346. % Octmeshes
  347. % Octmeshes are supported. Currently, provided colors must be
  348. % per-vertex and consist of RGBA vectors. Octmeshes can be rendered
  349. % as 3D textures on machines which have the GL_3DTEXTURE_EXT
  350. % extension to OpenGL (SGI's). Otherwise, your choices are more
  351. % limited, and they tend to run rather slowly.
  352. %
  353. %
  354. %
  355. % Two-dimensional and three-dimensional text.
  356. %
  357. %
  358. % 2d Textures
  359. % Texture mapping of two-dimensional images onto three-dimensional surfaces.
  360. % In OpenGL, there is a requirement that all textures be an even
  361. % power of two in size. Render will resize your textures to be an
  362. % even power of two if they're not; the computed size will be the largest
  363. % number which is an even power of two but that is smaller than the
  364. % texture map size; width and height are separately computed. For more
  365. % control, use the kroutine "gresample" to resample Khoros data objects
  366. % to a particular size. Use the kroutine "gcreate2dtex" to create a
  367. % texture map from a Khoros data object, then use "gbindtexture" to actually
  368. % bind the texture to the geometry. You need not directly connect any
  369. % textures to Render as input - the transport name for them is buried
  370. % inside of the geometry object output by gbindtexture. If you do provide
  371. % a texture as input, nothing happens. It actually has to be "bound"
  372. % to a geometry object.
  373. %
  374. %
  375. %
  376. % VR device events. These include control of the camera position and
  377. % orientation as well as position and orientation of objects within the
  378. % world.
  379. %
  380. %
  381. % \fBSTAY TUNED"
  382. %
  383. % Directed points and three dimensional textures didn't make it into the
  384. % the Khoros 2.1 release. Sorry.
  385. %
  386. %
  387. % \fBKNOWN BUGS"
  388. %
  389. % The following list (probably incomplete) enumerates the known bugs in
  390. % the Render.
  391. %
  392. %
  393. % 1. When the color quantize display mode is selected, the initial
  394. % image displayed is not the same as the background color. This may be
  395. % ignored. The next time an image is put to this window, the correct colors
  396. % are displayed.
  397. %
  398. % 2. Polygon clipping is not fully implemented. Those polygons that are
  399. % "too close" to the viewer are rejected, but those off-screen to the
  400. % left or right still get scan converted. The result is that the
  401. % runtime of Render is excessive in some conditions.
  402. %
  403. %
  404. % 3. Software Rendering of Spheres. Is wrong.
  405. %
  406. %
  407. %
  408. % EXAMPLES
  409. % render -i geometry:ytter_iso2
  410. %
  411. % "SEE ALSO"
  412. % geometry
  413. %
  414. % RESTRICTIONS
  415. %
  416. % REFERENCES
  417. %
  418. % COPYRIGHT
  419. % Copyright (C) 1996,1997 , The Regents of the University of California. All rights reserved.
  420. %
  421. function varargout = krender(varargin)
  422. if nargin ==0
  423. Inputs={};arglist={'',''};
  424. elseif nargin ==1
  425. Inputs=varargin{1};arglist={'',''};
  426. elseif nargin ==2
  427. Inputs=varargin{1}; arglist=varargin{2};
  428. else error('Usage: [out1,..] = krender(Inputs,arglist).');
  429. end
  430. if size(arglist,2)~=2
  431. error('arglist must be of form {''ParameterTag1'',value1;''ParameterTag2'',value2}')
  432. end
  433. narglist={'i1', '__input';'i2', '__input';'i3', '__input';'i4', '__input';'i5', '__input';'i6', '__input';'i7', '__input';'iscene', '__input';'wsize', 256;'hsize', 256;'eye_x', 0;'up_x', 0;'at_x', 0;'eye_y', 10;'up_y', 1;'at_y', 0;'eye_z', 50;'up_z', 0;'at_z', 0;'hither', 0.05;'yon', 2;'o', '__output';'oxfrm', '__output';'oscene', '__output'};
  434. maxval={1,1,1,1,1,1,1,1,4096,4096,100,100,100,100,100,100,100,100,100,1,1e+07,1,1,1};
  435. minval={1,1,1,1,1,1,1,1,32,32,-100,-100,-100,-100,-100,-100,-100,-100,-100,0.05,0,1,1,1};
  436. istoggle=[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1];
  437. was_set=istoggle * 0;
  438. paramtype={'InputFile','InputFile','InputFile','InputFile','InputFile','InputFile','InputFile','InputFile','Integer','Integer','Double','Double','Double','Double','Double','Double','Double','Double','Double','Double','Double','OutputFile','OutputFile','OutputFile'};
  439. % identify the input arrays and assign them to the arguments as stated by the user
  440. if ~iscell(Inputs)
  441. Inputs = {Inputs};
  442. end
  443. NumReqOutputs=0; nextinput=1; nextoutput=1;
  444. for ii=1:size(arglist,1)
  445. wasmatched=0;
  446. for jj=1:size(narglist,1)
  447. if strcmp(arglist{ii,1},narglist{jj,1}) % a given argument was matched to the possible arguments
  448. wasmatched = 1;
  449. was_set(jj) = 1;
  450. if strcmp(narglist{jj,2}, '__input')
  451. if (nextinput > length(Inputs))
  452. error(['Input ' narglist{jj,1} ' has no corresponding input!']);
  453. end
  454. narglist{jj,2} = 'OK_in';
  455. nextinput = nextinput + 1;
  456. elseif strcmp(narglist{jj,2}, '__output')
  457. if (nextoutput > nargout)
  458. error(['Output nr. ' narglist{jj,1} ' is not present in the assignment list of outputs !']);
  459. end
  460. if (isempty(arglist{ii,2}))
  461. narglist{jj,2} = 'OK_out';
  462. else
  463. narglist{jj,2} = arglist{ii,2};
  464. end
  465. nextoutput = nextoutput + 1;
  466. if (minval{jj} == 0)
  467. NumReqOutputs = NumReqOutputs - 1;
  468. end
  469. elseif isstr(arglist{ii,2})
  470. narglist{jj,2} = arglist{ii,2};
  471. else
  472. if strcmp(paramtype{jj}, 'Integer') & (round(arglist{ii,2}) ~= arglist{ii,2})
  473. error(['Argument ' arglist{ii,1} ' is of integer type but non-integer number ' arglist{ii,2} ' was supplied']);
  474. end
  475. if (minval{jj} ~= 0 | maxval{jj} ~= 0)
  476. if (minval{jj} == 1 & maxval{jj} == 1 & arglist{ii,2} < 0)
  477. error(['Argument ' arglist{ii,1} ' must be bigger or equal to zero!']);
  478. elseif (minval{jj} == -1 & maxval{jj} == -1 & arglist{ii,2} > 0)
  479. error(['Argument ' arglist{ii,1} ' must be smaller or equal to zero!']);
  480. elseif (minval{jj} == 2 & maxval{jj} == 2 & arglist{ii,2} <= 0)
  481. error(['Argument ' arglist{ii,1} ' must be bigger than zero!']);
  482. elseif (minval{jj} == -2 & maxval{jj} == -2 & arglist{ii,2} >= 0)
  483. error(['Argument ' arglist{ii,1} ' must be smaller than zero!']);
  484. elseif (minval{jj} ~= maxval{jj} & arglist{ii,2} < minval{jj})
  485. error(['Argument ' arglist{ii,1} ' must be bigger than ' num2str(minval{jj})]);
  486. elseif (minval{jj} ~= maxval{jj} & arglist{ii,2} > maxval{jj})
  487. error(['Argument ' arglist{ii,1} ' must be smaller than ' num2str(maxval{jj})]);
  488. end
  489. end
  490. end
  491. if ~strcmp(narglist{jj,2},'OK_out') & ~strcmp(narglist{jj,2},'OK_in')
  492. narglist{jj,2} = arglist{ii,2};
  493. end
  494. end
  495. end
  496. if (wasmatched == 0 & ~strcmp(arglist{ii,1},''))
  497. error(['Argument ' arglist{ii,1} ' is not a valid argument for this function']);
  498. end
  499. end
  500. % match the remaining inputs/outputs to the unused arguments and test for missing required inputs
  501. for jj=1:size(narglist,1)
  502. if strcmp(paramtype{jj}, 'Toggle')
  503. if (narglist{jj,2} ==0)
  504. narglist{jj,1} = '';
  505. end;
  506. narglist{jj,2} = '';
  507. end;
  508. if ~strcmp(narglist{jj,2},'__input') && ~strcmp(narglist{jj,2},'__output') && istoggle(jj) && ~ was_set(jj)
  509. narglist{jj,1} = '';
  510. narglist{jj,2} = '';
  511. end;
  512. if strcmp(narglist{jj,2}, '__input')
  513. if (minval{jj} == 0) % meaning this input is required
  514. if (nextinput > size(Inputs))
  515. error(['Required input ' narglist{jj,1} ' has no corresponding input in the list!']);
  516. else
  517. narglist{jj,2} = 'OK_in';
  518. nextinput = nextinput + 1;
  519. end
  520. else % this is an optional input
  521. if (nextinput <= length(Inputs))
  522. narglist{jj,2} = 'OK_in';
  523. nextinput = nextinput + 1;
  524. else
  525. narglist{jj,1} = '';
  526. narglist{jj,2} = '';
  527. end;
  528. end;
  529. else
  530. if strcmp(narglist{jj,2}, '__output')
  531. if (minval{jj} == 0) % this is a required output
  532. if (nextoutput > nargout & nargout > 1)
  533. error(['Required output ' narglist{jj,1} ' is not stated in the assignment list!']);
  534. else
  535. narglist{jj,2} = 'OK_out';
  536. nextoutput = nextoutput + 1;
  537. NumReqOutputs = NumReqOutputs-1;
  538. end
  539. else % this is an optional output
  540. if (nargout - nextoutput >= NumReqOutputs)
  541. narglist{jj,2} = 'OK_out';
  542. nextoutput = nextoutput + 1;
  543. else
  544. narglist{jj,1} = '';
  545. narglist{jj,2} = '';
  546. end;
  547. end
  548. end
  549. end
  550. end
  551. if nargout
  552. varargout = cell(1,nargout);
  553. else
  554. varargout = cell(1,1);
  555. end
  556. global KhorosRoot
  557. if exist('KhorosRoot') && ~isempty(KhorosRoot)
  558. w=['"' KhorosRoot];
  559. else
  560. if ispc
  561. w='"C:\Program Files\dip\khorosBin\';
  562. else
  563. [s,w] = system('which cantata');
  564. w=['"' w(1:end-8)];
  565. end
  566. end
  567. [varargout{:}]=callKhoros([w 'render" '],Inputs,narglist);