Archive for August, 2011

Perceived stretch from partial view of twist

Wednesday, August 31st, 2011

Here’s a twist applied to a bar.

But when the movie is cropped the viewer gets a sense that the bar is also being stretched, to the right.

Putting a texture (here just a the edges of the 3D model’s mesh), helps perceive the true deformation: twist.

It also helps reduce the perceived stretch effect on the original full-view movie.

svn get last commit message

Wednesday, August 31st, 2011

Here’s a quick bash one-liner to get the last svn commit message:


svn log -q -v --xml --with-all-revprops -r committed | grep msg | sed -e "s/<msg>$$[^<]*$$<\/msg>/\1/g"


Update:
Not sure what the difference between “committed” and “head” is, but now “head” is giving me the correct message:


svn log -q -v --xml --with-all-revprops -r head | grep msg | sed -e "s/<msg>$$[^<]*$$<\/msg>/\1/g"


Death Instinct

Sunday, August 28th, 2011

marcus rothkowitz died mark rothko

Friday, August 26th, 2011

Change matlab figure’s grey background to white

Friday, August 26th, 2011

To change the default gray background of the matlab figure window to white issue:


set(gcf, 'Color', [1,1,1]);


Extract all images from a pdf as png files (at full resolution)

Friday, August 26th, 2011

Here’s a two-liner to extract all the embedded color images in a pdf and convert then to png files. pdfimages extracts the images as ppm files. But I couldn’t open these immediately on my mac with my favorite image editing tools, so I convert them with mogrify from the imagemagick suite to png files.


pdfimages original.pdf ./extracted-images
mogrify -format png ./extracted-images*.ppm


and to get rid of the ppm files


rm ./extracted-images*.ppm


Pseudo-color a mesh using random colors for multiple (weight) functions

Tuesday, August 23rd, 2011

Often it’s useful to visualize many functions on a mesh at the same time. Here I assign each function a random pseudocolor, then the color at each vertex of the mesh is just a blend of the function colors weighted by their respective function values. This is especially useful if your functions are already weight functions themselves (defined between 0 and 1). So, if your mesh is defined by V and F then you have a set of function values defined on the vertices W: #V by #functions, then you can use a previously posted function for randomly generating a #functions list of colors. Putting it all together with a matrix multiplication you have:


trisurf([F],V(:,1),V(:,2),V(:,3),'FaceVertexCData',W*random_color(size(W,2),'Pastel'));


To make the rendering a little nicer you can use:


light('Position',[-1.0,-1.0,100.0],'Style','infinite');
lighting gouraud
axis equal
view(2)


Here’s a visualization of bounded biharmonic weights on the Armadillo.

And here’s an easy way to visualize segmenting the mesh based on the maximum function value:


% get indices of max value for each row
[~,I]=max(W,[],2);
trisurf([F],V(:,1),V(:,2),V(:,3),'FaceVertexCData',sparse(1:size(W,1),I,1)*random_color(size(W,2),'Pastel'));


which produces something like:

Generate list of random colors, matlab

Tuesday, August 23rd, 2011

Here’s a little matlab function to generate a list of random RGB colors. Save it in random_color.m


function R = random_color(n,preset)
% RANDOM_COLOR  generate a list of random colors
%
% R = random_color(size)
% or
% R = random_color(size,preset)
%
% Inputs:
%   size size of matrix of random colors to generate
%   preset  string containing colormap name or 'Pastel'
% Outputs:
%   R  size by 3 list of RGB colors
%

if(~exist('n','var'))
N = 1;
end
if(~exist('preset','var'))
preset = '';
end

if(strcmp(preset,''))
R = rand([n,3]);
else if(strcmp(preset,'Pastel'))
attempt = 0;
% probably should be between O(n) and O(log n)
max_attempts = 10*prod(n);
retry = true([prod(n),1]);
R = zeros([prod(n),3]);
while(attempt < max_attempts)
num_retry = sum(retry);
R(retry,:) = rand(num_retry,3);
R(retry,:) = (291/255) * R(retry,:)./repmat(sum(R(retry,:),2),1,3);
%retry(retry) = max(R(retry,:),[],2) > 0;
% too bright
next_retry = retry;
next_retry(retry) = ...
(max(R(retry,:),[],2) - min(R(retry,:),[],2)) > (221/255) ;
% too grey
next_retry(retry) = std(R(retry,:),0,2) < (68/255);
if(~any(next_retry))
break;
end
retry = next_retry;
attempt = attempt+1;
end
R=reshape(R,[n 3]) +  34/255;
else
error('Preset not supported');
end

end


Use the ‘Pastel’ preset to force it to produce colors that are little easier to differentiate between especially on a white background with black foreground (e.g. text, mesh lines, etc.)

Bounded biharmonic weights for real-time deformation SIGGRAPH Fast Forward

Friday, August 19th, 2011

I’ve uploaded our SIGGRAPH 2011 Fast Forward video to youtube. For those not familiar with the SIGGRAPH Technical Papers Fast Forward, its a 2 hour event in which each paper has 50 seconds to present a teaser for their paper talk.

Getting Safari to play a short audio clip with HTML5’s audio tag

Friday, August 19th, 2011

I had a really annoying time trying to get Safari to load and play a small audio clip (mp3) I’d posted. The clip is only 2 seconds. Here’s the HTML I was using


<audio src="audio.mp3" autoplay preload="auto" controls loop>


But this resulting in nothing. Upon closer inspection I found out the the “onstalled” even was being fired so I added an “onstalled” even handler to try to load the clip again:




But this was to no avail, the “onstalled” event just fired each time recursively.

In the end I gave up on Safari’s ability to play/load small mp3 files. I’m not sure what the problem is since quicktime played the file fine. Also if my html and audio.mp3 files lived locally, Safari played it correctly.

I instead made use of HTML5 ability to specify fallback sources. For this I converted my mp3 file to a m4a:

First convert to wav with mplayer:


mplayer -quiet -vo null -vc dummy -ao pcm:waveheader:file="audio.wav" "audio.mp3"


Then convert to m4a with faac:


faac -o audio.m4a audio.wav


Finally use the .m4a file as a fallback source in the audio tag: