PageRenderTime 46ms CodeModel.GetById 8ms RepoModel.GetById 0ms app.codeStats 0ms

/TREES/IO/pov_tree.m

http://treestoolbox.googlecode.com/
MATLAB | 696 lines | 632 code | 7 blank | 57 comment | 92 complexity | d2d876ba9607021995d4dacf04165884 MD5 | raw file
Possible License(s): GPL-3.0
  1. % POV_TREE POV-Ray rendering of trees.
  2. % (trees package)
  3. %
  4. % [name path] = pov_tree (intree, name, v, options)
  5. % -------------------------------------------------
  6. %
  7. % writes POV-ray files using the anatomy-data contained in intree.
  8. %
  9. % Input
  10. % -----
  11. % - intree::integer:index of tree in trees or structured tree or
  12. % cell-array of trees. Also: at any point instead of a full tree give a
  13. % Nx4 matrix containing points [X Y Z D] rendered as spheres then.
  14. % - name::string: name of file including the extension ".pov"
  15. % {DEFAULT : open gui fileselect} spaces and other weird symbols not
  16. % allowed!
  17. % - v::vector: values to be color-coded, cell array if for more than one
  18. % tree, same organization as intree.
  19. % - options::string: {DEFAULT: '-b -w', because blob much much faster}
  20. % '-b' : blob, draws a skin around the cylinders
  21. % '-s' : show, write an extra standard file to display the povray object -
  22. % filename is same but starts with 'sh'. Options are -s1.. -s6.
  23. % -s1 : green fluorescence on black {DEFAULT}
  24. % -s2 : black on sand (add a photoshop canvas texture afterwards)
  25. % -s3 : black on white (no color mapping either)
  26. % -s4 : alien
  27. % -s5 : glass on cork
  28. % -s6 : red coral and watersurface on z = 0 plane
  29. % '-w' : waitbar
  30. % '-v' : adopt viewpoint from currently active axis
  31. % '-c' : brainbow colors (and '-z' sharp contrast brainbow)
  32. % '-minmax' : normalizes v values between min and max before
  33. % coloring, else: normalizes v values from zero to max before coloring
  34. % '->' : send directly to windows (necessitates -s option)
  35. %
  36. % Output
  37. % ------
  38. % - name::string: name of output file; [] no file was selected -> no output
  39. % - path::sting: path of the file, complete string is therefore: [path name]
  40. % - rpot::vector:output is the binned vector used for the coloring
  41. %
  42. % Example
  43. % -------
  44. % pov_tree (sample_tree, [], [], '-w -b -s ->')
  45. %
  46. % See also plot_tree x3d_tree swc_tree
  47. % Uses len_tree cyl_tree D
  48. %
  49. % the TREES toolbox: edit, visualize and analyze neuronal trees
  50. % Copyright (C) 2009 Hermann Cuntz
  51. function [tname path rpot] = pov_tree (intree, tname, v, options)
  52. % trees : contains the tree structures in the trees package
  53. global trees
  54. if (nargin<1)||isempty(intree),
  55. intree = length(trees); % {DEFAULT tree: last tree in trees cell array}
  56. end;
  57. % defining a name for the povray-tree
  58. if (nargin<2)||isempty(tname),
  59. [tname path] = uiputfile ('.pov', 'export to POV-Ray', 'tree.pov');
  60. if tname == 0,
  61. tname = [];
  62. return
  63. end
  64. else
  65. path = '';
  66. end
  67. % extract a sensible name from the filename string:
  68. nstart = unique ([0 strfind(tname, '/') strfind(tname, '\')]);
  69. name = tname (nstart (end) + 1 : end - 4);
  70. if nstart (end) > 0,
  71. path = [path tname(1 : nstart (end))];
  72. tname (1 : nstart (end)) = '';
  73. end
  74. name2 = [path name '.dat']; % imaging file, if v not empty or '-c' option
  75. name3 = [path 'sh' name '.pov']; % show file, with '-s' option
  76. if (nargin<3)||isempty(v),
  77. v = []; % {DEFAULT: no color mapping}
  78. end
  79. if (nargin<4)||isempty(options),
  80. options = '-b -w'; % {DEFAULT: blobs and waitbar}
  81. end
  82. if isempty (v) && isempty (strfind (options, '-c')) && isempty (strfind (options, '-z')),
  83. iflag = 0; % imaging is off, no specified colors.
  84. else
  85. iflag = 1; % imaging is on, colors specified by v or random (brainbow)
  86. map = jet (256); % colormap, change if necessary
  87. lenm = size (map, 1); % number of colormap entries
  88. povray = fopen (name2, 'w'); % open file
  89. if strfind (options, '-c') % brainbow
  90. if iscell (intree), % many cells
  91. rpot = cell (1, length (intree)); % concatenate all values between 0 and 1
  92. for ward = 1 : length (intree)
  93. if isstruct (intree {ward})
  94. len = len_tree (intree{ward});
  95. lenner = sum (len > 0.0001);
  96. else
  97. lenner = size (intree {ward}, 1);
  98. end
  99. colorcode = repmat (rand (1, 3), lenner, 1);
  100. colorcode = reshape (colorcode', numel (colorcode), 1);
  101. rpot {ward} = repmat (ward / length (intree), lenner, 1);
  102. fprintf (povray, '%12.8f,\n', colorcode);
  103. end
  104. else % single cell: random color
  105. rpot = {};
  106. if isstruct (intree) || (numel (intree) == 1),
  107. len = len_tree (intree);
  108. lenner = sum (len > 0.0001);
  109. else
  110. lenner = size (intree, 1);
  111. end
  112. colorcode = repmat (rand (1, 3), lenner, 1);
  113. colorcode = reshape (colorcode', numel (colorcode), 1);
  114. rpot {1} = zeros (lenner, 1);
  115. fprintf (povray, '%12.8f,\n', colorcode);
  116. end
  117. elseif strfind (options, '-z') % brainbow high contrast
  118. if iscell (intree), % many cells
  119. rpot = cell (1, length (intree)); % concatenate all values between 0 and 1
  120. for ward = 1 : length (intree)
  121. if isstruct (intree {ward})
  122. len = len_tree (intree {ward});
  123. lenner = sum (len > 0.0001);
  124. else
  125. lenner = size (intree {ward}, 1);
  126. end
  127. R = rand (1, 3); R = R - min (R); R = R ./ max (R);
  128. colorcode = repmat (R, lenner, 1);
  129. colorcode = reshape (colorcode', numel (colorcode), 1);
  130. rpot {ward} = repmat (ward / length (intree), lenner, 1);
  131. fprintf (povray, '%12.8f,\n', colorcode);
  132. end
  133. else % single cell: random color
  134. rpot = {};
  135. if isstruct (intree) || (numel (intree) == 1),
  136. len = len_tree (intree);
  137. lenner = sum (len > 0.0001);
  138. else
  139. lenner = size (intree, 1);
  140. end
  141. R = rand (1, 3); R = R - min (R); R = R ./ max (R);
  142. colorcode = repmat (R, lenner, 1);
  143. colorcode = reshape (colorcode', numel (colorcode), 1);
  144. rpot {1} = zeros (lenner, 1);
  145. fprintf (povray, '%12.8f,\n', colorcode);
  146. end
  147. else
  148. if iscell (intree),
  149. if isstruct (intree {1})
  150. len = len_tree (intree {1});
  151. else
  152. len = ones (size (intree {1}, 1), 1);
  153. end
  154. vt = v {1};
  155. if size (vt, 2) == 3,
  156. rpot = cell (1, length (intree));
  157. for ward = 1 : length (intree),
  158. if isstruct (intree {ward})
  159. len = len_tree (intree {ward});
  160. else
  161. len = ones( size (intree {ward}, 1), 1);
  162. end
  163. vt = v {ward};
  164. if islogical (vt), vt = double (vt); end
  165. vt = vt (len > 0.0001, :);
  166. colorcode = reshape (vt', length (vt) * 3, 1);
  167. rpot {ward} = vt;
  168. fprintf (povray, '%12.8f,\n', colorcode);
  169. end
  170. else
  171. if islogical (vt), vt = double (vt); end
  172. vt = vt (len > 0.0001);
  173. if isempty (strfind (options, '-minmax')),
  174. irange = [min(vt) max(vt)];
  175. else
  176. irange = [0 max(vt)];
  177. end
  178. for ward = 2 : length (intree) % first find v value range
  179. if isstruct (intree {ward})
  180. len = len_tree (intree {ward});
  181. else
  182. len = ones (size (intree {ward}, 1), 1);
  183. end
  184. vt = v {ward};
  185. if islogical (vt), vt = double (vt); end
  186. vt = vt (len > 0.0001);
  187. if max (vt) > irange (2),
  188. irange (2) = max (vt);
  189. end
  190. if strfind (options, '-minmax'),
  191. if min (vt) < irange (1),
  192. irange (1) = min (vt);
  193. end
  194. end
  195. end
  196. rpot = cell (1, length (intree));
  197. for ward = 1 : length (intree)
  198. if isstruct (intree {ward})
  199. len = len_tree (intree {ward});
  200. else
  201. len = ones (size (intree {ward}, 1), 1);
  202. end
  203. vt = v {ward};
  204. if islogical (vt), vt = double (vt); end
  205. vt = vt (len > 0.0001);
  206. vt = floor ((vt - irange (1)) ./ ((irange (2) - irange (1)) ./ lenm));
  207. vt (vt < 1) = 1; vt (vt > lenm) = lenm;
  208. colorcode = map (vt, :);
  209. colorcode = reshape (colorcode', length (vt) * 3, 1);
  210. rpot {ward} = vt;
  211. fprintf (povray, '%12.8f,\n', colorcode);
  212. end
  213. end
  214. else
  215. if isstruct (intree) || (numel (intree) == 1),
  216. len = len_tree (intree);
  217. else
  218. len = ones (size (intree, 1), 1);
  219. end
  220. if size (v, 2) == 3,
  221. if islogical (v), v = double (v); end
  222. v = v (len > 0.0001, :);
  223. colorcode = reshape (v', length (v) * 3, 1);
  224. rpot = {}; rpot {1} = v;
  225. fprintf (povray, '%12.8f,\n', colorcode);
  226. else
  227. if islogical (v), v = double (v); end
  228. v = v (len > 0.0001);
  229. if strfind (options, '-minmax'),
  230. irange = [min(v) max(v)];
  231. else
  232. irange = [0 max(v)];
  233. end
  234. v = floor((v - irange (1))./((irange (2) - irange (1)) ./ lenm));
  235. v (v < 1) = 1; v (v > lenm) = lenm;
  236. colorcode = map (v, :);
  237. colorcode = reshape (colorcode', length (v) * 3, 1);
  238. rpot = {}; rpot {1} = v;
  239. fprintf (povray, '%12.8f,\n', colorcode);
  240. end
  241. end
  242. end
  243. fclose (povray); % close file
  244. end
  245. if iscell (intree),
  246. if strfind (options, '-s') % show option: extra file
  247. X = cell (length (intree), 1); Y = cell (length (intree), 1);
  248. for ward = 1 : length (intree),
  249. if isstruct (intree {ward}),
  250. X {ward} = intree {ward}.X; Y {ward} = intree {ward}.Y;
  251. else
  252. X {ward} = intree {ward} (:, 1); Y {ward} = intree {ward} (:, 2);
  253. end
  254. end
  255. end
  256. % file-pointer to the povray-file
  257. povray = fopen ([path tname], 'w');
  258. % Writing the cylinders into a povray variable called 'name'
  259. fwrite (povray, ['#declare ' name ' = union{', char(13), char(10)], 'char');
  260. if strfind (options, '-w') % waitbar option: initialization
  261. HW = waitbar (0, 'writing trees ...');
  262. set (HW, 'Name', '..PLEASE..WAIT..YEAH..');
  263. end
  264. for te = 1 : length (intree),
  265. if strfind (options, '-w') % waitbar option: update
  266. if mod (te, 500) == 0,
  267. waitbar (te ./ length (intree), HW);
  268. end
  269. end
  270. if isstruct (intree {te}),
  271. if strfind (options, '-b'), % blob option: skin around bodies, faster but sloppier
  272. fwrite (povray, ['blob { threshold .15 // cell obj #', num2str(te), ...
  273. char(13), char(10)], 'char');
  274. end
  275. D = intree {te}.D;
  276. cyl = cyl_tree (intree {te});
  277. len = len_tree (intree {te});
  278. N = length (D);
  279. for ward = 1 : N,
  280. if len (ward) > 0.0001,
  281. fwrite (povray, ['cylinder { <', num2str(cyl (ward, 1)), ',', ...
  282. num2str(cyl (ward, 3)), ',', num2str(cyl (ward, 5)), '>, <', ...
  283. num2str(cyl (ward, 2)), ',', num2str(cyl (ward, 4)), ',', ...
  284. num2str(cyl (ward, 6)), '>, ', num2str(D (ward) ./ 2)], 'char');
  285. if strfind (options, '-b') % blob option: skin around bodies, faster but sloppier
  286. fwrite (povray, ', 1', 'char');
  287. end
  288. if iflag
  289. fwrite (povray, [' texture {#read (inning, R) #read (inning, G) #read (inning, B) ', ...
  290. 'pigment {color red R green G blue B}}'], 'char');
  291. end
  292. fwrite (povray, ['}', char(13), char(10)], 'char');
  293. end
  294. end
  295. else
  296. if strfind (options, '-b'), % blob option: skin around bodies, faster but sloppier
  297. fwrite (povray, ['blob { threshold .15 // points obj #', num2str(te), ...
  298. char(13), char(10)], 'char');
  299. end
  300. for ward = 1 : size (intree {te}, 1),
  301. fwrite (povray, ['sphere { <', num2str(intree {te} (ward, 1)), ',', ...
  302. num2str(intree {te} (ward, 2)), ',', num2str(intree {te} (ward, 3)), '>, ', ...
  303. num2str(intree {te} (ward, 4) ./ 2)], 'char');
  304. if findstr (options, '-b'),
  305. fwrite (povray, ', 1', 'char');
  306. end
  307. if iflag,
  308. fwrite (povray, [' texture {#read (inning, R) #read (inning, G) #read (inning, B) ', ...
  309. 'pigment {color red R green G blue B}}'], 'char');
  310. end
  311. fwrite (povray, ['}', char(13), char(10)], 'char');
  312. end
  313. end
  314. if strfind (options, '-b'), % blob option: skin around bodies, faster but sloppier
  315. fwrite (povray, ['}', char(13), char(10)], 'char');
  316. end
  317. end
  318. if strfind (options, '-w') % waitbar option: close
  319. close (HW);
  320. end
  321. fwrite (povray, ['}', char(13), char(10)], 'char');
  322. fclose (povray);
  323. else
  324. X = {}; Y = {};
  325. if ~isstruct (intree),
  326. if (numel (intree) == 1)
  327. D = trees {intree}.D;
  328. if strfind (options, '-s') % show option: extra file
  329. X {1} = trees {intree}.X;
  330. Y {1} = trees {intree}.Y;
  331. end
  332. else
  333. if strfind (options, '-s') % show option: extra file
  334. X {1} = intree (:, 1);
  335. Y {1} = intree (:, 2);
  336. end
  337. end
  338. else
  339. D = intree.D;
  340. if strfind (options, '-s') % show option: extra file
  341. X {1} = intree.X;
  342. Y {1} = intree.Y;
  343. end
  344. end
  345. % file-pointer to the povray-file
  346. povray = fopen ([path tname], 'w');
  347. % Writing the cylinders into a povray variable called 'name'
  348. fwrite (povray, ['#declare ' name ' = union{', char(13), char(10)], 'char');
  349. if strfind (options, '-w') % waitbar option: initialization
  350. HW = waitbar (0, 'writing cylinders ...');
  351. set (HW, 'Name', '..PLEASE..WAIT..YEAH..');
  352. end
  353. if strfind (options, '-b'), % blob option: skin around bodies, faster but sloppier
  354. fwrite (povray, ['blob { threshold .15', char(13), char(10)], 'char');
  355. end
  356. if isstruct (intree) || (numel (intree) == 1),
  357. N = length (D);
  358. cyl = cyl_tree (intree);
  359. len = len_tree (intree);
  360. for ward = 1 : N,
  361. if strfind (options, '-w') % waitbar option: update
  362. if mod (ward, 500) == 0,
  363. waitbar (ward ./ N, HW);
  364. end
  365. end
  366. if len (ward) > 0.0001,
  367. fwrite (povray ,['cylinder { <', num2str(cyl (ward, 1)), ',', ...
  368. num2str(cyl (ward, 3)), ',', num2str(cyl (ward, 5)), '>, <', ...
  369. num2str(cyl (ward, 2)), ',', num2str(cyl (ward, 4)), ',', ...
  370. num2str(cyl (ward, 6)), '>, ', num2str(D (ward) ./ 2)], 'char');
  371. if strfind (options, '-b'), % blob option: skin around bodies, faster but sloppier
  372. fwrite (povray, ', 1', 'char');
  373. end
  374. if iflag
  375. fwrite (povray, [' texture {#read (inning, R) #read (inning, G) #read (inning, B) ', ...
  376. 'pigment {color red R green G blue B}}'], 'char');
  377. end
  378. fwrite (povray, ['}', char(13), char(10)], 'char');
  379. end
  380. end
  381. else
  382. for ward = 1 : size (intree, 1),
  383. if findstr (options, '-w'), % waitbar option: update
  384. if mod (ward, 500) == 0,
  385. waitbar (ward ./ size (intree, 1), HW);
  386. end
  387. end
  388. fwrite (povray, ['sphere { <', num2str(intree (ward, 1)), ',', ...
  389. num2str(intree (ward, 2)), ',', num2str(intree (ward, 3)), '>, ', ...
  390. num2str(intree (ward, 4) ./ 2)], 'char');
  391. if findstr (options, '-b'),
  392. fwrite (povray, ', 1', 'char');
  393. end
  394. if iflag,
  395. fwrite (povray, [' texture {#read (inning, R) #read (inning, G) #read (inning, B) ', ...
  396. 'pigment {color red R green G blue B}}'], 'char');
  397. end
  398. fwrite (povray, ['}', char(13), char(10)], 'char');
  399. end
  400. end
  401. if strfind (options, '-w') % waitbar option: close
  402. close (HW);
  403. end
  404. fwrite (povray, ['}', char(13), char(10)], 'char');
  405. if strfind (options, '-b'), % blob option: skin around bodies, faster but sloppier
  406. fwrite (povray, ['}', char(13), char(10)], 'char');
  407. end
  408. fclose (povray);
  409. end
  410. if strfind (options, '-s') % show option: extra file
  411. a1 = strfind (options, '-s');
  412. if length (options) > a1 + 1
  413. typ = str2double (options (a1 + 2));
  414. if isnan (typ),
  415. typ = 1;
  416. end
  417. else
  418. typ = 1;
  419. end
  420. povray = fopen (name3, 'w');
  421. X = cat (1, X {:}); Y = cat (1, Y {:});
  422. dX = abs (max (X) - min (X));
  423. mX = min (X)+(max (X) - min (X)) ./ 2;
  424. mY = min (Y)+(max (Y) - min (Y)) ./ 2;
  425. if strfind (options, '-v'),
  426. ax = get (gcf, 'CurrentAxes');
  427. if ~isempty (ax),
  428. cpos = get (ax, 'cameraposition');
  429. cangle = get (ax, 'cameraviewangle') * 1.3;
  430. tpos = get (ax, 'cameratarget');
  431. skyvec = get (ax, 'CameraUpVector');
  432. uvec = [1 0 0];
  433. cX = cpos (1); cY = cpos (2); cZ = cpos (3);
  434. tX = tpos (1); tY = tpos (2); tZ = tpos (3);
  435. else
  436. cX = mX; cY = mY; cZ = -dX;
  437. tX = mX; tY = mY; tZ = 0; cangle = 65;
  438. end
  439. else
  440. cX = mX; cY = mY; cZ = -dX;
  441. tX = mX; tY = mY; tZ = 0; cangle = 65;
  442. end
  443. if iflag
  444. fwrite (povray, ['#fopen inning "' name '.dat" read', char(13), char(10)], 'char');
  445. end
  446. fwrite (povray, ['#include "' name '.pov"', char(13), char(10)], 'char');
  447. fwrite (povray, ['#include "colors.inc"', char(13), char(10)], 'char');
  448. switch typ
  449. case 1
  450. fwrite (povray, ['', char(13), char(10)], 'char');
  451. fwrite (povray, ['background {rgbt <0,0,0,0.75>}', char(13), char(10)], 'char');
  452. fwrite (povray, ['camera {', char(13), char(10)], 'char');
  453. if strfind (options, '-v'),
  454. fwrite (povray, [' sky<' num2str(skyvec (1)), ',' , num2str(skyvec (2)), ',' ,...
  455. num2str(skyvec (3)), '>' , char(13), char(10)], 'char');
  456. fwrite (povray, [' up<' num2str(uvec (1)), ',' , num2str(uvec (2)), ',' ,...
  457. num2str(uvec (3)), '>' , char(13), char(10)], 'char');
  458. end
  459. fwrite (povray, [' right x*image_width/image_height', char(13), char(10)], 'char');
  460. fwrite (povray, [' location <' num2str(cX) ',' num2str(cY) ',' num2str(cZ) '>', char(13), char(10)], 'char');
  461. fwrite (povray, [' look_at <' num2str(tX) ',' num2str(tY) ',' num2str(tZ) '>', char(13), char(10)], 'char');
  462. fwrite (povray, [' /*focal_point <' num2str(tX) ',' num2str(tY) ',' num2str(tZ) '-150> ', char(13), char(10)], 'char');
  463. fwrite (povray, [' aperture 50 // increase for more focal blur', char(13), char(10)], 'char');
  464. fwrite (povray, [' blur_samples 150*/ // add focal blur if you want', char(13), char(10)], 'char');
  465. fwrite (povray, [' angle ' num2str(cangle), char(13), char(10)], 'char');
  466. fwrite (povray, ['}', char(13), char(10)], 'char');
  467. fwrite (povray, ['', char(13), char(10)], 'char');
  468. fwrite (povray, ['light_source { <' num2str(cX) ',' num2str(cY) ',' num2str(cZ) '> White fade_distance 500}', char(13), char(10)], 'char');
  469. fwrite (povray, ['', char(13), char(10)], 'char');
  470. fwrite (povray, ['/*plane { // uncomment for water surface', char(13), char(10)], 'char');
  471. fwrite (povray, [' z, 50', char(13), char(10)], 'char');
  472. fwrite (povray, [' pigment{rgbt <1,1,0.9,0.95>}', char(13), char(10)], 'char');
  473. fwrite (povray, [' finish {ambient 0.15 diffuse 1 brilliance 16.0 reflection 0}', char(13), char(10)], 'char');
  474. fwrite (povray, [' normal {bumps 0.5 scale 120 turbulence .1}', char(13), char(10)], 'char');
  475. fwrite (povray, ['} ', char(13), char(10)], 'char');
  476. fwrite (povray, ['', char(13), char(10)], 'char');
  477. fwrite (povray, ['plane {', char(13), char(10)], 'char');
  478. fwrite (povray, [' z, -200', char(13), char(10)], 'char');
  479. fwrite (povray, [' pigment{rgbt <1,1,0.9,0.95>}', char(13), char(10)], 'char');
  480. fwrite (povray, [' finish {ambient 0.15 diffuse 0.55 brilliance 16.0 reflection 0.5}', char(13), char(10)], 'char');
  481. fwrite (povray, [' normal {bumps 0.5 scale 60 turbulence .1}', char(13), char(10)], 'char');
  482. fwrite (povray, ['} */ ', char(13), char(10)], 'char');
  483. fwrite (povray, ['', char(13), char(10)], 'char');
  484. fwrite (povray, ['light_source {', char(13), char(10)], 'char');
  485. fwrite (povray, [' <0, 0, 0>', char(13), char(10)], 'char');
  486. fwrite (povray, [' color rgb <1, 1, 0>', char(13), char(10)], 'char');
  487. fwrite (povray, [' looks_like {' name, char(13), char(10)], 'char');
  488. fwrite (povray, [' texture {', char(13), char(10)], 'char');
  489. fwrite (povray, [' pigment {rgbft <0.2, 1.0, 0.2, 0.15,0.5>}', char(13), char(10)], 'char');
  490. fwrite (povray, [' finish {ambient 0.8 diffuse 0.6 reflection .28 ior 3 specular 1 roughness .001}', char(13), char(10)], 'char');
  491. fwrite (povray, [' }', char(13), char(10)], 'char');
  492. fwrite (povray, [' }', char(13), char(10)], 'char');
  493. fwrite (povray, ['}', char(13), char(10)], 'char');
  494. fclose (povray);
  495. case 2
  496. fwrite (povray, ['', char(13), char(10)], 'char');
  497. fwrite (povray, ['background {rgbt <0.95,0.85,0.75,0.55>}', char(13), char(10)], 'char');
  498. fwrite (povray, ['camera {', char(13), char(10)], 'char');
  499. if strfind(options,'-v'),
  500. fwrite (povray, [' sky<' num2str(skyvec (1)), ',' , num2str(skyvec (2)), ',' ,...
  501. num2str(skyvec (3)), '>' , char(13), char(10)], 'char');
  502. fwrite (povray, [' up<' num2str(uvec (1)), ',' , num2str(uvec (2)), ',' ,...
  503. num2str(uvec (3)), '>' , char(13), char(10)], 'char');
  504. end
  505. fwrite (povray, [' right x*image_width/image_height', char(13), char(10)], 'char');
  506. fwrite (povray, [' location <' num2str(cX) ',' num2str(cY) ',' num2str(cZ) '>', char(13), char(10)], 'char');
  507. fwrite (povray, [' look_at <' num2str(tX) ',' num2str(tY) ',' num2str(tZ) '>', char(13), char(10)], 'char');
  508. fwrite (povray, [' angle ' num2str(cangle), char(13), char(10)], 'char');
  509. fwrite (povray, ['}', char(13), char(10)], 'char');
  510. fwrite (povray, ['', char(13), char(10)], 'char');
  511. fwrite (povray, ['light_source { <' num2str(cX) ',' num2str(cY) ',' num2str(cZ) '> White fade_distance 500}', char(13), char(10)], 'char');
  512. fwrite (povray, ['', char(13), char(10)], 'char');
  513. fwrite (povray, ['plane { // paper 1', char(13), char(10)], 'char');
  514. fwrite (povray, [' z, 50', char(13), char(10)], 'char');
  515. fwrite (povray, [' pigment{ color rgbt <.95,.95,0.05,0.7>}', char(13), char(10)], 'char');
  516. fwrite (povray, [' normal {wrinkles 1 scale 0.4}', char(13), char(10)], 'char');
  517. fwrite (povray, [' finish {diffuse .7 roughness .085 ambient 0.1}', char(13), char(10)], 'char');
  518. fwrite (povray, ['} ', char(13), char(10)], 'char');
  519. fwrite (povray, ['', char(13), char(10)], 'char');
  520. fwrite (povray, ['plane { // paper 2', char(13), char(10)], 'char');
  521. fwrite (povray, [' z, 51', char(13), char(10)], 'char');
  522. fwrite (povray, [' pigment{ color rgbt <1,0,0,0.85>}', char(13), char(10)], 'char');
  523. fwrite (povray, [' normal {wrinkles 1 scale 100}', char(13), char(10)], 'char');
  524. fwrite (povray, [' finish {diffuse .7 roughness .085 ambient 0.1}', char(13), char(10)], 'char');
  525. fwrite (povray, ['} ', char(13), char(10)], 'char');
  526. fwrite (povray, ['', char(13), char(10)], 'char');
  527. fwrite (povray, ['plane { // paper 3', char(13), char(10)], 'char');
  528. fwrite (povray, [' z, 52', char(13), char(10)], 'char');
  529. fwrite (povray, [' pigment{ color rgbt <.5,1,0,.85>}', char(13), char(10)], 'char');
  530. fwrite (povray, [' normal {wrinkles 1 scale 1}', char(13), char(10)], 'char');
  531. fwrite (povray, [' finish {diffuse .7 roughness .85 ambient 0.1}', char(13), char(10)], 'char');
  532. fwrite (povray, ['} ', char(13), char(10)], 'char');
  533. fwrite (povray, ['', char(13), char(10)], 'char');
  534. fwrite (povray, ['light_source {', char(13), char(10)], 'char');
  535. fwrite (povray, [' <0, 0, 0>', char(13), char(10)], 'char');
  536. fwrite (povray, [' color rgbt <0, 0, 0, 0.5>', char(13), char(10)], 'char');
  537. fwrite (povray, [' looks_like {' name, char(13), char(10)], 'char');
  538. fwrite (povray, [' normal {wrinkles 1 scale 0.4}', char(13), char(10)], 'char');
  539. fwrite (povray, [' finish {diffuse .7 roughness .085 ambient 0.1}', char(13), char(10)], 'char');
  540. fwrite (povray, [' }', char(13), char(10)], 'char');
  541. fwrite (povray, ['}', char(13), char(10)], 'char');
  542. fclose (povray);
  543. case 3
  544. fwrite (povray, ['', char(13), char(10)], 'char');
  545. fwrite (povray, ['background {rgbt <1,1,1,0>}', char(13), char(10)], 'char');
  546. fwrite (povray, ['camera {', char(13), char(10)], 'char');
  547. if strfind(options,'-v'),
  548. fwrite (povray, [' sky<' num2str(skyvec (1)), ',' , num2str(skyvec (2)), ',' ,...
  549. num2str(skyvec (3)), '>' , char(13), char(10)], 'char');
  550. fwrite (povray, [' up<' num2str(uvec (1)), ',' , num2str(uvec (2)), ',' ,...
  551. num2str(uvec (3)), '>' , char(13), char(10)], 'char');
  552. end
  553. fwrite (povray, [' right x*image_width/image_height', char(13), char(10)], 'char');
  554. fwrite (povray, [' location <' num2str(cX) ',' num2str(cY) ',' num2str(cZ) '>', char(13), char(10)], 'char');
  555. fwrite (povray, [' look_at <' num2str(tX) ',' num2str(tY) ',' num2str(tZ) '>', char(13), char(10)], 'char');
  556. fwrite (povray, [' angle ' num2str(cangle), char(13), char(10)], 'char');
  557. fwrite (povray, ['}', char(13), char(10)], 'char');
  558. fwrite (povray, ['', char(13), char(10)], 'char');
  559. fwrite (povray, ['light_source { <' num2str(cX) ',' num2str(cY) ',' num2str(cZ) '>}', char(13), char(10)], 'char');
  560. fwrite (povray, ['', char(13), char(10)], 'char');
  561. fwrite (povray, ['light_source {', char(13), char(10)], 'char');
  562. fwrite (povray, [' <0, 0, 0>', char(13), char(10)], 'char');
  563. fwrite (povray, [' color rgbt <0, 0, 0, 0.5>', char(13), char(10)], 'char');
  564. fwrite (povray, [' looks_like {' name '}', char(13), char(10)], 'char');
  565. fwrite (povray, ['}', char(13), char(10)], 'char');
  566. fclose (povray);
  567. case 4
  568. fwrite (povray, ['', char(13), char(10)], 'char');
  569. fwrite (povray, ['background {rgbt <0.05,0.05,0.05,0.75>}', char(13), char(10)], 'char');
  570. fwrite (povray, ['camera {', char(13), char(10)], 'char');
  571. if strfind(options,'-v'),
  572. fwrite (povray, [' sky<' num2str(skyvec (1)), ',' , num2str(skyvec (2)), ',' ,...
  573. num2str(skyvec (3)), '>' , char(13), char(10)], 'char');
  574. fwrite (povray, [' up<' num2str(uvec (1)), ',' , num2str(uvec (2)), ',' ,...
  575. num2str(uvec (3)), '>' , char(13), char(10)], 'char');
  576. end
  577. fwrite (povray, [' right x*image_width/image_height', char(13), char(10)], 'char');
  578. fwrite (povray, [' location <' num2str(cX) ',' num2str(cY) ',' num2str(cZ) '>', char(13), char(10)], 'char');
  579. fwrite (povray, [' look_at <' num2str(tX) ',' num2str(tY) ',' num2str(tZ) '>', char(13), char(10)], 'char');
  580. fwrite (povray, [' angle ' num2str(cangle), char(13), char(10)], 'char');
  581. fwrite (povray, ['}', char(13), char(10)], 'char');
  582. fwrite (povray, ['', char(13), char(10)], 'char');
  583. fwrite (povray, ['light_source { <' num2str(cX) ',' num2str(cY) ',' num2str(cZ) '> White fade_distance 500}', char(13), char(10)], 'char');
  584. fwrite (povray, ['', char(13), char(10)], 'char');
  585. fwrite (povray, ['plane {', char(13), char(10)], 'char');
  586. fwrite (povray, [' z, 50', char(13), char(10)], 'char');
  587. fwrite (povray, [' pigment{rgbt <1,1,0.5,0.75>}', char(13), char(10)], 'char');
  588. fwrite (povray, [' finish {ambient 0.15 diffuse 1 brilliance 16.0 reflection 0}', char(13), char(10)], 'char');
  589. fwrite (povray, [' normal {bumps 0.5 scale 120 turbulence .1}', char(13), char(10)], 'char');
  590. fwrite (povray, ['} ', char(13), char(10)], 'char');
  591. fwrite (povray, ['', char(13), char(10)], 'char');
  592. fwrite (povray, ['plane {', char(13), char(10)], 'char');
  593. fwrite (povray, [' z, -200', char(13), char(10)], 'char');
  594. fwrite (povray, [' pigment{rgbt <1,1,0.5,0.75>}', char(13), char(10)], 'char');
  595. fwrite (povray, [' finish {ambient 0.15 diffuse 0.55 brilliance 16.0 reflection 0.5}', char(13), char(10)], 'char');
  596. fwrite (povray, [' normal {bumps 0.5 scale 60 turbulence .1}', char(13), char(10)], 'char');
  597. fwrite (povray, ['} ', char(13), char(10)], 'char');
  598. fwrite (povray, ['', char(13), char(10)], 'char');
  599. fwrite (povray, ['light_source {', char(13), char(10)], 'char');
  600. fwrite (povray, [' <0, 0, 0>', char(13), char(10)], 'char');
  601. fwrite (povray, [' color rgb <1, 1, 1>', char(13), char(10)], 'char');
  602. fwrite (povray, [' looks_like {' name, char(13), char(10)], 'char');
  603. fwrite (povray, [' hollow interior{media {emission 0}}', char(13), char(10)], 'char');
  604. fwrite (povray, [' pigment{color rgbt <0.5,0,0,0.2>}', char(13), char(10)], 'char');
  605. fwrite (povray, [' normal {wrinkles 1.25 scale 0.35}', char(13), char(10)], 'char');
  606. fwrite (povray, [' finish { reflection 0.75}', char(13), char(10)], 'char');
  607. fwrite (povray, [' }', char(13), char(10)], 'char');
  608. fwrite (povray, ['}', char(13), char(10)], 'char');
  609. fclose (povray);
  610. case 5
  611. fwrite (povray, ['#include "textures.inc"', char(13), char(10)], 'char');
  612. fwrite (povray, ['', char(13), char(10)], 'char');
  613. fwrite (povray, ['camera {', char(13), char(10)], 'char');
  614. if strfind(options,'-v'),
  615. fwrite (povray, [' sky<' num2str(skyvec (1)), ',' , num2str(skyvec (2)), ',' ,...
  616. num2str(skyvec (3)), '>' , char(13), char(10)], 'char');
  617. fwrite (povray, [' up<' num2str(uvec (1)), ',' , num2str(uvec (2)), ',' ,...
  618. num2str(uvec (3)), '>' , char(13), char(10)], 'char');
  619. end
  620. fwrite (povray, [' right x*image_width/image_height', char(13), char(10)], 'char');
  621. fwrite (povray, [' location <' num2str(cX) ',' num2str(cY) ',' num2str(cZ) '>', char(13), char(10)], 'char');
  622. fwrite (povray, [' look_at <' num2str(tX) ',' num2str(tY) ',' num2str(tZ) '>', char(13), char(10)], 'char');
  623. fwrite (povray, [' angle ' num2str(cangle), char(13), char(10)], 'char');
  624. fwrite (povray, ['}', char(13), char(10)], 'char');
  625. fwrite (povray, ['', char(13), char(10)], 'char');
  626. fwrite (povray, ['light_source { <' num2str(cX) ',' num2str(cY) ',' num2str(cZ) '> White fade_distance 500}', char(13), char(10)], 'char');
  627. fwrite (povray, ['', char(13), char(10)], 'char');
  628. fwrite (povray, ['plane {', char(13), char(10)], 'char');
  629. fwrite (povray, [' z, 150', char(13), char(10)], 'char');
  630. fwrite (povray, [' texture {White_Wood scale 5}', char(13), char(10)], 'char');
  631. fwrite (povray, ['} ', char(13), char(10)], 'char');
  632. fwrite (povray, ['', char(13), char(10)], 'char');
  633. fwrite (povray, ['light_source {', char(13), char(10)], 'char');
  634. fwrite (povray, [' <0, 0, 0>', char(13), char(10)], 'char');
  635. fwrite (povray, [' color rgb <0, 0, 1>', char(13), char(10)], 'char');
  636. fwrite (povray, [' looks_like {' name, char(13), char(10)], 'char');
  637. fwrite (povray, [' pigment {rgbft <0.2, 0.2, 1, 1,0.7>}', char(13), char(10)], 'char');
  638. fwrite (povray, [' finish {ambient 0.1 diffuse 0.1 reflection .2 ior 1 specular 1 roughness .001}', char(13), char(10)], 'char');
  639. fwrite (povray, [' }', char(13), char(10)], 'char');
  640. fwrite (povray, ['}', char(13), char(10)], 'char');
  641. fclose (povray);
  642. case 6
  643. fwrite (povray, ['', char(13), char(10)], 'char');
  644. fwrite (povray, ['background {rgbt <0.7,0.7,0.7,0.75>}', char(13), char(10)], 'char');
  645. fwrite (povray, ['camera {', char(13), char(10)], 'char');
  646. if strfind(options,'-v'),
  647. fwrite (povray, [' sky<' num2str(skyvec (1)), ',' , num2str(skyvec (2)), ',' ,...
  648. num2str(skyvec (3)), '>' , char(13), char(10)], 'char');
  649. fwrite (povray, [' up<' num2str(uvec (1)), ',' , num2str(uvec (2)), ',' ,...
  650. num2str(uvec (3)), '>' , char(13), char(10)], 'char');
  651. end
  652. fwrite (povray, [' right x*image_width/image_height', char(13), char(10)], 'char');
  653. fwrite (povray, [' location <' num2str(cX) ',' num2str(cY) ',' num2str(cZ) '>', char(13), char(10)], 'char');
  654. fwrite (povray, [' look_at <' num2str(tX) ',' num2str(tY) ',' num2str(tZ) '>', char(13), char(10)], 'char');
  655. fwrite (povray, [' /*focal_point <' num2str(tX) ',' num2str(tY) ',' num2str(tZ) '-150> ', char(13), char(10)], 'char');
  656. fwrite (povray, [' aperture 50 // increase for more focal blur', char(13), char(10)], 'char');
  657. fwrite (povray, [' blur_samples 150*/ // add focal blur if you want', char(13), char(10)], 'char');
  658. fwrite (povray, [' angle ' num2str(cangle), char(13), char(10)], 'char');
  659. fwrite (povray, ['}', char(13), char(10)], 'char');
  660. fwrite (povray, ['', char(13), char(10)], 'char');
  661. fwrite (povray, ['light_source { <' num2str(cX) ',' num2str(cY) ',' num2str(cZ) '> White fade_distance 500}', char(13), char(10)], 'char');
  662. fwrite (povray, ['', char(13), char(10)], 'char');
  663. fwrite (povray, ['plane { //plane of water at z=0', char(13), char(10)], 'char');
  664. fwrite (povray, [' z, 0', char(13), char(10)], 'char');
  665. fwrite (povray, [' pigment{rgbt <1,1,0.5,0.75>}', char(13), char(10)], 'char');
  666. fwrite (povray, [' finish {ambient 0.15 diffuse 0.55 brilliance 6.0 reflection 0.2}', char(13), char(10)], 'char');
  667. fwrite (povray, [' normal {bumps 0.5 scale 20 turbulence 1}', char(13), char(10)], 'char');
  668. fwrite (povray, ['} ', char(13), char(10)], 'char');
  669. fwrite (povray, ['', char(13), char(10)], 'char');
  670. fwrite (povray, ['light_source {', char(13), char(10)], 'char');
  671. fwrite (povray, [' <0, 0, 0>', char(13), char(10)], 'char');
  672. fwrite (povray, [' color rgb <1, 1, 0>', char(13), char(10)], 'char');
  673. fwrite (povray, [' looks_like {' name, char(13), char(10)], 'char');
  674. fwrite (povray, [' hollow interior{ media {emission 0}}', char(13), char(10)], 'char');
  675. fwrite (povray, [' pigment{ color rgbt <0.5,0,0,0.2>}', char(13), char(10)], 'char');
  676. fwrite (povray, [' normal { wrinkles 1.25 scale 0.35}', char(13), char(10)], 'char');
  677. fwrite (povray, [' }', char(13), char(10)], 'char');
  678. fwrite (povray, ['}', char(13), char(10)], 'char');
  679. fclose (povray);
  680. end
  681. if strfind (options, '->')
  682. if ispc, % this even calls the file directly (only windows)
  683. winopen (name3);
  684. end
  685. end
  686. end