source: proiecte/pmake3d/make3d_original/Make3dSingleImageStanford_version0.1/third_party/vlutil/toolbox/tightsubplot.m @ 37

Last change on this file since 37 was 37, checked in by (none), 14 years ago

Added original make3d

File size: 3.8 KB
Line 
1function H = tightsubplot(varargin)
2% TIGHTSUBPLOT  Tiles axes without wasting space
3%   H = TIGHTSUBPLOT(K,P) returns an handle to the P-th axis in a
4%   regular grid of K axes. The K axes are numbered from left to right
5%   and from top to bottom.  The function operates similarly to
6%   SUBPLOT(), but by default it does not put any margin between axes.
7%
8%   H = TIGHTSUBPLOT(M,N,P) retursn an handle to the P-th axes in a
9%   regular subdivision with M rows and N columns.
10%
11%   The function accepts the following option-value pairs:
12%
13%   'Spacing' [0]
14%     Set extra spacing between axes.  The space is added between the
15%     inner or outer boxes, depending on the setting below.
16%
17%   'Box' ['inner'] (** ONLY >R14 **)
18%     If set to 'outer', the function displaces the axes by their
19%     outer box, thus protecting title and labels. Unfortunately
20%     MATLAB typically picks unnecessarily large insets, so that a bit
21%     of space is wasted in this case.  If set to 'inner', the
22%     function uses the inner box. This causes the instets of nearby
23%     axes to overlap, but it is very space conservative.
24%
25%   REMARK. While SUBPLOT kills any pre-existing axes that overalps a
26%   new one, this function does not.
27%
28%   See also SUBPLOT().
29
30% AUTORIGHTS
31% Copyright (C) 2006 Andrea Vedaldi
32%       
33% This file is part of VLUtil.
34%
35% VLUtil is free software; you can redistribute it and/or modify
36% it under the terms of the GNU General Public License as published by
37% the Free Software Foundation; either version 2, or (at your option)
38% any later version.
39%
40% This program is distributed in the hope that it will be useful,
41% but WITHOUT ANY WARRANTY; without even the implied warranty of
42% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
43% GNU General Public License for more details.
44%
45% You should have received a copy of the GNU General Public License
46% along with this program; if not, write to the Free Software Foundation,
47% Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
48
49sp=0.0 ;
50use_outer=0 ;
51
52% --------------------------------------------------------------------
53%                                                      Parse arguments
54% --------------------------------------------------------------------
55K=varargin{1} ;
56p=varargin{2} ;
57N = ceil(sqrt(K)) ;
58M = ceil(K/N) ;
59
60a=3 ;
61NA = length(varargin) ;
62if NA > 2
63  if isa(varargin{3},'char')
64    % Called with K and p
65  else
66    % Called with M,N and p
67    a = 4 ;
68    M = K ;
69    N = p ;
70    p = varargin{3} ;
71  end
72end
73
74for a=a:2:NA
75  switch varargin{a}
76    case 'Spacing'
77      sp=varargin{a+1} ;
78    case 'Box'     
79      switch varargin{a+1}
80        case 'inner'
81          use_outer = 0 ;
82        case 'outer'
83        if ~strcmp(version('-release'), '14')
84          %warning(['Box option supported only on MATALB 14']) ;
85          continue;
86        end
87        use_outer = 1 ;
88        otherwise
89          error(['Box is either ''inner'' or ''outer''']) ;
90      end
91    otherwise
92      error(['Uknown parameter ''', varargin{a}, '''.']) ;
93  end     
94end
95
96% --------------------------------------------------------------------
97%                                                  Check the arguments
98% --------------------------------------------------------------------
99
100[j,i]=ind2sub([N M],p) ;
101i=i-1 ;
102j=j-1 ;
103
104dt = sp/2 ;
105db = sp/2 ;
106dl = sp/2 ;
107dr = sp/2 ;
108
109pos = [  j*1/N+dl,...
110       1-i*1/M-1/M+dt,...
111       1/N-dl-dr,...
112       1/M-dt-db] ;
113
114switch use_outer
115  case 0
116    H = findobj(gcf, 'Type', 'axes', 'Position', pos) ;
117    if(isempty(H))
118      H = axes('Position', pos) ;
119    else
120      axes(H) ;
121    end
122   
123  case 1
124    H = findobj(gcf, 'Type', 'axes', 'OuterPosition', pos) ;
125    if(isempty(H))
126      H = axes('ActivePositionProperty', 'outerposition',...
127               'OuterPosition', pos) ;
128    else
129      axes(H) ;
130    end
131end   
Note: See TracBrowser for help on using the repository browser.