mlynch Ich liebe es, wenn ein Plan funktioniert

More pages of me

about me
publications
photos
older home page

Project Euler

I’ve started working through some Project Euler exercises as a way to keep my brain sharp. Unfortunately, after years of neglect, my brain is as blunt as a spoon and needs some serious sharpening.

Needless to say, I’m trying to implement the solutions in C++ in my QT Creator IDE.

Check out Project Euler at http://projecteuler.net/


Out of dll Hell and into purgatory

So finally got out of DLL hell, or in this case .so hell, and managed to get my app running well in ubuntu. The problem was with setting the library path at runtime. For some reason, for the Run env. variables, there was a typo on my LD_LIBRARY_PATH. All fixed now thankfully.

Have some more tweaks to the visualizer to make the vtkImageReslice panels more interactive and then I can concentrate on algorithms.


Installation of GDCM on ubuntu 10.10

Installation of the GDCM libraries for reading DICOM files directly to VTK.

  • download GDCM source and unzip
  • create GDCMBuild directory
  • cd to GDCMBuild directory
  • open cmake GUI and set sources to GDCM and build directory to GDCMBuild (or command line type cmake ../VTK)
  • make changes either in cmake GUI or to CMakeCache.txt to check GDCM_BUILD_SHARED_LIBS and GDCM_USE_VTK
  • call cmake again or hit configure
  • open terminal and navigate to GDCMBuild directory
  • run commands ‘make’ and then sudo ‘make install’
  • this moves all headers to /usr/local/include/gdcm-X.X/ and all ‘.so’ files to /usr/local/lib/gdcm-X.X/ (you may need to check to see if they are in the correct directories. For some reason my .so files were placed outside the gdcm-X.X directory)

Installation of vtk on ubuntu 10.10

I installed Ubuntu 10.10 using wubi yesterday. After some messing around with Compiz I decided this will be my new environment for coding. I’m documenting the installation procedure to date. This will be updated as I progress.

  • install QT creator
  • install cmake & cmake GUI
  • download vtk source and untar/unzip
  • create VTKBuild directory
  • cd to VTKBuild directory
  • open cmake GUI and set sources to VTK and build directory to VTKBuild (or command line type cmake ../VTK)
  • make changes either in cmake GUI or to CMakeCache.txt to include VTK_USE_GUISUPPORT, BUILD_SHARED_LIBS and VTK_USE_QVTK
  • Change install prefix to location of output files (in my case this is changed to /usr/local)
  • call cmake again or hit configure
  • set desired QT version (in my case to 4)
  • hit configure again
  • open terminal and navigate to VTKBuild directory
  • run commands ‘make’ and then sudo ‘make install’
  • this moves all headers to /usr/local/include/vtkXX/ and all lib files to /usr/local/lib/vtkXX/

After another extended absence…

..I’m back.

Since my last post I’ve been messing around with visualization in VTK, frustratingly not making massive progress and getting completely side-tracked. I implemented a few widgets and messed with putting together a more extensive MPR viewer…but just realized that it is pointless. I’m not going to need some robust viewer. I’ve decided to stick with what I have for the time being and focus on some of the algorithmic stuff. Starting with a fairly simple euclidean distance transform for a 3D surface…level-set style. I’ve a few papers to work from but the value of it will be on getting back into the implementation side.

I’ll report back when I’ve something worth reporting.


Z-spacing in DICOM stack

Started back exactly where I left off…problems. I’m stuck trying to determine the z-spacing of a DICOM stack. The GDCM plugin is having problems calculating the distance based on Image Position (0020, 0032) and Image Orientation (0020, 0037).

I’m going to invest a bit more time reading into the calculation itself but I think the problem lies in getting a negative value at some point.

More details on the reasons for using this calculation instead of the DICOM tag can be found here.

Edit

I seemed to have fixed the problem by updating the data with the calculated z-spacing using

vtkImageChangeInformation *v16 = vtkImageChangeInformation::New();


New Years Resolution 2010

I promised myself that I’d get back on the saddle to try to produce something in 2010. I just checked my last entry and it was back in October. It’s disgraceful that I haven’t been keeping up to date with things.

I’m going to set out a regime for myself and spend at least 4 hours a week on my research. There are a number of things that I would like to achieve this year but nothing is going to happen if I put it on the long finger. I really need to get on top of things by;

  1. Reading more papers in the area. That’s the only way that I will be able to get up to date on the topic and perform credible research.
  2. Choose a specific question. I’ve already had some vague ideas on this, but I need to work on those in a bit more depth.
  3. Make contact with peers. Without the push of others I will never make progress. I have a few people in mind when I gather my thoughts together.
  4. Implementation of the ideas. This is what I was tricking around with up to now. I really need a goal if I am to move this forward. It’s OK getting familiar with the environment and data but unless I have a clear objective then I am not going to learn anything useful.

Hopefully, this site will start to see more of what it was intended for. Documenting real progress and helping to define the research questions that I want to address.

Here’s to 2010.


GDCM2

Installing GDCM2 for reading and sorting DICOM images. My first task is to select a number if dcm files, sort them based on spatial position and display the volume image in a qt window.

GDCM2 has a sorter already in the library called IPPSorter. It was simple a case of passing it the file names and asking it to sort. I then read the dicom files using;

1
vtkGDCMImageReader *reader = vtkGDCMImageReader::New();

I had some trouble with visualizing the volume until I realized that I should pass the renderer a vtkVolume instead of an Actor.
[Read more →]


VTK and DICOM

Next on the agenda is rendering DICOM images. For this, I use [CODE]vtkDICOMImageReader[/CODE] which works a treat. I’m still playing around with the whole process flow (source -> filter -> mapper -> actor). In this case I use [CODE]vtkImageCast[/CODE] which seems to do the same job.

Here is a rendering of a single DICOM with transparent arrow on top!
renderedDicomImage


QT and VTK in QTCreator – A live tutorial

I’m calling this a live tutorial, because at the time of writing I don’t have a completely working system. But it took me quite a lot of effort and time to get this far, so I thought I would document it for others to follow….plus, no doubt I will have to do the same again on some other system or computer in the future, so this post will hopefully serve as a reminder for me too.

Anyways, I’m using Microsoft Windows XP – Service Pack 3 on a Lenova T400. I downloaded and installed QT 4.5.1 with qmake version 2.01a. I also installed the latest version of QT Creator, which at the time was v 1.2.1.

I found QTCreator to be a very satisfying IDE, with the right balance of hand-holding and learning what is going on behind the scenes. I played around with some initial projects, creating some meaningless GUIs and pointless dll libraries. When sufficiently bored, I decided to move on to something more complicated. As my background is imaging, I wanted to develop a GUI for visualisation of volumetric data.

I choose to work with VTK. I downloaded the latest version from the website….5.4.2. Once downloaded, I unpacked to my root directory C:\.

I downloaded and installed CMake 2.6 and cracked up the CMake-gui to build my VTK source. I specified the location of my VTK source (C:\vtk-5.4.2) and specified where I wanted to build my binaries (C:\vtk) and hit Configure. I choose MinGW MakeFiles as the generator and left the default of ‘Use default native compiler’. Here is a screenshot of CMake-gui.

cmake-gui

I didn’t forget to set VTK_USE_GUISUPPORT and VTK_USE_QVTK. I also set CMAKE_INSTALL_PREFIX to C:\vtk-build\release and generated the files.

Once the files had been build to C:\vtk I opened up QT Creator. I created a project called vtk from a Makefile and specified the location to be in C:\vtk. This loaded all my newly built VTK files into the project. I then used Build- Build all to ‘make’ the files.

To install the files (I have to admit that a couple of weeks passed as I didn’t know how to proceed) I was required to open an instance of ‘QT Command Prompt’, and change directories to C:\vtk. I then used the following command to install VTK onto my system;

1
mingw32-make install

The output of my VTK-build directory

1
2
3
4
[DIR] bin
[DIR] include
[DIR] lib
[DIR] plugins

…and these folders contained the dlls, the header files and the dll.a files for the VTK installation.

I ran some minimal VTK code to make sure everything was in the correct place. I added C:\VTK-build\release\bin directory to my %PATH%. I then wanted to create a debug build so I could debug VTK in QTCreator. This was achieved by repeating the process but setting the CMake variable CMAKE_BUILD_TYPE to Debug.

I also added the following to the pro file…

1
2
3
win32:debug:LIBS += -Lc:/vtk-build/debug/lib/vtk-5.4/
win32:release:LIBS += -Lc:/vtk-build/release/lib/vtk-5.4/
win32:LIBS += -lvtkCommon.dll -lvtksys.dll -lQVTK.dll -lvtkQtChart.dll -lvtkViews.dll -lvtkWidgets.dll -lvtkInfovis.dll -lvtkRendering.dll -lvtkGraphics.dll -lvtkImaging.dll -lvtkIO.dll -lvtkFiltering.dll -lvtklibxml2.dll -lvtkDICOMParser.dll -lvtkpng.dll -lvtkpng.dll -lvtktiff.dll -lvtkzlib.dll -lvtkjpeg.dll -lvtkalglib.dll -lvtkexpat.dll -lvtkverdict.dll -lvtkmetaio.dll -lvtkNetCDF.dll -lvtkexoIIc.dll -lvtkftgl.dll -lvtkfreetype.dll -lvtkHybrid.dll
1
INCLUDEPATH += C:/vtk-build/include/vtk-5.4

QTCreator has the nice feature of being able to sent specific environmental variables separately for debug and release. You can find this feature under projects-Build Environment. I then added C:/vtk-build/debug/bin to the path for debug mode and C:/vtk-build/release/bin to the path for release mode.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include "vtkSphereSource.h"
#include "vtkPolyDataMapper.h"
#include "vtkActor.h"
#include "vtkRenderWindow.h"
#include "vtkRenderer.h"
#include "vtkRenderWindowInteractor.h"

int main ()
{

// create sphere geometry
vtkSphereSource *sphere = vtkSphereSource::New();
sphere->SetRadius(1.0);
sphere->SetThetaResolution(18);
sphere->SetPhiResolution(18);

// map to graphics library
vtkPolyDataMapper *map = vtkPolyDataMapper::New();
map->SetInput(sphere->GetOutput());

// actor coordinates geometry, properties, transformation
vtkActor *aSphere = vtkActor::New();
aSphere->SetMapper(map);
//aSphere->GetProperty()->SetColor(0,0,1); // sphere color blue

// a renderer and render window
vtkRenderer *ren1 = vtkRenderer::New();
vtkRenderWindow *renWin = vtkRenderWindow::New();
renWin->AddRenderer(ren1);

// an interactor
vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
iren->SetRenderWindow(renWin);

// add the actor to the scene
ren1->AddActor(aSphere);
ren1->SetBackground(1,1,1); // Background color white

// render an image (lights and cameras are created automatically)
renWin->Render();

// begin mouse interaction
iren->Start();
}

Everything compiled and ran correctly.

I then tried to use QVTKWidget using the following ‘Hello World’ example;
main.cpp

1
2
3
4
5
6
7
8
#include "vtk_example.h"

int main(int argc, char *argv[])
{
QApplication a(argc, argv);
VTK_Example w;
w.show();
return a.exec();
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include "vtk_example.h"
#include "QVTKWidget.h"
#include "ui_vtk_example.h"

VTK_Example::VTK_Example(QWidget *parent)
: QMainWindow(parent), ui(new Ui::VTK_Example)
{
ui->setupUi(this);

setFixedSize(640,360);

QVTKWidget *widget;

widget = new QVTKWidget;
widget->show();
setCentralWidget(widget);
//
vtkTextSource *text = vtkTextSource::New();
text->SetText("Michael Lynch!");
text->BackingOff();
vtkVectorText *vectorText = vtkVectorText::New();
vectorText->SetText("MITACS");
vtkPolyDataMapper *textMapper = vtkPolyDataMapper::New();
textMapper->SetInput(text->GetOutput());
vtkPolyDataMapper *vectorTextMapper = vtkPolyDataMapper::New();
vectorTextMapper->SetInput(vectorText->GetOutput());
vtkActor *textActor = vtkActor::New();
textActor->SetMapper(textMapper);
vtkActor *vectorTextActor = vtkActor::New();
vectorTextActor->SetMapper(vectorTextMapper);
vtkRenderer *renderer = vtkRenderer::New();
renderer->SetBackground(0.4,0.6,0.8);
renderer->AddActor(textActor);
renderer->AddActor(vectorTextActor);
vtkRenderWindow *renderWindow = vtkRenderWindow::New();
renderWindow->AddRenderer(renderer);
renderWindow->SetStereoTypeToDresden();
//
widget->SetRenderWindow(renderWindow);

}

This compiled and ran in release mode without any problems. However, in debug mode I got a runtime error. I tracked all my dll’s using dependency walker and found that QVTK.dll uses QTCORE4.dll and QTGUI4.dll and I had a feeling that this might conflict with QTCORE4D.dll and QTGUI4D.dll.

1
2
3
4
VTK_Example::~VTK_Example()
{
delete ui;
}

Here is the result of a cone object viewed in QVTKWidget;
Clipboard01


← Before