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 ITKWriter.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 <itkImageFileWriter.h>
40 #if defined(__clang__)
41 #pragma clang diagnostic pop
45 #pragma GCC diagnostic pop
47 ///////////////////////////////////////////////////////////////////////////////
48 // IMPLEMENTATION of inline methods.
49 ///////////////////////////////////////////////////////////////////////////////
52 template<typename I,typename F>
54 ITKWriter<I,F>::exportITK(const std::string& filename, const I& aImage, const Functor& aFunctor)
55 throw(DGtal::IOException)
57 typedef typename Image::Domain Domain;
58 const Domain& domain = aImage.domain();
60 typedef ConstImageAdapter<Image, Domain, functors::Identity, ValueOut, Functor> AdaptedImage;
61 const functors::Identity identityFunctor{};
62 const AdaptedImage adapted(aImage, domain, identityFunctor, aFunctor);
64 typedef ImageContainerByITKImage<Domain, ValueOut> DGtalITKImage;
65 DGtalITKImage itk_image(aImage.domain());
67 std::copy(adapted.constRange().begin(), adapted.constRange().end(), itk_image.range().outputIterator());
69 typedef itk::ImageFileWriter<typename DGtalITKImage::ITKImage> ITKImageWriter;
70 typename ITKImageWriter::Pointer writer = ITKImageWriter::New();
74 writer->SetFileName(filename);
75 writer->SetInput(itk_image.getITKImagePointer());
78 catch (itk::ExceptionObject &e)