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

Alec Jacobson

August 23, 2011

weblog/

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
shading interp
view(2)
Here's a visualization of bounded biharmonic weights on the Armadillo.

armadillo bbw pseudo color

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:

armadillo bbw pseudo color max value segmentation