]> Creatis software - CreaPhase.git/blob - octave_packages/vrml-1.0.13/vrml_interp.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / vrml-1.0.13 / vrml_interp.m
1 ## Copyright (C) 2005-2012 Etienne Grossmann <etienne@egdn.net>
2 ##
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
6 ## version.
7 ##
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
11 ## details.
12 ##
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/>.
15
16 ## s = vrml_interp (typ, val,...)
17
18 function s = vrml_interp (typ, val, varargin)
19
20 key = [];
21 DEF = "";
22 if nargin < 1, help vrml_interp; return; end
23 if nargin < 2
24   val = [];
25 elseif nargin > 2
26   op1 = " key DEF ";
27   df = tars (key, DEF);
28   s = read_options (varargin, "op1", op1, "default", df);
29   [key, DEF] = getfields (s, "key", "DEF");
30 end
31
32
33 persistent nname = struct ("col"        , "Color",
34                        "Color"      , "Color",
35                        "coord"      , "Coordinate",
36                        "Coordinate" , "Coordinate",
37                        "normal"     , "Normal",
38                        "Normal"     , "Normal",
39                        "orient"     , "Orientation",
40                        "Orientation", "Orientation",
41                        "pos"        , "Position",
42                        "Position"   , "Position",
43                        "scal"       , "Scalar",
44                        "Scalar"     , "Scalar");
45 if isfield (nname, typ)
46   typs = nname.(typ);
47 elseif ischar(typ)
48 #  e2 = leval ("sprintf",\
49 #             append (list("    '%s'\n"), fieldnames (nname)));
50   e2 = sprintf("    '%s'\n", fieldnames (nname){:});
51   error ("vrml_interp : Unknown type '%s'. Should be in:\n%s",typ,e2);
52 else
53 #  e2 = leval ("sprintf",\
54 #             append (list("    '%s;\n"), fieldnames (nname)));
55   e2 = sprintf("    '%s'\n", fieldnames (nname){:});
56   error ("vrml_interp : typ should be a string in:\n%s",typ,e2);
57 end
58
59 if isempty (val)
60   vs = "";
61 else 
62   vs = sprintf ("%8.5f, ", val);
63   vs = sprintf ("    keyValue [ %s ]\n", vs(1:length(vs)-2));
64 end
65 if isempty (key)
66   ks = "";
67 else              
68   ks = sprintf ("%8.5f, ", key);
69   ks = sprintf ("    key [ %s ]\n", ks(1:length(ks)-2));
70 end
71 if length (DEF),  defs = ["DEF ",DEF," "];
72 else              defs = "";
73 end 
74
75 s = [defs,typs,"Interpolator {\n", vs, ks,"}\n"];endfunction
76