From b2f3eedb2f9dbc65a887e5eae6a392838b4077c6 Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Thu, 24 Nov 2022 16:14:11 +0000 Subject: [PATCH] 3d Demo: Try to read bmp files --- .../include/CGAL/IO/read_vtk_image_data.h | 6 +- .../Plugins/Mesh_3/Io_image_plugin.cpp | 76 +++++++++++++++---- 2 files changed, 64 insertions(+), 18 deletions(-) diff --git a/CGAL_ImageIO/include/CGAL/IO/read_vtk_image_data.h b/CGAL_ImageIO/include/CGAL/IO/read_vtk_image_data.h index ccce66f3ca6..3b7efa6c4df 100644 --- a/CGAL_ImageIO/include/CGAL/IO/read_vtk_image_data.h +++ b/CGAL_ImageIO/include/CGAL/IO/read_vtk_image_data.h @@ -85,9 +85,9 @@ read_vtk_image_data(vtkImageData* vtk_image, Image_3::Own owning = Image_3::OWN_ CGAL_assertion(vtk_image->GetPointData()->GetScalars()->GetNumberOfTuples() == dims[0]*dims[1]*dims[2]); if(owning == Image_3::OWN_THE_DATA) { image->data = ::ImageIO_alloc(dims[0]*dims[1]*dims[2]*image->wdim); - // std::cerr << "GetNumberOfTuples()=" << vtk_image->GetPointData()->GetScalars()->GetNumberOfTuples() - // << "\nimage->size()=" << dims[0]*dims[1]*dims[2] - // << "\nwdim=" << image->wdim << '\n'; + std::cerr << "GetNumberOfTuples()=" << vtk_image->GetPointData()->GetScalars()->GetNumberOfTuples() + << "\nimage->size()=" << dims[0]*dims[1]*dims[2] + << "\nwdim=" << image->wdim << '\n'; vtk_image->GetPointData()->GetScalars()->ExportToVoidPointer(image->data); } else { image->data = vtk_image->GetPointData()->GetScalars()->GetVoidPointer(0); diff --git a/Polyhedron/demo/Polyhedron/Plugins/Mesh_3/Io_image_plugin.cpp b/Polyhedron/demo/Polyhedron/Plugins/Mesh_3/Io_image_plugin.cpp index f74562e6e58..671850655d6 100644 --- a/Polyhedron/demo/Polyhedron/Plugins/Mesh_3/Io_image_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Plugins/Mesh_3/Io_image_plugin.cpp @@ -49,6 +49,7 @@ #include #include +#include #include #include @@ -60,8 +61,10 @@ #include #include +#include #include #include +#include #include #include #include @@ -1314,24 +1317,67 @@ Image* Io_image_plugin::createDCMImage(QString dirname) { Image* image = nullptr; #ifdef CGAL_USE_VTK - vtkNew dicom_reader; - dicom_reader->SetDirectoryName(dirname.toUtf8()); - auto executive = - vtkDemandDrivenPipeline::SafeDownCast(dicom_reader->GetExecutive()); - if (executive) - { - executive->SetReleaseDataFlag(0, 0); // where 0 is the port index + bool is_dcm = false; + bool is_bmp = false; + + vtkStringArray* files = vtkStringArray::New(); + boost::filesystem::path p(dirname.toUtf8().data()); + for(boost::filesystem::directory_entry& x : boost::filesystem::directory_iterator(p)){ + std::string s(x.path().extension().string()); + if(s == std::string(".dcm") || (s == std::string(".DCM"))){ is_dcm = true;} + if(s == std::string(".bmp") || (s == std::string(".BMP"))){ is_bmp = true;} + std::cout << x.path().string() << std::endl; + files->InsertNextValue(x.path().string()); + } + + if(is_dcm){ + vtkNew dicom_reader; + dicom_reader->SetDirectoryName(dirname.toUtf8()); + + auto executive = + vtkDemandDrivenPipeline::SafeDownCast(dicom_reader->GetExecutive()); + if (executive) + { + executive->SetReleaseDataFlag(0, 0); // where 0 is the port index + } + + vtkNew smoother; + smoother->SetStandardDeviations(1., 1., 1.); + smoother->SetInputConnection(dicom_reader->GetOutputPort()); + smoother->Update(); + auto vtk_image = smoother->GetOutput(); + vtk_image->Print(std::cerr); + image = new Image; + *image = CGAL::IO::read_vtk_image_data(vtk_image); // copy the + // image data + } + + if(is_bmp){ + vtkNew bmp_reader; + bmp_reader->SetFileNames(files); + + auto executive = + vtkDemandDrivenPipeline::SafeDownCast(bmp_reader->GetExecutive()); + if (executive) + { + executive->SetReleaseDataFlag(0, 0); // where 0 is the port index + } + vtkNew smoother; + smoother->SetStandardDeviations(1., 1., 1.); + smoother->SetInputConnection(bmp_reader->GetOutputPort()); + smoother->Update(); + auto vtk_image = smoother->GetOutput(); + vtk_image->Print(std::cerr); + image = new Image; + + std::cout << "A" << std::endl; + *image = CGAL::IO::read_vtk_image_data(vtk_image); // copy the + // image data + + std::cout << "B" << std::endl; } - vtkNew smoother; - smoother->SetStandardDeviations(1., 1., 1.); - smoother->SetInputConnection(dicom_reader->GetOutputPort()); - smoother->Update(); - auto vtk_image = smoother->GetOutput(); - vtk_image->Print(std::cerr); - image = new Image; - *image = CGAL::IO::read_vtk_image_data(vtk_image); // copy the image data #else CGAL::Three::Three::warning("You need VTK to read a DCM file"); CGAL_USE(dirname);