Raspberry Pi likes VTK
|Index To the Series|
|1. Raspberery Pi likes Open Source|
|2. Cross-Compiling for Raspberry Pi|
|3. Cross-Compiling ITK for Raspberry Pi|
|4. Raspberry Pi likes VTK|
|5. Raspberry Pi likes Node.js|
p style=”text-align: center;”>To further increase the happiness, we learned that
the Graphics Stack of the Raspberry Pi is fully Open Source.
p style=”padding-left: 150px;”>“…the BCM2835 used in the Raspberry Pi
is the first ARM-based multimedia SoC
with fully-functional, vendor-provided
(as opposed to partial, reverse engineered)
fully open-source drivers,
…Broadcom is the first vendor to open
their mobile GPU drivers up in this way…”
Given that Open Source is not real until you can download the source code and
read the license, here is the userland repository with the drivers for your enjoyment.
(Note that they use CMake for configuration as well).
p style=”text-align: left;”>All these news make us realize that this little gadget is a good platform
for playing with visualization, and what better tool for doing so than VTK ! 🙂
Here is how we built VTK natively in the Raspberry Pi.
Note: as with the previous posts, many of the screenshot images below
may appear blurred due to subsampling. Please simply click on them,
to see them in full resolution, where the text will be clearly readable.
Step 1. Install Required Packages
First, in the Raspberry Pi we install several pre-requisite packages with the commands:
- sudo apt-get install libgl1-mesa-dev
- sudo apt-get install libxt-dev
- sudo apt-get install libosmesa-dev
Step 2 Download VTK
Then we download VTK’s source code:
- cd ~/src
- wget http://www.vtk.org/files/release/5.10/vtk-5.10.1.tar.gz
- tar -xzf vtk-5.10.1.tar.gz
This leaves VTK in a directory:
Step 3 Configure VTK with CMake
As usual, we create a binary directory and from there we invoke
ccmake giving it as argument the location of the source directory.
- mkdir -p ~/bin/VTK
- cd ~/bin/VTK
- ccmake ~/src/VTK5.10.1/
There we do
- Turn OFF Testing
- Turn OFF Examples
- Turn ON Shared Libraries
- Select “Release” compilation mode in CMAKE_BUILD_TYPE
As usual we do
- Hit “c” to Configure
- Hit “g” to Generate
and we are back to the command line prompt.
Step 4 Build !
We can now happily type
we actually did “time make” since we are curious about the time that it will take to compile.
and while this builds, we go and read more about the graphics capabilities of the Raspberry Pi
- http://www.raspberrypi.org/archives/1967 (Penguins)
- http://www.raspberrypi.org/archives/106 (Quake 3)
Our VTK build finishes in about 13 hours:
Step 5 Try a VTK Example
We are ready to build our first VTK example in the Raspberry Pi.
- We choose to go to the VTK Examples Wiki page,
- and from the C++ Examples,
- we select the OBJ Reader Example.
Hovering the mouse over the link that says:
- “Click here to download ReadOBJ. and its CMakeLists.txt file”
We get the URL address and we use it in the Pi
- cd /tmp
- wget http://gitorious.org/vtkwikiexamplestarballs/vtkwikiexamplestarballs/blobs/raw/master/ReadOBJ.tar
- tar xf ReadOBJ.tar
- cd ReadOBJ
- cd build
We configure the example by pointing CMake to the binary directory where we just built VTK.
- cmake -DVTK_DIR=/home/pi/bin/VTK ..
then build it by simply calling “make”
Now we need an OBJ dataset to load, that we can procure ourselves with some Google magic from
- wget http://pages.cs.wisc.edu/~yetkin/smvr/obj/cow.obj
and finally we can run our first VTK example in the Pi
- ./ReadOBJ cow.obj
and we got the display of a Magnificent Cow !,
that we can of course rotate around with the mouse,
and get into wireframe mode by using the “w” key.
NOTE: In this case, this was done with a remote SSH login in the Raspberry Pi,
therefore, for this display to work, we had to previously had started the X Server in the board,
which is done by simply typing:
and then we had to login from a different shell into the board using the -X option of SSH.
- ssh -X pi@raspberrypi
in this way the X Windows that may be open during that shell session
get exported to the remote display (our Dell Laptop in this case).
…and this concludes our session on building VTK.
Enjoy Visualization in the Raspberry Pi !