## Archive for April, 2013

### Initializing Eigen matrix to zeros, the wrong way.

Tuesday, April 30th, 2013

I recently found a pretty silly bug in the way I was initializing an Eigen matrix to be all zeros. Say, my matrix was A, then I wrote this (admittedly in haste) to resize to an m by n matrix of zeros using:


A.resize(m,n);
A *= 0;


This worked most of the time. As should be expected if A is initialized to numbers. But unfortunately, the resize doesn’t initialize the values to anything, and some of the random leftovers in memory will be, when interpreted as floats, not-a-numbers (NaNs). Thus when I thought I was zeroing them out I was keeping the NaNs: 0*NaN = NaN. Luckily, this is also why NaN-related bugs are so easy to trace.

Of course the correct thing to do is explicit set each value to zero. Eigen even has a dedicated function:


A.setZero(m,n);


### Source code and Demo for Robust Inside-Outside Segmentation using Generalized Winding Numbers

Monday, April 29th, 2013

### 3d demo:

I’ve release a 2D and 3D matlab demo (with mex functions) of our SIGGRAPH 2013 paper “Robust Inside-Outside Segmentation using Generalized Winding Numbers”. You can find it on our project page.

### Source code and Demo for Fast Automatic Skinning Transformations

Monday, April 29th, 2013

I finally released the C++ source code for a 3D demo our SIGGRAPH 2012 paper “Fast Automatic Skinning Transformations”. You can find it on our project page. The only major dependencies are Eigen and the newly release libigl.

### Find and replace deprecated eigen coeffRef(…,…) += … lines with Triplet

Friday, April 26th, 2013

This is the vim find and replace command I used to switch from the legacy DynamicSparseMatrix command coeffRef to the new format using the Triplet class.


%s/$$[^\.]*$$.coeffRef($$[^,]*$$,$$[^)]*$$) *+= *$$[^;]*$$;/\1_IJV.push_back(Triplet<Scalar>(\2,\3,\4));/g


### bug

Wednesday, April 24th, 2013

I realized it doesn’t make much sense for me not to know how to use a professional 3d computer graphics tool. Especially since Autodesk products are free for students. Here’s what I came up with my first morning using Maya.

### public alpha release of libigl – a c++ geometry processing library

Monday, April 22nd, 2013

We’ve finally released our in-house C++ library for geometry processing called libigl.

libigl is a simple c++ geometry processing library. We have a wide functionality including construction of sparse discrete differential geometry operators and finite-elements matrices such as the contangent Laplacian and diagonalized mass matrix, simple facet and edge-based topology data structures, mesh-viewing utilities for opengl and glsl, and many core functions for matrix manipulation which make Eigen feel a lot more like MATLAB.

It is first and foremost a header library. Each header file contains a single function. Most are tailored to operate on a generic triangle mesh stored in an n-by-3 matrix of vertex positions V and an m-by-3 matrix of triangle indices F.

The library may also be compiled into a statically linked library, for faster compile times with your projects.

We use the Eigen library heavily in our code. Our group prototypes a lot in MATLAB, and we have a useful conversion table from MATLAB to libigl/Eigen.

### Composite thumbnails of multipage pdf into stacked image

Monday, April 22nd, 2013

Here’s a bash script that takes a multipage pdf and produces a stack of thumbnails with nice shadows: Save this in multipagethumb.sh: #!/bin/bash

# montage -gravity center null: null: 'supplemental_opt.pdf' null: null:
# -thumbnail 128x128 -sharpen 10 -bordercolor white -border 0 -background none
# +polaroid -set label '' -background Transparent -tile x1 -geometry -0+64
# -reverse -flop png:- | convert png:- -flop -trim output.png
if [ $# -lt 2 ] then echo "Usage:" echo " ./multipagethumb input.pdf output.png" exit 1 fi output="${2%.*}"
## this occassionally gives a concatentation of number of pages number of pages
## times: 10101010101010101010
#n=identify -format %n $1 n=pdftk$1 dump_data | grep NumberOfPages | sed 's/[^0-9]*//'

# 88+12+30*16 = 580
w="88"
x="30"
y="3"
for p in $(seq 1$n)
do
p=echo "$p-1"|bc echo "convert$1[$p] -flatten -thumbnail${w}x -bordercolor none -border 0 $$+clone \ -background none -shadow 80x3+2+2$$ +swap -background none -layers \
merge +repage  $output-$p.png"
convert $1[$p] -flatten -thumbnail ${w}x -bordercolor none -border 0 $$+clone \ -background none -shadow 80x3+2+2$$ +swap -background none -layers \ merge +repage$output-$p.png if [[$p == "0" ]]
then
echo "convert $output-$p.png $2" convert$output-$p.png$2
else
echo "convert $output.png -gravity SouthEast -background none -splice${x}x${y}$output.png"
convert $output.png -gravity SouthEast -background none -splice${x}x${y}$output.png
echo "composite -compose dst-over $output-$p.png $output.png -gravity SouthEast$output.png"
composite -compose dst-over $output-$p.png $output.png -gravity SouthEast$output.png
fi
rm $output-$p.png
done


Then issue:

./multipagethumb.sh input.pdf output.png


Note: You can achieve something similar with the montage and +polaroid command but it was difficult to achieve diagonal stacking and the correct order.

### Mismatching axis size of subplots due to colorbar

Sunday, April 21st, 2013

When using subplots and axis commands the colorbar command in matlab can mess up alignments:


subplot(1,2,1);
plot([0 100],[0 100]);
axis equal;
subplot(1,2,2);
plot([0 100],[0 100]);
axis equal;
colorbar


Produces:

A quick fix to get the fix axis to be the same size as the second is to use:


set(colorbar,'Visible','off');


So that


subplot(1,2,1);
plot([0 100],[0 100]);
axis equal;
set(colorbar,'Visible','off');
subplot(1,2,2);
plot([0 100],[0 100]);
axis equal;
colorbar


Produces:

### DOM Exception in XMLHttpRequest

Thursday, April 18th, 2013

I was getting this error when trying to set up an XMLHttpRequest using javascript:


INVALID_STATE_ERR: DOM Exception 11: An attempt was made to use an object that is not, or is no longer, usable


The problem was that I was calling req.setRequestHeader(...) before calling req.open(...). Reversing the order fixed the problem.

### Robust Inside-Outside Segmentation using Generalized Winding Numbers project page

Wednesday, April 10th, 2013

My colleagues, Ladislav Kavan, Olga Sorkine, and I have just submitted the camera ready version of paper “Robust Inside-Outside Segmentation using Generalized Winding Numbers” to be presented at ACM SIGGRAPH 2013. I’ve put up a Robust Inside-Outside Segmentation using Generalized Winding Numbers page where you can find the preprint version of the article, videos and more to come.

### Abstract

Solid shapes in computer graphics are often represented with boundary descriptions, e.g. triangle meshes, but animation, physically-based simulation, and geometry processing are more realistic and accurate when explicit volume representations are available. Tetrahedral meshes which exactly contain (interpolate) the input boundary description are desirable but difficult to construct for a large class of input meshes. Character meshes and CAD models are often composed of many connected components with numerous self-intersections, non-manifold pieces, and open boundaries, precluding existing meshing algorithms. We propose an automatic algorithm handling all of these issues, resulting in a compact discretization of the input’s inner volume. We only require reasonably consistent orientation of the input triangle mesh. By generalizing the winding number for arbitrary triangle meshes, we define a function that is a perfect segmentation for watertight input and is well-behaved otherwise. This function guides a graphcut segmentation of a constrained Delaunay tessellation (CDT), providing a minimal description that meets the boundary exactly and may be fed as input to existing tools to achieve element quality. We highlight our robustness on a number of examples and show applications of solving PDEs, volumetric texturing and elastic simulation.

Update: The accompanying video (with narration)