Showing posts with label visualization. Show all posts
Showing posts with label visualization. Show all posts

Monday, October 18, 2010

3D Stereo in Linux w/ nVidia 3D Vision Continued

Finishing Touches for Stereo DLP Usage:
In the last post I detailed how to set up the Xorg.conf file for nVidia 3D vision in Ubuntu Linux with a Mitsubishi DLP TV and active shutter glasses. Because you cannot use overscan compensation correction during stereoscopic playback, you need to set overscan compensation to "0". This can cause the edges of your image to extend beyond the screen however, and make general system usage difficult.






To fix this, I made two scripts and put them in /usr/bin:


stereo_on:
#!/bin/bash -i
nvidia-settings -a OverscanCompensation=0 >> /dev/null 2>&1


stereo_off:
!/bin/bash -i
nvidia-settings -a OverscanCompensation=115 >> /dev/null 2>&1

With these scripts you can turn overscan compensation on and off with a simple command.

Linux Stereoscopic Video Player:
The only thing we were missing with our 3D setup was a stereoscopic video player. Luckily, the video player Bino was just released. It requires the newest version of the ffmpeg libraries, so I built them and then built bino. Here's my steps:

> git clone git://git.ffmpeg.org/ffmpeg/
> cd ffmpeg
> git clone git://git.ffmpeg.org/libswscale/
> ./configure --prefix=/usr/local --enable shared
> make install
> make -j 6
> cd ..
> cd bino
> autoreconf
> ./configure PKG_CONFIG_PATH="/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH"
> make

Tuesday, June 22, 2010

Installing VTK in Ubuntu and Making VTKPython Work

There are at least two ways to get VTK working in Ubuntu with Python wrapping. The first and easiest is to just install the packages with the Aptitude Package Manager:

sudo apt-get install libvtk5-dev python-vtk

Once you do that, you can run vtkpython and it just works. Unfortunately, the version of VTK in the packages for Ubuntu 10.04 is 5.2. That's a little out of date, and I needed a newer version. Here's how to install VTK 5.6 or newer with Python wrapping enabled:

Make sure CMake is installed:

sudo apt-get install cmake

Download the VTK source from the Downloads page.

Untar it:

tar xvzf vtk-5.6.0.tar.gz

Create an Out-Of-Source build and configure with CMake:

mkdir VTK_BUILD
cd VTK_BUILD
ccmake ../VTK

Make sure you enable python wrapping and set your install prefix to where you want the package to go. The default /usr/local works fine.

sudo make -j 8 install
(the -j 8 for make just makes the build process parallel assuming you've got the processors for it)

You now have VTK installed. Congrats! if you try to run vtkpython though, you'll get an error:


vtkpython: error while loading shared libraries: libvtksys.so.5.6: cannot open shared object file: No such file or directory

To fix this, append these lines to your .bash_profile, .bashrc, or .profile file in your home directory:


# add vtk paths
LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/usr/local/lib/vtk-5.6"
PYTHONPATH="$PYTHONPATH:/usr/local/lib/vtk-5.6"

You'll need to reset your terminal now.

That sets up your library and python paths for the vtkpython executable. To test this, you can run

brandt@amaterasu:~/work$ vtkpython
vtk version 5.6.0
Python 2.6.5 (r265:79063, Apr 16 2010, 14:15:55) 
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from vtk import *
>>> renderer = vtkRenderer()
>>> 

If you got that far, your installation works!





Monday, February 8, 2010

Dynamic Real-time Data Plotting with VTK

It is possible to interact with a dataset and generate a plot dynamically by probing the dataset. In VTK, you can do this with a few useful classes: vtkLineWidget, vtkSplineWidget, vtkProbeFilter, and vtkXYPlotActor.

Here is video of the dynamic plot in action:



It's impressive but simple. You can expand this capability by adding additional probes and using a spline instead of a line for probing, but to get the functionality you see in the video here's a python script.

The class interactionEvent will be used as a callback function for the lineWidget (or splineWidget):

#!/bin/python

from vtk import *;

#callbacks
class interactionEvent():
        def execute(self, obj, event):
                self.spline.GetPolyData(self.poly)
                self.probe.Update()

This just sets up the pipeline for reading in the dataset and all of the rendering window classes, etc...:

#Read in and set up dataset
reader = vtkDataSetReader()
reader.SetFileName("/Users/brandt/Work/pythonVTK/mummy.128.vtk")
reader.ReadAllScalarsOn()
reader.ReadAllVectorsOn()
reader.Update()

#set up rendering pipeline
renderer = vtkRenderer()
renWin = vtkRenderWindow()
iren = vtkRenderWindowInteractor()
renWin.SetSize(800,480)
renWin.AddRenderer(renderer)
iren.SetRenderWindow(renWin)

Here we set up out vtkXYPlotActor, which just controls how the plot will look:

plotActor = vtkXYPlotActor()
plotActor.SetPosition(0.6,.0)
plotActor.SetWidth(.40)
plotActor.SetHeight(.3)
plotActor.GetXAxisActor2D().SizeFontRelativeToAxisOn()
plotActor.GetYAxisActor2D().SizeFontRelativeToAxisOn()
plotActor.SetNumberOfYLabels(5)
plotActor.SetNumberOfXLabels(6)
plotActor.SetAdjustYLabels(0)
plotActor.SetNumberOfYMinorTicks(2)
plotActor.SetNumberOfXMinorTicks(2)
plotActor.AddInput(probe.GetOutput())
plotActor.SetXValuesToNormalizedArcLength()
plotActor.SetTitle( "Scalar Data" )
plotActor.SetXRange(0,1)

We set up our splineWidget here to probe the data, and add the interactionEvent class as the callback for any interaction event:

poly = vtkPolyData()
probe = vtkProbeFilter()
spline = vtkSplineWidget()
spline.GetPolyData(poly)
probe.SetInput(poly)
probe.SetSource(reader.GetOutput()) 
spline.SetInteractor(iren)
spline.SetInput(reader.GetOutput())
spline.PlaceWidget()
spline.On()
spline.SetNumberOfHandles(2)
probe.Update()
renderer.AddActor(plotActor)

Next we assign our probe, widget, and polydata to the interactionEvent class and add the class as the callback function:

#set up callback
cb = interactionEvent()
cb.spline = spline
cb.probe = probe
cb.poly = poly
spline.AddObserver("InteractionEvent", cb.execute)

Finally we create a contour of the mummy skull so we have something pretty to look at!

#draw contour
isoMapper = vtkPolyDataMapper()
isoActor = vtkActor()
iso = vtkContourFilter()
isoMapper.SetInput(iso.GetOutput())
iso.SetInput(reader.GetOutput())
iso.SetValue(0, 125)
isoActor.SetMapper(isoMapper)
renderer.AddActor(isoActor)

iren.Initialize()
iren.Start()