1 /*=========================================================================
2 Program: vv http://www.creatis.insa-lyon.fr/rio/vv
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
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.
13 It is distributed under dual licence
15 - BSD See included LICENSE.txt file
16 - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
17 ======================================================================-====*/
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;
28 for(unsigned int i=0; i<image->GetImageDimension(); i++) {
29 firstIndex[i] = region.GetIndex()[i];
30 lastIndex[i] = region.GetSize()[i];
33 typedef itk::BoundingBox<unsigned long,
34 ImageType::ImageDimension> BBType;
35 typedef typename BBType::PointType PointType;
38 image->TransformIndexToPhysicalPoint(firstIndex, firstPoint);
39 image->TransformIndexToPhysicalPoint(lastIndex, lastPoint);
41 bb->SetMaximum(lastPoint);
42 bb->SetMinimum(firstPoint);
44 //--------------------------------------------------------------------
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) {
53 typedef itk::BoundingBox<unsigned long, Dimension> BBType;
54 typedef typename BBType::PointType PointType;
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]);
65 bbo->SetMaximum(lastPoint);
66 bbo->SetMinimum(firstPoint);
68 //--------------------------------------------------------------------
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) {
78 typedef typename ImageType::IndexType IndexType;
79 typedef typename ImageType::PointType PointType;
80 typedef typename ImageType::RegionType RegionType;
81 typedef typename ImageType::SizeType SizeType;
83 // Region starting point
84 IndexType regionStart;
85 PointType start = bb->GetMinimum();
86 image->TransformPhysicalPointToIndex(start, regionStart);
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]);
97 region.SetIndex(regionStart);
98 region.SetSize(regionSize);
100 //--------------------------------------------------------------------