From 0e9905c4903008e29c32eb3ef4cfa97da8d6ca52 Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Tue, 24 Oct 2023 14:43:24 +0100 Subject: [PATCH] Fixes --- Mesh_3/examples/Mesh_3/mesh_3D_gray_vtk_image.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/Mesh_3/examples/Mesh_3/mesh_3D_gray_vtk_image.cpp b/Mesh_3/examples/Mesh_3/mesh_3D_gray_vtk_image.cpp index 8c895a87a952..52d123fd441c 100644 --- a/Mesh_3/examples/Mesh_3/mesh_3D_gray_vtk_image.cpp +++ b/Mesh_3/examples/Mesh_3/mesh_3D_gray_vtk_image.cpp @@ -57,7 +57,7 @@ int main(int argc, char* argv[]) return 0; } - vtkImageData* vtk_image; + vtkImageData* vtk_image = nullptr; Image_word_type iso = (argc>2)? boost::lexical_cast(argv[2]): 1; double fs = (argc>3)? boost::lexical_cast(argv[3]): 1; double fd = (argc>4)? boost::lexical_cast(argv[4]): 0.1; @@ -69,9 +69,8 @@ int main(int argc, char* argv[]) std::cout << "regular file" << std::endl; if (path.has_extension()){ fs::path stem = path.stem(); - if ((path.extension() == "nii") || (stem.has_extension() && (stem.extension() == "nii") && (path.extension() == "gz"))) { - - vtkNew reader; + if ((path.extension() == ".nii") || (stem.has_extension() && (stem.extension() == ".nii") && (path.extension() == ".gz"))) { + vtkNIFTIImageReader* reader = vtkNIFTIImageReader::New(); reader->SetFileName(argv[1]); reader->Update(); vtk_image = reader->GetOutput(); @@ -94,9 +93,13 @@ int main(int argc, char* argv[]) smoother->SetStandardDeviations(1., 1., 1.); smoother->SetInputConnection(dicom_reader->GetOutputPort()); smoother->Update(); - vtkImageData* vtk_image = smoother->GetOutput(); + vtk_image = smoother->GetOutput(); vtk_image->Print(std::cerr); } + if(vtk_image == nullptr){ + std::cout << "No image loaded" << std::endl; + return 0; + } CGAL::Image_3 image = CGAL::IO::read_vtk_image_data(vtk_image); if(image.image() == nullptr){ std::cerr << "could not create a CGAL::Image_3 from the vtk image\n";