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

 


Following on our series exploring the use of the Raspberry Pi,
Here we describe how to build VTK natively in the board.

http://www.vtk.org/doc/release/5.10/html/vtk-logo.gif

It turns out that the Raspberry Pi has a graphics stack with rendering capabilities
that are between a Playstation I and a Playstation II.

To further increase the happiness, we learned that
the Graphics Stack of the Raspberry Pi is fully Open Source.

 

and actually:

“…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).

 

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:

  • /home/pi/src/VTK5.10.1

 

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

  • make

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

 

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.

Hovering the mouse over the link that says:

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”

  • 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:

  • startx

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 !

6 Responses to Raspberry Pi likes VTK

  1. Elvis Chen says:

    hi,

    Thanks for the post! I am trying to compile/run VTK on raspberry pi running raspbian. while VTK compiles, I could not run the example. The error message I got relates to “Could not find decent visual”, which I assume was related to OpenGL driver issue.

    What linux/distribution are you running on raspberry pi to get VTK to work?

    thanks in advance,

  2. Luis Ibanez says:

    Elvis,

    I’m using both Raspbian and Occidentalis.

    Yes, I have seen the message that you mentioned.
    It relates to the actual rendering capabilities of the Pi.

    In this blog, since I was logging remotely, it turned out that I was using the X-Windows (and OpenGL) rendering capabilities of my remote machine (a laptop) instead of the local rendering of the Pi.

    In summary: If you render in a remote machine, you will see the same results that we showed in this current blog post. While if you attempt to render locally, you will find (as you just reported) that some of the capabilities required by the default VTK settings are not available in the Pi.

    Since this VTK blog post, we have been working with Pat Marion (more precisely, Pat has been working on it, while I just watch…), on a similar post showing how to use the VES library and the KiwiViewer to render natively in the Raspberry Pi. We hope to publish that blog very soon.

    Stay tuned 🙂

    Thanks

  3. Kay Jean says:

    Hi thank you for your blog post. I compile the code and run the example “Could not find a decent visual”. And I notice that Elvis Chen had the same problem.

    1. you mean that it is impossible to run vtk in native raspberry ?

    2. Is there any other package ( ex VES and KiwiViewer ) information for raspberry ?

    thank you very much

  4. Luis Ibanez says:

    Kay,

    Yes, when using the instructions here, it turns out that we are not using the real hardware, but the software rendering instead.

    In what I posted, since I was logging in remotely, I was using the rendering capabilities of the client.

    VES, as you pointed out, will use the capabilities of the Pi. We have a draft blog post on how to use VES in the Pi, but it needs some final retouches. Hope to get to it soon.

  5. Kay Jean says:

    Thank you. I really need a render module for my raspberry project.

    Hope your VES tutorial coming out very soon…

    Now I will study VES/WIKIVIEWER on mobile( android ) first. After you post the tutorial, I can port it to raspberry.

    Thank you very much

  6. Elvis Chen says:

    any update on VES and Raspberry Pi?

    or the experimental OpenGL driver (on jessie) for VTK?

    I recently got a new Raspberry Pi3; while vtk is pre-compiled on jessie, the standard driver defaults the VTK to use software rendering only. I have spent several nights trying to get the OpenGL driver to work (https://www.raspberrypi.org/blog/another-new-raspbian-release/), but it looks like this driver is very picking on the HDMI output and I cannot get it to work on my monitor(s) at all.

    I think VES may be the path-of-least-resistance to get VTK working with some forms of hardware acceleration. I would really appreciate if anyone at kitware can respond to this issue,

    thank you

Questions or comments are always welcome!