fw4spl
itkpp.hxx
1 /* ***** BEGIN LICENSE BLOCK *****
2  * FW4SPL - Copyright (C) IRCAD, 2009-2017.
3  * Distributed under the terms of the GNU Lesser General Public License (LGPL) as
4  * published by the Free Software Foundation.
5  * ****** END LICENSE BLOCK ****** */
6 
7 #ifndef __FWITKIO_ITKPP_HXX__
8 #define __FWITKIO_ITKPP_HXX__
9 
10 #include "fwItkIO/itk.hpp"
11 
12 #include <fwTools/DynamicType.hpp>
13 
14 #include <itkCastImageFilter.h>
15 
16 namespace fwItkIO
17 {
18 
19 //------------------------------------------------------------------------------
20 
21 template< class PIXELTYPE, int VDimension, class ScannerType >
22 typename ScannerType::Pointer itkppScannerFactory( ::fwData::Image::sptr imageData)
23 {
24  typedef itk::Image< PIXELTYPE, VDimension > ImageType;
25 
26  typename ImageType::Pointer itkRoi = ::fwItkIO::itkImageFactory< ImageType >( imageData );
27  typedef itk::Image< unsigned char, VDimension > ROIType;
28  typedef itk::CastImageFilter< ImageType, ROIType > CasterType;
29  typename CasterType::Pointer caster = CasterType::New();
30  caster->SetInput( itkRoi );
31  caster->Update();
32 
33  typename ScannerType::Pointer scanner = ScannerType::New();
34  typename ROIType::Pointer outImg = caster->GetOutput();
35  scanner->SetMaskImage( outImg );
36  outImg->DisconnectPipeline();
37 
38  return scanner;
39 }
40 
41 } // end namespace
42 
43 #endif // __FWITKIO_ITKPP_HXX__
The namespace fwItkIO contains reader, writer and helper for itk image.