]> Creatis software - CreaPhase.git/blob - octave_packages/vrml-1.0.13/vrml_parallelepiped.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / vrml-1.0.13 / vrml_parallelepiped.m
1 ## Copyright (C) 2007-2010 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_parallelogram (bnds,...)
17 ##
18 ## bnds = [xmin, ymin, zmin; xmax, ymax, zmax]
19 ##
20 ## OPTIONS :
21 ## ---------
22 ## col,   c : 3x1 : Color of surface
23 ## emit,  e : 1   :
24 ## tran,  t : 1   :
25 ##
26 ## border,b : 1   :
27 ## bocol, c : 3   :
28 ## boemit,e : 1   :
29 ## borad, r : 1   :
30 ##
31 ## balls, b : 1   :
32 ## bcol,  c : 3   :
33 ## bemit, e : 1   :
34 ## brad,  r : 1   :
35
36 function s = vrml_parallelepiped (bnds, varargin)
37
38 col = [0.3,0.4,0.9];
39 emit = 0;
40 tran = 0;
41 balls = 0;
42 border = 0;
43 bcol = btran = bemit = brad = borad = bocol = boemit = nan;
44
45 if !isnumeric (bnds)
46   error ("bnds must be a 2 x 3 matrix, not a %s",typeinfo(bnds));
47 endif
48 if prod (size (bnds)) != 6
49   error ("bnds must be 2 x 3, not %s",sprintf("%i x ",size(bnds))(1:end-3));
50 endif
51 if nargin > 1
52   op1 = " col emit tran balls border bcol btran bemit brad borad bocol boemit ";
53   df = tars (col,emit,tran,balls,border,bcol,btran,bemit,brad,borad,bocol,boemit);
54   s = read_options (varargin, "op1",op1, "default",df);
55   col=s.col; emit=s.emit; tran=s.tran; balls=s.balls; border=s.border;
56   bcol = s.bcol; btran = s.btran; bemit = s.bemit; brad = s.brad;
57   borad = s.borad; bocol = s.bocol; boemit = s.boemit;
58 end
59
60 if ! isnan (bcol) ||! isnan (brad) || ! isnan (bemit), balls = 1; end
61 if balls
62  if isnan (bcol), bcol = col; end
63  if isnan (btran), btran = tran; end
64  if isnan (brad)
65    brad = (max (abs (diff(bnds))))/20; 
66  end
67 end
68
69 x = [bnds([1 2 2 1 1 2 2 1],1)';\
70      bnds([1 1 2 2 1 1 2 2],2)';\
71      bnds([1 1 1 1 2 2 2 2],3)'];
72
73 faces = [1 2 3 4;\
74          5 6 7 8;\
75          1 2 6 5;\
76          2 3 7 6;\
77          3 4 8 7;\
78          4 1 5 8]';
79
80                                 # The facet
81 s = vrml_faces (x,faces,"col",col, "tran", tran,"emit",emit);
82
83                                 # Decoration : balls on vertices
84 if balls
85   if isnan (bemit), bemit = emit; end
86   s = [s,vrml_points(x,"balls","rad",brad,"col",bcol,"tran",btran,"emit",bemit)];
87 end
88
89                                 # Decoration : border
90
91 if ! isnan (bocol) ||! isnan (borad) || ! isnan (boemit), border = 1; end
92 if border
93   if isnan (borad)
94     borad = (norm (x(:,1)-x(:,2))+ norm(x(:,1)-x(:,2)))/80;
95   end
96   if isnan (boemit)
97     if isnan (bemit), boemit = emit; else boemit = bemit; end
98   end
99   if isnan (bocol), bocol = col; end
100     
101   if !balls                     # Make pretty junctions of cylinders
102     s = [s,\
103          vrml_cyl(x(:,[1:columns(x),1]),"rad",borad,"emit",boemit,"col",col),\
104          vrml_points(x(:,1),"balls","rad",borad,"emit",boemit,"col",col)];
105   else                          # but only if balls don't cover them
106     s = [s,vrml_cyl(x(:,[1:columns(x),1]),"rad",borad,"emit",boemit)];
107   end
108
109 end
110
111 endfunction
112