17 #include <mapRegistrationManipulator.h> 18 #include <mapPreCachedRegistrationKernel.h> 19 #include <mapCombinedRegistrationKernel.h> 20 #include <mapNullRegistrationKernel.h> 21 #include <mapRegistrationCombinator.h> 23 #include <itkCompositeTransform.h> 25 #include <boost/math/constants/constants.hpp> 28 : QWidget(parent), m_CenterOfRotationIsRelativeToTarget(false), m_internalUpdate(false)
32 connect(this->slideRotX, SIGNAL(valueChanged(
int)),
this, SLOT(
OnRotXSlideChanged(
int)));
33 connect(this->sbRotX, SIGNAL(valueChanged(
double)),
this, SLOT(
OnRotXChanged(
double)));
34 connect(this->slideRotY, SIGNAL(valueChanged(
int)),
this, SLOT(
OnRotYSlideChanged(
int)));
35 connect(this->sbRotY, SIGNAL(valueChanged(
double)),
this, SLOT(
OnRotYChanged(
double)));
36 connect(this->slideRotZ, SIGNAL(valueChanged(
int)),
this, SLOT(
OnRotZSlideChanged(
int)));
37 connect(this->sbRotZ, SIGNAL(valueChanged(
double)),
this, SLOT(
OnRotZChanged(
double)));
40 connect(this->sbTransX, SIGNAL(valueChanged(
double)),
this, SLOT(
OnTransXChanged(
double)));
42 connect(this->sbTransY, SIGNAL(valueChanged(
double)),
this, SLOT(
OnTransYChanged(
double)));
44 connect(this->sbTransZ, SIGNAL(valueChanged(
double)),
this, SLOT(
OnTransZChanged(
double)));
46 this->groupScale->setVisible(
false);
54 this->ResetTransforms();
60 this->ResetTransforms();
61 this->m_PreRegistration = precedingRegistration;
63 ::map::core::RegistrationManipulator<MAPRegistrationType> manipulator(m_CurrentRegistration);
64 ::map::core::PreCachedRegistrationKernel<3, 3>::Pointer kernel = ::map::core::PreCachedRegistrationKernel<3, 3>::New();
66 const map::core::RegistrationKernel<3, 3>* preKernel =
dynamic_cast<const map::core::RegistrationKernel<3, 3>*
>(&this->m_PreRegistration->getInverseMapping());
67 itk::CompositeTransform < ::map::core::continuous::ScalarType, 3>::Pointer compTransform = itk::CompositeTransform < ::map::core::continuous::ScalarType, 3>::New();
68 compTransform->AddTransform(preKernel->getTransformModel()->Clone());
69 compTransform->AddTransform(this->m_InverseCurrentTransform);
71 kernel->setTransformModel(compTransform);
72 manipulator.setInverseMapping(kernel);
79 this->ResetTransforms();
81 auto offset = targetReference - movingReference;
82 m_DirectCurrentTransform->SetOffset(
offset);
83 m_DirectCurrentTransform->GetInverse(m_InverseCurrentTransform);
88 void QmitkRegistrationManipulationWidget::ResetTransforms()
90 this->m_CenterOfRotation.Fill(0.0);
91 this->m_PreRegistration =
nullptr;
94 this->m_InverseCurrentTransform = TransformType::New();
95 this->m_InverseCurrentTransform->SetIdentity();
96 this->m_DirectCurrentTransform = TransformType::New();
97 this->m_DirectCurrentTransform->SetIdentity();
99 m_CurrentRegistration = MAPRegistrationType::New();
101 ::map::core::RegistrationManipulator<MAPRegistrationType> manipulator(m_CurrentRegistration);
102 ::map::core::PreCachedRegistrationKernel<3, 3>::Pointer kernel = ::map::core::PreCachedRegistrationKernel<3, 3>::New();
103 kernel->setTransformModel(m_InverseCurrentTransform);
104 manipulator.setInverseMapping(kernel);
106 manipulator.setDirectMapping(::map::core::NullRegistrationKernel < 3, 3 >::New());
111 this->m_CenterOfRotation = center;
112 this->ConfigureTransformCenter();
113 this->UpdateTransformWidgets();
119 this->m_CenterOfRotationIsRelativeToTarget = targetRelative;
120 this->ConfigureTransformCenter();
121 this->UpdateTransformWidgets();
124 void QmitkRegistrationManipulationWidget::InitControls()
126 this->ConfigureTransformCenter();
129 auto currenttrans = m_DirectCurrentTransform->GetTranslation();
130 this->slideTransX->setMinimum(currenttrans[0] - 250);
131 this->slideTransY->setMinimum(currenttrans[1] - 250);
132 this->slideTransZ->setMinimum(currenttrans[2] - 250);
133 this->slideTransX->setMaximum(currenttrans[0] + 250);
134 this->slideTransY->setMaximum(currenttrans[1] + 250);
135 this->slideTransZ->setMaximum(currenttrans[2] + 250);
138 void QmitkRegistrationManipulationWidget::UpdateTransformWidgets()
140 this->m_internalUpdate =
true;
141 this->sbTransX->setValue(this->m_DirectCurrentTransform->GetTranslation()[0]);
142 this->sbTransY->setValue(this->m_DirectCurrentTransform->GetTranslation()[1]);
143 this->sbTransZ->setValue(this->m_DirectCurrentTransform->GetTranslation()[2]);
144 this->slideTransX->setValue(this->m_DirectCurrentTransform->GetTranslation()[0]);
145 this->slideTransY->setValue(this->m_DirectCurrentTransform->GetTranslation()[1]);
146 this->slideTransZ->setValue(this->m_DirectCurrentTransform->GetTranslation()[2]);
148 this->sbRotX->setValue(this->m_DirectCurrentTransform->GetAngleX()*(180 / boost::math::double_constants::pi));
149 this->sbRotY->setValue(this->m_DirectCurrentTransform->GetAngleY()*(180 / boost::math::double_constants::pi));
150 this->sbRotZ->setValue(this->m_DirectCurrentTransform->GetAngleZ()*(180 / boost::math::double_constants::pi));
151 this->slideRotX->setValue(this->m_DirectCurrentTransform->GetAngleX()*(180 / boost::math::double_constants::pi));
152 this->slideRotY->setValue(this->m_DirectCurrentTransform->GetAngleY()*(180 / boost::math::double_constants::pi));
153 this->slideRotZ->setValue(this->m_DirectCurrentTransform->GetAngleZ()*(180 / boost::math::double_constants::pi));
154 this->m_internalUpdate =
false;
157 void QmitkRegistrationManipulationWidget::UpdateTransform(
bool updateRotation)
161 if (this->m_CenterOfRotationIsRelativeToTarget)
163 ConfigureTransformCenter();
166 this->m_DirectCurrentTransform->SetRotation(this->sbRotX->value()*(boost::math::double_constants::pi / 180),
167 this->sbRotY->value()*(boost::math::double_constants::pi / 180),
168 this->sbRotZ->value()*(boost::math::double_constants::pi / 180));
172 TransformType::OutputVectorType trans;
173 trans[0] = this->sbTransX->value();
174 trans[1] = this->sbTransY->value();
175 trans[2] = this->sbTransZ->value();
177 this->m_DirectCurrentTransform->SetTranslation(trans);
180 this->m_DirectCurrentTransform->GetInverse(this->m_InverseCurrentTransform);
182 this->UpdateTransformWidgets();
189 return this->m_CurrentRegistration.GetPointer();
194 MAPRegistrationType::Pointer newReg = MAPRegistrationType::New();
196 ::map::core::RegistrationManipulator<MAPRegistrationType> manipulator(newReg);
198 ::map::core::PreCachedRegistrationKernel<3, 3>::Pointer kernel = ::map::core::PreCachedRegistrationKernel<3, 3>::New();
199 kernel->setTransformModel(m_InverseCurrentTransform);
201 ::map::core::PreCachedRegistrationKernel<3, 3>::Pointer kernel2 = ::map::core::PreCachedRegistrationKernel<3, 3>::New();
202 kernel2->setTransformModel(m_InverseCurrentTransform->GetInverseTransform());
204 manipulator.setInverseMapping(kernel);
205 manipulator.setDirectMapping(kernel2);
207 if (this->m_PreRegistration.IsNotNull())
209 typedef ::map::core::RegistrationCombinator<MAPRegistrationType, MAPRegistrationType> CombinatorType;
210 CombinatorType::Pointer combinator = CombinatorType::New();
211 newReg = combinator->process(*m_PreRegistration, *newReg);
214 return newReg.GetPointer();
219 if (!m_internalUpdate)
221 m_internalUpdate =
true;
222 this->slideRotX->setValue(x);
223 m_internalUpdate =
false;
224 this->UpdateTransform(
true);
230 if (!m_internalUpdate)
232 this->sbRotX->setValue(x);
238 if (!m_internalUpdate)
240 m_internalUpdate =
true;
241 this->slideRotY->setValue(y);
242 m_internalUpdate =
false;
243 this->UpdateTransform(
true);
249 if (!m_internalUpdate)
251 this->sbRotY->setValue(y);
257 if (!m_internalUpdate)
259 m_internalUpdate =
true;
260 this->slideRotZ->setValue(z);
261 m_internalUpdate =
false;
262 this->UpdateTransform(
true);
268 if (!m_internalUpdate)
270 this->sbRotZ->setValue(z);
276 if (!m_internalUpdate)
278 m_internalUpdate =
true;
279 this->slideTransX->setValue(x);
280 m_internalUpdate =
false;
281 this->UpdateTransform();
287 if (!m_internalUpdate)
289 this->sbTransX->setValue(x);
295 if (!m_internalUpdate)
297 m_internalUpdate =
true;
298 this->slideTransY->setValue(y);
299 m_internalUpdate =
false;
300 this->UpdateTransform();
306 if (!m_internalUpdate)
308 this->sbTransY->setValue(y);
314 if (!m_internalUpdate)
316 m_internalUpdate =
true;
317 this->slideTransZ->setValue(z);
318 m_internalUpdate =
false;
319 this->UpdateTransform();
325 if (!m_internalUpdate)
327 this->sbTransZ->setValue(z);
331 void QmitkRegistrationManipulationWidget::ConfigureTransformCenter()
333 auto offset = m_DirectCurrentTransform->GetOffset();
336 if (this->m_CenterOfRotationIsRelativeToTarget)
338 auto newCenter = m_InverseCurrentTransform->TransformPoint(m_CenterOfRotation);
339 m_DirectCurrentTransform->SetCenter(newCenter);
343 m_DirectCurrentTransform->SetCenter(m_CenterOfRotation);
346 m_DirectCurrentTransform->SetOffset(
offset);
347 m_DirectCurrentTransform->GetInverse(m_InverseCurrentTransform);