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://www.centreleonberard.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 ======================================================================-====*/
21 //--------------------------------------------------------------------
22 template<class ImageType>
23 void ComputeBBFromImageRegion(const ImageType * image,
24 typename ImageType::RegionType region,
25 typename itk::BoundingBox<unsigned long,
26 ImageType::ImageDimension>::Pointer bb) {
27 typedef typename ImageType::IndexType IndexType;
30 for(unsigned int i=0; i<image->GetImageDimension(); i++) {
31 firstIndex[i] = region.GetIndex()[i];
32 lastIndex[i] = firstIndex[i]+region.GetSize()[i];
35 typedef itk::BoundingBox<unsigned long,
36 ImageType::ImageDimension> BBType;
37 typedef typename BBType::PointType PointType;
40 image->TransformIndexToPhysicalPoint(firstIndex, firstPoint);
41 image->TransformIndexToPhysicalPoint(lastIndex, lastPoint);
43 bb->SetMaximum(lastPoint);
44 bb->SetMinimum(firstPoint);
46 //--------------------------------------------------------------------
49 //--------------------------------------------------------------------
50 template<int Dimension>
51 void ComputeBBIntersection(typename itk::BoundingBox<unsigned long, Dimension>::Pointer bbo,
52 typename itk::BoundingBox<unsigned long, Dimension>::Pointer bbi1,
53 typename itk::BoundingBox<unsigned long, Dimension>::Pointer bbi2) {
54 typedef itk::BoundingBox<unsigned long, Dimension> BBType;
55 typedef typename BBType::PointType PointType;
58 for(unsigned int i=0; i<Dimension; i++) {
59 firstPoint[i] = std::max(bbi1->GetMinimum()[i], bbi2->GetMinimum()[i]);
60 lastPoint[i] = std::min(bbi1->GetMaximum()[i], bbi2->GetMaximum()[i]);
62 bbo->SetMaximum(lastPoint);
63 bbo->SetMinimum(firstPoint);
65 //--------------------------------------------------------------------
68 ///--------------------------------------------------------------------
69 template<int Dimension>
70 void ComputeBBIntersection(typename itk::BoundingBox<unsigned long, Dimension>::Pointer bbo,
71 typename itk::BoundingBox<unsigned long, Dimension>::Pointer bbi1,
72 typename itk::BoundingBox<unsigned long, Dimension>::Pointer bbi2,
74 typedef itk::BoundingBox<unsigned long, Dimension> BBType;
75 typedef typename BBType::PointType PointType;
78 firstPoint[dimension] = std::max(bbi1->GetMinimum()[dimension], bbi2->GetMinimum()[dimension]);
79 lastPoint[dimension] = std::min(bbi1->GetMaximum()[dimension], bbi2->GetMaximum()[dimension]);
80 bbo->SetMaximum(lastPoint);
81 bbo->SetMinimum(firstPoint);
83 //--------------------------------------------------------------------
86 //--------------------------------------------------------------------
87 template<int Dimension>
88 void ComputeBBUnion(typename itk::BoundingBox<unsigned long, Dimension>::Pointer bbo,
89 typename itk::BoundingBox<unsigned long, Dimension>::Pointer bbi1,
90 typename itk::BoundingBox<unsigned long, Dimension>::Pointer bbi2) {
91 typedef itk::BoundingBox<unsigned long, Dimension> BBType;
92 typedef typename BBType::PointType PointType;
95 for(unsigned int i=0; i<Dimension; i++) {
96 firstPoint[i] = std::min(bbi1->GetMinimum()[i], bbi2->GetMinimum()[i]);
97 lastPoint[i] = std::max(bbi1->GetMaximum()[i], bbi2->GetMaximum()[i]);
99 bbo->SetMaximum(lastPoint);
100 bbo->SetMinimum(firstPoint);
102 //--------------------------------------------------------------------
105 //--------------------------------------------------------------------
106 template<class ImageType>
107 void ComputeRegionFromBB(const ImageType * image,
108 const typename itk::BoundingBox<unsigned long,
109 ImageType::ImageDimension>::Pointer bb,
110 typename ImageType::RegionType & region) {
112 typedef typename ImageType::IndexType IndexType;
113 typedef typename ImageType::PointType PointType;
114 typedef typename ImageType::RegionType RegionType;
115 typedef typename ImageType::SizeType SizeType;
117 // Region starting point
118 IndexType regionStart;
119 PointType start = bb->GetMinimum();
120 image->TransformPhysicalPointToIndex(start, regionStart);
124 PointType maxs = bb->GetMaximum();
125 PointType mins = bb->GetMinimum();
126 for(unsigned int i=0; i<ImageType::ImageDimension; i++) {
127 regionSize[i] = lrint((maxs[i] - mins[i])/image->GetSpacing()[i]);
131 region.SetIndex(regionStart);
132 region.SetSize(regionSize);
134 //--------------------------------------------------------------------
137 } // end of namespace