]> Creatis software - bbtk.git/blob - packages/itkvtk/src/bbitkvtkitkImage2vtkImageData.cxx
3fe9fe370701bd9d566cc48fdd68fb62d9854f5c
[bbtk.git] / packages / itkvtk / src / bbitkvtkitkImage2vtkImageData.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   bbtk
4   Module:    $RCSfile: bbitkvtkitkImage2vtkImageData.cxx,v $
5   Language:  C++
6   Date:      $Date: 2008/04/18 12:59:50 $
7   Version:   $Revision: 1.2 $
8                                                                                 
9   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
10   l'Image). All rights reserved. See Doc/License.txt or
11   http://www.creatis.insa-lyon.fr/Public/bbtk/License.html for details.
12                                                                                 
13      This software is distributed WITHOUT ANY WARRANTY; without even
14      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15      PURPOSE.  See the above copyright notices for more information.
16                                                                                 
17 =========================================================================*/
18 /**
19  *  \file 
20  *  \brief 
21  */
22 #ifdef _USE_ITK_
23 #ifdef _USE_VTK_
24
25 #include "bbitkvtkitkImage2vtkImageData.h"
26 #include "bbitkvtkPackage.h"
27 // VtkToItkConnection 
28 //#include "itkVTKImageToImageFilter.h"
29 // ItkToVtkConnection
30 #include "itkImageToVTKImageFilter.h"
31
32
33 namespace bbitkvtk 
34 {
35   BBTK_BLACK_BOX_IMPLEMENTATION(itkImage2vtkImageData,bbtk::AtomicBlackBox);
36
37   BBTK_ADD_BLACK_BOX_TO_PACKAGE(itkvtk,itkImage2vtkImageData);
38
39
40
41
42   void itkImage2vtkImageData::Convert()
43   {
44     bbtk::TypeInfo t = bbGetInputIn().type();
45     BBTK_TEMPLATE_ITK_IMAGE_SWITCH(t,Convert);
46   }
47   
48
49
50    template<class T>
51    void itkImage2vtkImageData::Convert()
52   {
53     bbtkDebugMessageInc("Core",9,"itkImage2vtkImageData<"
54                         <<bbtk::TypeName<T>()
55                         <<">::Convert()"<<std::endl);
56
57     typedef T itkImageType;
58     //   typedef itk::VTKImageToImageFilter< itkImageType > VtkToItkConnection;
59     typedef itk::ImageToVTKImageFilter< itkImageType > ItkToVtkConnection;
60
61
62     try 
63       {
64         typename ItkToVtkConnection::Pointer conv = ItkToVtkConnection::New();
65         conv->SetInput( this->bbGetInputIn().get<itkImageType*>() );
66         conv->Update();
67         vtkImageData* o = vtkImageData::New();
68         //      o->SetReferenceCount(10);
69         o->DeepCopy(conv->GetOutput());
70
71         //      o->Print(std::cout);
72         if (bbGetOutputOut()) bbGetOutputOut()->Delete();
73         bbSetOutputOut(o);
74       }
75     catch( itk::ExceptionObject & e) 
76       {
77         bbtkError("itkImage2vtkImageData<"
78                   <<bbtk::TypeName<T>()
79                   <<">::Convert() : "<<e);
80       } 
81
82     
83
84     bbtkDebugDecTab("Core",9);
85   }
86
87
88
89 }
90 // eo namespace bbitkvtk
91
92 #endif
93 // _USE_VTK_
94 #endif
95 // _USE_ITK_