2 * This program is free software: you can redistribute it and/or modify
3 * it under the terms of the GNU Lesser General Public License as
4 * published by the Free Software Foundation, either version 3 of the
5 * License, or (at your option) any later version.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 * @author Pierre Gueth (\c pierre.gueth@gmail.com )
20 * Laboratoire d'InfoRmatique en Image et Systèmes d'information - LIRIS (CNRS, UMR 5205), CNRS, France
24 * Header file for module ITKReader.cpp
26 * This file is part of the DGtal library.
29 #include "DGtal/images/ConstImageAdapter.h"
30 #include "DGtal/images/ImageContainerByITKImage.h"
32 #pragma GCC diagnostic push
33 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
35 #if defined(__clang__)
36 #pragma clang diagnostic push
37 #pragma clang diagnostic ignored "-Wdocumentation"
39 #include <itkImageFileReader.h>
40 #if defined(__clang__)
41 #pragma clang diagnostic pop
45 #pragma GCC diagnostic pop
48 template<typename I,typename F>
50 ITKReader<I,F>::importITK(const std::string& filename, const Functor& aFunctor)
51 throw(DGtal::IOException)
53 typedef typename Image::Domain Domain;
55 typedef ImageContainerByITKImage<Domain, ValueOut> DGtalITKImage;
56 typedef typename DGtalITKImage::ITKImagePointer ITKImagePointer;
57 ITKImagePointer itk_image = DGtalITKImage::ITKImage::New();
61 typedef itk::ImageFileReader<typename DGtalITKImage::ITKImage> ITKImageReader;
62 typename ITKImageReader::Pointer reader = ITKImageReader::New();
64 reader->SetFileName(filename);
68 itk_image = reader->GetOutput();
70 catch (itk::ExceptionObject &e)
76 const DGtalITKImage dgtal_itk_image(itk_image);
77 const Domain& domain = dgtal_itk_image.domain();
79 typedef ConstImageAdapter<DGtalITKImage, Domain, functors::Identity, Value, Functor> AdaptedImage;
80 const functors::Identity identityFunctor{};
81 const AdaptedImage adapted(dgtal_itk_image, domain, identityFunctor, aFunctor);
84 std::copy(adapted.constRange().begin(), adapted.constRange().end(), image.range().outputIterator());