From: <et...@us...> - 2010-04-12 04:19:00
|
Revision: 7174 http://octave.svn.sourceforge.net/octave/?rev=7174&view=rev Author: etienne Date: 2010-04-12 04:18:53 +0000 (Mon, 12 Apr 2010) Log Message: ----------- A few new functions Modified Paths: -------------- trunk/octave-forge/main/vrml/DESCRIPTION trunk/octave-forge/main/vrml/inst/vmesh.m trunk/octave-forge/main/vrml/inst/vrml_faces.m trunk/octave-forge/main/vrml/inst/vrml_surf.m Added Paths: ----------- trunk/octave-forge/main/vrml/inst/checker_color.m trunk/octave-forge/main/vrml/inst/vrml_Box.m trunk/octave-forge/main/vrml/inst/vrml_Sphere.m trunk/octave-forge/main/vrml/inst/vrml_parallelepiped.m Modified: trunk/octave-forge/main/vrml/DESCRIPTION =================================================================== --- trunk/octave-forge/main/vrml/DESCRIPTION 2010-04-11 18:53:31 UTC (rev 7173) +++ trunk/octave-forge/main/vrml/DESCRIPTION 2010-04-12 04:18:53 UTC (rev 7174) @@ -1,6 +1,6 @@ Name: Vrml -Version: 1.0.11 -Date: 2010-02-07 +Version: 1.0.12 +Date: 2010-04-11 Author: Etienne Grossmann Maintainer: Etienne Grossmann Title: VRML. Added: trunk/octave-forge/main/vrml/inst/checker_color.m =================================================================== --- trunk/octave-forge/main/vrml/inst/checker_color.m (rev 0) +++ trunk/octave-forge/main/vrml/inst/checker_color.m 2010-04-12 04:18:53 UTC (rev 7174) @@ -0,0 +1,25 @@ +## col = checker_color (R,C, checker, col) +function col = checker_color (checker, col, R,C) + +if length (checker) == 1, checker = [checker, checker]; end + +if checker(1) > 0, checker(1) = - (C-1)/checker(1); end +if checker(2) > 0, checker(2) = - (R-1)/checker(2); end + +checker *= -1; + +colx = 2 * (rem (0:C-2,2*checker(1)) < checker(1)) - 1; +coly = 2 * (rem (0:R-2,2*checker(2)) < checker(2)) - 1; +icol = 1 + ((coly'*colx) > 0); + # Keep at most 1st 2 colors of col for the + # checker +if prod (size (col)) == 2, + col = [1;1;1]*col; +elseif prod (size (col)) < 6, # Can't be < 3 because of previous code + col = col(1:3)(:); + if all (col >= 1-eps), col = [col [0;0;0]]; # Black and White + else col = [col [1;1;1]]; # X and White + end +end +col = reshape (col(:),3,2); +col = col(:,icol); Modified: trunk/octave-forge/main/vrml/inst/vmesh.m =================================================================== --- trunk/octave-forge/main/vrml/inst/vmesh.m 2010-04-11 18:53:31 UTC (rev 7173) +++ trunk/octave-forge/main/vrml/inst/vmesh.m 2010-04-12 04:18:53 UTC (rev 7174) @@ -58,6 +58,7 @@ ## function ## ## "bars" : Represent surface as a bar plot +## "bwid" : Bar width, relative to point separation. Default = 2/3 ## ## "level", l : 1xN : Display one or more horizontal translucent plane(s) ## @@ -65,6 +66,7 @@ ## ## "lcol", lc : Nx3 : Color of the plane(s). Default = [.7 .7 .7] ## "ltran",lt : Nx1 : Transparency of the plane(s). Default = 0.3 +## "tex", texFile ## ## "normalize" : Normalize z to [-1,1] ## @@ -106,11 +108,11 @@ if numel (varargin) - op1 = [" tran col checker creaseAngle emit colorPerVertex tex zcol",\ - " level lcol ltran "]; + op1 = [" tran col checker creaseAngle emit colorPerVertex tex zcol frame ",\ + " level lcol ltran bwid "]; op0 = " smooth zgray zrb normalize steps bars "; - df = tars (level, lcol, ltran, normalize); + df = tars (level, lcol, ltran, normalize, frame); opts = read_options (varargin,"op0",op0,"op1",op1,"default",df); @@ -119,7 +121,7 @@ # "colorPerVertex", "smooth", "tex",\ # "zgray","zrb","zcol"); all_surf_opts = {"tran", "col", "checker", "creaseAngle", "emit", \ - "colorPerVertex", "smooth", "steps", "bars", "tex",\ + "colorPerVertex", "smooth", "steps", "bars", "bwid", "tex",\ "zgray","zrb","zcol"}; for i = 1:length(all_surf_opts) @@ -134,9 +136,10 @@ end end end + lcol = opts.lcol; level = opts.level; ltran = opts.ltran; - lcol = opts.lcol; + frame = opts.frame; normalize = opts.normalize; end @@ -174,10 +177,11 @@ # pl = [pl1 pl2]; -pl = [vrml_DirectionalLight("direction",[-1,-1,-1],"intensity",0.9),\ - vrml_DirectionalLight("direction",[-1, 1,-1],"intensity",0.7),\ - vrml_DirectionalLight("direction",[ 1,-1,-1],"intensity",0.7),\ - vrml_DirectionalLight("direction",[ 1, 1,-1],"intensity",0.5)]; +pl = [vrml_DirectionalLight("direction",[-1,-1,-1],"intensity",0.75),\ + vrml_DirectionalLight("direction",[-1, 1,-1],"intensity",0.5),\ + vrml_DirectionalLight("direction",[ 1,-1,-1],"intensity",0.5),\ + vrml_DirectionalLight("direction",[ 1, 1,-1],"intensity",0.33),\ + vrml_DirectionalLight("direction",[ 0, 0, 1],"intensity",0.5)]; # distance = max ([max (x(:)) - min (x(:)),\ # max (y(:)) - min (y(:)),\ @@ -232,9 +236,11 @@ s = [pl, sbg, s , fr, slevel]; -vrml_browse (s); -if ! nargout, clear s; end +if ! nargout, + vrml_browse (s); + clear s; +end %!demo %! % Test the vmesh and vrml_browse functions with the test_vmesh script Added: trunk/octave-forge/main/vrml/inst/vrml_Box.m =================================================================== --- trunk/octave-forge/main/vrml/inst/vrml_Box.m (rev 0) +++ trunk/octave-forge/main/vrml/inst/vrml_Box.m 2010-04-12 04:18:53 UTC (rev 7174) @@ -0,0 +1,18 @@ +## s = vrml_Box (sz) - Box { ... } node +## +## If sz is not given, returns Box { } +## If sz has size 1, returns Box { <sz> <sz> <sz> } +## If sz has size 3, returns Box { <sz(1)> <sz(2)> <sz(3)> } +function s = vrml_Box (sz) + +if nargin < 1, sz = []; end +if length (sz) == 1, sz = sz * [1 1 1]; end +if !isempty (sz) + assert (numel (sz) == 3); + ssz = sprintf ("\n size %f %f %f\n",sz); +else + ssz = ""; +end + +s = ["Box {",ssz,"}\n"]; + Added: trunk/octave-forge/main/vrml/inst/vrml_Sphere.m =================================================================== --- trunk/octave-forge/main/vrml/inst/vrml_Sphere.m (rev 0) +++ trunk/octave-forge/main/vrml/inst/vrml_Sphere.m 2010-04-12 04:18:53 UTC (rev 7174) @@ -0,0 +1,14 @@ +## s = vrml_Sphere (radius) - VRML code for a sphere +function s = vrml_Sphere (sz) + +if nargin < 1, sz = []; end + +if !isempty (sz) + assert (numel (sz) == 1); + ssz = sprintf ("\n radius %f\n",sz); +else + ssz = ""; +end + +s = ["Sphere {",ssz,"}\n"]; + Modified: trunk/octave-forge/main/vrml/inst/vrml_faces.m =================================================================== --- trunk/octave-forge/main/vrml/inst/vrml_faces.m 2010-04-11 18:53:31 UTC (rev 7173) +++ trunk/octave-forge/main/vrml/inst/vrml_faces.m 2010-04-12 04:18:53 UTC (rev 7174) @@ -72,7 +72,7 @@ if rows (x) != 3 if columns (x) != 3 - error ("x is %i x %i, has neither 3 rows nor 3 columns.", size (f)); + error ("x is %i x %i, has neither 3 rows nor 3 columns.", size (x)); else x = x'; end @@ -257,7 +257,7 @@ if is_list (f), nfaces = length (f); else nfaces = columns (f); end - tpl0 = sprintf ("%%%dd, ",floor (log10 (columns (x)))+1); + tpl0 = sprintf ("%%%dd, ",floor (log10 (max (1, columns (x))))+1); ltpl0 = length (tpl0); ptsface = zeros (1,nfaces); Added: trunk/octave-forge/main/vrml/inst/vrml_parallelepiped.m =================================================================== --- trunk/octave-forge/main/vrml/inst/vrml_parallelepiped.m (rev 0) +++ trunk/octave-forge/main/vrml/inst/vrml_parallelepiped.m 2010-04-12 04:18:53 UTC (rev 7174) @@ -0,0 +1,111 @@ +## Copyright (C) 2007-2010 Tyzx +## +## This program is free software; you can redistribute it and/or modify it +## under the terms of the GNU General Public License as published by the +## Free Software Foundation; either version 2, or (at your option) any +## later version. +## +## This is distributed in the hope that it will be useful, but WITHOUT +## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +## for more details. + +## s = vrml_parallelogram (bnds,...) +## +## bnds = [xmin, ymin, zmin; xmax, ymax, zmax] +## +## OPTIONS : +## --------- +## col, c : 3x1 : Color of surface +## emit, e : 1 : +## tran, t : 1 : +## +## border,b : 1 : +## bocol, c : 3 : +## boemit,e : 1 : +## borad, r : 1 : +## +## balls, b : 1 : +## bcol, c : 3 : +## bemit, e : 1 : +## brad, r : 1 : + +## Author: Etienne Grossmann <et...@ty...> + +function s = vrml_parallelepiped (bnds, varargin) + +col = [0.3,0.4,0.9]; +emit = 0; +tran = 0; +balls = 0; +border = 0; +bcol = btran = bemit = brad = borad = bocol = boemit = nan; + +if !isnumeric (bnds) + error ("bnds must be a 2 x 3 matrix, not a %s",typeinfo(bnds)); +endif +if prod (size (bnds)) != 6 + error ("bnds must be 2 x 3, not %s",sprintf("%i x ",size(bnds))(1:end-3)); +endif +if nargin > 1 + op1 = " col emit tran balls border bcol btran bemit brad borad bocol boemit "; + df = tars (col,emit,tran,balls,border,bcol,btran,bemit,brad,borad,bocol,boemit); + s = read_options (varargin, "op1",op1, "default",df); + col=s.col; emit=s.emit; tran=s.tran; balls=s.balls; border=s.border; + bcol = s.bcol; btran = s.btran; bemit = s.bemit; brad = s.brad; + borad = s.borad; bocol = s.bocol; boemit = s.boemit; +end + +if ! isnan (bcol) ||! isnan (brad) || ! isnan (bemit), balls = 1; end +if balls + if isnan (bcol), bcol = col; end + if isnan (btran), btran = tran; end + if isnan (brad) + brad = (max (abs (diff(bnds))))/20; + end +end + +x = [bnds([1 2 2 1 1 2 2 1],1)';\ + bnds([1 1 2 2 1 1 2 2],2)';\ + bnds([1 1 1 1 2 2 2 2],3)']; + +faces = [1 2 3 4;\ + 5 6 7 8;\ + 1 2 6 5;\ + 2 3 7 6;\ + 3 4 8 7;\ + 4 1 5 8]'; + + # The facet +s = vrml_faces (x,faces,"col",col, "tran", tran,"emit",emit); + + # Decoration : balls on vertices +if balls + if isnan (bemit), bemit = emit; end + s = [s,vrml_points(x,"balls","rad",brad,"col",bcol,"tran",btran,"emit",bemit)]; +end + + # Decoration : border + +if ! isnan (bocol) ||! isnan (borad) || ! isnan (boemit), border = 1; end +if border + if isnan (borad) + borad = (norm (x(:,1)-x(:,2))+ norm(x(:,1)-x(:,2)))/80; + end + if isnan (boemit) + if isnan (bemit), boemit = emit; else boemit = bemit; end + end + if isnan (bocol), bocol = col; end + + if !balls # Make pretty junctions of cylinders + s = [s,\ + vrml_cyl(x(:,[1:columns(x),1]),"rad",borad,"emit",boemit,"col",col),\ + vrml_points(x(:,1),"balls","rad",borad,"emit",boemit,"col",col)]; + else # but only if balls don't cover them + s = [s,vrml_cyl(x(:,[1:columns(x),1]),"rad",borad,"emit",boemit)]; + end + +end + +endfunction + Modified: trunk/octave-forge/main/vrml/inst/vrml_surf.m =================================================================== --- trunk/octave-forge/main/vrml/inst/vrml_surf.m 2010-04-11 18:53:31 UTC (rev 7173) +++ trunk/octave-forge/main/vrml/inst/vrml_surf.m 2010-04-12 04:18:53 UTC (rev 7174) @@ -64,6 +64,7 @@ ## between facets forming an angle less than a. ## default = 0 ## "smooth" : same as "creaseAngle",pi. +## "tex", texFile ## ## See also: vmesh(), vrml_faces(), test_moving_surf() @@ -95,12 +96,14 @@ x = xx ; y = yy ; z = zz ; end +defaultCol = [0.3; 0.4; 0.9]; + # Read options # Default values upper = 1; # Do "upper" triangulation of square grid tran = 0 ; # Transparency -col = [0.3, 0.4, 0.9] ; # Color +col = defaultCol ; # Color checker = 0; # Checkered coloring colorPerVertex = 1; # Color vertices or faces zrb = zgray = zcol = 0; # Color by elevation @@ -108,15 +111,17 @@ smooth = creaseAngle = nan ; steps = 0; bars = 0; +tex = 0; +bwid = -1; DEFcoord = DEFcol = ""; # Give a name to VRML objects if numel (varargin) - op1 = " tran col creaseAngle emit colorPerVertex checker DEFcoord DEFcol zcol "; + op1 = " tran col creaseAngle emit colorPerVertex checker DEFcoord DEFcol zcol bwid tex "; op0 = " smooth zgray zrb steps bars " ; default = tars (tran, col, creaseAngle, emit, colorPerVertex, steps, bars, \ - DEFcoord, DEFcol, zcol, smooth, checker, zgray, zrb); + bwid, DEFcoord, DEFcol, zcol, smooth, checker, zgray, zrb, tex); s = read_options (varargin,"op0",op0,"op1",op1,"default",default); @@ -131,6 +136,11 @@ smooth= s.smooth; steps= s.steps; bars= s.bars; + bwid= s.bwid; + tex= s.tex; + if bwid >= 0 + bars = 1; + end checker= s.checker; zgray= s.zgray; zrb= s.zrb; @@ -144,19 +154,24 @@ if bars + if bwid < 0 + bwid = 2/3; + end + brad = bwid/2; + R4 = 4*R; C4 = 4*C; x2 = y2 = z2 = zeros (R4,C4); - x2(:,1) = x2(:,2) = kron ((4*x(:,1)-x(:,2))/3, [1;1;1;1]); - x2(:,C4-1) = x2(:,C4) = kron ((4*x(:,C)-x(:,C-1))/3, [1;1;1;1]); - x2(:,5:4:C4) = x2(:,6:4:C4) = kron ((2*x(:,2:C)+x(:,1:C-1))/3, [1;1;1;1]); - x2(:,3:4:C4-4) = x2(:,4:4:C4-4) = kron ((2*x(:,1:C-1)+x(:,2:C))/3, [1;1;1;1]); + x2(:,1) = x2(:,2) = kron ((1+brad)*x(:,1) - brad*x(:,2), [1;1;1;1]); + x2(:,C4-1) = x2(:,C4) = kron ((1+brad)*x(:,C) - brad*x(:,C-1), [1;1;1;1]); + x2(:,5:4:C4) = x2(:,6:4:C4) = kron ((1-brad)*x(:,2:C) + brad*x(:,1:C-1), [1;1;1;1]); + x2(:,3:4:C4-4) = x2(:,4:4:C4-4) = kron ((1-brad)*x(:,1:C-1)+brad*x(:,2:C), [1;1;1;1]); - y2(1,:) = y2(2,:) = kron ((4*y(1,:)-y(2,:))/3, [1 1 1 1]); - y2(R4-1,:) = y2(R4,:) = kron ((4*y(R,:)-y(R-1,:))/3, [1 1 1 1]); - y2(5:4:R4,:) = y2(6:4:R4,:) = kron ((2*y(2:R,:)+y(1:R-1,:))/3, [1 1 1 1]); - y2(3:4:R4-4,:) = y2(4:4:R4-4,:) = kron ((2*y(1:R-1,:)+y(2:R,:))/3, [1 1 1 1]); + y2(1,:) = y2(2,:) = kron ((1+brad)*y(1,:) - brad*y(2,:), [1 1 1 1]); + y2(R4-1,:) = y2(R4,:) = kron ((1+brad)*y(R,:) - brad*y(R-1,:), [1 1 1 1]); + y2(5:4:R4,:) = y2(6:4:R4,:) = kron ((1-brad)*y(2:R,:) + brad*y(1:R-1,:), [1 1 1 1]); + y2(3:4:R4-4,:) = y2(4:4:R4-4,:) = kron ((1-brad)*y(1:R-1,:) + brad*y(2:R,:), [1 1 1 1]); z2([2:4:R4;3:4:R4],[2:4:C4;3:4:C4]) = kron(z,ones(2)); @@ -166,6 +181,43 @@ R = R4; C = C4; + if numel (size (col)) == 2 && all (size (col) == size (defaultCol)) && all (col == defaultCol) + col = [col, 0.8*col, 0.9*col] + end + if numel (col) == 3 + col = col(:); + topCol = col; + botCol = col; + sideCol = [col,col,col,col]; + elseif numel (col) == 6 + col = col(:); + topCol = col(1:3); + botCol = col(1:3); + sideCol = col(4:6)*ones(1,4); + elseif numel (col) == 9 + col = col(:); + topCol = col(1:3) + botCol = col(7:9) + sideCol = col(4:6)*ones(1,4) + end + col = ones(3, R-1, C-1); + for i=1:3 + col(i,2:4:R-1,2:4:C-1) = topCol(i); + col(i,4:4:R-1,:) = botCol(i); + col(i,:,4:4:C-1) = botCol(i); + col(i,3:4:R-1,2:4:C-1) = sideCol(i,1); + col(i,2:4:R-1,1:4:C-1) = sideCol(i,2); + col(i,1:4:R-1,2:4:C-1) = sideCol(i,3); + col(i,2:4:R-1,3:4:C-1) = sideCol(i,2); + end + iOnFloor = find (! z(1:R-1,1:C-1)); + if ! isempty (iOnFloor) + ## keyboard + col(3*(iOnFloor-1)+1) = botCol(1); + col(3*(iOnFloor-1)+2) = botCol(2); + col(3*(iOnFloor-1)+3) = botCol(3); + end + elseif steps # Constant by parts # Intermediate coordinates (R+1) x (C+1) @@ -195,6 +247,22 @@ y = y2; z = z2; + if checker + col = checker_color (checker, col, 2*R,2*C); + end + if numel (col) == R*C + col = [1;1;1]*col(:)'; + end + if numel (col) == 3*R*C + col = reshape (col, 3,R,C); + col2 = zeros (3,2*R-1,2*C-1); + col2(1,:,:) = defaultCol(1); + col2(2,:,:) = defaultCol(2); + col2(3,:,:) = defaultCol(3); + col2(:,1:2:end,1:2:end) = col; + col = reshape (col2,3,(2*R-1)*(2*C-1)); + end + R *= 2; C *= 2; end @@ -203,6 +271,10 @@ keepp = all (!isnan(pts) & finite(pts)) ; keepip = find (keepp); +if tex + [texX,texY] = meshgrid (linspace (0,1,C), linspace (0,1,R)); + texXY = [texX(:)'; texY(:)']; +end trgs = zeros(3,2*(R-1)*(C-1)) ; @@ -282,6 +354,9 @@ trgs(3,tmp) = trgs(1,tmp) - R + 1 - tmp3 ; end # EOF "upper" triangulation +#trgs = trgs(:,find(rem(1:R-1,2)'*rem(1:C-1,2))); + + if length (col) == 1 # Convert graylevel to RGB col = [1 1 1]*col; @@ -307,28 +382,33 @@ end # EOF zgray zrb and zcol options -if checker +if checker && numel (col) <= 6 if isnan (checker), checker = 10; end if length (checker) == 1, checker = [checker, checker]; end + + col = checker_color (checker, col, R,C); - if checker(1) > 0, checker(1) = - C/checker(1); end - if checker(2) > 0, checker(2) = - R/checker(2); end - checker *= -1; - colx = 2 * (rem (0:C-2,2*checker(1)) < checker(1)) - 1; - coly = 2 * (rem (0:R-2,2*checker(2)) < checker(2)) - 1; - icol = 1 + ((coly'*colx) > 0); + if 0 + if checker(1) > 0, checker(1) = - (C-1)/checker(1); end + if checker(2) > 0, checker(2) = - (R-1)/checker(2); end + + checker *= -1; + colx = 2 * (rem (0:C-2,2*checker(1)) < checker(1)) - 1; + coly = 2 * (rem (0:R-2,2*checker(2)) < checker(2)) - 1; + icol = 1 + ((coly'*colx) > 0); # Keep at most 1st 2 colors of col for the # checker - if prod (size (col)) == 2, - col = [1;1;1]*col; - elseif prod (size (col)) < 6, # Can't be < 3 because of previous code - col = col(1:3)(:); - if all (col >= 1-eps), col = [col [0;0;0]]; # Black and White - else col = [col [1;1;1]]; # X and White + if prod (size (col)) == 2, + col = [1;1;1]*col; + elseif prod (size (col)) < 6, # Can't be < 3 because of previous code + col = col(1:3)(:); + if all (col >= 1-eps), col = [col [0;0;0]]; # Black and White + else col = [col [1;1;1]]; # X and White + end end + col = reshape (col(:),3,2); + col = col(:,icol); end - col = reshape (col(:),3,2); - col = col(:,icol); end # EOF if checker @@ -394,11 +474,26 @@ end ## printf ("Calling vrml_faces\n"); -s = vrml_faces (pts, trgs, "col", col,\ - "colorPerVertex",colorPerVertex,\ - "creaseAngle", creaseAngle,\ - "tran", tran, "emit", emit,\ - "DEFcoord",DEFcoord,"DEFcol",DEFcol); +if !tex + s = vrml_faces (pts, trgs, "col", col,\ + "colorPerVertex",colorPerVertex,\ + "creaseAngle", creaseAngle,\ + "tran", tran, "emit", emit,\ + "DEFcoord",DEFcoord,"DEFcol",DEFcol); +else + texXY = texXY(:,keepip); +# texXY(:,[1:5,232:236]) +# pts(:,[1:5,232:236]) +# trgs(:,1:20) +# [texXY; pts] +# trgs +# texXY(:,trgs(:)) +# R, C +# keyboard + s = vrml_faces (pts, trgs,\ + "tran", tran, "tex", tex, "tcoord", texXY,\ + "DEFcoord",DEFcoord,"DEFcol",DEFcol); +end ## printf ("Done\n"); ## R=5; C=11; ## x = ones(R,1)*[1:C]; y = [1:R]'*ones(1,C); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |