1 ## Copyright (C) 2002-2012 Etienne Grossmann <etienne@egdn.net>
3 ## This program is free software; you can redistribute it and/or modify it under
4 ## the terms of the GNU General Public License as published by the Free Software
5 ## Foundation; either version 3 of the License, or (at your option) any later
8 ## This program is distributed in the hope that it will be useful, but WITHOUT
9 ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13 ## You should have received a copy of the GNU General Public License along with
14 ## this program; if not, see <http://www.gnu.org/licenses/>.
16 ## v = vrml_frame (t, r, ...)
18 ## t : 3 Translation Default : [0,0,0]
19 ## r : 3x3 Matrix, or Default : eye(3)
20 ## 3 Argument for rotv
22 ## name : size : function : default
23 ## "scale" : 3 or 1 : Length of frame's branches (including cone) <1>
24 ## "diam" : 3 or 1 : Diameter of cone's base
25 ## "col" : 3 or 3x3 : Color of branches (may be stacked vertically) <[3 4 9]/10>
26 ## "hcol" : 3 or 3x3 : Color of head (may be stacked vertically) <col>
29 function v = vrml_frame (varargin)
31 ### Test with : frame with R,G,B vectors of len 3,2,1 and cone's diam are .2,
34 ### vrml_browse (vrml_frame ("scale",[3,2,1],"diam",0.2*[1,2,3],"col",eye(3)));
47 ######################################################################
50 args = nargin; # nargin is now a function
51 while args && numeric_args<2 && numeric_args<numel(varargin)
52 tmp = varargin{numeric_args + 1};
53 if ischar (tmp), break; end
56 if numeric_args == 1, t = tmp ;
63 leftover_args = {varargin{numeric_args+1:end}}; # pos 2.1.39
67 ## df = tars (col, hcol, diam, scale, verbose);
68 df = struct ("dc", dc, \ # Diameter of cone (absolute)
69 "dr", dr, \ # Diameter of rod (absolute)
71 "hcol", hcol, \ # Color of head (if different)
72 "diam", diam, \ # Diameter of cone relative to branch length
73 "scale", scale, \ # Lenght of branches
75 op1 = " col hcol diam scale dc dr ";
77 s = read_options (leftover_args, "op1",op1,"op0",op0,"default",df,"skipnan",1);
86 ######################################################################
87 if isempty (hcol), hcol = col; end
91 if prod (size (r)) == 3, r = rotv (r); end
93 ## col is 3x3 from now on
94 if prod (size (col))==3, col = [1;1;1]*col(:)' ; end
95 if prod (size (hcol))==3, hcol = [1;1;1]*hcol(:)' ; end
96 if prod (size (diam))==1, diam = [1,1,1]*diam ; end
97 if prod (size (scale))==1, scale = [1,1,1]*scale ; end
101 diam = - ones(1,3) * nanmax (scale) / 16;
102 rdiam = - ones(1,3) * nanmax (scale) / 32;
104 sz = [scale; nan*ones(1,3); diam; rdiam] ;
106 if any (! isnan (dc))
107 ii = find (! isnan (dc));
110 if any (! isnan (dr))
111 ii = find (! isnan (dr));
116 ## roddiam = min (nze (scale))/12 ;
117 ## if roddiam, d = roddiam.*scale ; else d = [nan,nan,nan] ; end
119 ## diam = diam.*scale ;
120 ## d = diam = nan*scale;
122 n = sqrt (sum (r2.^2));
128 tmp = [r2(:,1), null(r2(:,1)')](:,[2,1,3])';
129 if det (tmp) < 0, tmp(3,:) *= -1; end
130 a1 = vrml_transfo (vrml_arrow(sz(:,1),[col(1,:);hcol(1,:)],0),\
133 tmp = [r2(:,2), null(r2(:,2)')](:,[2,1,3])';
134 if det (tmp) < 0, tmp(3,:) *= -1; end
135 a2 = vrml_transfo (vrml_arrow(sz(:,2),[col(2,:);hcol(2,:)],0),\
138 tmp = [r2(:,3), null(r2(:,3)')](:,[2,1,3])';
139 if det (tmp) < 0, tmp(3,:) *= -1; end
140 a3 = vrml_transfo (vrml_arrow(sz(:,3),[col(3,:);hcol(3,:)],0),\
143 f0 = vrml_group (a1, a2, a3);
144 v = vrml_transfo (f0, t, nan);