]> Creatis software - bbtk.git/blob - packages/itk/src/bbitkImageRegion.cxx
11026e57e8d724f96b34e273d3beee4715541b80
[bbtk.git] / packages / itk / src / bbitkImageRegion.cxx
1 /*=========================================================================                                                                               
2   Program:   bbtk
3   Module:    $RCSfile: bbitkImageRegion.cxx,v $
4   Language:  C++
5   Date:      $Date: 2008/10/17 08:18:21 $
6   Version:   $Revision: 1.4 $
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::DoIt()
47   {
48     const std::vector<long>& index = bbGetInputIndex();
49     const std::vector<long>& size = bbGetInputSize();
50     //             std::cout<< "isize="<<index.size()<<std::endl;
51     //     std::cout<< "ssize="<<size.size()<<std::endl;
52     unsigned long maxs = index.size() > size.size() ? index.size() : size.size();
53     switch (maxs) 
54       {
55       case 2 : DoIt<2>(); break;
56       case 3 : DoIt<3>(); break;
57       case 4 : DoIt<4>(); break;
58       default : bbtkError("ImageRegionCreator : cannot build a region of dimension "<<maxs);
59       }
60      
61
62   }
63
64   template <unsigned int Dimension>
65   void ImageRegionCreator::DoIt()
66   {
67     std::vector<long> index = bbGetInputIndex();
68     std::vector<long> size = bbGetInputSize();
69     //             std::cout<< "isize="<<index.size()<<std::endl;
70     //             std::cout<< "ssize="<<size.size()<<std::endl;
71  
72     int ds = index.size() - size.size();
73     if (ds<0) 
74       {
75         for (int i=0;i<-ds;++i) 
76  index.push_back(0);
77       }
78     else 
79       {
80         for (int i=0;i<ds;++i) size.push_back(0);
81       }
82
83     typename itk::ImageRegion<Dimension>::IndexType I;
84     typename itk::ImageRegion<Dimension>::SizeType S;
85
86     std::vector<long>::const_iterator ii,si;
87     int d(0);
88     for (ii=index.begin(), si=size.begin(); 
89          ii!=index.end(); ++ii, ++si, ++d)
90       {
91         I[d] = *ii;
92         S[d] = *si;
93         //  std::cout << "o="<<*ii<<" d="<<*si<<std::endl;
94       }
95
96
97     bbSetOutputOut ( itk::ImageRegion<Dimension>(I,S) );
98   }
99
100 }
101 // eo namespace
102
103 #endif