How to prevent LATEX-labels in MATLAB GUI to become blurry? - user-interface

Within my current MATLAB GUI project, i have two axes objects. The first is used by the workaround "uibutton" (I don't use GUIDE) in order to display a LaTeX-formula (as far as I know, only axes labels are capable to use LaTeX whereas normal static text fields aren't...). The other axes object is used to actually plot a 3D-function.
The program has the following steps:
the first axes creats the LATEX-formula (e.g. f(x)=).
User enters a function in the edit field after the LaTeX-formula (e.g. f(x)=a+b).
User presses a "plot"-button.
3D-function is plotted in the second axes object.
Problem:
As soon as the 3D-function is plotted, the nicely rendered LaTeX-formular becomes crisp. Is there any way to prevent this from happening?
http://i42.tinypic.com/348pq2u.png (See picture for problem demonstration)

Check your figure properties before and after you draw the 3D plot
get(gcf, 'renderer')
My guess is that plotting the 3D function changes the renderer from the default ("painters") to another (likely OpenGL). Matlab's Latex rendering does not seem to play well with zbuffer or OpenGL (these produce bitmaps rather than line art).
You may be stuck if painters can't render your 3D graphics properly, but you can try to force it by setting the renderer manually back to painters
set(gcf, 'renderer', 'painters')

Related

Sprite sheet used for diffuse animation

I'm trying to use a sprite sheet in my background animation. The sprite sheet is made up of multiple objects of varying sizes and shapes. I want the sizes/shapes to be used consecutively in a "floating" type backgound animation. I have no clue how to start the code. Can't seem to find anything like this on the Stack Overflow site. Ps. I'm not trying to animate one (1) object (such as a running man). Please HELP!!
I tried using JS code for animating bubbles and just replacing with my script.png. It didn't work. The example background that I'm trying to duplicate is found at https://lusion.co - If you page down until you reach about the third page, you will find a colored background with floating objects, along with a scattered light and fog. Lusion used a sprite sheet for the objects. I have a copy of the sprite sheet. They seem to hide their code, so I can't use their site for learning.

Xcode GLKit printing Text on GLKView without using UIImages

I have an app, its a small game using opengles with GLKit.
No im wondering how it works when i want to draw text on
my screen (if it is possible).
How can i do it?
i draw all of my game objects using images (wrapped in some kind
of sprite). its possible to scale, to move, and to rotate.
everything works fine.
but finding out how it works to print text on that glkview
gets me deep inside of problems ^^
I dont want to use uiimages cause i also dont know how
to present uiimages on a glkview.
There are a number of ways to do what you want:
1) Have an image with all the text glyphs you need in it. For example, if your application is in English, you'd have the 26 uppercase and 26 lowercase letters in the image. Upload that texture to the GPU and use the proper texture coordinates or glSubTexImage2d() to pull out the glyphs you need. (It's not clear to me if this is what you meant by not wanting a UIImage. It doesn't have to be a UIImage, though that's probably easiest.)
2) Every time you need to display text, draw it on the CPU on the fly, and upload the entire word, phrase, or sentence as a texture. You could create a CGBitmapContext and use Core Graphics to draw text to it. Then upload it using glTexImage2D().
3) Get the individual glyphs out of the fonts and draw directly using the bezier curves that make up the glyphs. This allows for 3D extrusion, too. However, this option is the most time consuming to code and probably least performant. It also involves dealing with the many small problems that fonts have (like degenerate segments, and incorrect winding orders). IF you want to go down this path, I think maybe Core Text can help.
There are at least two clean ways to do this, depending on your requirements.
While documentation advises against compositing over a CAEAGLLayer (GLKView), it works quite well, at least in recent iOS versions, when transparent content is layered on top of the CAEAGLLayer. For example, try dropping a UITextView, with opaque set to false and a clear background color, on top of a GLKView in your Storyboard in Interface Builder in the Apple GLKit template or your app. In my test on an iPhone 5, frame rendering time remained around 1ms, even while scrolling in the text view. If your text needs are static, or you don't want the user to interact with the text, use CATextLayer as a child layer of your EAGLLayer instead of a view.
The second approach is to render the text into a texture. You can then composite the text onto your view by disabling the depth buffer and rendering the texture on a full screen rectangle. Look at UIGraphicsBeginImageContextWithOptions to see how to render to an offscreen image with Quartz. UIGraphicsGetImageFromCurrentImageContext allows you to retrieve the UIImage to use as a texture.

Getting a text included in a Mesh

i need some help in my webGL code.
I created a TextGeometry and i included it in a mesh, i didn't have any problem about that. However, i would like updating this text without creating another TextGeometry.
Indeed, my main goal is to translate a text (from right to left) and to make it disappear when he reaches to the left side, but only character by character (like a fade effect).
I tried some attempts : for example, according to text position, deleting it with a :
scene.remove(text)
and creating another text which is the same as previously minus the first character. I don't know if i was clear... But this solution makes my application very slow : that's why i don't want creating an Object every time, but just updating his text property.
I didn't find many help in three.js documentation, may you give me a hand about that ?
Cheers
You could try this:
Create a PlaneGeometry and texture it using the image from a hidden canvas object that contains your text, then apply image transforms to the canvas itself (fading as necessary) and continually update the texture in Three.js as it moves across the scene.
For an example of how to use a canvas object as an image (of text), I have an example posted at: http://stemkoski.github.com/Three.js/Texture-From-Canvas.html

How do I attach a text to the vertices of a cube in three.js? Also, Can I add a Text at any point inside the Cube?

I am trying to create a cube using three.js for a project. I need to add text to vertices and at different points inside the cube. Any idea how this can be done?
For some basic code examples of using Sprite objects in Three.js, check out:
http://stemkoski.github.com/Three.js/Sprites.html
And for an easy way to create images that contain text to use as your sprite textures, check out the sample code at:
http://stemkoski.github.com/Three.js/Texture-From-Canvas.html
I think a combination of these two ideas will achieve what you are looking to do.
If you want to have label-style texts, so that the text begins at a specific point, but is always oriented with the camera and easily readable no matter the camera position, you can use sprites. (example of canvas-created text label sprites: http://i.imgur.com/e9I68xD.jpg - here they are rendered on a separate pass to that they are never obscured by the scene but you can do it on the same pass)
If that's what you are looking for, I'd suggest first checking the Sprites examples, and learn to attach some static image as a sprite to correct position in the scene. After you get that working, you modify the code so that you generate the text to an image canvas using standard Javascript Canvas functions, and using that image as the sprite.

Can MATLAB generate, save, and then load axes into a gui axes object dynamically?

Edited for clarity:
I have a GUI that controls a script that generates approximately 40 plots. I want to display any given plot in the GUI window on demand by selecting its number in a drop-down box. The problem is that the plots take a while to generate so I would rather make them once and then load them as needed into the axes object in the GUI. The plots each have different properties, labels, legends, etc..
I tried generating figures and then saving them and trying to load that into the axes object in the GUI and it did not work.
If I initially make the plots using the axes object in the GUI as the target axes I can't save the plot and the legends, etc..
Is this possible in MATLAB?
If I understand the question correctly, you have a GUI with axes and a callback to plot stuff into the axes. For some reason, e.g. because plotting takes a while, you want to be able to save a specific plot and have the ability to reload it.
The easiest way to deal with this issue is to not put an axes object into your GUI, but to use a two-window GUI, where one window has all the controls, and the other is the figure into which you plot stuff. This is advantageous for several reasons: Saving/loading becomes easy, you have access to the figure toolbar, and you can resize etc the figure as you wish (resizing GUIs is generally hairy). You can store the handle to the axes of the figure in the GUI handle structure via SETAPPDATA and access it via GETAPPDATA. Note that you'll want to put a small check at the beginning of your plotting callback, where you check whether the figure still exists using ISHANDLE on the axes handle, and open a new figure if the check returns false.
If you really want to have an axes object in your GUI, the easiest is to just save the x and y data, as well as other properties of the plot that a user may be able to customize (whether the legend is on, or off, or the legend's position property), so that you can regenerate it on the fly.
If, for some reason it is not sufficient to save just properties, you can generate a hidden figure, and use COPYOBJ to copy the axes and its children to that figure, which you then save. However, this is rather clumsy and might come with all kinds of surprising annoyances.
You need to know the handles of axes within the figure. Otherwise it will be difficult to change the axes properties if the figure contains a newer axes object, because gca will refer to the new axes.
The axes can be accessed post figure generation through the figure object because individual axes of a figure are children of the figure object. The following code snippet may help you.
close all
subplot(2,1,1)
subplot(2,1,2)
hAxes = get(gcf, 'Children')
get(hAxes(1)) %shows axes properties of one axes obj
get(hAxes(2)) %shows axes properties of the other
set(hAxes(1), 'YTickLabel', ['a';'b';'c';'d';'e';'f']) %set an axis property
I'm guessing a bit here, but it sounds like you want to create a GUI with an axes that displays different plots, legends, etc. based on which item of a drop-down menu is selected. If this is right, I'm guessing the problem you are having is that plotting a new set of data in the axes causes the old data to be replaced, leaving you to have to regenerate the entire plot anew every time you select a new menu item.
One way I would consider approaching this problem would be to make use of UIPANELs and the 'Visible' property of graphics objects. You could create one panel per menu item, add an axes to each along with whatever data you wish to plot, then simply toggle the visibility of the panels using the SET command instead of replotting everything when a new menu item is selected. Here's an example:
hFigure = figure; %# Create a figure
hPanelA = uipanel('Parent',hFigure); %# Add panel A to the figure
hAxesA = axes('Parent',hPanelA); %# Add an axes to panel A
plot(hAxesA,1:10,rand(1,10),'r'); %# Plot a red line
text(5,0.5,'hello','Parent',hAxesA); %# Plot some text
legend(hAxesA,'red line'); %# Add a legend
hPanelB = uipanel('Parent',hFigure); %# Add panel B to the figure
hAxesB = axes('Parent',hPanelB); %# Add an axes to panel B
plot(hAxesB,1:10,rand(1,10),'b'); %# Plot a blue line
text(5,0.5,'world','Parent',hAxesB); %# Plot some text
legend(hAxesB,'blue line'); %# Add a legend
Now, you can make panel A visible and panel B invisible by doing the following:
set([hPanelA hPanelB],{'Visible'},{'on'; 'off'});
And you can do the reverse (hide panel A and show panel B) by doing this:
set([hPanelA hPanelB],{'Visible'},{'off'; 'on'});
You should notice that toggling between the two panels with their two separate axes is quick and smooth, which likely wouldn't be the case if you had to erase and replot data in a single set of axes every time you wanted to look at a new plot. Creating all the graphics objects you need when the GUI is created, then modifying the visibility (or other properties) as needed with the SET command makes for a more efficient GUI.
Also note that you can still modify object properties even when they are invisible, so (continuing from my example above) I could do something like this:
set([hPanelA hPanelB],{'Visible'},{'on'; 'off'}); %# Hide panel B
set(hPanelB,'BackgroundColor','b'); %# Change the color of panel B
set([hPanelA hPanelB],{'Visible'},{'off'; 'on'}); %# Show panel B
And now you should see that the background color of panel B is blue. If you also saved handles to your plotted lines and text, you could update them with new values before making them visible again.

Resources