1 ## Copyright (C) 2002 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 ## s = vrml_points(x,options)
18 ## x : 3xP : 3D points
20 ## Makes a vrml2 "point [ ... ]" node from a 3xP matrix x.
22 ## OPTIONS (name and size/type, if applicable):
23 ## ---------------------------------------
24 ## "balls" : Displays spheres rather than points. Overrides the
25 ## "hide" options and no Coordinate node is defined;makes
26 ## "name" ineffective.
29 ## "cubes" : Displays cubes rather than points. Overrides the "hide"
30 ## options and no Coordinate node is defined;makes "name"
33 ## "rad", 1 or P: Radius of balls/size of cubes. default = 0.1
35 ## "nums" : Displays numbers rather than points. Overrides the
36 ## "hide" options and no Coordinate node is defined;
37 ## makes "name" ineffective.
39 ## WARNING : This option seems to make freewrl 0.34 hang, so that it
40 ## is necessary to kill it (do vrml_browse ("-kill")). Other
41 ## browsers can can view the code produced by this option.
43 ## "col", 3x1 : Points will have RGB col. default = [0.3,0.4,0.9]
44 ## or 3xP : The color of each point.
45 ## "tran", 1x1 : Transparency default = 0
46 ## "emit", e : Use or not emissiveColor default = 1
48 ## "name", str : The Coordinate node will be called name
49 ## (default="allpoints").
50 ## "hide" : The points will be defined, but not showed.
52 function s = vrml_points(x,varargin)
55 cubes = balls = nums = 0;
67 if strcmp(tmp,"hide") ,
69 elseif strcmp(tmp,"balls") ,
71 elseif strcmp(tmp,"cubes") || strcmp(tmp,"boxes") ,
73 elseif strcmp(tmp,"rad") ,
76 elseif strcmp(tmp,"nums") ,
78 elseif strcmp(tmp,"emit") ,
81 elseif strcmp(tmp,"col") ,
84 elseif strcmp(tmp,"name") ,
87 elseif strcmp(tmp,"tran") ,
96 error ("vrml_points : input is neither 3xP or Px3\n");
102 if !balls && !cubes && !nums,
104 if prod (size (col)) == 3*P # One color per point
106 scol = sprintf (" color Color { color [\n %s]\n }\n",\
107 sprintf (" %8.3f %8.3f %8.3f\n", col));
109 smat = [" appearance Appearance {\n",\
110 vrml_material(col, emit),"\n",\
115 s = sprintf(["Shape {\n",\
117 " geometry PointSet {\n",\
119 " coord DEF %s Coordinate {\n point [\n " ],name); # ]
122 s0 = sprintf("%10.6g %10.6g %10.6g ,\n ",x);
124 s = sprintf("%s%s]\n }\n }\n }\n",s,s0); # [
126 if hide, s = ["Switch {\nchoice\n[\n",s,"\n]\n}"]; end
132 if prod (size (col)) == 3, col = col(:) * ones (1,P); end
136 " translation %10.6g %10.6g %10.6g\n",\
137 " children [\n",\ # ]
139 " children [\n",\ # ]
141 " appearance Appearance {\n",\
142 vrml_material(col(:,i), emit, tran),"\n",\
144 " geometry Text {\n",\
146 " fontStyle FontStyle { size 0.25 }\n",\
153 x(:,i),sprintf("%d",i-1));
154 ## x(:,i),col,col,sprintf("%d",i-1));
155 ## " emissiveColor %8.3f %8.3f %8.3f\n",\
156 ## " axisOfRotation 0.0 0.0 0.0\n",\
158 s = sprintf("%s%s",s,s0);
161 # If all radiuses are the same, do a single
162 # geometry node for all points
163 if all (size (rad) == 1) || ! any (abs (diff (rad))>eps)
165 if balls, shapestr = sprintf("Sphere { radius %8.3f}",rad) ;
166 else shapestr = sprintf("Box { size %8.3f %8.3f %8.3f}",rad,rad,rad) ;
172 # If all colors are the same, do a single
173 # geometry node for all points
174 if prod (size (col)) == 3 || ! any (abs (diff (col'))>eps)
176 colorstr = vrml_material (col(1:3), emit);
183 # If some radiuses differ, I must do
184 # geometry nodes individually
186 # Skip zero-sized objects
187 if ! rad(:,i), continue; end
190 shapestr = sprintf("Sphere { radius %8.3f}",rad(:,i));
192 shapestr = sprintf("Box { size %8.3f %8.3f %8.3f}",rad(:,[i,i,i]));
195 # If some colors differ, I must do material
197 if ! all_same_col, colorstr = vrml_material (col(:,i), emit); end
201 " translation %10.6g %10.6g %10.6g\n",\
202 " children [\n",\ # ]
204 " appearance Appearance {\n",\
207 " geometry ",shapestr,"\n",\
212 ## " emissiveColor %8.3f %8.3f %8.3f\n",\
213 ## x(:,i),col,col,shape);
214 s = sprintf("%s%s",s,s0);