Added support for vtk images (vti format)

This commit is contained in:
ange-clement 2023-09-11 17:21:37 +02:00
parent bf027d4154
commit b77659beb2
2 changed files with 23 additions and 4 deletions

View File

@ -34,14 +34,14 @@ if(ITK_FOUND)
target_link_libraries(mesh_3_plugin PUBLIC CGAL::ITK_support)
endif(ITK_FOUND)
find_package(VTK QUIET COMPONENTS vtkImagingGeneral vtkIOImage NO_MODULE)
find_package(VTK QUIET COMPONENTS vtkImagingGeneral vtkIOImage vtkIOXML NO_MODULE)
if(VTK_FOUND)
if(VTK_USE_FILE)
include(${VTK_USE_FILE})
endif()
if("${VTK_VERSION_MAJOR}" GREATER "5" OR VTK_VERSION VERSION_GREATER 5)
if(TARGET VTK::IOImage)
set(VTK_LIBRARIES VTK::IOImage VTK::ImagingGeneral)
set(VTK_LIBRARIES VTK::IOImage VTK::ImagingGeneral VTK::IOXML)
endif()
if(NOT VTK_LIBRARIES)
message(STATUS "NOTICE: DICOM files (.dcm) require the VTK libraries, and will not be readable.")

View File

@ -56,6 +56,7 @@
#include <vtkNew.h>
#include <vtkStringArray.h>
#include <vtkImageData.h>
#include <vtkXMLImageDataReader.h>
#include <vtkDICOMImageReader.h>
#include <vtkBMPReader.h>
#include <vtkNIFTIImageReader.h>
@ -1089,6 +1090,7 @@ QString Io_image_plugin::nameFilters() const
return QString("Inrimage files (*.inr *.inr.gz) ;; "
"Analyze files (*.hdr *.img *.img.gz) ;; "
"Stanford Exploration Project files (*.H *.HH) ;; "
"VTK image files (*.vti) ;; "
"NRRD image files (*.nrrd) ;; "
"NIFTI image files (*.nii *.nii.gz)");
}
@ -1128,8 +1130,25 @@ Io_image_plugin::load(QFileInfo fileinfo, bool& ok, bool add_to_scene)
QApplication::restoreOverrideCursor();
Image* image = new Image;
// read a vti file
if(fileinfo.suffix() == "vti")
{
#ifdef CGAL_USE_VTK
vtkNew<vtkXMLImageDataReader> reader;
reader->SetFileName(fileinfo.filePath().toUtf8());
reader->Update();
auto vtk_image = reader->GetOutput();
vtk_image->Print(std::cerr);
*image = CGAL::IO::read_vtk_image_data(vtk_image); // copy the image data
#else
CGAL::Three::Three::warning("VTK is required to read VTI files");
delete image;
return QList<Scene_item*>();
#endif
}
// read a nrrd file
if(fileinfo.suffix() == "nrrd")
else if(fileinfo.suffix() == "nrrd")
{
#ifdef CGAL_USE_VTK
vtkNew<vtkNrrdReader> reader;
@ -1146,7 +1165,7 @@ Io_image_plugin::load(QFileInfo fileinfo, bool& ok, bool add_to_scene)
}
// read a NIFTI file
if(fileinfo.suffix() == "nii"
else if(fileinfo.suffix() == "nii"
|| ( fileinfo.suffix() == "gz"
&& fileinfo.fileName().endsWith(QString(".nii.gz"), Qt::CaseInsensitive)))
{