]> Creatis software - bbtk.git/blob - packages/itkvtk/src/bbitkvtkitkImageVector2vtkImageDataVector.cxx
435719cfa492822eff4a46b957b04118dc54679c
[bbtk.git] / packages / itkvtk / src / bbitkvtkitkImageVector2vtkImageDataVector.cxx
1 /*=========================================================================                                                                               
2   Program:   bbtk
3   Module:    $RCSfile: bbitkvtkitkImageVector2vtkImageDataVector.cxx,v $
4   Language:  C++
5   Date:      $Date: 2011/06/16 12:28:57 $
6   Version:   $Revision: 1.1 $
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 "bbitkvtkitkImageVector2vtkImageDataVector.h"
39 #include "bbitkvtkPackage.h"
40 #include "itkImageToVTKImageFilter.h"
41
42
43 namespace bbitkvtk 
44 {
45   BBTK_BLACK_BOX_IMPLEMENTATION(itkImageVector2vtkImageDataVector,bbtk::AtomicBlackBox);
46
47   BBTK_ADD_BLACK_BOX_TO_PACKAGE(itkvtk,itkImageVector2vtkImageDataVector);
48
49   void itkImageVector2vtkImageDataVector::Convert()
50   {
51   // suppose *all* the images have the same type // JPR
52     bbtk::TypeInfo t = bbGetInputIn()[0].type();
53     BBTK_TEMPLATE_ITK_IMAGE_SWITCH(t,Convert);
54   }
55
56    template<class T>
57    void itkImageVector2vtkImageDataVector::Convert()
58    {
59     bbtkDebugMessage("process",5,"==> ["<<bbGetFullName()<<"] : Convert<"
60                      <<bbtk::TypeName<T>()
61                      <<">()"<<std::endl);
62
63     typedef T itkImageType;
64     typedef itkImageType* itkImageTypePointer;
65     typedef itk::ImageToVTKImageFilter< itkImageType > ItkToVtkConnection;
66     typename ItkToVtkConnection::Pointer conv;
67
68 int vectorSize = bbGetInputIn().size();
69 std::cout << " itkImageVector2vtkImageDataVector vector size :" << vectorSize << std::endl;
70 for (int i=0; i< vectorSize ; i++)
71 {
72     // No converter yet : create it and set its input
73     if (!mConverter) 
74       {
75         bbtkDebugMessage("process",5,"    ["<<bbGetFullName()<<"] : No converter yet : creating it"<<std::endl);
76         conv = ItkToVtkConnection::New();
77         mConverter = conv;
78         conv->SetInput( this->bbGetInputIn()[i].get< itkImageTypePointer >() );
79       }
80     else 
81       {
82         bbtkDebugMessage("process",5,"    ["<<bbGetFullName()<<"] : Converter ok "<<std::endl);
83         
84         // Input itkImageType type changed ? 
85         // Have to change the converter and set its input
86         conv = dynamic_cast<ItkToVtkConnection*>
87           ((itk::ProcessObject*)mConverter);
88         if (!conv) 
89           {
90             bbtkDebugMessage("process",5,"    ["<<bbGetFullName()<<"] : Converter of wrong input type : reacreating it "<<std::endl);
91
92             mConverter->UnRegister();
93             conv = ItkToVtkConnection::New();
94             mConverter = conv;
95             conv->SetInput( this->bbGetInputIn()[i].get<itkImageTypePointer>() );
96           }
97         // Input image type did not change but input image pointer did:
98         // set new input
99         else if ( this->bbGetInputIn()[i].get<itkImageTypePointer>() 
100                   != (itkImageType*)(conv->GetExporter()->GetInputs()[0].GetPointer()))
101           {
102             bbtkDebugMessage("process",5,"    ["<<bbGetFullName()<<"] : Converter input changed : resetting it"<<std::endl);
103
104             conv->SetInput( this->bbGetInputIn()[i].get<itkImageTypePointer>() );
105           }
106         else 
107           {
108             bbtkDebugMessage("process",5,"    ["<<bbGetFullName()<<"] : Nothing changed"<<std::endl);
109           }
110       }
111     try
112       {
113         bbtkDebugMessage("process",5,"    ["<<bbGetFullName()<<"] : Trying update"<<std::endl);  
114
115         conv->Update();
116         m_Output_Vector.push_back(conv->GetOutput());
117       }
118     catch( itk::ExceptionObject & e) 
119       {
120         bbtkError("itkImageVector2vtkImageDataVector<"
121                   <<bbtk::TypeName<T>()
122                   <<">::Convert() : "<<e);
123       } 
124     bbtkDebugMessage("process",5,"<== ["<<bbGetFullName()<<"] : Convert<"
125                      <<bbtk::TypeName<T>()
126                      <<">() *DONE*"<<std::endl);
127                      
128 } // end iterate on vector size
129
130 bbSetOutputOut(m_Output_Vector);
131    
132 }
133
134
135   void itkImageVector2vtkImageDataVector::bbUserSetDefaultValues()
136   {
137    // bbSetOutputOut(std::vector<vtkImageData*>); // syntax? JPR
138     mConverter = 0;
139   }
140
141   void itkImageVector2vtkImageDataVector::bbUserInitializeProcessing()
142         {
143         }
144         
145   void itkImageVector2vtkImageDataVector::bbUserFinalizeProcessing()    
146         {
147         }
148
149         
150 }
151 // eo namespace bbitkvtk
152
153 #endif
154 // _USE_VTK_
155 #endif
156 // _USE_ITK_