将VTK与CLion一起使用时,我有一个问题。我正在使用cmake3.12在c ++中使用VTK 8.1。当我使用类“ vtkMetaImageReader”读取图像(其他继承“ vtkImageReader2”的类具有相同的问题)时,程序崩溃,并显示“ 进程已完成,退出代码为-1073741515(0xC0000135)“(按字母顺序显示)。但是类“ vtkStructuredPointsReader”可以正确运行。我认为它可能缺少一些与图像相关的库。现在,我不知道这个问题。
CMakeLists.txt
cmake_minimum_required(VERSION 3.12)
project(vtk_demo)
set(CMAKE_CXX_STANDARD 14)
aux_source_directory(src SOURCE_FILES)
set(RES_FILES res/brain.mhd res/brain.raw)
include_directories(include)
#vtk
set(VTK_DIR G:\\VTK)
find_package(VTK REQUIRED)
include(${VTK_USE_FILE})
add_executable(vtk_demo ${SOURCE_FILES} ${RES_FILES})
target_link_libraries(vtk_demo ${VTK_LIBRARIES})
main.cpp
#include <vtkSmartPointer.h>
#include <vtkImageViewer2.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkRenderer.h>
#include <vtkMetaImageReader.h>
int main(int argc, char* argv[])
{
auto reader =
vtkSmartPointer<vtkMetaImageReader>::New();
reader->SetFileName("../res/brain.mhd");
reader->Update();
auto imageViewer =
vtkSmartPointer<vtkImageViewer2>::New();
imageViewer->SetInputConnection(reader->GetOutputPort());
auto renderWindowInteractor =
vtkSmartPointer<vtkRenderWindowInteractor>::New();
imageViewer->SetupInteractor(renderWindowInteractor);
imageViewer->SetColorLevel(500);
imageViewer->SetColorWindow(2000);
imageViewer->SetSlice(40);
imageViewer->SetSliceOrientationToXY();
imageViewer->Render();
imageViewer->GetRenderer()->SetBackground(1.0, 1.0, 1.0);
imageViewer->SetSize(640, 480);
imageViewer->GetRenderWindow()->SetWindowName("DisplayImageExample");
renderWindowInteractor->Start();
return 0;
}
非常感谢您, 最好的祝福, 弗兰克斯