16 #include <itkImageDuplicator.h> 23 #include <mapImageRegistrationAlgorithmInterface.h> 24 #include <mapRegistrationAlgorithmInterface.h> 25 #include <mapPointSetRegistrationAlgorithmInterface.h> 26 #include <mapDummyImageRegistrationAlgorithm.h> 27 #include <mapAlgorithmIdentificationInterface.h> 33 : m_AlgorithmBase(algorithm), m_Error(
CheckError::none)
35 m_AllowImageCasting =
true;
40 using InternalDefault2DImageType = itk::Image<map::core::discrete::InternalPixelType, 2>;
41 using InternalDefault3DImageType = itk::Image<map::core::discrete::InternalPixelType, 3>;
43 using Alg2DType = const ::map::algorithm::facet::ImageRegistrationAlgorithmInterface<InternalDefault2DImageType, InternalDefault2DImageType>;
44 if (dynamic_cast<Alg2DType*>(algorithm) !=
nullptr)
return true;
45 using Alg3DType = const ::map::algorithm::facet::ImageRegistrationAlgorithmInterface<InternalDefault3DImageType, InternalDefault3DImageType>;
46 if (dynamic_cast<Alg3DType*>(algorithm) !=
nullptr)
return true;
47 using Alg2D3DType = const ::map::algorithm::facet::ImageRegistrationAlgorithmInterface<InternalDefault2DImageType, InternalDefault3DImageType>;
48 if (dynamic_cast<Alg2D3DType*>(algorithm) !=
nullptr)
return true;
49 using Alg3D2DType = const ::map::algorithm::facet::ImageRegistrationAlgorithmInterface<InternalDefault3DImageType, InternalDefault2DImageType>;
50 if (dynamic_cast<Alg3D2DType*>(algorithm) !=
nullptr)
return true;
57 typedef ::map::core::continuous::Elements<3>::InternalPointSetType InternalDefaultPointSetType;
58 typedef const ::map::algorithm::facet::PointSetRegistrationAlgorithmInterface<InternalDefaultPointSetType, InternalDefaultPointSetType>
61 return dynamic_cast<PointSetRegInterface*
>(algorithm) !=
nullptr;
64 map::core::RegistrationBase::Pointer
68 map::core::RegistrationBase::Pointer spResult;
70 unsigned int movingDim = m_AlgorithmBase->getMovingDimensions();
71 unsigned int targetDim = m_AlgorithmBase->getTargetDimensions();
73 if (movingDim != targetDim)
75 mapDefaultExceptionStaticMacro( <<
76 "Error, algorithm instance has unequal dimensionality and is therefore not supported in the current version of MITKAlgorithmHelper.");
81 mapDefaultExceptionStaticMacro( <<
82 "Error, algorithm instance has a dimensionality larger than 3 and is therefore not supported in the current version of MITKAlgorithmHelper.");
85 typedef ::map::algorithm::facet::RegistrationAlgorithmInterface<2, 2> RegistrationAlg2D2DInterface;
86 typedef ::map::algorithm::facet::RegistrationAlgorithmInterface<3, 3> RegistrationAlg3D3DInterface;
88 RegistrationAlg2D2DInterface* pRegAlgorithm2D2D =
dynamic_cast<RegistrationAlg2D2DInterface*
> 89 (m_AlgorithmBase.GetPointer());
90 RegistrationAlg3D3DInterface* pRegAlgorithm3D3D =
dynamic_cast<RegistrationAlg3D3DInterface*
> 91 (m_AlgorithmBase.GetPointer());
93 if (pRegAlgorithm2D2D)
95 spResult = pRegAlgorithm2D2D->getRegistration();
98 if (pRegAlgorithm3D3D)
100 spResult = pRegAlgorithm3D3D->getRegistration();
110 map::core::RegistrationBase::Pointer spInternalResult =
GetRegistration();
112 spResult->SetRegistration(spInternalResult);
131 if (! m_AlgorithmBase)
133 mapDefaultExceptionStaticMacro( <<
"Error, cannot check data. Helper has no algorithm defined.");
138 mapDefaultExceptionStaticMacro( <<
"Error, cannot check data. Moving data pointer is nullptr.");
143 mapDefaultExceptionStaticMacro( <<
"Error, cannot check data. Target data pointer is nullptr.");
149 unsigned int movingDim = m_AlgorithmBase->getMovingDimensions();
150 unsigned int targetDim = m_AlgorithmBase->getTargetDimensions();
152 if (movingDim != targetDim)
161 typedef ::map::core::continuous::Elements<3>::InternalPointSetType InternalDefaultPointSetType;
162 typedef ::map::algorithm::facet::PointSetRegistrationAlgorithmInterface<InternalDefaultPointSetType, InternalDefaultPointSetType>
163 PointSetRegInterface;
165 PointSetRegInterface* pPointSetInterface =
dynamic_cast<PointSetRegInterface*
> 166 (m_AlgorithmBase.GetPointer());
168 if (!pPointSetInterface)
181 else if (movingDim == 3)
206 this->m_AllowImageCasting = allowCasting;
211 return this->m_AllowImageCasting;
216 if (! m_AlgorithmBase)
218 mapDefaultExceptionStaticMacro( <<
"Error, cannot check data. Helper has no algorithm defined.");
223 mapDefaultExceptionStaticMacro( <<
"Error, cannot check data. Moving data pointer is nullptr.");
228 mapDefaultExceptionStaticMacro( <<
"Error, cannot check data. Target data pointer is nullptr.");
231 unsigned int movingDim = m_AlgorithmBase->getMovingDimensions();
232 unsigned int targetDim = m_AlgorithmBase->getTargetDimensions();
234 if (movingDim != targetDim)
236 mapDefaultExceptionStaticMacro( <<
237 "Error, cannot set data. Current version of MITKAlgorithmHelper only supports images/point sets with same dimensionality.");
242 typedef ::map::core::continuous::Elements<3>::InternalPointSetType InternalDefaultPointSetType;
243 typedef ::map::algorithm::facet::PointSetRegistrationAlgorithmInterface<InternalDefaultPointSetType, InternalDefaultPointSetType>
244 PointSetRegInterface;
246 PointSetRegInterface* pPointSetInterface =
dynamic_cast<PointSetRegInterface*
> 247 (m_AlgorithmBase.GetPointer());
260 else if (movingDim == 3)
267 template<
typename TInImageType,
typename TOutImageType>
268 typename TOutImageType::Pointer MITKAlgorithmHelper::CastImage(
const TInImageType* input)
const 270 typedef itk::CastImageFilter< TInImageType, TOutImageType > CastFilterType;
271 typename CastFilterType::Pointer spImageCaster = CastFilterType::New();
273 spImageCaster->SetInput(input);
275 typename TOutImageType::Pointer spImage = spImageCaster->GetOutput();
276 spImageCaster->Update();
281 template<
typename TPixelType1,
unsigned int VImageDimension1,
282 typename TPixelType2,
unsigned int VImageDimension2>
283 void MITKAlgorithmHelper::DoSetImages(
const itk::Image<TPixelType1, VImageDimension1>* moving,
284 const itk::Image<TPixelType2, VImageDimension2>* target)
286 typedef itk::Image<TPixelType1, VImageDimension1> MovingImageType;
287 typedef itk::Image<TPixelType2, VImageDimension2> TargetImageType;
288 typedef itk::Image<map::core::discrete::InternalPixelType, VImageDimension1>
289 InternalDefaultMovingImageType;
290 typedef itk::Image<map::core::discrete::InternalPixelType, VImageDimension2>
291 InternalDefaultTargetImageType;
293 typedef ::map::algorithm::facet::ImageRegistrationAlgorithmInterface<MovingImageType, TargetImageType>
295 typedef ::map::algorithm::facet::ImageRegistrationAlgorithmInterface<InternalDefaultMovingImageType, InternalDefaultTargetImageType>
296 DefaultImageRegInterface;
299 ImageRegInterface* pImageInterface =
dynamic_cast<ImageRegInterface*
>(m_AlgorithmBase.GetPointer());
300 DefaultImageRegInterface* pDefaultImageInterface =
dynamic_cast<DefaultImageRegInterface*
> 301 (m_AlgorithmBase.GetPointer());
313 typedef itk::ImageDuplicator< MovingImageType > MovingDuplicatorType;
314 typedef itk::ImageDuplicator< TargetImageType > TargetDuplicatorType;
315 typename MovingDuplicatorType::Pointer mDuplicator = MovingDuplicatorType::New();
316 mDuplicator->SetInputImage(moving);
317 mDuplicator->Update();
319 typename TargetDuplicatorType::Pointer tDuplicator = TargetDuplicatorType::New();
320 tDuplicator->SetInputImage(target);
321 tDuplicator->Update();
323 typename MovingImageType::Pointer clonedMoving = mDuplicator->GetOutput();
324 typename TargetImageType::Pointer clonedTarget = tDuplicator->GetOutput();
326 pImageInterface->setTargetImage(clonedTarget);
327 pImageInterface->setMovingImage(clonedMoving);
329 else if (pDefaultImageInterface)
332 if (! m_AllowImageCasting)
334 mapDefaultExceptionStaticMacro( <<
335 "Error, cannot set images. MITKAlgorithmHelper has to convert them into MatchPoint default images, but is not allowed. Please reconfigure helper.");
338 typename InternalDefaultTargetImageType::Pointer spCastedTarget =
339 CastImage<TargetImageType, InternalDefaultTargetImageType>(target);
340 typename InternalDefaultMovingImageType::Pointer spCastedMoving =
341 CastImage<MovingImageType, InternalDefaultMovingImageType>(moving);
342 pDefaultImageInterface->setTargetImage(spCastedTarget);
343 pDefaultImageInterface->setMovingImage(spCastedMoving);
347 mapDefaultExceptionStaticMacro( <<
"Error, algorithm is not able to use the based images.");
351 template<
typename TPixelType1,
unsigned int VImageDimension1,
352 typename TPixelType2,
unsigned int VImageDimension2>
353 void MITKAlgorithmHelper::DoCheckImages(
const itk::Image<TPixelType1, VImageDimension1>* ,
354 const itk::Image<TPixelType2, VImageDimension2>* )
const 356 typedef itk::Image<TPixelType1, VImageDimension1> MovingImageType;
357 typedef itk::Image<TPixelType2, VImageDimension2> TargetImageType;
358 typedef itk::Image<map::core::discrete::InternalPixelType, VImageDimension1>
359 InternalDefaultMovingImageType;
360 typedef itk::Image<map::core::discrete::InternalPixelType, VImageDimension2>
361 InternalDefaultTargetImageType;
363 typedef ::map::algorithm::facet::ImageRegistrationAlgorithmInterface<MovingImageType, TargetImageType>
365 typedef ::map::algorithm::facet::ImageRegistrationAlgorithmInterface<InternalDefaultMovingImageType, InternalDefaultTargetImageType>
366 DefaultImageRegInterface;
368 ImageRegInterface* pImageInterface =
dynamic_cast<ImageRegInterface*
>(m_AlgorithmBase.GetPointer());
369 DefaultImageRegInterface* pDefaultImageInterface =
dynamic_cast<DefaultImageRegInterface*
> 370 (m_AlgorithmBase.GetPointer());
377 else if (pDefaultImageInterface)
395 DummyRegType::Pointer regAlg = DummyRegType::New();
398 map::core::discrete::Elements<3>::InternalImageType::Pointer dummyImg =
399 map::core::discrete::Elements<3>::InternalImageType::New();
400 dummyImg->Allocate();
401 regAlg->setTargetImage(dummyImg);
402 regAlg->setMovingImage(dummyImg);
405 dummyReg->SetRegistration(regAlg->getRegistration());
void SetAllowImageCasting(bool allowCasting)
Base of all data objects.
map::core::RegistrationBase::Pointer GetRegistration() const
mapGenerateAlgorithmUIDPolicyMacro(DummyRegIDPolicy, "de.dkfz.dipp", "Identity", "1.0.0", "")
DataCollection - Class to facilitate loading/accessing structured data.
static bool HasImageAlgorithmInterface(const map::algorithm::RegistrationAlgorithmBase *algorithm)
bool CheckData(const mitk::BaseData *moving, const mitk::BaseData *target, CheckError::Type &error) const
MITKMATCHPOINTREGISTRATION_EXPORT ::map::core::continuous::Elements< 3 >::InternalPointSetType::Pointer ConvertPointSetMITKtoMAP(const mitk::PointSet::DataType *mitkSet)
Data structure which stores a set of points. Superclass of mitk::Mesh.
void SetData(const mitk::BaseData *moving, const mitk::BaseData *target)
Image class for storing images.
static const mitk::Image * GetDataAsImage(const mitk::BaseData *data)
static const mitk::PointSet * GetDataAsPointSet(const mitk::BaseData *data)
static bool HasPointSetAlgorithmInterface(const map::algorithm::RegistrationAlgorithmBase *algorithm)
#define AccessTwoImagesFixedDimensionByItk(mitkImage1, mitkImage2, itkImageTypeFunction, dimension)
Access two mitk-images with known dimension by itk-images.
mitk::MAPRegistrationWrapper::Pointer GenerateIdentityRegistration3D()
bool GetAllowImageCasting() const
itk::Image< mitk::ScalarType, 3 > InternalImageType
MITKAlgorithmHelper(map::algorithm::RegistrationAlgorithmBase *algorithm)
mitk::MAPRegistrationWrapper::Pointer GetMITKRegistrationWrapper() const