diff --git a/CGAL_ImageIO/include/CGAL/Image_3.h b/CGAL_ImageIO/include/CGAL/Image_3.h index 34133fc176a..2f6fd158759 100644 --- a/CGAL_ImageIO/include/CGAL/Image_3.h +++ b/CGAL_ImageIO/include/CGAL/Image_3.h @@ -64,6 +64,7 @@ public: class CGAL_IMAGEIO_EXPORT Image_3 { + struct Image_deleter { void operator()(_image* image) { @@ -164,7 +165,7 @@ public: vx,vy,vz,offset)); } -#ifdef CGAL_USE_VTK +#if 0 bool read_vtk_image_data(vtkImageData*); #endif // CGAL_USE_VTK diff --git a/CGAL_ImageIO/include/CGAL/Image_3_impl.h b/CGAL_ImageIO/include/CGAL/Image_3_impl.h index 79737e97f78..deeae53e950 100644 --- a/CGAL_ImageIO/include/CGAL/Image_3_impl.h +++ b/CGAL_ImageIO/include/CGAL/Image_3_impl.h @@ -157,7 +157,7 @@ void Image_3::gl_draw_bbox(const float line_width, } // end namespace CGAL -#ifdef CGAL_USE_VTK +#if 0 #include #include diff --git a/CGAL_ImageIO/include/CGAL/Image_3_vtk_interface.h b/CGAL_ImageIO/include/CGAL/Image_3_vtk_interface.h index 89b4bd7ea03..2a4737432ae 100644 --- a/CGAL_ImageIO/include/CGAL/Image_3_vtk_interface.h +++ b/CGAL_ImageIO/include/CGAL/Image_3_vtk_interface.h @@ -23,7 +23,6 @@ #include -#ifdef CGAL_USE_VTK #include #include #include @@ -126,7 +125,5 @@ struct VTK_type_generator { } //end namespace CGAL -#endif // CGAL_USE_VTK - #endif // CGAL_IMAGE_3_VTK_INTERFACE_H diff --git a/CGAL_ImageIO/include/CGAL/read_vtk_image_data.h b/CGAL_ImageIO/include/CGAL/read_vtk_image_data.h new file mode 100644 index 00000000000..eaa899505ff --- /dev/null +++ b/CGAL_ImageIO/include/CGAL/read_vtk_image_data.h @@ -0,0 +1,95 @@ +// Copyright (c) 2005-2008 INRIA Sophia-Antipolis (France). +// 2008 GeometryFactory +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org); you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public License as +// published by the Free Software Foundation; either version 3 of the License, +// or (at your option) any later version. +// +// Licensees holding a valid commercial license may use this file in +// accordance with the commercial license agreement provided with the software. +// +// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +// +// $URL$ +// $Id$ +// +// +// Author(s) : Laurent Rineau, Pierre Alliez + +#ifndef CGAL_READ_VTK_IMAGE_DATA_H +#define CGAL_READ_VTK_IMAGE_DATA_H + +#include +#include + +namespace CGAL { + +namespace { + +struct VTK_to_ImageIO_type_mapper { + WORD_KIND wordKind; + SIGN sign; + unsigned int wdim; +}; + +static const VTK_to_ImageIO_type_mapper VTK_to_ImageIO_type[VTK_ID_TYPE] = + { { WK_UNKNOWN, SGN_UNKNOWN, 0}, // 0=VTK_VOID + { WK_UNKNOWN, SGN_UNKNOWN, 0}, // 1=VTK_BIT + { WK_FIXED, SGN_SIGNED, 1}, // 2=VTK_CHAR + { WK_FIXED, SGN_UNSIGNED, 1}, // 3=VTK_UNSIGNED_CHAR + { WK_FIXED, SGN_SIGNED, 2}, // 4=VTK_SHORT + { WK_FIXED, SGN_UNSIGNED, 2}, // 5=VTK_UNSIGNED_SHORT + { WK_FIXED, SGN_SIGNED, 4}, // 6=VTK_INT + { WK_FIXED, SGN_UNSIGNED, 4}, // 7=VTK_UNSIGNED_INT + { WK_FIXED, SGN_SIGNED, 8}, // 8=VTK_LONG + { WK_FIXED, SGN_UNSIGNED, 8}, // 9=VTK_UNSIGNED_LONG + { WK_FLOAT, SGN_SIGNED, 4}, // 10=VTK_FLOAT + { WK_FIXED, SGN_SIGNED, 8} // 11=VTK_DOUBLE + }; + +} //end anonymous namespace + +inline +Image_3 +read_vtk_image_data(vtkImageData* vtk_image) +{ + if(!vtk_image) + return Image_3(); + + _image* image = ::_initImage(); + const int* dims = vtk_image->GetDimensions(); + const double* spacing = vtk_image->GetSpacing(); + image->vectMode = VM_SCALAR; + image->xdim = dims[0]; + image->ydim = dims[1]; + image->zdim = dims[2]; + image->vdim = 1; + image->vx = spacing[0]; + image->vy = spacing[1]; + image->vz = spacing[2]; + image->endianness = ::_getEndianness(); + int vtk_type = vtk_image->GetScalarType(); + if(vtk_type == VTK_SIGNED_CHAR) vtk_type = VTK_CHAR; + if(vtk_type < 0 || vtk_type > VTK_DOUBLE) + vtk_type = VTK_DOUBLE; + const VTK_to_ImageIO_type_mapper& imageio_type = + VTK_to_ImageIO_type[vtk_type]; + image->wdim = imageio_type.wdim; + image->wordKind = imageio_type.wordKind; + image->sign = imageio_type.sign; + 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'; + CGAL_assertion(vtk_image->GetPointData()->GetScalars()->GetNumberOfTuples() == dims[0]*dims[1]*dims[2]); + vtk_image->GetPointData()->GetScalars()->ExportToVoidPointer(image->data); + + return Image_3(image); +} + +} // namespace CGAL + +#endif // CGAL_READ_VTK_IMAGE_DATA_H diff --git a/CGAL_ImageIO/src/CGAL_ImageIO/CMakeLists.txt b/CGAL_ImageIO/src/CGAL_ImageIO/CMakeLists.txt index 795e89ac10d..7b0a1fa3e37 100644 --- a/CGAL_ImageIO/src/CGAL_ImageIO/CMakeLists.txt +++ b/CGAL_ImageIO/src/CGAL_ImageIO/CMakeLists.txt @@ -3,11 +3,6 @@ message("Configuring libCGAL_ImageIO") find_package( OpenGL ) find_package( ZLIB ) -#option(WITH_VTK "Add VTK support to libCGAL_ImageIO." OFF) - -if(WITH_VTK) - find_package(VTK COMPONENTS vtkImagingCore vtkIOImage vtkFiltersImaging NO_MODULE REQUIRED) -endif(WITH_VTK) if(OPENGL_FOUND) message( STATUS "OpenGL include: ${OPENGL_INCLUDE_DIR}" ) @@ -26,20 +21,6 @@ if(OPENGL_FOUND) set( CGAL_ImageIO_BASENAME CGAL_ImageIO) - if(WITH_VTK) - if( VTK_FOUND ) - - message(STATUS "VTK-${VTK_MAJOR_VERSION}.${VTK_MINOR_VERSION}.${VTK_BUILD_VERSION} found. Build VTK support in ${CGAL_ImageIO_BASENAME}.") - include( ${VTK_USE_FILE} ) - cache_set(CGAL_ImageIO_3RD_PARTY_DEFINITIONS ${CGAL_ImageIO_3RD_PARTY_DEFINITIONS} -DCGAL_USE_VTK) - 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} ${vtkImagingCore_RUNTIME_LIBRARY_DIRS} ${vtkImagingCore_LIBRARY_DIRS} ${vtkIOImage_RUNTIME_LIBRARY_DIRS} ${vtkIOImage_LIBRARY_DIRS} ${vtkFiltersImaging_RUNTIME_LIBRARY_DIRS} ${vtkFiltersImaging_LIBRARY_DIRS}) - cache_set(CGAL_ImageIO_3RD_PARTY_LIBRARIES ${CGAL_ImageIO_3RD_PARTY_LIBRARIES} ${VTK_LIBRARIES} ) - else() - message(STATUS "VTK not found.") - endif() - endif() - if(COMMAND add_config_flag) set( CGAL_HAS_IMAGEIO TRUE ) add_config_flag( CGAL_HAS_IMAGEIO ) diff --git a/Mesh_3/examples/Mesh_3/CMakeLists.txt b/Mesh_3/examples/Mesh_3/CMakeLists.txt index 57585206126..6d981945dea 100644 --- a/Mesh_3/examples/Mesh_3/CMakeLists.txt +++ b/Mesh_3/examples/Mesh_3/CMakeLists.txt @@ -8,9 +8,6 @@ cmake_minimum_required(VERSION 2.8.11) include_directories(../../include) -include_directories(../../../Triangulation_3/include) -include_directories(../../../STL_Extension/include) -include_directories(../../../AABB_tree/include) add_definitions(-DCGAL_MESH_3_NO_DEPRECATED_SURFACE_INDEX -DCGAL_MESH_3_NO_DEPRECATED_C3T3_ITERATORS) @@ -48,6 +45,21 @@ if ( CGAL_FOUND ) endif() + set(VTK_LIBS "") + find_package(VTK QUIET COMPONENTS vtkImagingGeneral vtkIOImage NO_MODULE) + if(VTK_FOUND) + include(${VTK_USE_FILE}) + if ("${VTK_VERSION_MAJOR}" GREATER "5") + message(STATUS "VTK found") + set( VTK_LIBS vtkImagingGeneral vtkIOImage ) + else() + message(STATUS "VTK version 6.0 or greater is required") + endif() + else() + message(STATUS "VTK was not found") + endif() + + if ( Boost_FOUND AND Boost_VERSION GREATER 103400 ) include( CGAL_CreateSingleSourceCGALProgram ) @@ -62,6 +74,11 @@ if ( CGAL_FOUND ) create_single_source_cgal_program( "mesh_polyhedral_domain.cpp" ) create_single_source_cgal_program( "mesh_polyhedral_domain_with_features.cpp" ) if( WITH_CGAL_ImageIO ) + if( VTK_FOUND ) + add_executable ( mesh_3D_gray_vtk_image mesh_3D_gray_vtk_image.cpp ) + target_link_libraries( mesh_3D_gray_vtk_image ${CGAL_LIBRARIES} ${CGAL_3RD_PARTY_LIBRARIES} ${VTK_LIBS}) + endif() + if( CGAL_ImageIO_USE_ZLIB ) create_single_source_cgal_program( "mesh_optimization_example.cpp" ) create_single_source_cgal_program( "mesh_optimization_lloyd_example.cpp" ) 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 new file mode 100644 index 00000000000..beee8aa4f8f --- /dev/null +++ b/Mesh_3/examples/Mesh_3/mesh_3D_gray_vtk_image.cpp @@ -0,0 +1,79 @@ + +#include +#include +#include +#include +#include + +#include + +#include +#include +#include + +#include +#include +#include +#include + +typedef short Image_word_type; + +// Domain +typedef CGAL::Exact_predicates_inexact_constructions_kernel K; +typedef CGAL::Gray_image_mesh_domain_3 > > Mesh_domain; + +// Triangulation +typedef CGAL::Mesh_triangulation_3::type Tr; +typedef CGAL::Mesh_complex_3_in_triangulation_3 C3t3; + +// Criteria +typedef CGAL::Mesh_criteria_3 Mesh_criteria; + +// To avoid verbose function and named parameters call +using namespace CGAL::parameters; + +int main(int argc, char* argv[]) +{ + // Loads image + + + vtkDICOMImageReader*dicom_reader = vtkDICOMImageReader::New(); + dicom_reader->SetDirectoryName(argv[1]); + + vtkDemandDrivenPipeline*executive = + vtkDemandDrivenPipeline::SafeDownCast(dicom_reader->GetExecutive()); + if (executive) + { + executive->SetReleaseDataFlag(0, 0); // where 0 is the port index + } + + vtkImageGaussianSmooth* smoother = vtkImageGaussianSmooth::New(); + smoother->SetStandardDeviations(1., 1., 1.); + smoother->SetInputConnection(dicom_reader->GetOutputPort()); + smoother->Update(); + vtkImageData* vtk_image = smoother->GetOutput(); + vtk_image->Print(std::cerr); + + CGAL::Image_3 image = CGAL::read_vtk_image_data(vtk_image); + if(image.image() == 0){ + std::cerr << "could not create a CGAL::Image_3 from the vtk image\n"; + return 0; + } + // Domain + Mesh_domain domain(image, std::bind1st(std::less(), -555), -1000); + + // Mesh criteria + Mesh_criteria criteria(facet_angle=30, facet_size=6, facet_distance=1, + cell_radius_edge_ratio=3, cell_size=8); + + // Meshing + C3t3 c3t3 = CGAL::make_mesh_3(domain, criteria); + + // Output + std::ofstream medit_file("out.mesh"); + c3t3.output_to_medit(medit_file); + + return 0; +} diff --git a/Surface_mesher/demo/Surface_mesher/CMakeLists.txt b/Surface_mesher/demo/Surface_mesher/CMakeLists.txt index 0cf262ed5e0..9a504d4601a 100644 --- a/Surface_mesher/demo/Surface_mesher/CMakeLists.txt +++ b/Surface_mesher/demo/Surface_mesher/CMakeLists.txt @@ -97,20 +97,18 @@ if ( CGAL_FOUND AND CGAL_Qt5_FOUND AND CGAL_ImageIO_FOUND) add_to_cached_list( CGAL_EXECUTABLE_TARGETS ${prj} ) set(VTK_LIBS "") - if (WITH_VTK) - message(STATUS "VTK support ON, CGAL ImageIO must have been compiled with VTK support ON (WITH_VTK=ON at the cmake level)") - find_package(VTK QUIET COMPONENTS vtkImagingCore) - if(VTK_FOUND) - include(${VTK_USE_FILE}) - if ("${VTK_VERSION_MAJOR}" GREATER "5") - add_definitions(-DCGAL_USE_VTK) - set(VTK_LIBS vtkImagingCore) - else() - message(STATUS "VTK support switched OFF, VTK version 6.0 or greater is required") - endif() + find_package(VTK QUIET COMPONENTS vtkImagingGeneral vtkIOImage NO_MODULE) + if(VTK_FOUND) + include(${VTK_USE_FILE}) + if ("${VTK_VERSION_MAJOR}" GREATER "5") + message(STATUS "VTK found") + add_definitions(-DCGAL_USE_VTK) + set(VTK_LIBS vtkImagingGeneral vtkIOImage) else() - message(STATUS "VTK support switched OFF, VTK was not found") + message(STATUS "Vtk must be at least Rel 6") endif() + else() + message(STATUS "For reading Dicom files install VTK first") endif() # Link the executable to CGAL and third-party libraries diff --git a/Surface_mesher/demo/Surface_mesher/binary_image.h b/Surface_mesher/demo/Surface_mesher/binary_image.h index 16b0e6e0e71..6c8753977ec 100644 --- a/Surface_mesher/demo/Surface_mesher/binary_image.h +++ b/Surface_mesher/demo/Surface_mesher/binary_image.h @@ -44,10 +44,17 @@ public: typedef FT_ FT; public: - CBinary_image_3() : Image_3(), interpolate_(true) + CBinary_image_3() + : Image_3(), interpolate_(true) { } + CBinary_image_3(const Image_3& bi) + : Image_3(bi), interpolate_(true) + { + } + + CBinary_image_3(const CBinary_image_3& bi) : Image_3(bi), interpolate_(bi.interpolate_),labellized_(bi.labellized_) { @@ -56,9 +63,6 @@ public: max_value = bi.max_value; } - ~CBinary_image_3() - { - } void finish_open() { CGAL_IMAGE_IO_CASE(image_ptr.get(), diff --git a/Surface_mesher/demo/Surface_mesher/volume.cpp b/Surface_mesher/demo/Surface_mesher/volume.cpp index 82fda99dafb..582615ffa63 100644 --- a/Surface_mesher/demo/Surface_mesher/volume.cpp +++ b/Surface_mesher/demo/Surface_mesher/volume.cpp @@ -325,6 +325,9 @@ void Volume::only_in() } #ifdef CGAL_USE_VTK + +#include + #include #include #include @@ -368,7 +371,8 @@ bool Volume::opendir(const QString& dirname) smoother->Update(); vtk_image = smoother->GetOutput(); vtk_image->Print(std::cerr); - if(!m_image.read_vtk_image_data(vtk_image)) + m_image = CGAL::read_vtk_image_data(vtk_image); + if(m_image.image() == 0) { QMessageBox::warning(mw, mw->windowTitle(), tr("Error with file %1/:\nunknown file format!").arg(dirname)); @@ -418,7 +422,8 @@ bool Volume::open_vtk(const QString& filename) vtk_reader->Print(std::cerr); vtk_image = vtk_reader->GetOutput(); vtk_image->Print(std::cerr); - if(!m_image.read_vtk_image_data(vtk_image)) + m_image = CGAL::read_vtk_image_data(vtk_image); + if(m_image.image() == NULL) { QMessageBox::warning(mw, mw->windowTitle(), tr("Error with file %1:\nunknown file format!").arg(filename)); @@ -485,7 +490,8 @@ bool Volume::open_xt(const QString& filename) vtk_reader->Print(std::cerr); vtkImageData* vtk_image = vtk_reader->GetOutput(); vtk_image->Print(std::cerr); - if(!m_image.read_vtk_image_data(vtk_image)) + m_image = CGAL::read_vtk_image_data(vtk_image); + if(m_image.image() != NULL) { QMessageBox::warning(mw, mw->windowTitle(), tr("Error with file %1:\nunknown file format!").arg(filename));