From: David Sarrut Date: Wed, 19 Oct 2011 13:06:20 +0000 (+0200) Subject: Utils for bounding box calculation (formerly in clitkSegmentationUtils) X-Git-Tag: v1.3.0~174^2~46 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=184e72d6817dd7450c804735686745c6ba712943;p=clitk.git Utils for bounding box calculation (formerly in clitkSegmentationUtils) --- diff --git a/itk/clitkBoundingBoxUtils.h b/itk/clitkBoundingBoxUtils.h new file mode 100644 index 0000000..2138d63 --- /dev/null +++ b/itk/clitkBoundingBoxUtils.h @@ -0,0 +1,53 @@ +/*========================================================================= + 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://oncora1.lyon.fnclcc.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 + ======================================================================-====*/ + +#ifndef CLITKBOUNDINGBOXUTILS_H +#define CLITKBOUNDINGBOXUTILS_H + +// clitk +#include "clitkCommon.h" + +// itk +#include + +namespace clitk { + + //-------------------------------------------------------------------- + template + void ComputeBBFromImageRegion(const ImageType * image, + typename ImageType::RegionType region, + typename itk::BoundingBox::Pointer bb); + + //-------------------------------------------------------------------- + template + void ComputeBBIntersection(typename itk::BoundingBox::Pointer bbo, + typename itk::BoundingBox::Pointer bbi1, + typename itk::BoundingBox::Pointer bbi2); + + //-------------------------------------------------------------------- + template + void ComputeRegionFromBB(const ImageType * image, + const typename itk::BoundingBox::Pointer bb, + typename ImageType::RegionType & region); +} // end clitk namespace + +#include "clitkBoundingBoxUtils.txx" + +#endif diff --git a/itk/clitkBoundingBoxUtils.txx b/itk/clitkBoundingBoxUtils.txx new file mode 100644 index 0000000..26f38b2 --- /dev/null +++ b/itk/clitkBoundingBoxUtils.txx @@ -0,0 +1,106 @@ +/*========================================================================= + 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 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 +