]> Creatis software - clitk.git/blob - itk/clitkSegmentationUtils.txx
reconstruct with dilatation (jef)
[clitk.git] / itk / clitkSegmentationUtils.txx
1 /*=========================================================================
2   Program:   vv                     http://www.creatis.insa-lyon.fr/rio/vv
3
4   Authors belong to: 
5   - University of LYON              http://www.universite-lyon.fr/
6   - Léon Bérard cancer center       http://oncora1.lyon.fnclcc.fr
7   - CREATIS CNRS laboratory         http://www.creatis.insa-lyon.fr
8
9   This software is distributed WITHOUT ANY WARRANTY; without even
10   the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11   PURPOSE.  See the copyright notices for more information.
12
13   It is distributed under dual licence
14
15   - BSD        See included LICENSE.txt file
16   - CeCILL-B   http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
17 ======================================================================-====*/
18
19 //--------------------------------------------------------------------
20 template<class ImageType>
21 void clitk::ComputeBBFromImageRegion(typename ImageType::Pointer image, 
22                               typename ImageType::RegionType region,
23                               typename itk::BoundingBox<unsigned long, 
24                                      ImageType::ImageDimension>::Pointer bb) {
25   typedef typename ImageType::IndexType IndexType;
26   IndexType firstIndex;
27   IndexType lastIndex;
28   for(unsigned int i=0; i<image->GetImageDimension(); i++) {
29     firstIndex[i] = region.GetIndex()[i];
30     lastIndex[i] = region.GetSize()[i];
31   }
32
33   typedef itk::BoundingBox<unsigned long, 
34     ImageType::ImageDimension> BBType;
35   typedef typename BBType::PointType PointType;
36   PointType lastPoint;
37   PointType firstPoint;
38   image->TransformIndexToPhysicalPoint(firstIndex, firstPoint);
39   image->TransformIndexToPhysicalPoint(lastIndex, lastPoint);
40
41   bb->SetMaximum(lastPoint);
42   bb->SetMinimum(firstPoint);
43 }
44 //--------------------------------------------------------------------
45
46
47 //--------------------------------------------------------------------
48 template<int Dimension>
49 void clitk::ComputeBBIntersection(typename itk::BoundingBox<unsigned long, Dimension>::Pointer bbo, 
50                            typename itk::BoundingBox<unsigned long, Dimension>::Pointer bbi1, 
51                            typename itk::BoundingBox<unsigned long, Dimension>::Pointer bbi2) {
52
53   typedef itk::BoundingBox<unsigned long, Dimension> BBType;
54   typedef typename BBType::PointType PointType;
55   PointType lastPoint;
56   PointType firstPoint;
57
58   for(unsigned int i=0; i<Dimension; i++) {
59     firstPoint[i] = std::max(bbi1->GetMinimum()[i], 
60                              bbi2->GetMinimum()[i]);
61     lastPoint[i] = std::min(bbi1->GetMaximum()[i], 
62                             bbi2->GetMaximum()[i]);
63   }
64
65   bbo->SetMaximum(lastPoint);
66   bbo->SetMinimum(firstPoint);
67 }
68 //--------------------------------------------------------------------
69
70
71 //--------------------------------------------------------------------
72 template<class ImageType>
73   void clitk::ComputeRegionFromBB(typename ImageType::Pointer image, 
74                            const typename itk::BoundingBox<unsigned long, 
75                            ImageType::ImageDimension>::Pointer bb, 
76                            typename ImageType::RegionType & region) {
77     // Types
78     typedef typename ImageType::IndexType  IndexType;
79     typedef typename ImageType::PointType  PointType;
80     typedef typename ImageType::RegionType RegionType;
81     typedef typename ImageType::SizeType   SizeType;
82
83     // Region starting point
84     IndexType regionStart;
85     PointType start = bb->GetMinimum();
86     image->TransformPhysicalPointToIndex(start, regionStart);
87     
88     // Region size
89     SizeType regionSize;
90     PointType maxs = bb->GetMaximum();
91     PointType mins = bb->GetMinimum();
92     for(unsigned int i=0; i<ImageType::ImageDimension; i++) {
93       regionSize[i] = floor((maxs[i] - mins[i])/image->GetSpacing()[i]);
94     }
95    
96     // Create region
97     region.SetIndex(regionStart);
98     region.SetSize(regionSize);
99   }
100   //--------------------------------------------------------------------