From 6380e075531009ae8ef1197a06594e0f867f8b74 Mon Sep 17 00:00:00 2001 From: Laurent Rineau Date: Fri, 2 Apr 2021 12:02:33 +0200 Subject: [PATCH 1/5] Add an example for CGAL ImageIO --- .../examples/CGALimageIO/CMakeLists.txt | 1 + .../examples/CGALimageIO/slice_image.cpp | 23 +++++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 CGAL_ImageIO/examples/CGALimageIO/slice_image.cpp diff --git a/CGAL_ImageIO/examples/CGALimageIO/CMakeLists.txt b/CGAL_ImageIO/examples/CGALimageIO/CMakeLists.txt index 388320a6938..806669e9ffe 100644 --- a/CGAL_ImageIO/examples/CGALimageIO/CMakeLists.txt +++ b/CGAL_ImageIO/examples/CGALimageIO/CMakeLists.txt @@ -16,6 +16,7 @@ if(CGAL_ImageIO_FOUND) create_single_source_cgal_program("convert_raw_image_to_inr.cpp") create_single_source_cgal_program("test_imageio.cpp") create_single_source_cgal_program("extract_a_sub_image.cpp") + create_single_source_cgal_program("slice_image.cpp") else() message( STATUS diff --git a/CGAL_ImageIO/examples/CGALimageIO/slice_image.cpp b/CGAL_ImageIO/examples/CGALimageIO/slice_image.cpp new file mode 100644 index 00000000000..8d6b9056ead --- /dev/null +++ b/CGAL_ImageIO/examples/CGALimageIO/slice_image.cpp @@ -0,0 +1,23 @@ +#include +#include +#include + +int main(int argc, char **argv) { + _image *image = ::_readImage(argv[1]); + if (!image) + return 2; + auto *new_image = ::_createImage(image->xdim, image->ydim, image->zdim / 2 + 1, 1, + image->vx, image->vy, image->vz*2, image->wdim, + image->wordKind, image->sign); + const auto* const data = static_cast(image->data); + auto* new_data = static_cast(new_image->data); + const auto slice_size = image->wdim * image->xdim * image->ydim; + for (auto k = 0ul; k < image->zdim; k+=2) { + auto pos = data + slice_size * k; + new_data = std::copy(pos, pos + slice_size, new_data); + } + auto r = ::_writeImage(new_image, argv[2]); + if(r != ImageIO_NO_ERROR) return 3; + ::_freeImage(image); + ::_freeImage(new_image); +} From c5334e5d25abae37648e1a8d230ca206282b74bc Mon Sep 17 00:00:00 2001 From: Laurent Rineau Date: Fri, 2 Apr 2021 12:04:30 +0200 Subject: [PATCH 2/5] Fix a typo --- CGAL_ImageIO/examples/CGALimageIO/extract_a_sub_image.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CGAL_ImageIO/examples/CGALimageIO/extract_a_sub_image.cpp b/CGAL_ImageIO/examples/CGALimageIO/extract_a_sub_image.cpp index a5065e09b3b..39e91274cb6 100644 --- a/CGAL_ImageIO/examples/CGALimageIO/extract_a_sub_image.cpp +++ b/CGAL_ImageIO/examples/CGALimageIO/extract_a_sub_image.cpp @@ -33,7 +33,7 @@ int main(int argc, char **argv) { for (auto k = zmin; k < zmax; ++k) for (auto j = ymin; j <= ymax; ++j) for (auto i = xmin; i <= xmax; ++i) { - auto pos = data + image->wdim * (i + image->xdim * (j + image->zdim * k)); + auto pos = data + image->wdim * (i + image->xdim * (j + image->ydim * k)); std::copy(pos, pos + image->wdim, new_data); new_data += image->wdim; } From 0f2bcf2aa682236881a7fd30dbb81863e0287a96 Mon Sep 17 00:00:00 2001 From: Laurent Rineau Date: Fri, 2 Apr 2021 12:05:44 +0200 Subject: [PATCH 3/5] Fix the CMakeLists.txt for image_to_vtk_viewer.cpp --- CGAL_ImageIO/archive/demo/CGALimageIO/CMakeLists.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CGAL_ImageIO/archive/demo/CGALimageIO/CMakeLists.txt b/CGAL_ImageIO/archive/demo/CGALimageIO/CMakeLists.txt index 08e42e919b7..6c0c738586f 100644 --- a/CGAL_ImageIO/archive/demo/CGALimageIO/CMakeLists.txt +++ b/CGAL_ImageIO/archive/demo/CGALimageIO/CMakeLists.txt @@ -30,8 +30,8 @@ if(VTK_FOUND) if(TARGET vtkRenderingQt AND TARGET vtkFiltersModeling) find_package(VTK COMPONENTS vtkRenderingQt vtkFiltersModeling NO_MODULE) include(${VTK_USE_FILE}) - find_package(Qt${VTK_QT_VERSION} COMPONENTS QtGui) - if(NOT TARGET Qt${VTK_QT_VERSION}::QtGui) + find_package(Qt${VTK_QT_VERSION} COMPONENTS Gui) + if(NOT TARGET Qt${VTK_QT_VERSION}::Gui) message( STATUS "NOTICE: vtkRenderingQt needs Qt${VTK_QT_VERSION}, and will not be compiled." @@ -44,7 +44,7 @@ if(VTK_FOUND) target_link_libraries( image_to_vtk_viewer ${CGAL_LIBRARIES} ${CGAL_3RD_PARTY_LIBRARIES} - ${VTK_LIBRARIES} Qt${VTK_QT_VERSION}::QtGui) + ${VTK_LIBRARIES} Qt${VTK_QT_VERSION}::Gui) else() message( STATUS From ab1c30a9a5267bc97112976d06b31ba4468f4a6a Mon Sep 17 00:00:00 2001 From: Laurent Rineau Date: Fri, 2 Apr 2021 12:06:20 +0200 Subject: [PATCH 4/5] Add support for tx/ty/tz (the origin) in Image_3_vtk_interface.h --- CGAL_ImageIO/include/CGAL/Image_3_vtk_interface.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CGAL_ImageIO/include/CGAL/Image_3_vtk_interface.h b/CGAL_ImageIO/include/CGAL/Image_3_vtk_interface.h index 1ef3d90f7ec..a5271fe59e9 100644 --- a/CGAL_ImageIO/include/CGAL/Image_3_vtk_interface.h +++ b/CGAL_ImageIO/include/CGAL/Image_3_vtk_interface.h @@ -110,6 +110,9 @@ struct VTK_type_generator { vtk_image->SetSpacing(image.vx(), image.vy(), image.vz()); + vtk_image->SetOrigin(image.tx(), + image.ty(), + image.tz()); vtk_image->AllocateScalars(type, 1); vtk_image->GetPointData()->SetScalars(data_array); return vtk_image; From b6d0c086ef100d5f29a9225c94f3bd5714408e0b Mon Sep 17 00:00:00 2001 From: Laurent Rineau Date: Tue, 13 Apr 2021 11:33:32 +0200 Subject: [PATCH 5/5] Fix for the testsuite --- CGAL_ImageIO/examples/CGALimageIO/slice_image.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CGAL_ImageIO/examples/CGALimageIO/slice_image.cpp b/CGAL_ImageIO/examples/CGALimageIO/slice_image.cpp index 8d6b9056ead..ec2622c2e32 100644 --- a/CGAL_ImageIO/examples/CGALimageIO/slice_image.cpp +++ b/CGAL_ImageIO/examples/CGALimageIO/slice_image.cpp @@ -3,6 +3,10 @@ #include int main(int argc, char **argv) { + if (argc != 3) { + std::cerr << "Usage: slice_size \n"; + return argc != 1; + } _image *image = ::_readImage(argv[1]); if (!image) return 2;