Skip to Content.
Sympa Menu

cgal-discuss - Re: [cgal-discuss] VTK image interface

Subject: CGAL users discussion list

List archive

Re: [cgal-discuss] VTK image interface


Chronological Thread 
  • From: Johannes Totz <>
  • To: "Laurent Rineau (CGAL/GeometryFactory)" <>, <>
  • Subject: Re: [cgal-discuss] VTK image interface
  • Date: Thu, 17 Jul 2014 16:45:01 +0100

On 16/07/2014 15:17, Laurent Rineau (CGAL/GeometryFactory) wrote:
> Le Wednesday 16 July 2014 15:03:28 Johannes Totz a écrit :
>> Hi there,
>>
>> we are using the VTK bits in CGAL_ImageIO/Image_3.cpp and related header
>> file. Has worked fine so far, if used with VTK 5.10+.
>>
>> Now we have upgraded to VTK 6.1 and CGAL no longer compiles due to API
>> changes in VTK.
>> Is there a fix planned for the next release? Or shall I fix myself and
>> submit a patch? If you have something in the pipe already then I wont
>> duplicate your work, otherwise happy to contribute back.
>
> That is funny you ask that question today. Yesterday I was trying to make
> it compile with VTK 6, too. But I do not know VTK at all, and I had
> difficulties and not enough time to solve the issues. That would be great
> if you can make it compile and run correctly with VTK 6. Please send us a
> patch if you are successful.

Actually, I dont have much of a clue about VTK either...
But the attached diff against cgal-4.4 seems to work for both vtk-6 and
vtk-5.10. I did not test many pixel types, only the byte-sized one we
use in our code.

> My patch, so far, was the following one. But be careful: I a pretty sure
> you cannot trust it!
>
> commit ff6d63e03b2fa66efa0dfb185a488815cc3517dc
> Author: Laurent Rineau
> <>
> Date: Tue Jul 15 16:10:46 2014 +0200
>
> Initial experimental support of VTK6
>
> diff --git a/CGAL_ImageIO/include/CGAL/Image_3_vtk_interface.h
> b/CGAL_ImageIO/include/CGAL/Image_3_vtk_interface.h
> index 9f8501f..185cc25 100644
> --- a/CGAL_ImageIO/include/CGAL/Image_3_vtk_interface.h
> +++ b/CGAL_ImageIO/include/CGAL/Image_3_vtk_interface.h
> @@ -113,13 +113,15 @@ struct VTK_type_generator<boost::uint32_t> {
> vtk_image->SetDimensions(image.xdim(),
> image.ydim(),
> image.zdim());
> +#if VTK_MAJOR_VERSION < 6
> vtk_image->SetWholeExtent(0, image.xdim(),
> 0, image.ydim(),
> 0, image.zdim());
> + vtk_image->SetScalarType(type);
> +#endif // VTK < 6.x
> vtk_image->SetSpacing(image.vx(),
> image.vy(),
> image.vz());
> - vtk_image->SetScalarType(type);
> vtk_image->GetPointData()->SetScalars(data_array);
> return vtk_image;
> } // end vtk_image_sharing_same_data_pointer
> diff --git a/CGAL_ImageIO/src/CGAL_ImageIO/Image_3.cpp
> b/CGAL_ImageIO/src/CGAL_ImageIO/Image_3.cpp
> index f0f5e02..d617043 100644
> --- a/CGAL_ImageIO/src/CGAL_ImageIO/Image_3.cpp
> +++ b/CGAL_ImageIO/src/CGAL_ImageIO/Image_3.cpp
> @@ -197,7 +197,9 @@ Image_3::read_vtk_image_data(vtkImageData* vtk_image)
> image->vx = spacing[0];
> image->vy = spacing[1];
> image->vz = spacing[2];
> +#if VTK_MAJOR_VERSION < 6
> vtk_image->Update();
> +#endif
> image->endianness = ::_getEndianness();
> int vtk_type = vtk_image->GetScalarType();
> if(vtk_type == VTK_SIGNED_CHAR) vtk_type = VTK_CHAR;
>

diff --git a/include/CGAL/Image_3_vtk_interface.h
b/include/CGAL/Image_3_vtk_interface.h
index 9f8501f..db30c03 100644
--- a/include/CGAL/Image_3_vtk_interface.h
+++ b/include/CGAL/Image_3_vtk_interface.h
@@ -113,13 +113,12 @@ struct VTK_type_generator<boost::uint32_t> {
vtk_image->SetDimensions(image.xdim(),
image.ydim(),
image.zdim());
- vtk_image->SetWholeExtent(0, image.xdim(),
- 0, image.ydim(),
- 0, image.zdim());
+ vtk_image->SetExtent(0, image.xdim(),
+ 0, image.ydim(),
+ 0, image.zdim());
vtk_image->SetSpacing(image.vx(),
image.vy(),
image.vz());
- vtk_image->SetScalarType(type);
vtk_image->GetPointData()->SetScalars(data_array);
return vtk_image;
} // end vtk_image_sharing_same_data_pointer
diff --git a/src/CGAL_ImageIO/CMakeLists.txt b/src/CGAL_ImageIO/CMakeLists.txt
index d08f74f..e3338bc 100644
--- a/src/CGAL_ImageIO/CMakeLists.txt
+++ b/src/CGAL_ImageIO/CMakeLists.txt
@@ -34,7 +34,11 @@ if(OPENGL_FOUND)
cache_set(CGAL_ImageIO_3RD_PARTY_DEFINITIONS
${CGAL_ImageIO_3RD_PARTY_DEFINITIONS} -DCGAL_USE_VTK
${VTK_REQUIRED_CXX_FLAGS})
cache_set(CGAL_ImageIO_3RD_PARTY_INCLUDE_DIRS
${CGAL_ImageIO_3RD_PARTY_INCLUDE_DIRS} ${VTK_INCLUDE_DIRS} )
cache_set(CGAL_ImageIO_3RD_PARTY_LIBRARIES_DIRS
${CGAL_ImageIO_3RD_PARTY_LIBRARIES_DIRS} ${VTK_LIBRARY_DIRS} )
- cache_set(CGAL_ImageIO_3RD_PARTY_LIBRARIES
${CGAL_ImageIO_3RD_PARTY_LIBRARIES} vtkImaging vtkIO )
+ if(VTK_MAJOR_VERSION LESS 6)
+ cache_set(CGAL_ImageIO_3RD_PARTY_LIBRARIES
${CGAL_ImageIO_3RD_PARTY_LIBRARIES} vtkImaging vtkIO )
+ else()
+ cache_set(CGAL_ImageIO_3RD_PARTY_LIBRARIES
${CGAL_ImageIO_3RD_PARTY_LIBRARIES} vtkImagingCore vtkIOImage )
+ endif()

else()
message(STATUS "VTK not found.")
diff --git a/src/CGAL_ImageIO/Image_3.cpp b/src/CGAL_ImageIO/Image_3.cpp
index f0f5e02..e92bbca 100644
--- a/src/CGAL_ImageIO/Image_3.cpp
+++ b/src/CGAL_ImageIO/Image_3.cpp
@@ -197,7 +197,6 @@ Image_3::read_vtk_image_data(vtkImageData* vtk_image)
image->vx = spacing[0];
image->vy = spacing[1];
image->vz = spacing[2];
- vtk_image->Update();
image->endianness = ::_getEndianness();
int vtk_type = vtk_image->GetScalarType();
if(vtk_type == VTK_SIGNED_CHAR) vtk_type = VTK_CHAR;



Archive powered by MHonArc 2.6.18.

Top of Page