赞
踩
#include <vtkSmartPointer.h> #include <vtkImageViewer2.h> #include <vtkDICOMImageReader.h> #include <vtkRenderWindow.h> #include <vtkRenderWindowInteractor.h> #include <vtkRenderer.h> #include <vtkPNGWriter.h> #include <vtkImageCast.h> #include <vtkAutoInit.h> VTK_MODULE_INIT(vtkRenderingOpenGL2) int main(int argc, char* argv[]) { // Verify input arguments //if (argc != 2) //{ // std::cout << "Usage: " << argv[0] // << " Filename(.img)" << std::endl; // return EXIT_FAILURE; //} std::string inputFilename = "/home/tiger/dicom/data/test/004/CT_5fd5cc06429eb17f.dcm"; // Read all the DICOM files in the specified directory. vtkSmartPointer<vtkDICOMImageReader> reader = vtkSmartPointer<vtkDICOMImageReader>::New(); reader->SetFileName(inputFilename.c_str()); reader->Update(); // Visualize vtkSmartPointer<vtkImageViewer2> imageViewer = vtkSmartPointer<vtkImageViewer2>::New(); imageViewer->SetInputConnection(reader->GetOutputPort()); vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor = vtkSmartPointer<vtkRenderWindowInteractor>::New(); imageViewer->SetupInteractor(renderWindowInteractor); imageViewer->Render(); imageViewer->GetRenderer()->ResetCamera(); imageViewer->Render(); vtkSmartPointer<vtkImageCast> castFilter = vtkSmartPointer<vtkImageCast>::New(); castFilter->SetOutputScalarTypeToUnsignedShort(); castFilter->SetInputConnection(reader->GetOutputPort()); castFilter->Update(); vtkSmartPointer<vtkPNGWriter> writer = vtkSmartPointer<vtkPNGWriter>::New(); writer->SetFileName("out.png"); writer->SetInputConnection(castFilter->GetOutputPort()); writer->Write(); renderWindowInteractor->Start(); return EXIT_SUCCESS; }
// CMakeLists.txt cmake_minimum_required(VERSION 3.3 FATAL_ERROR) project(AnimateActors) find_package(Qt5 REQUIRED Widgets) # opencv find_package(OpenCV REQUIRED ) find_package(VTK COMPONENTS vtkCommonColor vtkCommonCore vtkCommonDataModel vtkFiltersSources vtkInteractionStyle vtkRenderingContextOpenGL2 vtkRenderingCore vtkIOExport vtkInteractionImage vtkRenderingFreeType vtkRenderingGL2PSOpenGL2 vtkRenderingOpenGL2 QUIET ) if (NOT VTK_FOUND) message("Skipping AnimateActors: ${VTK_NOT_FOUND_MESSAGE}") return () endif() message (STATUS "VTK_VERSION: ${VTK_VERSION}") if (VTK_VERSION VERSION_LESS "8.90.0") # old system include(${VTK_USE_FILE}) add_executable(AnimateActors MACOSX_BUNDLE AnimateActors.cxx ) target_link_libraries(AnimateActors PRIVATE ${VTK_LIBRARIES} ${OpenCV_LIBS} Qt5::Widgets) else () # include all components add_executable(AnimateActors MACOSX_BUNDLE AnimateActors.cxx ) target_link_libraries(AnimateActors PRIVATE ${VTK_LIBRARIES} ${OpenCV_LIBS} Qt5::Widgets) # vtk_module_autoinit is needed vtk_module_autoinit( TARGETS AnimateActors MODULES ${VTK_LIBRARIES} ) endif ()
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。