From 184e72d6817dd7450c804735686745c6ba712943 Mon Sep 17 00:00:00 2001 From: David Sarrut Date: Wed, 19 Oct 2011 15:06:20 +0200 Subject: [PATCH] Utils for bounding box calculation (formerly in clitkSegmentationUtils) --- itk/clitkBoundingBoxUtils.h | 53 +++++++++++++++++ itk/clitkBoundingBoxUtils.txx | 106 ++++++++++++++++++++++++++++++++++ 2 files changed, 159 insertions(+) create mode 100644 itk/clitkBoundingBoxUtils.h create mode 100644 itk/clitkBoundingBoxUtils.txx 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 + -- 2.45.1