Medical Imaging Interaction Toolkit  2016.11.0
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,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
16 
17 
18 #include "mitkRegistrationHelper.h"
19 
20 //MatchPoint
21 #include "mapRegistrationKernel.h"
22 
23 namespace mitk
24 {
25 
28  getAffineMatrix(const mitk::MAPRegistrationWrapper* wrapper, bool inverseKernel)
29  {
30  Affine3DTransformType::Pointer result = NULL;
31 
32  if (wrapper)
33  {
34  result = getAffineMatrix(wrapper->GetRegistration(), inverseKernel);
35  }
36  return result;
37  }
38 
41  getAffineMatrix(const RegistrationBaseType* registration, bool inverseKernel)
42  {
43  Affine3DTransformType::Pointer result = NULL;
44 
45  if (registration && is3D(registration))
46  {
47  const Registration3DType* pReg = dynamic_cast<const Registration3DType*>(registration);
48  if (pReg)
49  {
50  if (inverseKernel)
51  {
52  result = getAffineMatrix(pReg->getInverseMapping());
53  }
54  else
55  {
56  result = getAffineMatrix(pReg->getDirectMapping());
57  }
58  }
59  }
60  return result;
61  }
62 
63 
65  {
66  Affine3DTransformType::Pointer result = NULL;
67 
68  typedef ::map::core::RegistrationKernel<3,3> KernelType;
69 
70  const KernelType* pModelKernel = dynamic_cast<const KernelType*>(&kernel);
71 
72  if (pModelKernel)
73  {
74 
75  KernelType::TransformType::MatrixType matrix;
76  KernelType::TransformType::OutputVectorType offset;
77 
78  if(pModelKernel->getAffineMatrixDecomposition(matrix,offset))
79  {
80  result = Affine3DTransformType::New();
81  Affine3DTransformType::MatrixType resultMatrix;
82  Affine3DTransformType::OffsetType resultOffset;
83 
87  //The conversion of matrix and offset is needed
88  //because mitk uses float and MatchPoint currently
89  //double as scalar value.
90  for (unsigned int i=0; i<matrix.GetVnlMatrix().size(); ++i)
91  {
92  resultMatrix.GetVnlMatrix().begin()[i] = static_cast<mitk::ScalarType>(matrix.GetVnlMatrix().begin()[i]);
93  }
94  resultOffset.CastFrom(offset); //needed because mitk uses float and MatchPoint currently double as scalar value
95 
96  result->SetMatrix(resultMatrix);
97  result->SetOffset(resultOffset);
98  }
99  }
100  return result;
101  }
102 
104  {
105  bool result = false;
106 
107  if (wrapper)
108  {
109  result = wrapper->GetMovingDimensions()==3 && wrapper->GetTargetDimensions()==3;
110  }
111  return result;
112  }
113 
115  {
116  bool result = false;
117 
118  if (reBase)
119  {
120  result = reBase->getMovingDimensions()==3 && reBase->getTargetDimensions()==3;
121  }
122  return result;
123  }
124 
126  {
127  if (!node) return false;
128 
129  mitk::BaseData* data = node->GetData();
130 
131  if (data != NULL)
132  {
133  return std::string("MAPRegistrationWrapper").compare(data->GetNameOfClass()) == 0;
134  }
135 
136  return false;
137  }
138 }
static Affine3DTransformType::Pointer getAffineMatrix(const mitk::MAPRegistrationWrapper *wrapper, bool inverseKernel)
itk::SmartPointer< Self > Pointer
Base of all data objects.
Definition: mitkBaseData.h:39
double ScalarType
DataCollection - Class to facilitate loading/accessing structured data.
::map::core::RegistrationBase RegistrationBaseType
BaseData * GetData() const
Get the data object (instance of BaseData, e.g., an Image) managed by this DataNode.
MAPRegistrationWrapper Wrapper class to allow the handling of MatchPoint registration objects as mitk...
virtual unsigned int GetMovingDimensions() const
Gets the number of moving dimensions.
static Vector3D offset
map::core::RegistrationBase * GetRegistration()
static bool is3D(const mitk::MAPRegistrationWrapper *wrapper)
::map::core::Registration< 3, 3 > Registration3DType
static bool IsRegNode(const mitk::DataNode *node)
virtual unsigned int GetTargetDimensions() const
Gets the number of target dimensions.
Class for nodes of the DataTree.
Definition: mitkDataNode.h:66
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.