All text is lost when using openGL rendering in batch mode

When starting MATLAB in batch mode without displaying (for example, when the $DISPLAY UNIX environment variable is disabled or when the matlab -nodisplay sign is started), you usually cannot use the opengl renderer tool. Instead, you should agree to render painters . For example:

 >> print -dpng -opengl fig.png Warning: OpenGL mode can not be used in terminal emulation mode; ignoring option. 

Unfortunately, painters often give poor results when working with 3D scenes with patches, lighting, transparency, etc. Here is one simple example (using display at the moment) where alpha is lost:

 peaks alpha(0.5) print -dpng -opengl peaks_opengl.png print -dpng -painters peaks_painters.png 

enter image description here


Due to these limitations, I was very happy to find the mostly undocumented MATLAB hardcopy() built-in function, which somehow allows the use of the opengl renderer without display. This function underlies the awesome export_fig() function. Now I can save high-quality 3D shapes in batch mode very quickly.

However, there is one catch: All text is lost when the shape passes through the hardcopy() function. For example:

 plot(1,1) title('TEST') 
 >> A = hardcopy(gcf, '-Dopengl', '-r300'); Warning: Failed to draw text string > In /Applications/MATLAB_R2010b.app/toolbox/matlab/graphics/hardcopy.p>hardcopy at 21 

The output indicator is completely devoid of any text (without a tick mark of the axis and without a name):

 export_fig axis.png -opengl 

enter image description here

So I'm wondering: How can I get the opengl handler to work with text in batch mode? Is there a way to make text work with hardcopy() function? Perhaps a way to rasterize the text in advance? Or a way to combine the painters hard copy of the text and the opengl hard copy of the plot? Alternatively, is there a completely different way to do this than the hardcopy() function? Also note that the problem is unlikely to be related to my system setup, as it plays on both Mac OS and Ubuntu.

+7
source share
1 answer

If you use Linux, you can use OpenGL software rendering (there is one bundle in modern versions of Matlab ). This option does not exist for Mac OS, at least not with current versions of Matlab . Windows is easy - even batch mode starts displaying, so you can work as usual.

  • Launch Xvfb :1 & , which creates the (virtual) framebuffer X server.
  • Prepare your code in some file, say bla.m :

     opengl software; peaks alpha(0.5); print -dpng -opengl peaks_opengl.png exit 

    It is very important not to forget opengl software , as you imagine.

  • Run the following command:

     cat bla.m | matlab -display :1 -logfile log.txt 

    which makes Matlab execute everything in bla.m on a virtual display and writes any Matlab outputs to log.txt . You can delete the log file when everything works. Also note that :display :1 must match the number specified in the Xvfb call.

  • Profit

+8
source

All Articles