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('',

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')

Neumann vs. von Neumann

Tuesday, July 30th, 2013

neumann is not von neumann

von neumann is not neumann

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:

axis equal
G = grad(V,F);
GZ = G*Z;
BC = barycenter(V,F);
hold on;
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: gradient vector field visualization in matlab on woody 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:


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:


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

Interactive bilinear interpolation visualization with derivatives

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()

  [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);

  tsh = trisurf(F,V(:,1),V(:,2), ...
    bi(V(:,1),V(:,2),corner(1),corner(2),corner(3),corner(4)), ...
  caxis([0 2]);
  title('Bilinear function f','FontSize',20);
  axis equal;

  xsh = trisurf(F,V(:,1),V(:,2), ...
    grad_bi_x(V(:,1),V(:,2),corner(1),corner(2),corner(3),corner(4)), ...
  axis equal;
  caxis([-2 2]);

  ysh = trisurf(F,V(:,1),V(:,2), ...
    grad_bi_y(V(:,1),V(:,2),corner(1),corner(2),corner(3),corner(4)), ...
  axis equal;
  caxis([-2 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, ...
    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));

  function update(val,ind)
    corner(ind) = val;
    Z = bi(V(:,1),V(:,2),corner(1),corner(2),corner(3),corner(4));
    set(tsh,'Vertices',[V Z],'CData',Z);
    Z = grad_bi_x(V(:,1),V(:,2),corner(1),corner(2),corner(3),corner(4));
    set(xsh,'Vertices',[V Z],'CData',Z);
    Z = grad_bi_y(V(:,1),V(:,2),corner(1),corner(2),corner(3),corner(4));
    set(ysh,'Vertices',[V Z],'CData',Z);

Trilinear interpolation in Maple

Friday, July 19th, 2013

enclosing points on cubetrilinear interpolation in a cube

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)) +

Buttons inside forms are default type submit

Thursday, July 18th, 2013

I was frustrated that my undo button was submitting my form. My HTML code looked something like:

<form action="." method="GET">
<button onclick="undo();">Undo</button>
<button onclick="redo();">Redo</button>

At first I thought it was a javascript problem and some how my undo() function was submitting the form erroneously. But lo and behold this is the default behavior of a button inside of a form.

So, I needed to change my HTML to:

<form action="." method="GET">
<button type=button onclick="undo();">Undo</button>
<button type=button onclick="redo();">Redo</button>

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!