Tag Archives: Study the

Howto Install and Configure VTK on Ubuntu

Howto Install and Configure VTK on Ubuntu

    Download vtk-5.10.1.tar.gz fromhttp://vtk.org/VTK/resources/software.html#latestand extract; $cd/home/chen/Downloads/VTK5.10.1/ $mkdir VTKBin $cd VTKBin $cmake .. $ccmake .. configure as follows:
    press c to configure, and press g togenerate and exit;
    $make copy the include files andlibraries to system directories: $sudo make install copy the plugin to qt:

      $cd /usr/lib/qt4 sudo mkdir plugins cd plugins sudo mkdir designer sudo cp~/Downloads/VTK5.10.1/VTKBin/bin/libQVTKWidgetPlugin. so/usr/lib/qt4/plugins/designer open qtcreator (can be installedfrom Ubuntu Software Center) create one Gui application and open the ui by qtdesigner tocheck QVTKWidget.

To use VTK in your own project, addfollowing to the CMakeLists.txt in your project:
########################################################
#VTK
#set(VTK_DIR”~/Downloads/vtk/VTK5.10.1/build”)
set(VTK_DIR “/usr/local/lib/vtk-5.10”)
find_package(VTK REQUIRED)
include(${VTK_USE_FILE})
########################################################

add target link libraries to yourproject: ${VTK_LIBRARIES} QVTK

A complete example of using VTKtogether with Qt in a CMake project can be found at:
http://blog.csdn.net/owldestiny/article/details/8806128.

Herewe give a complete CMake project using both Qt and VTK, the completeprogram can be download athttp://download.csdn.net/detail/owldestiny/5262489:
Theproject structure is:
└──QtVtkTest
├──bin
│  └── QtVtkTest
├──build
├──CMakeLists.txt
├──include
│  └── QtVtkTest.h
├──qrc
├──src
│  ├── main.cpp
│  └── QtVtkTest.cpp
└──ui
└── QtVtkTest.ui

Inthis project we do not use qrc.
TheCMakeLists.txt is:
======================================================================
cmake_minimum_required(VERSION2.8)
project(QtVtkPCLTest)

set(CMAKE_BUILD_TYPEdebug)
########################################################
#Qt
find_package(Qt4REQUIRED)
include(${QT_USE_FILE})
add_definitions(${QT_DEFINITIONS})
########################################################

########################################################
#VTK
#set(VTK_DIR”~/Downloads/vtk/VTK5.10.1/build”)
set(VTK_DIR”/usr/local/lib/vtk-5.10″)
find_package(VTKREQUIRED)
include(${VTK_USE_FILE})
#MESSAGE(STATUS${VTK_LIBRARIES})
########################################################

########################################################
#PCL
find_package(PCL1.3 REQUIRED)
include_directories(${PCL_INCLUDE_DIRS})
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})
########################################################

########################################################
#Projectsettings
#set(PROJECT_SOURCESmain.cpp)#all sources files
set(LIBRARY_OUTPUT_PATH${PROJECT_SOURCE_DIR}/lib)
set(EXECUTABLE_OUTPUT_PATH${PROJECT_SOURCE_DIR}/bin)
include_directories(${PROJECT_SOURCE_DIR}/include${CMAKE_CURRENT_BINARY_DIR})#to include ui_*.h generated byQT4_WRAP_UI, you should include ${CMAKE_CURRENT_BINARY_DIR}
aux_source_directory(${PROJECT_SOURCE_DIR}/src/PROJECT_SOURCES)
########################################################

########################################################
#GenerateQt files
set(PROJECT_HEADERS${PROJECT_SOURCE_DIR}/include/QtVtkPCLTest.h)#only headers includeQ_OBJECT
QT4_WRAP_CPP(PROJECT_HEADERS_MOC${PROJECT_HEADERS})

set(PROJECT_UI${PROJECT_SOURCE_DIR}/ui/QtVtkPCLTest.ui)#ui file
QT4_WRAP_UI(PROJECT_UI_UIC${PROJECT_UI})
#file(COPY${PROJECT_UI_UIC} DESTINATION ${PROJECT_SOURCE_DIR}/include/)#copyui_.h file to include
#message(STATUSPROJECT_UI: ${PROJECT_UI})
#message(STATUSPROJECT_UI_UIC: ${PROJECT_UI_UIC})
#message(STATUSCMAKE_BINARY_DIR: ${CMAKE_BINARY_DIR})
#message(STATUSPROJECT_BINARY_DIR: ${PROJECT_BINARY_DIR})
#message(STATUSCMAKE_SOURCE_DIR: ${CMAKE_SOURCE_DIR})
#message(STATUSPROJECT_SOURCE_DIR: ${PROJECT_SOURCE_DIR})
#message(STATUSCMAKE_CURRENT_BINARY_DIR: ${CMAKE_CURRENT_BINARY_DIR})

#set(PROJECT_RC${PROJECT_SOURCE_DIR}/qrc)#resource files
#QT4_WRAP_RESOURCES(PROJECT_RC_RCC${PROJECT_RC})
########################################################

########################################################
#generateexecutables and link libraries
add_executable(QtVtkPCLTest${PROJECT_SOURCES} ${PROJECT_HEADERS_MOC} ${PROJECT_UI_UIC})#${PROJECT_RC_RCC})
target_link_libraries(QtVtkPCLTest${QT_LIBRARIES} ${VTK_LIBRARIES} QVTK ${PCL_LIBRARIES})#QVTKQVTKWidget for VTK in Qt
======================================================================

The QtVtkTest. ui(only including one QVTKWidget) can be generated and edited by QtDesigner as:
======================================================================

<?xml version="1.0"encoding="UTF-8"?>
<ui version="4.0">
<class>mainWindow</class>
<widget class="QMainWindow"name="mainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>722</width>
<height>512</height>
</rect>
</property>
<property name="windowTitle">
<string>Qt VTK Test</string>
</property>
<widget class="QWidget"name="centralwidget">
<widget class="QVTKWidget"name="qvtkWidget">
<property name="geometry">
<rect>
<x>20</x>
<y>10</y>
<width>691</width>
<height>471</height>
</rect>
</property>
</widget>
</widget>
<widget class="QStatusBar"name="statusbar"/>
</widget>
<customwidgets>
<customwidget>
<class>QVTKWidget</class>
<extends>QWidget</extends>
<header>QVTKWidget.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>

======================================================================

The main.cpp is:
======================================================================

#include <QApplication>
#include "QtVtkTest.h"


int main(int argc, char**argv)
{
QApplication app(argc,argv);
Qt_QtVtkTest qtTest;
qtTest.show();

return app.exec();
}

======================================================================

TheQtVtkTest.h is:
======================================================================

#include <QtGui/QMainWindow>
#include "ui_QtVtkTest.h"

class Qt_QtVtkTest: publicQMainWindow
{
Q_OBJECT
public:
Qt_QtVtkTest()
{
ui.setupUi(this);
}
public:
Ui::mainWindow ui;

};

======================================================================