Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
mitkPointSetMappingHelper.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 #include "mapRegistration.h"
18 
20 #include "mitkRegistrationHelper.h"
21 
22 
23 #include "mapPointSetMappingTask.h"
24 
26 {
27  if (! mitkSet) mapDefaultExceptionStaticMacro(<< "Error, cannot convert point set. Passed mitk point set is null.");
28 
32  mapSet->SetPoints(mapContainer);
33  mapSet->SetPointData(mapDataContainer);
34 
35  unsigned int pointCount = mitkSet->GetNumberOfPoints();
36 
37  for (unsigned int pointId = 0; pointId < pointCount; ++pointId)
38  {
39  mapSet->SetPoint(pointId, mitkSet->GetPoint(pointId));
40 
42  if (mitkSet->GetPointData(pointId,&data))
43  {
44  mapSet->SetPointData(pointId,data.id);
45  }
46  }
47 
48  return mapSet;
49 }
50 
52  mitk::PointSetMappingHelper::map(const ::mitk::PointSet* input, const mitk::PointSetMappingHelper::RegistrationType* registration, int timeStep,
53  bool throwOnMappingError, const ::mitk::PointSet::PointDataType& errorPointValue)
54 {
55  if (!registration)
56  {
57  mitkThrow() << "Cannot map point set. Passed registration wrapper pointer is NULL.";
58  }
59  if (!input)
60  {
61  mitkThrow() << "Cannot map point set. Passed point set pointer is NULL.";
62  }
63  if (input->GetTimeSteps()<=timeStep && timeStep>=0)
64  {
65  mitkThrow() << "Cannot set point set. Selected time step is larger then mitk point set. MITK time step count: "<<input->GetTimeSteps()<<"; selected time step: "<<timeStep;
66  }
67 
68  ::mitk::PointSet::Pointer result = input->Clone();
69 
70  typedef ::map::core::continuous::Elements<3>::InternalPointSetType MAPPointSetType;
71  typedef ::map::core::Registration<3,3> ConcreteRegistrationType;
72  const ConcreteRegistrationType* castedReg = dynamic_cast<const ConcreteRegistrationType*>(registration);
73  if (!castedReg)
74  {
75  mitkThrow() <<"Moving and/or fixed dimension of the registration is not 3. Cannot map point 3D set.";
76  }
77 
78  typedef ::map::core::PointSetMappingTask<ConcreteRegistrationType, MAPPointSetType, MAPPointSetType> MappingTaskType;
79  MappingTaskType::ErrorPointValueType internalErrorValue = itk::NumericTraits<MappingTaskType::ErrorPointValueType>::NonpositiveMin();
81  spTask->setRegistration(castedReg);
82  spTask->setThrowOnMappingError(throwOnMappingError);
83  spTask->setErrorPointValue(internalErrorValue);
84 
85  unsigned int timePos = timeStep;
86  unsigned int timeEndPos = timeStep+1;
87  if (timeStep < 0)
88  {
89  timePos = 0;
90  timeEndPos = input->GetTimeSteps();
91  }
92 
93  while (timePos<timeEndPos)
94  {
95  MAPPointSetType::Pointer inputTempSet = ConvertPointSetMITKtoMAP(input->GetPointSet(timePos));
96  spTask->setInputPointSet(inputTempSet);
97  spTask->execute();
98 
99  MAPPointSetType::Pointer mappedSet = spTask->getResultPointSet();
100 
101  unsigned int pointCount = input->GetSize(timePos);
102 
103  for (unsigned int pointId = 0; pointId < pointCount; ++pointId)
104  {
105  result->SetPoint(pointId, mappedSet->GetPoint(pointId), timePos);
106  bool invalid = true;
107  MAPPointSetType::PixelType mappedData;
108  if (mappedSet->GetPointData(pointId,&mappedData))
109  {
110  invalid = mappedData == internalErrorValue;
111  }
112 
113  if (invalid)
114  {
115  result->GetPointSet(timePos)->GetPointData()->SetElement(pointId,errorPointValue);
116  }
117  else
118  {
119  result->GetPointSet(timePos)->GetPointData()->SetElement(pointId,input->GetPointSet(timePos)->GetPointData()->GetElement(pointId));
120  }
121  }
122 
123  ++timePos;
124  }
125 
126  return result;
127 }
128 
130  mitk::PointSetMappingHelper::map(const ::mitk::PointSet* input, const MITKRegistrationType* registration, int timeStep,
131  bool throwOnMappingError, const ::mitk::PointSet::PointDataType& errorPointValue)
132 {
133  if (!registration)
134  {
135  mitkThrow() << "Cannot map point set. Passed registration wrapper pointer is NULL.";
136  }
137  if (!registration->GetRegistration())
138  {
139  mitkThrow() << "Cannot map point set. Passed registration wrapper containes no registration.";
140  }
141  if (!input)
142  {
143  mitkThrow() << "Cannot map point set. Passed point set pointer is NULL.";
144  }
145 
146  ::mitk::PointSet::Pointer result = map(input, registration->GetRegistration(), timeStep, throwOnMappingError, errorPointValue);
147  return result;
148 }
MeshType DataType
Definition: mitkPointSet.h:133
itk::SmartPointer< Self > Pointer
struct for data of a point
Definition: mitkPointSet.h:95
MAPRegistrationWrapper Wrapper class to allow the handling of MatchPoint registration objects as mitk...
MITKMATCHPOINTREGISTRATION_EXPORT::mitk::PointSet::Pointer map(const ::mitk::PointSet *input, const RegistrationType *registration, int timeStep=-1, bool throwOnMappingError=true, const ::mitk::PointSet::PointDataType &errorPointValue=::mitk::PointSet::PointDataType())
map::core::RegistrationBase * GetRegistration()
MITKMATCHPOINTREGISTRATION_EXPORT::map::core::continuous::Elements< 3 >::InternalPointSetType::Pointer ConvertPointSetMITKtoMAP(const mitk::PointSet::DataType *mitkSet)
#define mitkThrow()
::map::core::RegistrationBase RegistrationType
MITKMATCHPOINTREGISTRATION_EXPORT ResultImageType::Pointer map(const InputImageType *input, const RegistrationType *registration, bool throwOnOutOfInputAreaError=false, const double &paddingValue=0, const ResultImageGeometryType *resultGeometry=NULL, bool throwOnMappingError=true, const double &errorValue=0, mitk::ImageMappingInterpolator::Type interpolatorType=mitk::ImageMappingInterpolator::Linear)
unsigned short PixelType
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.