Medical Imaging Interaction Toolkit  2018.4.99-bd7b41ba
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"
17 #include <mitkNodePredicateAnd.h>
18 #include <mitkNodePredicateOr.h>
19 #include <mitkPointSet.h>
20 
21 //MatchPoint
22 #include "mapRegistrationKernel.h"
23 
24 namespace mitk
25 {
29 
30 
31  MITKRegistrationHelper::Affine3DTransformType::Pointer
33  getAffineMatrix(const mitk::MAPRegistrationWrapper* wrapper, bool inverseKernel)
34  {
35  Affine3DTransformType::Pointer result = nullptr;
36 
37  if (wrapper)
38  {
39  result = getAffineMatrix(wrapper->GetRegistration(), inverseKernel);
40  }
41  return result;
42  }
43 
44  MITKRegistrationHelper::Affine3DTransformType::Pointer
46  getAffineMatrix(const RegistrationBaseType* registration, bool inverseKernel)
47  {
48  Affine3DTransformType::Pointer result = nullptr;
49 
50  if (registration && is3D(registration))
51  {
52  const Registration3DType* pReg = dynamic_cast<const Registration3DType*>(registration);
53  if (pReg)
54  {
55  if (inverseKernel)
56  {
57  result = getAffineMatrix(pReg->getInverseMapping());
58  }
59  else
60  {
61  result = getAffineMatrix(pReg->getDirectMapping());
62  }
63  }
64  }
65  return result;
66  }
67 
68 
69  MITKRegistrationHelper::Affine3DTransformType::Pointer MITKRegistrationHelper::getAffineMatrix(const RegistrationKernel3DBase& kernel)
70  {
71  Affine3DTransformType::Pointer result = nullptr;
72 
73  typedef ::map::core::RegistrationKernel<3,3> KernelType;
74 
75  const KernelType* pModelKernel = dynamic_cast<const KernelType*>(&kernel);
76 
77  if (pModelKernel)
78  {
79 
80  KernelType::TransformType::MatrixType matrix;
81  KernelType::TransformType::OutputVectorType offset;
82 
83  if(pModelKernel->getAffineMatrixDecomposition(matrix,offset))
84  {
85  result = Affine3DTransformType::New();
86  Affine3DTransformType::MatrixType resultMatrix;
87  Affine3DTransformType::OffsetType resultOffset;
88 
92  //The conversion of matrix and offset is needed
93  //because mitk uses float and MatchPoint currently
94  //double as scalar value.
95  for (unsigned int i=0; i<matrix.GetVnlMatrix().size(); ++i)
96  {
97  resultMatrix.GetVnlMatrix().begin()[i] = static_cast<mitk::ScalarType>(matrix.GetVnlMatrix().begin()[i]);
98  }
99  resultOffset.CastFrom(offset); //needed because mitk uses float and MatchPoint currently double as scalar value
100 
101  result->SetMatrix(resultMatrix);
102  result->SetOffset(resultOffset);
103  }
104  }
105  return result;
106  }
107 
109  {
110  bool result = false;
111 
112  if (wrapper)
113  {
114  result = wrapper->GetMovingDimensions()==3 && wrapper->GetTargetDimensions()==3;
115  }
116  return result;
117  }
118 
120  {
121  bool result = false;
122 
123  if (reBase)
124  {
125  result = reBase->getMovingDimensions()==3 && reBase->getTargetDimensions()==3;
126  }
127  return result;
128  }
129 
131  {
132  if (!node) return false;
133 
134  return InternalRegNodePredicate->CheckNode(node);
135  }
136 
138  {
139  return InternalRegNodePredicate.GetPointer();
140  }
141 
143  {
144  return InternalImageNodePredicate.GetPointer();
145  }
146 
148  {
149  return InternalPointSetNodePredicate.GetPointer();
150  }
151 
153  {
154  auto isLabelSetImage = mitk::NodePredicateDataType::New("LabelSetImage");
155  auto hasBinaryProperty = mitk::NodePredicateProperty::New("binary", mitk::BoolProperty::New(true));
156  auto isLegacyMask = mitk::NodePredicateAnd::New(ImageNodePredicate(), hasBinaryProperty);
157 
158  return isLegacyMask.GetPointer();
159  //Deactivated due to T27435. Should be reactivated as soon T27435 is fixed
160  //auto isLabelSetOrLegacyMask = mitk::NodePredicateOr::New(isLabelSetImage, isLegacyMask);
161  //
162  //return isLabelSetOrLegacyMask.GetPointer();
163  }
164 
165 }
mitk::TNodePredicateDataType< mitk::PointSet >::ConstPointer InternalPointSetNodePredicate
static Affine3DTransformType::Pointer getAffineMatrix(const mitk::MAPRegistrationWrapper *wrapper, bool inverseKernel)
static NodePredicateBase::ConstPointer RegNodePredicate()
mitk::TNodePredicateDataType< mitk::MAPRegistrationWrapper >::ConstPointer InternalRegNodePredicate
static Pointer New()
virtual unsigned int GetTargetDimensions() const
Gets the number of target dimensions.
double ScalarType
static NodePredicateBase::ConstPointer ImageNodePredicate()
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 Pointer New()
static Vector3D offset
::map::core::RegistrationBase * GetRegistration()
mitk::TNodePredicateDataType< mitk::Image >::ConstPointer InternalImageNodePredicate
static bool is3D(const mitk::MAPRegistrationWrapper *wrapper)
static Pointer New(const char *_arg)
static NodePredicateBase::ConstPointer PointSetNodePredicate()
static Pointer New(const char *_arg)
::map::core::Registration< 3, 3 > Registration3DType
static bool IsRegNode(const mitk::DataNode *node)
static NodePredicateBase::ConstPointer MaskNodePredicate()
Class for nodes of the DataTree.
Definition: mitkDataNode.h:57
virtual unsigned int GetMovingDimensions() const
Gets the number of moving dimensions.