Hi,
I am trying to open and display an image with QuickView, however the linker is unable to find QuickView::AddImage.
CMakeFiles/viewer.dir/viewer.cc.o: In function `main':
viewer.cc:(.text+0x12d): undefined reference to `void QuickView::AddImage<itk::Image<short, 3u> >(itk::Image<short, 3u>*, bool, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)'
collect2: error: ld returned 1 exit status
In the cmake file I have:
cmake_minimum_required(VERSION 3.11)
project(itkTest)
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()
add_executable(itkTest itkTest.cc)
target_link_libraries(itkTest ${ITK_LIBRARIES})
add_executable(vtkTest vtkTest.cc)
target_link_libraries(vtkTest ${VTK_LIBRARIES})
add_executable(viewer viewer.cc)
target_link_libraries(viewer ${Glue} ${ITK_LIBRARIES} ${VTK_LIBRARIES})
message(STATUS "${ITK_LIBRARIES}")
I have tried ITK, opening an image, and VTK, displaying a cylinder (VTKExamples/Cxx/Rendering/CylinderRenderingProperties), independently and both compile and run fine.
In ITK_LIBRARIES is included the ITKVtkGlue module (I have compiled the lastest ITK with the Module_ITKVtkGlue option ON) and according to this is there where QuickView should be.
I am working on Archlinux with ITK 5.0.0 installed from git (with make install) and VTK 8.1.0 from the repositories. Cmake 3.11.4.
The code:
#include <QuickView.h>
#include <itkImageFileReader.h>
int main(int argc, char* argv[])
{
const std::string inputFilepath("../resources/training_001/mr_PD/training_001_mr_PD.mhd");
static constexpr unsigned int ImageDimensions = 3;
using PixelType = short;
using ImageType = itk::Image<PixelType, ImageDimensions>;
using ReaderType = itk::ImageFileReader<ImageType>;
ReaderType::Pointer imageReader = ReaderType::New();
imageReader->SetFileName(inputFilepath);
imageReader->Update();
QuickView viewer;
viewer.AddImage(imageReader->GetOutput());
viewer.Visualize();
return 0;
}
Thanks!
PD: The else part in the cmake file is no longer necessary because ITKVtkGlue is (from now on) included in ITK, right?
EDIT: Maybe if I install vtk from github also? I would like to avoid that, because I prefer to pacman to admin my packages. Maybe a cmake variable about VTK, which ITKVtkGlue needs, is not defined correctly?