Medical Imaging Interaction Toolkit  2018.4.99-b7f3afaa
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"
16 #include <mitkPointSet.h>
17 
18 //MatchPoint
19 #include "mapRegistrationKernel.h"
20 
21 namespace mitk
22 {
26 
27 
28  MITKRegistrationHelper::Affine3DTransformType::Pointer
30  getAffineMatrix(const mitk::MAPRegistrationWrapper* wrapper, bool inverseKernel)
31  {
32  Affine3DTransformType::Pointer result = nullptr;
33 
34  if (wrapper)
35  {
36  result = getAffineMatrix(wrapper->GetRegistration(), inverseKernel);
37  }
38  return result;
39  }
40 
41  MITKRegistrationHelper::Affine3DTransformType::Pointer
43  getAffineMatrix(const RegistrationBaseType* registration, bool inverseKernel)
44  {
45  Affine3DTransformType::Pointer result = nullptr;
46 
47  if (registration && is3D(registration))
48  {
49  const Registration3DType* pReg = dynamic_cast<const Registration3DType*>(registration);
50  if (pReg)
51  {
52  if (inverseKernel)
53  {
54  result = getAffineMatrix(pReg->getInverseMapping());
55  }
56  else
57  {
58  result = getAffineMatrix(pReg->getDirectMapping());
59  }
60  }
61  }
62  return result;
63  }
64 
65 
66  MITKRegistrationHelper::Affine3DTransformType::Pointer MITKRegistrationHelper::getAffineMatrix(const RegistrationKernel3DBase& kernel)
67  {
68  Affine3DTransformType::Pointer result = nullptr;
69 
70  typedef ::map::core::RegistrationKernel<3,3> KernelType;
71 
72  const KernelType* pModelKernel = dynamic_cast<const KernelType*>(&kernel);
73 
74  if (pModelKernel)
75  {
76 
77  KernelType::TransformType::MatrixType matrix;
78  KernelType::TransformType::OutputVectorType offset;
79 
80  if(pModelKernel->getAffineMatrixDecomposition(matrix,offset))
81  {
82  result = Affine3DTransformType::New();
83  Affine3DTransformType::MatrixType resultMatrix;
84  Affine3DTransformType::OffsetType resultOffset;
85 
89  //The conversion of matrix and offset is needed
90  //because mitk uses float and MatchPoint currently
91  //double as scalar value.
92  for (unsigned int i=0; i<matrix.GetVnlMatrix().size(); ++i)
93  {
94  resultMatrix.GetVnlMatrix().begin()[i] = static_cast<mitk::ScalarType>(matrix.GetVnlMatrix().begin()[i]);
95  }
96  resultOffset.CastFrom(offset); //needed because mitk uses float and MatchPoint currently double as scalar value
97 
98  result->SetMatrix(resultMatrix);
99  result->SetOffset(resultOffset);
100  }
101  }
102  return result;
103  }
104 
106  {
107  bool result = false;
108 
109  if (wrapper)
110  {
111  result = wrapper->GetMovingDimensions()==3 && wrapper->GetTargetDimensions()==3;
112  }
113  return result;
114  }
115 
117  {
118  bool result = false;
119 
120  if (reBase)
121  {
122  result = reBase->getMovingDimensions()==3 && reBase->getTargetDimensions()==3;
123  }
124  return result;
125  }
126 
128  {
129  if (!node) return false;
130 
131  return InternalRegNodePredicate->CheckNode(node);
132  }
133 
135  {
136  return InternalRegNodePredicate.GetPointer();
137  }
138 
140  {
141  return InternalImageNodePredicate.GetPointer();
142  }
143 
145  {
146  return InternalPointSetNodePredicate.GetPointer();
147  }
148 
149 }
static Affine3DTransformType::Pointer getAffineMatrix(const mitk::MAPRegistrationWrapper *wrapper, bool inverseKernel)
static NodePredicateBase::ConstPointer RegNodePredicate()
virtual unsigned int GetTargetDimensions() const
Gets the number of target dimensions.
double ScalarType
static Affine3DTransformType::Pointer getAffineMatrix(const RegistrationBaseType *registration, bool inverseKernel)
static NodePredicateBase::ConstPointer ImageNodePredicate()
DataCollection - Class to facilitate loading/accessing structured data.
::map::core::RegistrationBase RegistrationBaseType
mitk::NodePredicateDataType::ConstPointer InternalPointSetNodePredicate
MAPRegistrationWrapper Wrapper class to allow the handling of MatchPoint registration objects as mitk...
static const char * GetStaticNameOfClass()
Definition: mitkBaseData.h:41
static Vector3D offset
static const char * GetStaticNameOfClass()
Definition: mitkImage.h:84
::map::core::RegistrationBase * GetRegistration()
static bool is3D(const mitk::MAPRegistrationWrapper *wrapper)
mitk::NodePredicateDataType::ConstPointer InternalRegNodePredicate
static NodePredicateBase::ConstPointer PointSetNodePredicate()
static Pointer New(const char *_arg)
static const char * GetStaticNameOfClass()
Definition: mitkPointSet.h:78
::map::core::Registration< 3, 3 > Registration3DType
static bool IsRegNode(const mitk::DataNode *node)
mitk::NodePredicateDataType::ConstPointer InternalImageNodePredicate
Class for nodes of the DataTree.
Definition: mitkDataNode.h:57
virtual unsigned int GetMovingDimensions() const
Gets the number of moving dimensions.