顯示具有 ITK 標籤的文章。 顯示所有文章
顯示具有 ITK 標籤的文章。 顯示所有文章

2014年2月16日 星期日

ITK + VTK + QT on Window 7 64bit and Visual Studio 2010 Pro 64bit project

building a 64-bit libraries and projects
  • ITK + VTK 6 + OpenCV + Qt 4.7.1
  • Windows 7 64-bit and visual studio 2010 sp1
=======================================

CHECK Your things

Visual Studio 2010

  1. assuming you have had it
  2. update to sp1 link

CMake

  1. cross platform
  2. build libraries and projects
  3. download it, e.g.,  Windows (Win32 Installer) cmake-2.8.11.2-win32-x86.exe

ITK & VTK

  1. download itk
  2. download vtk  (it works fine when i was using version 6.0)

Qt 4.7.1

  1. download

OpenCV

  1. download

I refer you to here, if you have not idea how to organize your directories!
Please check step 1 and 2


Now go on to the building part!

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

Building 64-bit libraries by Cmake

Two important things we must remember
  1. we run everything under RELEASE MODE on vs 2010
  2. the platform we use we choose "Visual Studio 10 Win64" in cmake setting

QT part

1. Make sure installed correctly

2. setting up environment variables
  • QTDIR=C:\Qt\4.7.1
  • QMAKESPEC=win32-msvc2010
  • add ”%QTDIR%\bin” to PATH
3.building a 64-bit library for QT (since Qt 4 not supporting 64-bit )
  1. download latest jom, then unzip to "C:\Qt\jom"
  2. using administrator mode to open ”Visual Studio x64 Win64 command line (2010)”
  3. doing the following command in order ( the total time about 40 minutes)
  • configure -debug-and-release -opensource -platform win32-msvc2010
  • ..\jom\jom.exe -j N
(N represent the core number of your computer, e.g., 4 or 8, do not use "N" directly)




VTK part

first, using cmake.....

1. open Cmake (cmake-gui)
2. fill up the Source code path, e.g., ” C:\VTK\vtk-5.10.1\VTK5.10.1” and Binaries code path, e.g., ” C:\VTK\vtk-5.10.1\vs2010_x64”
3. click Configure and choose  “Visual Studio 10 Win64” and  “Use default native compilers”
4. press Finish and wait for a while
5. after Configuration done, find and check the following items (Unbelievably important!!)
  • BUILD_EXAMPLES
  • BUILD_SHARED_LIBS
  • VTK_USE_GUISUPPORT
  • VTK_USE_QT
6. press Configure again, then press Generate
7.waiting for generating done
(note: build_examples checked only for testing those samples)

second, VS2010 part.....

8. go to the binary path where your VS project built, then find "VTK.sln" and open it
9. change this project mode to release mode and x64 platform
10. build this project (it takes at least one hour)

third, post-processing....

11.go to the path that your library should locate, e.g., “C:\vtk\VTK5.10.1\vs10\bin\Release” and make sure there are QVTKWidgetPlugin.lib and QVTKWidgetPlugin.dll inside

12.copy QVTKWidgetPlugin.lib and QVTKWidgetPlugin.dll to “C:\Qt\4.x.x\plugins\designer” and then open your Qt designer, make sure there is a QVTKWidget on the component closet

13.add ”C:\VTK\VTK-5.10.1\vs2010_x64\bin\Release” or whatever place you built it to PATH (important!!)

14. (optional) test if 64-BIT Qt + 64-BIT VTK is OK ,
C:\VTK\VTK-5.10.1\vs2010_x64\Examples\VTKExamples.sln

  • EasyView
  • SimpleView
  • Qtevents
  • qtimageviewer
  • QtVTKRenderWindows
  • EventQtSlotConnect


ITK part

first, using cmake.....

1. open Cmake (cmake-gui)
2. fill up the Source code path, e.g., "C:/ITK/itk-4.4.1/InsightToolkit-4.4.1" and Binaries code path, e.g.,"C:/ITK/itk-4.4.1/vs2010_x64"
3. click Configure and choose  “Visual Studio 10 Win64” and  “Use default native compilers”
4. press Finish and wait for a while

5.after configuration done, check this one (Unbelievably important!!)

  • BUILD_SHARED_LIBS

6. press Configure again, then press Generate
7.waiting for generating done

second, VS2010 part.....

8. go to the binary path where your VS project built, then find "ITK.sln" and open it
9. change this project mode to release mode and x64 platform
10. build this project (it takes at least one hour)

third, environmental variable.....

11. add ”C:\itk\itk-4.2.1\vs10_x64\bin\Release” or whatever place you built it to PATH (Unbelievably important!!)


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

Building 64-bit project by Cmake and check if it works

I refer you to here. Please check step 4
Do NOT forget to build your project on a 64-bit setting as the way you do to build 64-bit libraries above 




Note:
Qt 5+ provides a 64-bit library and it should be working with VTK 6.1+
And I haven't tried it yet!

some useful links....
if your hard-drive is not big enough....link

2013年4月6日 星期六

ITK VTK QT OpenCV Coding 架構


主要功能

  • ITK:
    Segmentation, Read in images, Write out images, Blah, Blah....
  • VTK:
    Show image on VTK window, Render 3D model, Blah...
  • Qt:
    Gui, Blah...
  • OpenCV:
    2D Image Processing, Read in 2D image, Write out 2D image, Show 2D image on OpenCV window, Blah...

主要架構

ITK +OpenCV <===> VTK + OpenCV <===> Qt + OpenCV 
  1. 建立一個ITK和OpenCV專用的Class
    負責最主要影像的處理
    會回傳ITK image
    會回傳OpenCV image
  2. 建立專用VTK和OpenCV的Class
    用來收ITK處理後及OpenCV處理後的影像
    會送出VTK image和OpenCV image
  3. 建立Qt的GUI,專門收VTK的影像和OpenCV的影像
    VTK to Qt -> 藉由QVtkWidget顯示
    OpenCV image to Qt Qimage -> 藉由一個轉換的method (在此) ,顯示在QLabel上

Programming   Form User View to Programmer View

Class Q
  • Using Library
    Qt Library -----> Qt widget
    VTK Library -----> QVtkWidget vtkEventQtSlotConnect
    OpenCV Library -----> show QImage from cv::Mat
  • get VTK image
  • get cv::Mat
  • Show on QVtkWidget or QLabel
Class V
  • Using Library
    VTK Library
    OpenCV Library
    ITK Library
  • get ITK image
  • send VTK image
  • get and send cv::Mat
  • CONVERT ITK image to VTK image
  • For cv::Mat, this class is just a relay
Class I
  • Using Library
    ITK Library
    OpenCV Library
  • produce and send ITK image
  • produce and send cv::Mat
[Note : Only the OpenCV Library shows on every Class. It can be excluded if it is not needed.]

還有....

  1. 這三個Class可以在同一個方案下,但是在三個不同的專案中建立。
  2. 三個專案可以個別編譯,不互相影響,利用互相Linking的方式,可以加快編譯的時間,且Class的封裝性更佳!

2013年2月27日 星期三

ITK + VTK + QT on Window 7 64bit and Visual Studio 2010 Pro 32bit project


STEP ONE

STEP TWO

  • Organize Source code
    • the recommended tree like this - 
      • library
        • library_version_number
          • library_source_code
          • library_build_platform1
          • library_build_platform2
          • library_build_platformX
    • for example:
    • prons:
      • organized and the binary codes for different platforms can be separated from each other
      • easy maintenance
      • easy upgrade

STEP THREE  (main part of this tutorial)

<<build a 32bit environment>> 

  1. build QT -> already done, leave this directory alone!!
  2. build ITK
    1. CMAKE PART
      • using CMake to build the visual studio 2010 32-bit environment
      • fill up the paths of source code and binary
      • click the "Configure" button
      • choose "Visual Studio 2010" and "Use default native compilers" and then click "Finish"
      • wait a few minutes....
      • Generally speaking, the message will show "Configuring done" like this snapshot:
      • Remember: Just leave default setting, because those unchecked items are not being used here for now.
      • click "Generate" button and wait for the "Generate done" message
    2. VISUAL STUDIO PART
      • go to the build directory, e.g. "C:\itk\itk-4.2.1\vs10"
      • open "ITK.sln"
      • build them all under the Debug mode and Release mode
      • wait a few minutes....( at lease one hour, depend on your machine )
      • NOTE HERE: building on the release mode is necessary, because if we want to combine ITK and QT together, visual studio project need to be under the Release mode!!This is a tricky part.
      • Until all the project being built successfully, the building process is over.
  3. build VTK( careful! )
    1. CMAKE PART
      • using CMake to build the visual studio 2010 32-bit environment
      • fill the paths of source code and binary up
      • click the "Configure" button
      • choose "Visual Studio 2010" and "Use default native compilers" and then click "Finish"
      • wait a few minutes....
      • Generally speaking, the message will show "Configuring done" like this snapshot:
      • BE CAREFUL: 
        • CHECK BUILD_EXAMPLES ( for QT + VTK project test )
        • CHECK BUILD_SHARED_LIBS ( for VTK work with QT )
        • CHECK VTK_USE_QT ( for VTK library to build QT-related components)
        • CHECK VTK_USE_GUISUPPORT (  you need to check the "Advanced" item first in order to see this setting)
        • click "Configure" button AGAIN!!
      • if everything goes well, then the result should look like this:
      • click "Generate" button and wait for the "Generate done" message
    2. VISUAL STUDIO PART
      • go to the build directory, e.g. "C:\vtk\VTK5.10.1\vs10"
      • open "VTK.sln"
      • build them all under the Release mode Release mode Release mode
      • wait a few minutes....(  the needed time depends on your machine )
      • NOTE HERE: building on the release mode is necessary, because if we want to combine VTK and QT together, visual studio project need to be under the Release mode!!This is a tricky part.
      • Until all the project being built successfully, the building process is over.
    3. QT SETUP PART
      • go to "C:\vtk\VTK5.10.1\vs10\bin\Release" and check if there are two file name QVTKWidgetPlugin.lib and QVTKWidgetPlugin.dll 
      • (Note: if they are NOT there, then you must have not check BUILD_SHARED_LIBS)
      • Copy QVTKWidgetPlugin.lib and QVTKWidgetPlugin.dll from "C:\vtk\VTK5.10.1\vs10\bin\Release" to C:\Qt\4.x.x\plugins\designer
      • if everything goes well, then open the QT designer. You will find the VTK WINDOW WIDGET at the bottom of the qt widget list like this snapshot:
    4. ENVIRONMENT VARIABLE SETUP PART ( THE MOST IMPORTANT!!!!! )
      • Add a new environment variable: QTDIR = C:\Qt\4.X.X (or whatever VERSION you installed QT)
      • Append the environment variable PATH to add
        • C:\Qt\4.8.4\bin
        • C:\vtk\VTK5.10.1\vs10\bin\Release

STEP FOUR

  • check whether the environment being setup correctly or not
  • check ITK + VTK + QT
  • check ITK + QT
  • check VTK + QT
    • in the VTK source code, there are a few examples can be used for checking under the Example folder
    • Tutorial Projects
      1. EasyView
      2. SimpleView
      3. Qtevents
      4. qtimageviewer
      5. QtVTKRenderWindows
      6. EventQtSlotConnect



References and other useful links



2014/02/25 update

2013年1月28日 星期一

ITK + VTK + QT + OpenCV VS2010 Project Setup


  • 首先Qt的專案格式:
    • 一般來說有五個檔案
      • Program Driver - 
        • ItkVtkQtProjectApp.cxx
        • 程式開始執行位置並初始化一個GUI
      • Qt Gui file - 
        • ItkVtkQtProjectGui.ui
        • 這個檔案是用Qt Designer設計來的GUI,當然也可以用hard-coding方式完成,使用的程式語言是XML
      • Gui Functionality spec & implementation - 
        • ItkVtkQtProjectGui.cxx and ItkVtkQtProjectGui.h
        • 這兩個負責實作Gui的functionality
        • 可以用hard-coding的方式一邊做gui介面,一邊做functionality
      • Qt Gui resources - 
        • ItkVtkQtProjectGui.qrc
        • 專門存放gui可能用到的資源位置,例如icon
    • 專案的檔案都設置好以後進行編譯跟執行時,Qt的meta-object compiler moc會將qt相關的程式部分產生對應的檔案在Generated資料夾下,主要有兩個
      • moc_ItkVtkQtProjectGui.cxx - 根據ItkVtkQtProjectGui.h產生的Meta object code,基本上可以不用動這個檔案
      • ui_ItkVtkQtProjectGui.h - 由ItkVtkQtProjectGui.ui產生的介面,含有C++ code,其中出現的Qt物件會對應Gui的元件以及Gui的Layout
      • 當有需要時,可以來這裡改Gui的設定,除此之外,這兩個不需要特別去動
  • 建立及執行專案
    • 環境設定 - 
      • Window 7 64bit 企業版 + Visual Studio 2010 professional
      • InsightToolkit-4.2.1 + VTK5.10.1 + Qt4.8.4 + OpenCV-2.4.3
    • Cautious:以上使用到的Library必須先正確的在機器上編譯好!
    • Download Project
    • Step 1:
      • 利用Cmake建立專案,過程中如果遇到找不到Library出現Error,就點一下找不到的那個LIBRARY的欄位,接著點右邊的按鈕,明確地給他路徑,然後再點一次Generate即可。
      • 必須直到Cmake皆找到所有Library位置即可,最終結果可能如:
      • Note: 過程中,Cmake可能找到OpenCV的路徑,但是是相對路徑,此時,仍然點OpenCV的欄位,明確地給他路徑,否則之後專案裡面可能會沒有include到OpenCV的Library;如果用不到OpenCV,也可以在CMakeLists.txt中把OpenCV相關的都刪掉,則可以忽略這個Note
    • Step 2:
      • 接著打開專案,在ItkVtkQtProject上點右鍵,將ItkVtkQtProject設成起始專案
      • 改成Release Mode( 非常重要! )
      • Note 1: 編譯過程中compiler可能找不到 「itkImageToVTKImageFilter.h」
        • #include <itkImageToVTKImageFilter.h>,必須在專案屬性頁手動加入這個include檔的原始位置
        • 路徑位置大概在C:\itk\itk-4.2.1\InsightToolkit-4.2.1\Modules\Bridge\VtkGlue\include
      • Note 2: 在執行第一次編譯以前,前面提到的moc_xxx.h 和 ui_xxx.h兩個檔案,會先在實作的code內出現,不過compiler會找不到這些檔案,但是不用擔心,只要執行第一次編譯後,這兩個檔案自然就會出現,程式也可以正常執行
      • 執行結果          
  • 主要概念
    • ITK image 和 VTK image利用itkImageToVTKImageFilter相互連結
    • VTK 和 Qt 利用QVTKWidget連結
    • VTK 和 Qt的差別可以看User Guide或是其他Reference得知,而其中最主要就是利用Qt中signal/slot Connection的概念