<?xml version="1.0"?>
<!-- name="generator" content="blosxom/2.0" -->
<!DOCTYPE rss PUBLIC "-//Netscape Communications//DTD RSS 0.91//EN" "http://my.netscape.com/publish/formats/rss-0.91.dtd">

<rss version="0.91">
  <channel>
    <title>dickscheid.net   </title>
    <link>http://www.dickscheid.net/cgi-bin/blosxom.cgi</link>
    <description>Timo Dickscheid's Weblog.</description>
    <language>en</language>

  <item>
    <title>How to convert Blender camera settings into a projection matrix</title>
    <link>http://www.dickscheid.net/cgi-bin/blosxom.cgi/2010/05/14#20100514_blenderprj</link>
    <description>&lt;p&gt;I was looking for an easy way to derive a projection matrix corresponding to the camera of images rendered with &lt;a href=&quot;http://www.blender.org/&quot;&gt;blender&lt;/a&gt;. Given such a &lt;code&gt;3&amp;times;4&lt;/code&gt; projection matrix &lt;code&gt;P&lt;/code&gt;, I want to define a 3D point in the blender scene, multiply it with the matrix and paint it into the existing image. For example, using Matlab to draw the scene origin as a red plus sign onto the image, I want to write&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&lt;br /&gt;
imshow('blender_img.jpg');&lt;br /&gt;
hold on;&lt;br /&gt;
X = [0 0 0 1]';&lt;br /&gt;
x = P*X; &lt;br /&gt;
x = x(1:2)/x(3);&lt;br /&gt;
plot(x(1),x(2),'r+');&lt;br /&gt;
hold off;&lt;br /&gt;
&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Deriving P turns out to be not documented at all, and besides knowledge on the computer graphics pipelines requires some trial and error. Today I managed to solve the problem, so here's the solution.&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;http://www.dickscheid.net/imgs/blender_transform.png&quot;&gt;&lt;img src=&quot;http://www.dickscheid.net/imgs/blender_transform.png&quot; /&gt;&lt;/a&gt;&lt;br /&gt;
First of all, collect the camera position and orientation from the &quot;Transform Properties&quot; dialog, as shown in the image above. In Matlab you get the translation vector and rotation matrix via&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&lt;br /&gt;
X0 = [2 -10 4]'; &lt;br /&gt;
o = 70*pi/180;&lt;br /&gt;
p = 15*pi/180;&lt;br /&gt;
k = -10*pi/180;&lt;br /&gt;
Ro=[1 0 0; 0 cos(o) -sin(o); 0 sin(o) cos(o)];&lt;br /&gt;
Rp=[cos(p) 0 sin(p); 0 1 0; -sin(p) 0 cos(p)];&lt;br /&gt;
Rk=[cos(k) -sin(k) 0; sin(k) cos(k) 0; 0 0 1];&lt;br /&gt;
R = Rk*Rp*Ro;&lt;br /&gt;
&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Now we need to derive the calibration matrix. Unfortunately, the focal length value in blender is neither documented nor standard. However, it is possible to display the lens angle &lt;code&gt;alpha&lt;/code&gt; in degrees, referring to the wider image dimension, as shown in the image below. In the example we have &lt;code&gt;alpha=49.13&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;http://www.dickscheid.net/imgs/blender_lens.png&quot;&gt;&lt;img src=&quot;http://www.dickscheid.net/imgs/blender_lens.png&quot; /&gt;&lt;/a&gt;&lt;br /&gt;
From the image resolution, which is here assumed to be &lt;code&gt;800&amp;times;600&lt;/code&gt;, we get the focal length in pixel from &lt;code&gt;fl=-400/(49.13*pi/180/2)&lt;/code&gt;. Observe the minus!&lt;/p&gt;

&lt;p&gt;The final projection matrix &lt;code&gt;P&lt;/code&gt; is obtained in Matlab using&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&lt;br /&gt;
fl = -400/(49.13*pi/180/2);&lt;br /&gt;
K = [fl 0 400; 0 fl 300; 0 0 1];&lt;br /&gt;
P = K*diag([1 -1 1])*R'*[eye(3) -X0];&lt;br /&gt;
&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Note the flipping of the y axis which results in a left handed system. A&lt;br /&gt;
student is planning to write an export script for blender to write&lt;br /&gt;
&lt;code&gt;P&lt;/code&gt; to file, which I'll post here.&lt;/p&gt;</description>
  </item>
  <item>
    <title>Eigen: A convenient and fast C++ template library for linear algebra</title>
    <link>http://www.dickscheid.net/cgi-bin/blosxom.cgi/2010/05/11#20100511_eigen</link>
    <description>&lt;p&gt;I just discovered &lt;a href=&quot;http://eigen.tuxfamily.org/index.php?title=Main_Page&quot;&gt;eigen&lt;/a&gt;, a really nice template library for linear algebra. I was using &lt;a href=&quot;http://www.robertnz.net/nm_intro.htm&quot;&gt;newmat&lt;/a&gt; until now, but was not very satisfied with its &lt;span class=&quot;caps&quot;&gt;API&lt;/span&gt; design, and was looking for a single efficient library for both small (3&amp;times;3) and large matrices. That is were eigen comes in: It has a very intuitive and handy &lt;span class=&quot;caps&quot;&gt;API&lt;/span&gt; and can handle both fixed and dynamic-sized matrices in a unified way. Some highlights are&lt;/p&gt;

&lt;ul&gt;&lt;li&gt;Direct mapping of &lt;span class=&quot;caps&quot;&gt;STL&lt;/span&gt; vector and C array memory into eigen's classes&lt;/li&gt;
&lt;li&gt;Classes for transformations, including quaternions (!)&lt;/li&gt;
&lt;li&gt;Sparse matrix support&lt;/li&gt;
&lt;li&gt;Handy typedefs for common structures, i.e. &lt;code&gt;Vector3f&lt;/code&gt; for a 3-float-vector and &lt;code&gt;Matrix2d&lt;/code&gt; for a 2&amp;times;2-double matrix&lt;/li&gt;
&lt;li&gt;Comma initialization aka &lt;code&gt;Vector3f &lt;span class=&quot;caps&quot;&gt;X &lt;/span&gt;= Vector3f::Zero(); X &lt;&lt; 1, 2, 3;&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Eigen is a pure template library, meaning that you can include it in your project by copying the 1-2 &lt;span class=&quot;caps&quot;&gt;MB&lt;/span&gt; of Header files into your source tree.&lt;/p&gt;

&lt;p&gt;Really great work!&lt;/p&gt;</description>
  </item>
  <item>
    <title>Don't use underscores in Java class names accessed through JNI</title>
    <link>http://www.dickscheid.net/cgi-bin/blosxom.cgi/2010/01/13#20100113_noUnderscoresInJni</link>
    <description>&lt;p&gt;You can use the &lt;a href=&quot;http://java.sun.com/j2se/1.4.2/docs/guide/jni/jni-14.html&quot; title=&quot;JNI&quot;&gt;Java Native Interface &lt;/a&gt; to call native code written in C++ directly from Java - and vice versa, which is less often used. When calling Java from C/C++, a virtual machine has to be launched before calling classes, using the so-called &quot;Invocation Interface&quot;. A simple example can be found &lt;a href=&quot;http://java.sun.com/docs/books/jni/html/invoke.html&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;It is important that you &lt;strong&gt;do not use underscores in the Java class names&lt;/strong&gt; when implementing this scenario - &lt;span class=&quot;caps&quot;&gt;JNI&lt;/span&gt; won't find your classes then, as happened to me using Sun's Java 6 &lt;span class=&quot;caps&quot;&gt;JRE. &lt;/span&gt;Unnecessary to mention that it took &lt;a href=&quot;http://www.ipb.uni-bonn.de/laebe&quot;&gt;Thomas&lt;/a&gt; and me about on hour to find the problem...&lt;/p&gt;</description>
  </item>
  <item>
    <title>Debugging and profiling C++ under Linux</title>
    <link>http://www.dickscheid.net/cgi-bin/blosxom.cgi/2009/12/07#20091207_gcc_debugging_and_profiling</link>
    <description>&lt;p&gt;Debugging and Profiling C++-Code with the standard &lt;span class=&quot;caps&quot;&gt;GNU&lt;/span&gt; tools under Linux may not be as intuitive too many people as it is with bigger &lt;span class=&quot;caps&quot;&gt;IDE&lt;/span&gt;'s like Visual Studio, XCode or Eclipse. Although I still think that using the &lt;span class=&quot;caps&quot;&gt;GNU&lt;/span&gt; debugger &lt;a href=&quot;http://www.gnu.org/software/gdb/&quot;&gt;gdb&lt;/a&gt; and profiler &lt;a href=&quot;http://www.cs.utah.edu/dept/old/texinfo/as/gprof_toc.html&quot;&gt;gprof&lt;/a&gt; on the command line is feasible, there are more userfriendly choices available:&lt;/p&gt;

&lt;ul&gt;&lt;li&gt;&lt;a href=&quot;$url/photos/20091207_gcc_debugging_and_profiling_01.html&quot;&gt;&lt;img src=&quot;http://www.dickscheid.net/imgs/nemiver_thumb.jpg&quot; style=&quot;float:right; padding-left:.5em;&quot;&lt;/a&gt;&lt;a href=&quot;http://projects.gnome.org/nemiver/&quot;&gt;Nemiver&lt;/a&gt; is a stand-alone graphical debugger for Gnome that can use gdb as a backend. I found it intuitive, well-designed and stable. I features easy browsing of sourcecode, setting breakpoints, and especially save and resume for sessions.&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://cgdb.sourceforge.net/&quot;&gt;cgdb&lt;/a&gt; is a curses frontend to gdb, that is, a graphical user interface on the command line. It is also intuitive, although tuned for vim-experienced users.&lt;/li&gt;
&lt;li&gt;A comfortable way of profiling your code is to use the &lt;span class=&quot;caps&quot;&gt;KDE&lt;/span&gt; call-graph viewer &lt;a href=&quot;http://kcachegrind.sourceforge.net/html/Home.html&quot;&gt;kcachegrind&lt;/a&gt; with the &lt;a href=&quot;http://valgrind.org/info/tools.html#callgrind&quot;&gt;callgrind&lt;/a&gt; tool of the &lt;a href=&quot;http://valgrind.org/&quot;&gt;valgrind&lt;/a&gt; suite. Other than using gprof, it does not require compiling your code with special flags. It requires no more than two steps: (1) Calling your binary within the valgrind framework: &lt;code&gt;valgrind --tool=callgrind [program] [arguments]&lt;/code&gt;. (2) Running kcachegrind on the output file &lt;code&gt;kcachegrind callgrind.out.[pid]&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Note that what you get with callgrind is not an exact analysis of the time your program consumed in every function and line, but rather an analysis of the cache accesses and processor instructions. This is of similar importance for many profiling purposes, but one should be aware of the differences, and read the &lt;a href=&quot;http://valgrind.org/docs/manual/cl-manual.html&quot;&gt;manuals&lt;/a&gt; carefully for more exact usage of profilers.&lt;/p&gt;

&lt;p&gt;On ubuntu, you get the whole setup via &lt;code&gt;aptitude install valgrind-callgrind kcachegrind nemiver cgdb&lt;/code&gt;.&lt;/p&gt;</description>
  </item>
  <item>
    <title>What if your STL containers get too large?</title>
    <link>http://www.dickscheid.net/cgi-bin/blosxom.cgi/2009/11/14#20091114_stxxl</link>
    <description>&lt;p&gt;
I recently encountered a problem with a &lt;code&gt;&lt;a
href=&quot;http://www.sgi.com/tech/stl/Vector.html&quot;&gt;std::vector&lt;/a&gt;&lt;/code&gt; of objects
needing more memory than available on the system. This occurs easily when using
the standard allocation procedure, which re-allocates the vector to double size
once it needs more memory, and hence suddenly needs triple the amount of
memory. On a 32 bit system the limit is at 2GB, so a 600+MB vector is probably
too big already. 
&lt;/p&gt;

&lt;p&gt;
What is the solution to this problem? First of all, you should pre-allocate the
&lt;code&gt;vector&lt;/code&gt; and check &lt;code&gt;max_size()&lt;/code&gt;, and also catch the allocation
exception that &lt;code&gt;vector&lt;/code&gt; throws. You may also consider using
more memory-efficient datatypes for your problem: Have a look
at the &lt;a
href=&quot;http://www.boost.org/doc/libs/1_41_0/libs/flyweight/doc/index.html&quot;&gt;boost
flyweight library&lt;/a&gt;, if you have many items taking on the same values, for example.
Second, rethink your algorithm - that's what I did. In most cases there is no
need to hold such massive data in memory. 
&lt;/p&gt;

&lt;p&gt;
However you might end up searching for a way to stream objects to disk
seamlessly &quot;in the background&quot; while still using the familiar STL-like syntax.
In such a case have a look at the &lt;a href=&quot;http://stxxl.sourceforge.net/&quot;&gt;STXXL
library&lt;/a&gt; (the &quot;Standard Template Library for Extra Large Data Sets&quot;) - it's just that.
&lt;/p&gt;
</description>
  </item>
  <item>
    <title>Creating high-quality graphics in LaTeX</title>
    <link>http://www.dickscheid.net/cgi-bin/blosxom.cgi/2009/08/22#20090822_tikz_sketch3d</link>
    <description>&lt;h4&gt;TikZ&lt;/h4&gt;

&lt;p&gt;&lt;a href=&quot;http://www.dickscheid.net/cgi-bin/blosxom.cgi/photos/20090822_tikz_sketch3d_01.html&quot;&gt;&lt;img src=&quot;http://www.dickscheid.net/imgs/tikz_hellinger_thumb.jpg&quot; /&gt;&lt;/a&gt;&lt;br /&gt;
Almost every LaTeX user loves and hates the good old &lt;a href=&quot;http://www.xfig.org/&quot;&gt;xfig&lt;/a&gt; vector graphics editor. I sticked quite long to it, but converted to the incredibly powerful &lt;a href=&quot;http://pgf.sourceforge.net&quot;&gt;TikZ&lt;/a&gt; package of &lt;a href=&quot;http://www.tcs.uni-luebeck.de/mitarbeiter/tantau/&quot;&gt;Till Tantau from L&amp;uuml;beck&lt;/a&gt;. It enables you to create high-quality vector graphics, node-based diagrams and much more directly from your LaTeX document. You should check the immense amount of examples in the &lt;a href=&quot;http://www.giref.ulaval.ca/~ctibirna/readings/pgfmanual.pdf&quot;&gt;Manual&lt;/a&gt;. Great German tutorials for TikZ can be found on &lt;a href=&quot;http://www.statistiker-wg.de/pgf/tutorials.htm&quot;&gt;www.statistiker-wg.de&lt;/a&gt;.&lt;/p&gt;

&lt;h4&gt;Sketch 3D&lt;/h4&gt;

&lt;p&gt;If you want to create high-quality sketches in 3D, and not use google's &lt;a href=&quot;http://sketchup.google.com/&quot;&gt;SketchUp&lt;/a&gt; for whatever reason, you should have a look  &lt;a href=&quot;http://www.frontiernet.net/~eugene.ressler/&quot;&gt;Sketch 3D&lt;/a&gt; and the very good tutorials on &lt;a href=&quot;http://www.fauskes.net/nb/introduction-to-sketch/&quot;&gt;fauskes.net&lt;/a&gt;.  The idea of Sketch 3D is simple:&lt;/p&gt;

&lt;ul&gt;&lt;li&gt;You describe a simple 3D scene sketch in a separate textfile&lt;/li&gt;
&lt;li&gt;Sketch creates a plain LaTeX file by applying an orthographic projection of the 3D sketch, which is defined by camera viewpoint and orientation.&lt;/li&gt;
&lt;li&gt;The LaTeX file is then included directly in your document.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Highlights of the package are the &quot;sweep&quot;-commands, which repeat a 3D drawing under a spatial motion and connect the resulting objects into a closed solid, and the &quot;fspecial&quot; function allowing to insert pstricks or TikZ commands at projections of 3D positions, taking proper care of the z-Buffer. This allows for example to insert LaTeX formulas right into your figures in proper size and rendering without using good old pstricks.&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;http://www.dickscheid.net/cgi-bin/blosxom.cgi/photos/20090822_tikz_sketch3d_02.html&quot;&gt;&lt;img src=&quot;http://www.dickscheid.net/imgs/tikz_example_thumb.jpg&quot; /&gt;&lt;/a&gt;&lt;br /&gt;
For a first impression have a look at this slide from my talk at &lt;a href=&quot;http://www.aimontefiore.org/ICVS2009/&quot;&gt;ICVS'09 in Liege, Belgium&lt;/a&gt;, where I modelled a camera at different 3D positions, projecting a 3D object. Such an image would be immense work in xfig, not to mention what happens if you want to change the viewpoint later on.&lt;/p&gt;</description>
  </item>
  <item>
    <title>Include files missing with gcc 4.4</title>
    <link>http://www.dickscheid.net/cgi-bin/blosxom.cgi/2009/03/21#20090321_gcc4_missing_includes</link>
    <description>&lt;p&gt;Switching from gcc 4.3 to 4.3 brought lots of missing include files for standard c functions. &lt;a href=&quot;http://www.cyrius.com/journal&quot;&gt;Martin Michlmayr&lt;/a&gt; has a good list of the necessary &lt;code&gt;#include&lt;/code&gt;'s &lt;a href=&quot;http://www.cyrius.com/journal/gcc/gcc-4.4-include&quot;&gt;here&lt;/a&gt; .&lt;/p&gt;</description>
  </item>
  </channel>
</rss>