]> Creatis software - bbtk.git/blob - packages/itk/src/bbitkImageProperties.cxx
Fix pb with ZDim of 2D images
[bbtk.git] / packages / itk / src / bbitkImageProperties.cxx
1 /*=========================================================================                                                                               
2   Program:   bbtk
3   Module:    $RCSfile: bbitkImageProperties.cxx,v $
4   Language:  C++
5   Date:      $Date: 2010/04/08 14:35:03 $
6   Version:   $Revision: 1.11 $
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
37 #include "bbitkImageProperties.h"
38 #include "bbitkPackage.h"
39
40 namespace bbitk 
41 {
42   BBTK_BLACK_BOX_IMPLEMENTATION(ImageProperties,bbtk::AtomicBlackBox);
43
44   BBTK_ADD_BLACK_BOX_TO_PACKAGE(itk,ImageProperties);
45
46         //-----------------------------------------------------------------     
47         void ImageProperties::bbUserSetDefaultValues()
48         {
49                 std::cout <<
50         "==============================================================ImageProperties::bbUserSetDefaultValues()"
51         << std::endl;   
52         }
53
54         //-----------------------------------------------------------------     
55         void ImageProperties::bbUserInitializeProcessing()
56         {
57         std::cout <<
58         "==============================================================ImageProperties::bbUserInitializeProcessing()"
59         << std::endl;   
60         }
61
62         //-----------------------------------------------------------------     
63         void ImageProperties::bbUserFinalizeProcessing()
64         {
65         std::cout <<
66         "==============================================================ImageProperties::bbUserFinalizeProcessing()"
67         << std::endl;
68         }
69
70   void ImageProperties::DoIt()
71   {
72     BBTK_TEMPLATE_ITK_IMAGE_SWITCH(bbGetInputIn().type(),DoIt);
73   }
74
75   /** 
76       Template Processing 
77   */
78   template<class itkImageType>
79   void ImageProperties::DoIt()
80   {
81     bbtkDebugMessageInc("Core",9,"bbitk::ImageProperties::DoIt<"
82                         <<bbtk::TypeName<itkImageType>()
83                         <<">()"<<std::endl);
84
85     itkImageType* im = bbGetInputIn().get<itkImageType*>();
86     unsigned int dim = im->GetImageDimension();
87
88     bbSetOutputTypeName(bbtk::TypeName<typename itkImageType::PixelType>());
89     bbSetOutputDimension(dim);
90     const typename itkImageType::RegionType& r =im->GetLargestPossibleRegion();
91     bbSetOutputLargestPossibleRegion(r);
92
93     const typename itkImageType::IndexType& ind = r.GetIndex();
94     std::vector<int> vind;
95     for (unsigned int i=0;i<dim;++i) 
96        vind.push_back(ind[i]);
97     bbSetOutputIndex(vind);
98
99     const typename itkImageType::SizeType& sz = r.GetSize();
100     std::vector<int> vsz;
101     for (unsigned int i=0;i<dim;++i) 
102        vsz.push_back(sz[i]);
103     
104   // brute hack to avoid failure of most black boxes that expects 3D images. // JPR
105    if (dim==2)
106         vsz.push_back(1);
107     bbSetOutputSize(vsz);
108
109     typename itkImageType::SpacingType sp = im->GetSpacing();
110     std::vector<float> vsp;
111     for (unsigned int i=0;i<dim;++i) 
112        vsp.push_back(sp[i]);
113        
114  // brute hack to avoid failure of most black boxes that expects 3D images. // JPR
115     if (dim==2)
116        vsp.push_back(1.0);
117   
118     bbSetOutputSpacing(vsp);
119
120     bbtkDebugDecTab("Core",9);
121   }
122 }
123 // eo namespace bbtk
124
125 #endif