ITK-VTK vtkResliceImageViewer undefined

时间:2015-08-27 15:42:32

标签: c++ qt vtk itk

关于编译应该使用VTK以及ITK库的小示例程序,我有一个严重的问题。 该示例的目标是将Dicom图像从文件夹加载到VTK图像格式,将它们转换为ITK图像格式,执行操作并将它们转换回VTK图像格式以显示它们。

以下是示例程序:

#include <iostream>
#include <math.h>  


#include <vtkSmartPointer.h>
#include <vtkDICOMImageReader.h>
#include <vtkRenderer.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkResliceImageViewer.h>
#include <vtkRenderWindow.h>


#include "itkRelabelComponentImageFilter.h"
#include "itkImage.h"
#include "itkVTKImageToImageFilter.h"
#include "itkBinaryThresholdImageFilter.h"
#include "itkLabelGeometryImageFilter.h"
#include "itkImageToVTKImageFilter.h"
#include "itkConnectedComponentImageFilter.h"
#include "itkBinaryImageToLabelMapFilter.h"
#include "itkLabelMapToLabelImageFilter.h"

#include "markerLib/markerlib.h"

int main(int argc, char *argv[]) {

    const unsigned int Dimension = 3;

    //Image Type
    typedef itk::Image<short, Dimension> ShortImageType;

    //Types for converting between ITK and VTK
    typedef itk::VTKImageToImageFilter<ShortImageType> VTKImageToImageType;
    typedef itk::ImageToVTKImageFilter<ShortImageType> ConnectorType;


    //Read DICOM Data
    vtkSmartPointer<vtkDICOMImageReader> reader = vtkSmartPointer<vtkDICOMImageReader>::New();
    reader->SetDirectoryName("some_path");//Type the correct absolute path to the Dicom data here.
    reader->Update();


    //Converting to ITK Image Format
    VTKImageToImageType::Pointer vtkImageToImageFilter = VTKImageToImageType::New();
    vtkImageToImageFilter->SetInput(reader->GetOutput());
    vtkImageToImageFilter->Update();

    //Converting Back from ITK to VTK Image for Visualization.
    ConnectorType::Pointer connector = ConnectorType::New();
    connector->SetInput(vtkImageToImageFilter->GetOutput());
    //connector->SetInput(removed->GetOutput()); //The current Threshold(minVoxelCount) seems to be to high. because the marker is not visible if looking at the filtered set.
    connector->Update();


//    //Showing slice imagesvtkResliceImageViewer
    vtkSmartPointer<vtkResliceImageViewer>viewer = vtkSmartPointer<vtkResliceImageViewer>::New();
    vtkSmartPointer<vtkRenderWindowInteractor>interactor = vtkSmartPointer<vtkRenderWindowInteractor>::New();
    interactor->SetRenderWindow(viewer->GetRenderWindow());

    viewer->SetupInteractor(interactor);
    viewer->SetInputData(connector->GetOutput());
    int midslice = viewer->GetSliceMax() / 2;
    viewer->SetSlice(midslice);
    viewer->SetSliceOrientationToXY();

    viewer->GetRenderer()->ResetCamera();
    viewer->Render();
    interactor->Start();
    return EXIT_SUCCESS;
}

VTK必须是6.1.0版。我使用cmake创建了一个make文件,其中包含标志共享库和qt组。机器上安装的Qt版本是5.3.1。 ITK版本不太相关,但我使用的是4.8.0版本。 我创建了一个启用了VTK-glue标志的make文件。 VTK和ITK都编译没有任何错误。我在两个库上执行了make install。 我的示例程序使用以下CMakeLists.txt创建一个makefile:

cmake_minimum_required(VERSION 2.8)

project(marker)

find_package(ITK REQUIRED)
include(${ITK_USE_FILE})
if (ITKVtkGlue_LOADED)
  find_package(VTK REQUIRED)
  include(${VTK_USE_FILE})
else()
  find_package(ItkVtkGlue REQUIRED)
  include(${ItkVtkGlue_USE_FILE})
  set(Glue ItkVtkGlue)
endif()

file(GLOB HEADER_FILES *.h)
file(GLOB CPP_FILES *.cpp)

add_executable(${PROJECT_NAME} ${SRC_LIST} ${CPP_FILES})
target_link_libraries(${PROJECT_NAME} ${Glue}  ${VTK_LIBRARIES} ${ITK_LIBRARIES})

message("VTK ${VTK_LIBRARIES}            ITK  ${ITK_LIBRARIES}")

尝试编译程序时,会抛出以下错误:

Scanning dependencies of target marker
[100%] Building CXX object CMakeFiles/marker.dir/main.cpp.o
Linking CXX executable marker
CMakeFiles/marker.dir/main.cpp.o: In function `vtkSmartPointer<vtkResliceImageViewer>::New()':
main.cpp:(.text._ZN15vtkSmartPointerI21vtkResliceImageViewerE3NewEv[_ZN15vtkSmartPointerI21vtkResliceImageViewerE3NewEv]+0xd): undefined reference to `vtkResliceImageViewer::New()'
collect2: error: ld returned 1 exit status
make[2]: *** [marker] Error 1
make[1]: *** [CMakeFiles/marker.dir/all] Error 2
make: *** [all] Error 2

无法解析vtkResliceImageViewer。另外,如果你查看cmake生成的消息,你可以看到VTK_LIBRARIES只有两个库,而ITK还有更多库。

cmake消息:

VTK vtkCommonCore;vtksys            ITK  itkdouble-conversion;itksys;itkvnl_algo;itkvnl;itkv3p_netlib;ITKCommon;itkNetlib........

奇怪的是,在另一台机器上程序编译没有任何错误和工作。因此,VTK和ITK的相当复杂的编译步骤必定存在一些差异。

我现在的问题是,是否有人看到过类似的错误,或者有人认为缺少VTK库的原因是什么?

1 个答案:

答案 0 :(得分:2)

之前我遇到过这个问题。 ITK的find_package覆盖了VTK_LIBRARIES。解决方法是将库存储在临时变量中,如下所示:

find_package(VTK) 
set(VTK_LIBS_ORIG ${VTK_LIBRARIES})  # store the libs in an extra variable
include(${VTK_USE_FILE})

find_package(ITK)
include(${ITK_USE_FILE})

# now restore the variables back:
set(VTK_LIBRARIES ${VTK_LIBS_ORIG})

HTH, 米罗