## Archive for July, 2013

### Exit in matlab blocked by questdlg in finish.m

Wednesday, July 31st, 2013

I was using matlab with the -nodesktop option from the command line. I tried to exit but I was blocked by the following error message:


Error using figure
This functionality is no longer supported under the options used to start this instance of MATLAB. For more
information, see "Startup Option Changes on Mac" in the MATLAB Release Notes. To view the release note in your
system browser, run  web('http://www.mathworks.com/help/matlab/release-notes.html#startup_options_changes',
'-browser')

Error in getnicedialoglocation (line 19)
convertData.hFig = figure('visible','off');

Error in questdlg (line 140)
FigPos    = getnicedialoglocation(FigPos, get(0,'DefaultFigureUnits'));

Error in finish (line 1)
button = questdlg('Are you sure you want to quit?', 'Exit Dialog','Cancel','Quit','Cancel');


The problem was that I have placed a safety prompt in my finish.m script that double checks whether I want to quit. But with the nodesktop option I get an error trying to create the prompt and then the quit is aborted.

I temporarily got around this by redefining questdlg:


questdlg = @(varargin) 2;


Then I could exit.

Note: I also have something in my finish.m that saves the state of the last session. So to get my prompt to come back I had to remove/delete this redefinition of questdlg that was saved in that state.

Update: The real solution is to enclose my prompt in finish.m inside an:


if usejava('desktop')
...
end


### Neumann vs. von Neumann

Tuesday, July 30th, 2013

### Using matlab to visualize vector fields on triangle meshes

Monday, July 29th, 2013

I recently discovered the quiver function in matlab, which can plot vector fields. I use this to plot a the piecewise constant gradient of a scalar field Z defined on a triangle mesh (V,F) like this:

trisurf(F,V(:,1),V(:,2),0*V(:,1),Z,'FaceColor','interp','FaceLighting','phong','EdgeColor','none');
axis equal
view(2);
colormap(jet(20));
GZ = G*Z;
BC = barycenter(V,F);
hold on;
quiver(BC(:,1),BC(:,2),GZ(1:size(F,1)),GZ(size(F,1)+(1:size(F,1))),1.1,'k','LineWidth',1.5);
hold off;


My grad and barycenter functions compute a #F*dim by #V gradient operator and #F by dim matrix of triangle barycenters respectively. This produces something like: It’d be cool to visualize streamlines, too, but it seems like matlab’s streamline function only works for grids.

### Slightly improved colored cal output

Monday, July 29th, 2013

I found a nice alias to color the output of the cal function. But on the 20th of July this produced:

     July <span style="color:red;font-weight:bold;">20</span>13
Su Mo Tu We Th Fr Sa
1  2  3  4  5  6
7  8  9 10 11 12 13
14 15 16 17 18 19 <span style="color:red;font-weight:bold;">20</span>
21 22 23 24 25 26 27
28 29 30 31


I refined the grep search a bit with this

alias cal='cal | grep --color=auto -E "( |^)$(date +%e)([^0-9]|$)|$"'  which produces the correct result:  July 2013 Su Mo Tu We Th Fr Sa 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 <span style="color:red;font-weight:bold;">20</span> 21 22 23 24 25 26 27 28 29 30 31  Update: The alias above ruins the ability to pass arguments to cal. Here’s a slightly improved version: cal() { /usr/bin/cal "$@" | grep --color=auto -E "( |^)$(date +%e)([^0-9]|$)|\$";}


Unfortunately it’ll still color today’s day of the week even if the month or year passed in the cal arguments are not the current month or year.

### Matlab’s trisurf confuses face colors with vertex colors

Sunday, July 28th, 2013

I recently had trouble getting matlab’s trisurf to display interpolated colors inside each face. I was calling:


set(trisurf(F,V(:,1),V(:,2),V(:,3)),'FaceColor','interp');


But the display looked like flat shading.

The problem turned out to be that I had 9 faces and 9 vertices. In this rare instance matlab decides that the vertex colors (which actually are just the Z coordinates in V(:,3)) should be attached (incorrectly) to the faces and are not interpolatable.

I hacked a fix to this by appending an extra ghost vertex:


set(trisurf(F,[V(:,1);0],[V(:,2);0],[V(:,3);0]),'FaceColor','interp');


### Robust Inside-Outside Segmentation using Generalized Winding Numbers SIGGRAPH 2013 fast forward

Monday, July 22nd, 2013

30 second SIGGRAPH 2013 fast forward for the paper “Robust Inside-Outside Segmentation using Generalized Winding Numbers” by Alec Jacobson, Ladislav Kavan and Olga Sorkine-Hornung. See the paper and more on the project page

### Interactive bilinear interpolation visualization with derivatives in matlab

Friday, July 19th, 2013

Here’s a little matlab gui to play with a bilinar function in a square, visualizing its value and partial derivatives with respect to x and y. Save it into a file bilinear_interactive.m.


function bilinear_interactive()
% BILINEAR_INTERACTIVE Create a little GUI to play with a bilinar function in
% a square, visualizing its value and partial derivatives with respect to x
% and y.
%
% bilinear_interactive()
%

clf;
[V,F] = create_regular_grid(50,50,0,0);
corner = [1 1 2 0];
bi = @(x,y,a,b,c,d) y.*(a+x.*(b-a)) + (1-y).*(c+x.*(d-c));
grad_bi_x = @(x,y,a,b,c,d) y.*((b-a)-(d-c))+(d-c);
grad_bi_y = @(x,y,a,b,c,d) x.*((b-a)-(d-c))+(a-c);

subplot(1,3,1);
tsh = trisurf(F,V(:,1),V(:,2), ...
bi(V(:,1),V(:,2),corner(1),corner(2),corner(3),corner(4)), ...
'EdgeColor','none','FaceColor','inter','FaceLighting','phong');
caxis([0 2]);
title('Bilinear function f','FontSize',20);
colormap(jet(15));
axis equal;
view(2);

subplot(1,3,2);
xsh = trisurf(F,V(:,1),V(:,2), ...
'EdgeColor','none','FaceColor','inter','FaceLighting','phong');
axis equal;
caxis([-2 2]);
title('df/dx','FontSize',20);
view(2);

subplot(1,3,3);
ysh = trisurf(F,V(:,1),V(:,2), ...
'EdgeColor','none','FaceColor','inter','FaceLighting','phong');
axis equal;
title('df/dy','FontSize',20);
caxis([-2 2]);
view(2);

set(gcf,'Position',[1 1 1440 830]);
pos = [ ...
[150-40 110+500 120 20];
[450-20 110+500 120 20];
[150-40 40+200  120 20];
[450-20 40+200  120 20];];
label = zeros(1,4);
for ind = 1:4
label(ind) = uicontrol('Style', 'text',...
'Position',pos(ind,:), ...
'FontSize',20, ...
'String',num2str(corner(ind)));
uicontrol('Style', 'slider',...
'Min',0,'Max',2, ...
'Value',corner(ind), ...
'Position',get(label(ind),'Position')-[0 20 0 0], ...
'Callback', @(src,evt) update(get(src,'Value'),ind));
end

function update(val,ind)
corner(ind) = val;
Z = bi(V(:,1),V(:,2),corner(1),corner(2),corner(3),corner(4));
set(label(ind),'String',num2str(val));
set(tsh,'Vertices',[V Z],'CData',Z);
set(xsh,'Vertices',[V Z],'CData',Z);
set(ysh,'Vertices',[V Z],'CData',Z);
drawnow;
end
end



### Trilinear interpolation in Maple

Friday, July 19th, 2013

Here’s a maple function for trilinear interpolation in a cube. I tried to match the notation in the wikipedia entry. I define C = (x,y,z) where x grows to the right, y grows up and z grows into the screen


tri := (x,y,z,C000,C001,C010,C011,C100,C101,C110,C111) ->
y*(z*(x*C000+(1-x)*C100)+(1-z)*(x*C010+(1-x)*C110)) +
(1-y)*(z*(x*C001+(1-x)*C101)+(1-z)*(x*C011+(1-x)*C111));


### VoxelBBW – bounded biharmonic weights on a voxel grid in 3D

Saturday, July 6th, 2013

Romain Prévost has kindly posted his reimplementation of our paper Bounded Biharmonic Weights for Real-time Deformation. He’s calling it VoxelBBW. The main advantage/disadvantage of his implementation is that it uses a voxel grid fit to the input shape, rather than a tetrahedral mesh. This is an advantage because tetrahedral meshing of an input triangle mesh is elusive in practice, where as voxel grids always give you something. It’s a disadvantage because voxel grids are dense, leading to slower computation. It all depends on your input, your application. This code might be perfect for you!