简体   繁体   English

ITK-VTK vtkResliceImageViewer未定义

[英]ITK-VTK vtkResliceImageViewer undefined

I have a serious problem concerning the compilation of a small example programm which should use the VTK as well as the ITK Library. 我有一个严重的问题,涉及一个小示例程序的编译,该程序应使用VTK以及ITK库。 Goal of the example is to load Dicom Images from a folder into VTK image format, convert them to ITK image format, perform operations and convert them back to VTK image format to display them. 该示例的目标是将文件夹中的Dicom图像加载为VTK图像格式,将其转换为ITK图像格式,执行操作,然后将其转换回VTK图像格式以显示它们。

Here is the sample program: 这是示例程序:

#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;
}

The VTK must be version 6.1.0. VTK必须为6.1.0版本。 I created a make file using cmake with the flag shared libs and qt group on. 我使用带有标记共享库和qt组的cmake创建了一个make文件。 the Qt Version is installed on the machine is 5.3.1. 机器上安装的Qt版本是5.3.1。 The ITK version is less relevant, but I used Version 4.8.0. ITK版本的相关性较小,但是我使用的是4.8.0版本。 I created a make file with the VTK-glue flag enabled. 我创建了一个启用了VTK-glue标志的make文件。 Both VTK and ITK compiled without any errors. VTK和ITK均已编译,没有任何错误。 I performed a make install on both libraries. 我在两个库上都进行了安装。 My sample programm creates a makefile with the following CMakeLists.txt: 我的示例程序使用以下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}")

When trying to compile the program the following error gets thrown: 尝试编译程序时,将引发以下错误:

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

It cannot resolve the vtkResliceImageViewer. 它无法解析vtkResliceImageViewer。 Also, if you look at the message of the cmake generation you can see that VTK_LIBRARIES is only two libs while ITK has many more. 另外,如果您查看cmake生成的消息,您会看到VTK_LIBRARIES只是两个库,而ITK还有更多。

cmake Message: cmake消息:

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

The strange thing is that on another machine the program compiles without any errors and works. 奇怪的是,该程序在另一台计算机上编译时没有任何错误,并且可以正常工作。 So there must be some differences in the pretty complicated compilation steps of VTK and ITK. 因此,VTK和ITK的非常复杂的编译步骤必须存在一些差异。

My Question now is, has somebody seen a similar error, or has somebody a glue what the reason for the missing VTK libs could be? 我现在的问题是,有人看到过类似的错误,还是有人粘了,丢失VTK库的原因可能是什么?

I had an issue with this before. 我以前对此有疑问。 ITK's find_package was overwriting VTK_LIBRARIES. ITK的find_package正在覆盖VTK_LIBRARIES。 The workaround is to store the libraries in a temp variable, like so: 解决方法是将库存储在临时变量中,如下所示:

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, Miro HTH,Miro

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM