]> Creatis software - bbtk.git/blob - packages/itkvtk/src/bbitkvtkitkImage2vtkImageData.cxx
re indent
[bbtk.git] / packages / itkvtk / src / bbitkvtkitkImage2vtkImageData.cxx
1 /*=========================================================================                                                                               
2   Program:   bbtk
3   Module:    $RCSfile: bbitkvtkitkImage2vtkImageData.cxx,v $
4   Language:  C++
5   Date:      $Date: 2010/02/08 15:15:25 $
6   Version:   $Revision: 1.10 $
7 =========================================================================*/
8
9 /* ---------------------------------------------------------------------
10
11 * Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
12 * Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
13 *
14 *  This software is governed by the CeCILL-B license under French law and 
15 *  abiding by the rules of distribution of free software. You can  use, 
16 *  modify and/ or redistribute the software under the terms of the CeCILL-B 
17 *  license as circulated by CEA, CNRS and INRIA at the following URL 
18 *  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html 
19 *  or in the file LICENSE.txt.
20 *
21 *  As a counterpart to the access to the source code and  rights to copy,
22 *  modify and redistribute granted by the license, users are provided only
23 *  with a limited warranty  and the software's author,  the holder of the
24 *  economic rights,  and the successive licensors  have only  limited
25 *  liability. 
26 *
27 *  The fact that you are presently reading this means that you have had
28 *  knowledge of the CeCILL-B license and that you accept its terms.
29 * ------------------------------------------------------------------------ */                                                                         
30
31 /**
32  *  \file 
33  *  \brief 
34  */
35 #ifdef _USE_ITK_
36 #ifdef _USE_VTK_
37
38 #include "bbitkvtkitkImage2vtkImageData.h"
39 #include "bbitkvtkPackage.h"
40 // VtkToItkConnection 
41 //#include "itkVTKImageToImageFilter.h"
42 // ItkToVtkConnection
43 #include "itkImageToVTKImageFilter.h"
44
45
46 namespace bbitkvtk 
47 {
48   BBTK_BLACK_BOX_IMPLEMENTATION(itkImage2vtkImageData,bbtk::AtomicBlackBox);
49
50   BBTK_ADD_BLACK_BOX_TO_PACKAGE(itkvtk,itkImage2vtkImageData);
51
52   void itkImage2vtkImageData::Convert()
53   {
54     bbtk::TypeInfo t = bbGetInputIn().type();
55     BBTK_TEMPLATE_ITK_IMAGE_SWITCH(t,Convert);
56   }
57
58    template<class T>
59    void itkImage2vtkImageData::Convert()
60    {
61     bbtkDebugMessage("process",5,"==> ["<<bbGetFullName()<<"] : Convert<"
62                      <<bbtk::TypeName<T>()
63                      <<">()"<<std::endl);
64
65     typedef T itkImageType;
66         typedef itkImageType* itkImageTypePointer;
67     typedef itk::ImageToVTKImageFilter< itkImageType > ItkToVtkConnection;
68     typename ItkToVtkConnection::Pointer conv;
69
70     // No converter yet : create it and set its input
71     if (!mConverter) 
72       {
73         bbtkDebugMessage("process",5,"    ["<<bbGetFullName()<<"] : No converter yet : creating it"<<std::endl);
74         conv = ItkToVtkConnection::New();
75         mConverter = conv;
76         conv->SetInput( this->bbGetInputIn().get< itkImageTypePointer >() );
77       }
78     else 
79       {
80         bbtkDebugMessage("process",5,"    ["<<bbGetFullName()<<"] : Converter ok "<<std::endl);
81         
82         // Input itkImageType type changed ? 
83         // Have to change the converter and set its input
84         conv = dynamic_cast<ItkToVtkConnection*>
85           ((itk::ProcessObject*)mConverter);
86         if (!conv) 
87           {
88             bbtkDebugMessage("process",5,"    ["<<bbGetFullName()<<"] : Converter of wrong input type : reacreating it "<<std::endl);
89
90             mConverter->UnRegister();
91             conv = ItkToVtkConnection::New();
92             mConverter = conv;
93             conv->SetInput( this->bbGetInputIn().get<itkImageTypePointer>() );
94           }
95         // Input image type did not change but input image pointer did:
96         // set new input
97         else if ( this->bbGetInputIn().get<itkImageTypePointer>() 
98                   != (itkImageType*)(conv->GetExporter()->GetInputs()[0].GetPointer()))
99           {
100             bbtkDebugMessage("process",5,"    ["<<bbGetFullName()<<"] : Converter input changed : resetting it"<<std::endl);
101
102             conv->SetInput( this->bbGetInputIn().get<itkImageTypePointer>() );
103           }
104         else 
105           {
106             bbtkDebugMessage("process",5,"    ["<<bbGetFullName()<<"] : Nothing changed"<<std::endl);
107           }
108       }
109     try
110       {
111         
112         bbtkDebugMessage("process",5,"    ["<<bbGetFullName()<<"] : Trying update"<<std::endl);  
113
114         conv->Update();
115         bbSetOutputOut(conv->GetOutput());
116       }
117     catch( itk::ExceptionObject & e) 
118       {
119         bbtkError("itkImage2vtkImageData<"
120                   <<bbtk::TypeName<T>()
121                   <<">::Convert() : "<<e);
122       } 
123     bbtkDebugMessage("process",5,"<== ["<<bbGetFullName()<<"] : Convert<"
124                      <<bbtk::TypeName<T>()
125                      <<">() *DONE*"<<std::endl);
126  }
127
128   void itkImage2vtkImageData::bbUserSetDefaultValues()
129   {
130     bbSetOutputOut(NULL);
131     mConverter = 0;
132   }
133
134   void itkImage2vtkImageData::bbUserInitializeProcessing()
135         {
136         }
137         
138   void itkImage2vtkImageData::bbUserFinalizeProcessing()        
139         {
140         }
141
142         
143 }
144 // eo namespace bbitkvtk
145
146 #endif
147 // _USE_VTK_
148 #endif
149 // _USE_ITK_