KerMor  0.9
Model order reduction for nonlinear dynamical systems and nonlinear approximation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
print2array.m
Go to the documentation of this file.
1 
2 
3 /* (Autoinserted by mtoc++)
4  * This source code has been filtered by the mtoc++ executable,
5  * which generates code that can be processed by the doxygen documentation tool.
6  *
7  * On the other hand, it can neither be interpreted by MATLAB, nor can it be compiled with a C++ compiler.
8  * Except for the comments, the function bodies of your M-file functions are untouched.
9  * Consequently, the FILTER_SOURCE_FILES doxygen switch (default in our Doxyfile.template) will produce
10  * attached source files that are highly readable by humans.
11  *
12  * Additionally, links in the doxygen generated documentation to the source code of functions and class members refer to
13  * the correct locations in the source code browser.
14  * However, the line numbers most likely do not correspond to the line numbers in the original MATLAB source files.
15  */
16 
17 function [A , bcol ] = print2array(fig,res,renderer) {
18 if nargin < 2
19  res = 1;
20  if nargin < 1
21  fig = gcf;
22  end
23 end
24 /* Warn if output is large */
25 old_mode = get(fig, " Units ");
26 set(fig, " Units ", " pixels ");
27 px = get(fig, " Position ");
28 set(fig, " Units ", old_mode);
29 npx = prod(px(3:4)*res)/1e6;
30 if npx > 30
31  /* 30M pixels or larger! */
32  warning(" MATLAB:LargeImage ", " print2array generating a %.1fM pixel image. This could be slow and might also cause memory problems. ", npx);
33 end
34 /* Retrieve the background colour */
35 bcol = get(fig, " Color ");
36 /* Set the resolution parameter */
37 res_str = [" -r " num2str(ceil(get(0, " ScreenPixelsPerInch ")*res))];
38 /* Generate temporary file name */
39 tmp_nam = [tempname " .tif "];
40 if nargin > 2 && strcmp(renderer, " -painters ")
41  /* Print to eps file */
42  tmp_eps = [tempname " .eps "];
43  print2eps(tmp_eps, fig, renderer, " -loose ");
44  try
45  /* Initialize the command to export to tiff using ghostscript */
46  cmd_str = [" -dEPSCrop -q -dNOPAUSE -dBATCH " res_str " -sDEVICE=tiff24nc "];
47  /* Set the font path */
48  fp = font_path();
49  if ~isempty(fp)
50  cmd_str = [cmd_str " -sFONTPATH=' " fp " ' "];
51  end
52  /* Add the filenames */
53  cmd_str = [cmd_str " -sOutputFile=' " tmp_nam " ' ' " tmp_eps " ' "];
54  /* Execute the ghostscript command */
55  ghostscript(cmd_str);
56  catch me
57  /* Delete the intermediate file */
58  delete(tmp_eps);
59  rethrow(me);
60  end
61  /* Delete the intermediate file */
62  delete(tmp_eps);
63  /* Read in the generated bitmap */
64  A = imread(tmp_nam);
65  /* Delete the temporary bitmap file */
66  delete(tmp_nam);
67  /* Set border pixels to the correct colour */
68  if isequal(bcol, " none ")
69  bcol = [];
70  elseif isequal(bcol, [1 1 1])
71  bcol = uint8([255 255 255]);
72  else
73  for l = 1:size(A, 2)
74  if ~all(reshape(A(:,l,:) == 255, [], 1))
75  break;
76  end
77  end
78  for r = size(A, 2):-1:l
79  if ~all(reshape(A(:,r,:) == 255, [], 1))
80  break;
81  end
82  end
83  for t = 1:size(A, 1)
84  if ~all(reshape(A(t,:,:) == 255, [], 1))
85  break;
86  end
87  end
88  for b = size(A, 1):-1:t
89  if ~all(reshape(A(b,:,:) == 255, [], 1))
90  break;
91  end
92  end
93  bcol = uint8(median(single([reshape(A(:,[l r],:), [], size(A, 3)); reshape(A([t b],:,:), [], size(A, 3))]), 1));
94  for c = 1:size(A, 3)
95  A(:,[1:l-1, r+1:end],c) = bcol(c);
96  A([1:t-1, b+1:end],:,c) = bcol(c);
97  end
98  end
99 else
100  if nargin < 3
101  renderer = " -opengl ";
102  end
103  err = false;
104  /* Set paper size */
105  old_pos_mode = get(fig, " PaperPositionMode ");
106  old_orientation = get(fig, " PaperOrientation ");
107  set(fig, " PaperPositionMode ", " auto ", " PaperOrientation ", " portrait ");
108  try
109  /* Print to tiff file */
110  print(fig, renderer, res_str, " -dtiff ", tmp_nam);
111  /* Read in the printed file */
112  A = imread(tmp_nam);
113  /* Delete the temporary file */
114  delete(tmp_nam);
115  catch ex
116  err = true;
117  end
118  /* Reset paper size */
119  set(fig, " PaperPositionMode ", old_pos_mode, " PaperOrientation ", old_orientation);
120  /* Throw any error that occurred */
121  if err
122  rethrow(ex);
123  end
124  /* Set the background color */
125  if isequal(bcol, " none ")
126  bcol = [];
127  else
128  bcol = bcol * 255;
129  if isequal(bcol, round(bcol))
130  bcol = uint8(bcol);
131  else
132  bcol = squeeze(A(1,1,:));
133  end
134  end
135 end
136 /* Check the output size is correct */
137 if isequal(res, round(res))
138  px = [px([4 3])*res 3];
139  if ~isequal(size(A), px)
140  /* Correct the output size */
141  A = A(1:min(end,px(1)),1:min(end,px(2)),:);
142  end
143 end
144 return
145 
146 /* Function to return (and create, where necessary) the font path */
147 }
158 function fp = print2array>font_path() {
159 fp = user_string(" gs_font_path ");
160 if ~isempty(fp)
161  return
162 end
163 /* Create the path
164  * Start with the default path */
165 fp = getenv(" GS_FONTPATH ");
166 /* Add on the typical directories for a given OS */
167 if ispc
168  if ~isempty(fp)
169  fp = [fp " ; "];
170  end
171  fp = [fp getenv(" WINDIR ") filesep " Fonts "];
172 else
173  if ~isempty(fp)
174  fp = [fp " : "];
175  end
176  fp = [fp " /usr/share/fonts:/usr/local/share/fonts:/usr/share/fonts/X11:/usr/local/share/fonts/X11:/usr/share/fonts/truetype:/usr/local/share/fonts/truetype "];
177 end
178 user_string(" gs_font_path ", fp);
179 return
180 
181 }
182 
function string = user_string(string_name, string)
Definition: user_string.m:17
function fp = print2array>font_path()
Definition: print2array.m:158
function print2eps(name, fig, varargin)
Definition: print2eps.m:17
function [ A , bcol ] = print2array(fig, res, renderer)
Generate default input arguments, if needed.
Definition: print2array.m:17
Speed test * all(1:3)
function varargout = ghostscript(cmd)
Initialize any required system calls before calling ghostscript.
Definition: ghostscript.m:17