]> Creatis software - bbtk.git/blob - packages/itk/src/bbitkImageRegion.cxx
.
[bbtk.git] / packages / itk / src / bbitkImageRegion.cxx
1 /*=========================================================================                                                                               
2   Program:   bbtk
3   Module:    $RCSfile: bbitkImageRegion.cxx,v $
4   Language:  C++
5   Date:      $Date: 2009/05/15 14:57:58 $
6   Version:   $Revision: 1.5 $
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 #ifdef _USE_ITK_
33
34 #include "bbitkImageRegion.h"
35 #include "bbitkPackage.h"
36
37 namespace bbitk
38 {
39
40   BBTK_BLACK_BOX_IMPLEMENTATION(ImageRegionCreator,
41                                 bbtk::AtomicBlackBox);
42
43   BBTK_ADD_BLACK_BOX_TO_PACKAGE(itk,ImageRegionCreator);
44
45         /*
46         void ImageRegionCreator::bbUserSetDefaultValues()               {       }       
47         void ImageRegionCreator::bbUserInitializeProcessing()   {       }
48         void ImageRegionCreator::bbUserFinalizeProcessing()             {       }       
49         
50         template <unsigned int Dimension>
51         void ImageRegionCreator::bbUserSetDefaultValues()               {       }
52         
53         template <unsigned int Dimension>
54         void ImageRegionCreator::bbUserInitializeProcessing()   {       }
55         
56         template <unsigned int Dimension>
57         void ImageRegionCreator::bbUserFinalizeProcessing()             {       }       
58         */
59         
60   void ImageRegionCreator::DoIt()
61   {
62     const std::vector<long>& index = bbGetInputIndex();
63     const std::vector<long>& size = bbGetInputSize();
64     //             std::cout<< "isize="<<index.size()<<std::endl;
65     //     std::cout<< "ssize="<<size.size()<<std::endl;
66     unsigned long maxs = index.size() > size.size() ? index.size() : size.size();
67     switch (maxs) 
68       {
69       case 2 : DoIt<2>(); break;
70       case 3 : DoIt<3>(); break;
71       case 4 : DoIt<4>(); break;
72       default : bbtkError("ImageRegionCreator : cannot build a region of dimension "<<maxs);
73       }
74      
75
76   }
77
78   template <unsigned int Dimension>
79   void ImageRegionCreator::DoIt()
80   {
81     std::vector<long> index = bbGetInputIndex();
82     std::vector<long> size = bbGetInputSize();
83     //             std::cout<< "isize="<<index.size()<<std::endl;
84     //             std::cout<< "ssize="<<size.size()<<std::endl;
85  
86     int ds = index.size() - size.size();
87     if (ds<0) 
88       {
89         for (int i=0;i<-ds;++i) 
90  index.push_back(0);
91       }
92     else 
93       {
94         for (int i=0;i<ds;++i) size.push_back(0);
95       }
96
97     typename itk::ImageRegion<Dimension>::IndexType I;
98     typename itk::ImageRegion<Dimension>::SizeType S;
99
100     std::vector<long>::const_iterator ii,si;
101     int d(0);
102     for (ii=index.begin(), si=size.begin(); 
103          ii!=index.end(); ++ii, ++si, ++d)
104       {
105         I[d] = *ii;
106         S[d] = *si;
107         //  std::cout << "o="<<*ii<<" d="<<*si<<std::endl;
108       }
109
110
111     bbSetOutputOut ( itk::ImageRegion<Dimension>(I,S) );
112   }
113
114 }
115 // eo namespace
116
117 #endif