Medical Imaging Interaction Toolkit  2018.4.99-6aa36ba9
Medical Imaging Interaction Toolkit
mitkRegistrationHelper.cpp
Go to the documentation of this file.
1 /*============================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
13 
14 #include "mitkRegistrationHelper.h"
15 
16 //MatchPoint
17 #include "mapRegistrationKernel.h"
18 
19 namespace mitk
20 {
21 
22  MITKRegistrationHelper::Affine3DTransformType::Pointer
24  getAffineMatrix(const mitk::MAPRegistrationWrapper* wrapper, bool inverseKernel)
25  {
26  Affine3DTransformType::Pointer result = nullptr;
27 
28  if (wrapper)
29  {
30  result = getAffineMatrix(wrapper->GetRegistration(), inverseKernel);
31  }
32  return result;
33  }
34 
35  MITKRegistrationHelper::Affine3DTransformType::Pointer
37  getAffineMatrix(const RegistrationBaseType* registration, bool inverseKernel)
38  {
39  Affine3DTransformType::Pointer result = nullptr;
40 
41  if (registration && is3D(registration))
42  {
43  const Registration3DType* pReg = dynamic_cast<const Registration3DType*>(registration);
44  if (pReg)
45  {
46  if (inverseKernel)
47  {
48  result = getAffineMatrix(pReg->getInverseMapping());
49  }
50  else
51  {
52  result = getAffineMatrix(pReg->getDirectMapping());
53  }
54  }
55  }
56  return result;
57  }
58 
59 
60  MITKRegistrationHelper::Affine3DTransformType::Pointer MITKRegistrationHelper::getAffineMatrix(const RegistrationKernel3DBase& kernel)
61  {
62  Affine3DTransformType::Pointer result = nullptr;
63 
64  typedef ::map::core::RegistrationKernel<3,3> KernelType;
65 
66  const KernelType* pModelKernel = dynamic_cast<const KernelType*>(&kernel);
67 
68  if (pModelKernel)
69  {
70 
71  KernelType::TransformType::MatrixType matrix;
72  KernelType::TransformType::OutputVectorType offset;
73 
74  if(pModelKernel->getAffineMatrixDecomposition(matrix,offset))
75  {
76  result = Affine3DTransformType::New();
77  Affine3DTransformType::MatrixType resultMatrix;
78  Affine3DTransformType::OffsetType resultOffset;
79 
83  //The conversion of matrix and offset is needed
84  //because mitk uses float and MatchPoint currently
85  //double as scalar value.
86  for (unsigned int i=0; i<matrix.GetVnlMatrix().size(); ++i)
87  {
88  resultMatrix.GetVnlMatrix().begin()[i] = static_cast<mitk::ScalarType>(matrix.GetVnlMatrix().begin()[i]);
89  }
90  resultOffset.CastFrom(offset); //needed because mitk uses float and MatchPoint currently double as scalar value
91 
92  result->SetMatrix(resultMatrix);
93  result->SetOffset(resultOffset);
94  }
95  }
96  return result;
97  }
98 
100  {
101  bool result = false;
102 
103  if (wrapper)
104  {
105  result = wrapper->GetMovingDimensions()==3 && wrapper->GetTargetDimensions()==3;
106  }
107  return result;
108  }
109 
111  {
112  bool result = false;
113 
114  if (reBase)
115  {
116  result = reBase->getMovingDimensions()==3 && reBase->getTargetDimensions()==3;
117  }
118  return result;
119  }
120 
122  {
123  if (!node) return false;
124 
125  mitk::BaseData* data = node->GetData();
126 
127  if (data != nullptr)
128  {
129  return std::string("MAPRegistrationWrapper").compare(data->GetNameOfClass()) == 0;
130  }
131 
132  return false;
133  }
134 }
static Affine3DTransformType::Pointer getAffineMatrix(const mitk::MAPRegistrationWrapper *wrapper, bool inverseKernel)
virtual unsigned int GetTargetDimensions() const
Gets the number of target dimensions.
Base of all data objects.
Definition: mitkBaseData.h:37
double ScalarType
DataCollection - Class to facilitate loading/accessing structured data.
::map::core::RegistrationBase RegistrationBaseType
MAPRegistrationWrapper Wrapper class to allow the handling of MatchPoint registration objects as mitk...
static Vector3D offset
::map::core::RegistrationBase * GetRegistration()
BaseData * GetData() const
Get the data object (instance of BaseData, e.g., an Image) managed by this DataNode.
static bool is3D(const mitk::MAPRegistrationWrapper *wrapper)
::map::core::Registration< 3, 3 > Registration3DType
static bool IsRegNode(const mitk::DataNode *node)
Class for nodes of the DataTree.
Definition: mitkDataNode.h:64
virtual unsigned int GetMovingDimensions() const
Gets the number of moving dimensions.