]> Creatis software - CreaPhase.git/blob - octave_packages/vrml-1.0.13/test_vrml_faces.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / vrml-1.0.13 / test_vrml_faces.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 ## Test that vrml_faces works with "tex" option
17
18 1;
19
20 ## Tetrahedron : Vertices
21 x = [ 1  1 -1  0;
22      -1  1  0  0;
23      -1 -1 -1  1];
24
25 ## Tetrahedron : Faces
26 trg = [1 2 3 1;
27        2 3 1 2;
28        4 4 4 3];
29
30 trgl = {[1 2 4],[2 3 4],[3 1 4],[1 2 3]};
31
32 slight = vrml_PointLight ("location", [0,5,0]);
33
34 if 1
35   s1 = vrml_faces (x, trg);
36
37   printf ("Going to show a tetrahedron\n");
38
39   printf (["\n     If nothing appears, it may be due to problems",\
40            "\n     with your FreeWRL installation\n"]);
41   vrml_browse ([slight, s1]);
42   printf ("Press a key in this terminal when done\n");pause;
43 end
44
45 if 1
46   s1 = vrml_faces (x, trgl,"col",[1,0.5,0.5]);
47
48   printf ("Going to show almost the same tetrahedron\n");
49
50   printf (["\n     If nothing appears, it may be due to problems",\
51            "\n     with your FreeWRL installation\n"]);
52   vrml_browse ([slight, s1]);
53   printf ("Press a key in this terminal when done\n");pause;
54 end
55
56 if 1
57   s1 = vrml_faces (x, trg, "col",[1 0 0 1;0 1 0 1;0 0 1 1]);
58
59   printf ("Coloring the vertices\n");
60   vrml_browse ([slight, s1]);
61   printf ("Press a key in this terminal when done\n");pause;
62 end
63 if 1
64   s1 = vrml_faces (x, trg, "col",[1 0 0 1;0 1 0 1;0 0 1 1],"colorPerVertex",0);
65
66   printf ("Coloring the faces\n");
67   vrml_browse ([slight, s1]);
68   printf ("Press a key in this terminal when done\n");pause;
69 end
70
71 ## Texture :
72 H = 50;
73 W = 100;                        # Texture width
74 w = floor (W/2);
75 h = floor (H/2);
76 tr = tg = tb = zeros (H,W+1);
77 [j,i] = meshgrid (1:W+1,1:H);
78
79 tr(find (i<=h & i*W>=j*H       )) = 1;
80 tg(find (i> h & i*W>=(j+w)*H     )) = 1;
81 tb(find (i> h & i*W>=j*H     & j> w)) = 1;
82
83
84 if 0
85
86   if 1
87     whiten = find(!(tr | tg | tb));
88     tr(whiten) = 1;
89     tg(whiten) = 1;
90     tb(whiten) = 1;
91   end
92   
93   t0 = reshape (255*[tr;tg;tb], H,(W+1)*3);
94   t0 = t0 + 0.75 * rot90 (t0,2);
95   t0 = [t0, 0.5*t0];
96   tex = mat2ims (t0,1);
97
98 ## ims_show (tex);
99
100
101   texfile = [pwd(),"/mytexfile.ppm"];
102   ims_save (tex, texfile);
103
104   s1 = vrml_faces (x, trg, "tex",texfile,"imsz",[H,W]);
105   s2 = vrml_faces (x, trg, "tex",texfile);
106
107   printf (["Tetrahedrons should appear like (R=red, G=green, B=blue)\n\n",\
108            "              R 2\n",\
109            "               /\n",\
110            "              / G\n",\
111            "     G     B /\n",\
112            "   3--------4 B\n",\
113            "     R     B \\\n",\
114            "              \\ R\n",\
115            "             G \\\n",\
116            "                 1\n"]);
117   
118   vrml_browse ([slight, s1, vrml_transfo(s2,[2,0,0])]);
119 end
120
121
122
123
124
125