15 #include <itkImageMaskSpatialObject.h> 21 #include "mapMaskedRegistrationAlgorithmInterface.h" 22 #include <mapRegistrationAlgorithmInterface.h> 33 using MaskedInterface2D = const ::map::algorithm::facet::MaskedRegistrationAlgorithmInterface<2, 2>;
34 using MaskedInterface3D = const ::map::algorithm::facet::MaskedRegistrationAlgorithmInterface<3, 3>;
36 return dynamic_cast<MaskedInterface2D*
>(algorithm) !=
nullptr && dynamic_cast<MaskedInterface3D*>(algorithm) !=
nullptr;
43 if (! m_AlgorithmBase) mapDefaultExceptionStaticMacro(<<
"Error, cannot check data. Helper has no algorithm defined.");
45 unsigned int movingDim = m_AlgorithmBase->getMovingDimensions();
46 unsigned int targetDim = m_AlgorithmBase->getTargetDimensions();
48 bool result = movingDim == targetDim;
52 result = result && (movingMask->
GetDimension() == movingDim);
57 result = result && (targetMask->
GetDimension() == targetDim);
62 typedef ::map::algorithm::facet::MaskedRegistrationAlgorithmInterface<2, 2> MaskedInterface;
63 const MaskedInterface* pMaskedReg =
dynamic_cast<const MaskedInterface*
>(m_AlgorithmBase.GetPointer());
65 result = result && pMaskedReg;
67 else if (movingDim == 3)
69 typedef ::map::algorithm::facet::MaskedRegistrationAlgorithmInterface<3, 3> MaskedInterface;
70 const MaskedInterface* pMaskedReg =
dynamic_cast<const MaskedInterface*
>(m_AlgorithmBase.GetPointer());
72 result = result && pMaskedReg;
84 if (! m_AlgorithmBase) mapDefaultExceptionStaticMacro(<<
"Error, cannot set data. Helper has no algorithm defined.");
86 if (!
CheckSupport(movingMask, targetMask))
return false;
88 unsigned int movingDim = m_AlgorithmBase->getMovingDimensions();
89 unsigned int targetDim = m_AlgorithmBase->getTargetDimensions();
91 if (movingDim!=targetDim)
return false;
95 return DoSetMasks<2,2>(movingMask, targetMask);
97 else if (movingDim == 3)
99 return DoSetMasks<3,3>(movingMask, targetMask);
104 template<
unsigned int VMovingDimension,
unsigned int VTargetDimension>
107 typedef itk::SpatialObject<VMovingDimension> MovingSpatialType;
108 typedef itk::SpatialObject<VTargetDimension> TargetSpatialType;
110 typedef ::map::algorithm::facet::MaskedRegistrationAlgorithmInterface<VMovingDimension, VTargetDimension> MaskedRegInterface;
111 MaskedRegInterface* pAlg =
dynamic_cast<MaskedRegInterface*
>(m_AlgorithmBase.GetPointer());
113 if (!pAlg)
return false;
118 typename MovingSpatialType::Pointer movingSpatial =
dynamic_cast<MovingSpatialType*
>(m_convertResult.GetPointer());
119 if (!movingSpatial) mapDefaultExceptionStaticMacro(<<
"Error, cannot convert moving mask.");
120 pAlg->setMovingMask(movingSpatial);
124 pAlg->setMovingMask(
nullptr);
130 typename TargetSpatialType::Pointer targetSpatial =
dynamic_cast<TargetSpatialType*
>(m_convertResult.GetPointer());
131 if (! targetSpatial) mapDefaultExceptionStaticMacro(<<
"Error, cannot convert moving mask.");
132 pAlg->setTargetMask(targetSpatial);
136 pAlg->setTargetMask(
nullptr);
142 template<
unsigned int VImageDimension>
143 typename itk::SpatialObject<VImageDimension>::Pointer
144 MaskedAlgorithmHelper::ConvertMaskSO(
const itk::Image<MaskPixelType, VImageDimension>*
mask)
const 146 typedef itk::ImageMaskSpatialObject<VImageDimension> SpatialType;
148 typename SpatialType::Pointer spatial = SpatialType::New();
149 spatial->SetImage(mask);
151 return spatial.GetPointer();
154 template<
typename TPixelType,
unsigned int VImageDimension>
155 void MaskedAlgorithmHelper::DoConvertMask(
const itk::Image<TPixelType,VImageDimension>* mask)
157 using InImageType = itk::Image<TPixelType, VImageDimension>;
158 using MaskImageType = itk::Image<MaskPixelType, VImageDimension>;
160 typedef itk::CastImageFilter< InImageType, MaskImageType > CastFilterType;
161 typename CastFilterType::Pointer imageCaster = CastFilterType::New();
163 imageCaster->SetInput(mask);
165 auto castedMask = imageCaster->GetOutput();
166 imageCaster->Update();
167 m_convertResult = ConvertMaskSO<VImageDimension>(castedMask);
170 template<
unsigned int VImageDimension>
171 void MaskedAlgorithmHelper::DoConvertMask(
const itk::Image<MaskPixelType, VImageDimension>* mask)
173 m_convertResult = ConvertMaskSO<VImageDimension>(
mask);
#define AccessFixedDimensionByItk(mitkImage, itkImageTypeFunction, dimension)
Access a mitk-image with known dimension by an itk-image.
DataCollection - Class to facilitate loading/accessing structured data.
bool CheckSupport(const mitk::Image *movingMask, const mitk::Image *targetMask) const
static bool HasMaskedRegistrationAlgorithmInterface(const map::algorithm::RegistrationAlgorithmBase *algorithm)
unsigned int GetDimension() const
Get dimension of the image.
Image class for storing images.
itk::Image< unsigned char, 3 > MaskImageType
bool SetMasks(const mitk::Image *movingMask, const mitk::Image *targetMask)
mitk::Image::Pointer mask
MaskedAlgorithmHelper(map::algorithm::RegistrationAlgorithmBase *algorithm)