Archive for October, 2011

julio le parc at bugada and cargnel

Saturday, October 29th, 2011

scale

http://alecjacobson.com/art/digital/
http://alecjacobson.com/art/

Mosek, matlab and mac ox x 10.7

Wednesday, October 19th, 2011

I recently got a new work machine with mac os x 10.7. Already having visions of last summer when I had a laptop with 10.5 and a desktop with 10.6. We’ll see how this goes…

My first issue is a simple one. I installed mosek and as per the instructions I changed the ~/.MacOSX/environment.plist file to contain:


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>DYLD_LIBRARY_PATH</key>
	<string>/usr/local/mosek/6/tools/platform/osx64x86/bin:/usr/local/mosek/6/tools/platform/osx32x86/bin:/usr/local/cuda/lib</string>
	<key>GL_ENABLE_DEBUG_ATTACH</key>
	<string>YES</string>
	<key>MOSEKLM_LICENSE_FILE</key>
	<string>/usr/local/mosek/6/licenses/mosek.lic</string>
</dict>
</plist>

But when I restarted matlab and issued


mosekopt

I saw that it was not finding the mosek binaries correctly:


??? Invalid MEX-file '/opt/local/mosek/6/toolbox/r2009b/mosekopt.mexmaci64':
dlopen(/opt/local/mosek/6/toolbox/r2009b/mosekopt.mexmaci64, 1): Library not loaded:
libmosek64.6.0.dylib
  Referenced from: /opt/local/mosek/6/toolbox/r2009b/mosekopt.mexmaci64
  Reason: image not found

The solution: Log out and back in.

BBW alligator demo

Wednesday, October 19th, 2011

alligator demo

I posted a small “bonus” demo that I’ve been distributing as a supplement for the Bounded Biharmonic Weights for Real-Time Deformation MATLAB demo. This shows a full pipeline for the alligator example in Figure 5 of our paper and in our videos. The example uses point, bone, and cages on the sample 2D character. The demo is now included in the bbw.zip folder of matlab code and can be called by issuing:


>> alligator_demo

scale

Wednesday, October 19th, 2011

scale

http://alecjacobson.com/art/digital/
http://alecjacobson.com/art/

Eigen gotcha, sparse matrix inneriterator type

Sunday, October 9th, 2011

I just experienced a really annoying Eigen gotcha. If I have a sparsematrix A, defined as:


SparseMatrix<double> A;
// ... filled in somehow

then I can loop over the values with:


for(int k=0; k<A.outerSize(); ++k)
{
  // Iterate over inside
  for(SparseMatrix<double>::InnerIterator it (A,k); it; ++it)
  {
      // it.row(),  it.col(), it.value()
  }
}

This works fine. But if instead I use the wrong type for the InnerIterator, say int, I get no complaint from the compiler, just occasional garbage when I use it.col(), it.row(), or it.value():


for(int k=0; k<A.outerSize(); ++k)
{
  // Iterate over inside
  for(SparseMatrix<int>::InnerIterator it (A,k); it; ++it)
  {
      // it.row(),  it.col(), it.value() produce occasional garbage
  }
}

calistatics

Wednesday, October 5th, 2011

calistatics

http://alecjacobson.com/art/digital/
http://alecjacobson.com/art/

glUniform invalid operation mystery

Sunday, October 2nd, 2011

I burned way too many hours tracking down a foolish bug I had in my GLSL/OpenGL code. The bug had to do with setting uniform variables in my GLSL vertex shader. My shader code looked something like:

uniform mat4 my_matrices[100];
uniform int my_int;
void main()
{
  // ... something using my_int and my_matrices
}
 I would then try to set them in my C++ OpenGL code with: 


glUniformMatrix4fv(my_matrices_location,100,false,my_matrices_data);
glUniform1i(my_int_location,my_int_value);

This should work as long as my_matrices_location and my_int_location are set properly. Here’s I was setting them

INCORRECTLY:

// get number of active uniforms
GLint n = 200;
glGetProgramiv(my_prog_id,GL_ACTIVE_UNIFORMS,&n);
// get max uniform name length
GLint max_name_length;
glGetProgramiv(my_prog_id,GL_ACTIVE_UNIFORM_MAX_LENGTH,&max_name_length);
// buffer for name
GLchar * name = new GLchar[max_name_length];
// buffer for length
GLsizei length = 100;
// Type of variable
GLenum type;
// Count of variables
GLint size;
// loop over active uniforms getting each's name
for(GLuint u = 0;u < n;u++)
{
  glGetActiveUniform(my_prog_id,u,max_name_length,&length,&size,&type,name);
  if(string(name) == "my_matrices[0]")
  {
    my_matrices_location = u;
  }else if(string(name) == "my_int")
  {
    my_int_location = u;
  }
}

The mistake is that I’m confusing the variable’s index which I pass to glGetActiveUniform with it’s location which cannot be retrieved by glGetActiveUniform. Instead I need to retrieve the variable’s location with glGetUniformLocation. Here’s how I’m now setting my uniform variable locations CORRECTLY:

my_matrices_location = glGetUniformLocation(my_prog_id,"my_matrices[0]");
my_int_location = glGetUniformLocation(my_prog_id,"my_int");