/*========================================================================= Program: vv http://www.creatis.insa-lyon.fr/rio/vv Authors belong to: - University of LYON http://www.universite-lyon.fr/ - Léon Bérard cancer center http://www.centreleonberard.fr - CREATIS CNRS laboratory http://www.creatis.insa-lyon.fr This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the copyright notices for more information. It is distributed under dual licence - BSD See included LICENSE.txt file - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html ======================================================================-====*/ namespace clitk { //-------------------------------------------------------------------- template void ComputeBBFromImageRegion(const ImageType * image, typename ImageType::RegionType region, typename itk::BoundingBox::Pointer bb) { typedef typename ImageType::IndexType IndexType; IndexType firstIndex; IndexType lastIndex; for(unsigned int i=0; iGetImageDimension(); i++) { firstIndex[i] = region.GetIndex()[i]; lastIndex[i] = firstIndex[i]+region.GetSize()[i]; } typedef itk::BoundingBox BBType; typedef typename BBType::PointType PointType; PointType lastPoint; PointType firstPoint; image->TransformIndexToPhysicalPoint(firstIndex, firstPoint); image->TransformIndexToPhysicalPoint(lastIndex, lastPoint); bb->SetMaximum(lastPoint); bb->SetMinimum(firstPoint); } //-------------------------------------------------------------------- //-------------------------------------------------------------------- template void ComputeBBIntersection(typename itk::BoundingBox::Pointer bbo, typename itk::BoundingBox::Pointer bbi1, typename itk::BoundingBox::Pointer bbi2) { typedef itk::BoundingBox BBType; typedef typename BBType::PointType PointType; PointType lastPoint; PointType firstPoint; for(unsigned int i=0; iGetMinimum()[i], bbi2->GetMinimum()[i]); lastPoint[i] = std::min(bbi1->GetMaximum()[i], bbi2->GetMaximum()[i]); } bbo->SetMaximum(lastPoint); bbo->SetMinimum(firstPoint); } //-------------------------------------------------------------------- ///-------------------------------------------------------------------- template void ComputeBBIntersection(typename itk::BoundingBox::Pointer bbo, typename itk::BoundingBox::Pointer bbi1, typename itk::BoundingBox::Pointer bbi2, int dimension) { typedef itk::BoundingBox BBType; typedef typename BBType::PointType PointType; PointType lastPoint; PointType firstPoint; firstPoint[dimension] = std::max(bbi1->GetMinimum()[dimension], bbi2->GetMinimum()[dimension]); lastPoint[dimension] = std::min(bbi1->GetMaximum()[dimension], bbi2->GetMaximum()[dimension]); bbo->SetMaximum(lastPoint); bbo->SetMinimum(firstPoint); } //-------------------------------------------------------------------- //-------------------------------------------------------------------- template void ComputeBBUnion(typename itk::BoundingBox::Pointer bbo, typename itk::BoundingBox::Pointer bbi1, typename itk::BoundingBox::Pointer bbi2) { typedef itk::BoundingBox BBType; typedef typename BBType::PointType PointType; PointType lastPoint; PointType firstPoint; for(unsigned int i=0; iGetMinimum()[i], bbi2->GetMinimum()[i]); lastPoint[i] = std::max(bbi1->GetMaximum()[i], bbi2->GetMaximum()[i]); } bbo->SetMaximum(lastPoint); bbo->SetMinimum(firstPoint); } //-------------------------------------------------------------------- //-------------------------------------------------------------------- template void ComputeRegionFromBB(const ImageType * image, const typename itk::BoundingBox::Pointer bb, typename ImageType::RegionType & region) { // Types typedef typename ImageType::IndexType IndexType; typedef typename ImageType::PointType PointType; typedef typename ImageType::RegionType RegionType; typedef typename ImageType::SizeType SizeType; // Region starting point IndexType regionStart; PointType start = bb->GetMinimum(); image->TransformPhysicalPointToIndex(start, regionStart); // Region size SizeType regionSize; PointType maxs = bb->GetMaximum(); PointType mins = bb->GetMinimum(); for(unsigned int i=0; iGetSpacing()[i]); } // Create region region.SetIndex(regionStart); region.SetSize(regionSize); } //-------------------------------------------------------------------- } // end of namespace