]> Creatis software - CreaPhase.git/blob - octave_packages/vrml-1.0.13/vrml_lines.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / vrml-1.0.13 / vrml_lines.m
1 ## Copyright (C) 2002 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_lines(x,f,...)
17 ##
18 ## x : 3xP   : The 3D points
19 ## f : 3xQ   : The indexes of the points forming the lines. Indexes
20 ##             should be in 1:P.
21 ##
22 ## Returns a Shape -> IndexedLineSet vrml node.
23 ##
24 ## No check is done on anything
25 ##
26 ## Options :
27 ## 
28 ## "col" , col  : 3x1 : Color, default = [1,0,0]
29
30 function s = vrml_lines(x,f,varargin)
31
32 if nargin < 2, f = ones (1,columns(x)); end
33 col = [1, 0, 0] ;
34
35 opt1 = " col " ;
36 opt0 = " " ;
37
38 verbose = 0 ;
39
40 i=1;
41
42 while (nargin -2) >=i ,
43
44   tmp = varargin{i++} ; # pos 2.1.39
45   if ! ischar(tmp) ,
46     error ("vrml_lines : Non-string option : \n") ;
47     ## keyboard
48
49   end
50   if index(opt1,[" ",tmp," "]) ,
51     
52
53     tmp2 = varargin{i++}; # pos 2.1.39
54     ## args-- ;
55     eval([tmp,"=tmp2;"]) ;
56
57     if verbose , printf ("vrml_lines : Read option : %s.\n",tmp); end
58
59   elseif index(opt0,[" ",tmp," "]) ,
60     
61     eval([tmp,"=1;"]) ;
62     if verbose , printf ("vrml_lines : Read boolean option : %s\n",tmp); end
63
64   else
65     error ("vrml_lines : Unknown option : %s\n",tmp) ;
66     ## keyboard
67   end
68 endwhile
69
70 if exist("col")!=1,  col = [0.5, 0.5, 0.8]; end
71
72 s = sprintf([...                        # string of indexed face set
73              "Shape {\n",...
74              "  appearance Appearance {\n",...
75              "    material Material {\n",...
76              "      diffuseColor %8.3f %8.3f %8.3f \n",...
77              "      emissiveColor %8.3f %8.3f %8.3f\n",...
78              "    }\n",...
79              "  }\n",...
80              "  geometry IndexedLineSet {\n",...
81              "    coordIndex [\n%s]\n",...
82              "    coord Coordinate {\n",...
83              "      point [\n%s]\n",...
84              "    }\n",...
85              "  }\n",...
86              "}\n",...
87              ],...
88             col,col,...
89             sprintf("                    %4d, %4d, %4d, -1,\n",f-1),...
90             sprintf("                 %8.3f %8.3f %8.3f,\n",x)) ;
91
92
93 endfunction
94