19 #include <vtkTransform.h>
20 #include <vtkTransformPolyDataFilter.h>
21 #include <vtkAppendPolyData.h>
22 #include <vtkPoints.h>
23 #include <vtkLandmarkTransform.h>
28 #define FRW_LOG MITK_INFO("Fiducial Registration Widget")
29 #define FRW_WARN MITK_WARN("Fiducial Registration Widget")
30 #define FRW_DEBUG MITK_DEBUG("Fiducial Registration Widget")
34 : QWidget(parent), m_Controls(NULL),m_MultiWidget(NULL), m_ImageFiducialsNode(NULL), m_TrackerFiducialsNode(NULL)
58 m_Controls =
new Ui::QmitkFiducialRegistrationWidget;
62 m_Controls->m_AddImageFiducialBtn->setHidden(
true);
64 m_Controls->m_spaceHolderGroupBox->setStyleSheet(
"QGroupBox {border: 0px transparent;}");
65 m_Controls->m_spaceHolderGroupBox2->setStyleSheet(
"QGroupBox {border: 0px transparent;}");
78 connect((QObject*)(
m_Controls->m_RegisterFiducialsBtn), SIGNAL(clicked()),
this, SLOT(
Register()));
88 if (activated)
m_Controls->m_RegistrationImagePoints->UnselectEditButton();
92 if (activated)
m_Controls->m_RegistrationTrackingPoints->UnselectEditButton();
104 this->
m_Controls->sourceLandmarksGroupBox->setTitle(
"Target/Reference landmarks");
105 this->
m_Controls->targetLandmarksGroupBox->setTitle(
"Source Landmarks");
106 this->
m_Controls->m_AddImageFiducialBtn->setText(
"Add target landmark");
107 this->
m_Controls->m_AddTrackingFiducialBtn->setText(
"Add source landmark");
116 this->
m_Controls->sourceLandmarksGroupBox->setTitle(
"Image fiducials");
117 this->
m_Controls->targetLandmarksGroupBox->setTitle(
"OR fiducials");
118 this->
m_Controls->m_AddImageFiducialBtn->setText(
"Add image fiducial");
119 this->
m_Controls->m_AddTrackingFiducialBtn->setText(
"Add current instrument position");
127 m_Controls->m_RegistrationQualityDisplay->setText(text);
132 if(
m_Controls->m_UseICPRegistration->isChecked())
140 if(imageFiducialsNode.IsNull())
142 FRW_WARN<<
"tracker fiducial node is NULL";
145 m_Controls->m_RegistrationImagePoints->SetPointSetNode(imageFiducialsNode);
156 if(trackerFiducialsNode.IsNull())
158 FRW_WARN<<
"tracker fiducial node is NULL";
161 m_Controls->m_RegistrationTrackingPoints->SetPointSetNode(trackerFiducialsNode);
177 m_Controls->m_RegistrationTrackingPoints->AddSliceNavigationController(snc);
178 m_Controls->m_RegistrationImagePoints->AddSliceNavigationController(snc);
193 m_Controls->m_rbStaticRegistration->setHidden(on);
199 m_Controls->m_rbContinousRegistration->setHidden(on);
205 if (
m_Controls->m_rbStaticRegistration->isHidden() &&
m_Controls->m_rbContinousRegistration->isHidden())
207 m_Controls->m_gbFiducialRegistration->setHidden(
true);
211 m_Controls->m_gbFiducialRegistration->setHidden(
false);
217 m_Controls->m_UseICPRegistration->setHidden(on);
222 m_Controls->m_AddImageFiducialBtn->setHidden(on);
229 m_Controls->m_AddTrackingFiducialBtn->setHidden(on);
235 if (
m_Controls->m_AddImageFiducialBtn->isHidden() &&
m_Controls->m_AddTrackingFiducialBtn->isHidden())
237 m_Controls->m_spaceHolderGroupBox->setHidden(
true);
238 m_Controls->m_spaceHolderGroupBox2->setHidden(
true);
242 m_Controls->m_spaceHolderGroupBox->setHidden(
false);
243 m_Controls->m_spaceHolderGroupBox2->setHidden(
false);
249 QString groupBoxTitle = sourceLandmarkName;
250 groupBoxTitle.append(
" Landmarks");
251 m_Controls->sourceLandmarksGroupBox->setTitle(groupBoxTitle);
252 QString buttonText =
"Add ";
253 buttonText.append(sourceLandmarkName);
254 buttonText.append(
" Landmark");
255 m_Controls->m_AddImageFiducialBtn->setText(buttonText);
260 QString groupBoxTitle = targetLandmarkName;
261 groupBoxTitle.append(
" Landmarks");
262 m_Controls->targetLandmarksGroupBox->setTitle(groupBoxTitle);
263 QString buttonText =
"Add ";
264 buttonText.append(targetLandmarkName);
265 buttonText.append(
" Landmark");
266 m_Controls->m_AddTrackingFiducialBtn->setText(buttonText);
285 ImageFiducialsNode->SetData(imagePointSet);
286 ImageFiducialsNode->SetName(
"Image Point Set");
293 TrackerFiducialsNode->SetData(trackerPointSet);
294 TrackerFiducialsNode->SetName(
"Tracker Point Set");
313 ) {
MITK_WARN <<
"Registration not correctly initialized";
return false;}
325 if (trackerFiducials->GetSize() != imageFiducials->GetSize())
327 MITK_WARN <<
"Not the same number of fiducials, cannot register";
330 else if (trackerFiducials->GetSize() < 3)
332 MITK_WARN <<
"Need at least 3 fiducials, cannot register";
340 for (
int i = 0; i<imageFiducials->GetSize(); i++)
342 double point[3] = { imageFiducials->GetPoint(i)[0], imageFiducials->GetPoint(i)[1], imageFiducials->GetPoint(i)[2] };
343 sourcePoints->InsertNextPoint(point);
344 double point_targets[3] = { trackerFiducials->GetPoint(i)[0], trackerFiducials->GetPoint(i)[1], trackerFiducials->GetPoint(i)[2] };
345 targetPoints->InsertNextPoint(point_targets);
351 transform->SetSourceLandmarks(sourcePoints);
352 transform->SetTargetLandmarks(targetPoints);
353 transform->SetModeToRigidBody();
354 transform->Modified();
365 itk::Matrix<float, 3, 3> rotationFloat = itk::Matrix<float, 3, 3>();
366 itk::Vector<float, 3> translationFloat = itk::Vector<float, 3>();
367 itk::Matrix<double, 3, 3> rotationDouble = itk::Matrix<double, 3, 3>();
368 itk::Vector<double, 3> translationDouble = itk::Vector<double, 3>();
370 vtkSmartPointer<vtkMatrix4x4> m = transform->GetMatrix();
371 for (
int k = 0; k<3; k++)
for (
int l = 0; l<3; l++)
373 rotationFloat[k][l] = m->GetElement(k, l);
374 rotationDouble[k][l] = m->GetElement(k, l);
377 for (
int k = 0; k<3; k++)
379 translationFloat[k] = m->GetElement(k, 3);
380 translationDouble[k] = m->GetElement(k, 3);
384 mitkTransform->SetMatrix(rotationDouble);
385 mitkTransform->SetOffset(translationDouble);
398 imageTransform->Compose(mitkTransform);
400 itk::Matrix<mitk::ScalarType, 3, 3> rotationFloatNew = imageTransform->GetMatrix();
401 itk::Vector<mitk::ScalarType, 3> translationFloatNew = imageTransform->GetOffset();
402 newImageTransform->SetMatrix(rotationFloatNew);
403 newImageTransform->SetOffset(translationFloatNew);
404 m_ImageNode->GetData()->GetGeometry()->SetIndexToWorldTransform(newImageTransform);
408 if (this->
m_Controls->m_MoveImagePoints->isChecked())
413 for (
int i = 0; i < pointSet_orig->
GetSize(); i++)
415 pointSet_moved->InsertPoint(mitkTransform->TransformPoint(pointSet_orig->
GetPoint(i)));
418 pointSet_orig->
Clear();
419 for (
int i = 0; i < pointSet_moved->GetSize(); i++)
420 pointSet_orig->
InsertPoint(pointSet_moved->GetPoint(i));
itk::SmartPointer< Self > Pointer
virtual int GetSize(unsigned int t=0) const
returns the current size of the point-list
PointType GetPoint(PointIdentifier id, int t=0) const
Get the point with ID id in world coordinates.
Controls the selection of the slice the associated BaseRenderer will display.
Data structure which stores a set of points. Superclass of mitk::Mesh.
static RenderingManager * GetInstance()
void InsertPoint(PointIdentifier id, PointType point, int t=0)
Set the given point in world coordinate system into the itkPointSet.
virtual void Clear()
Calls ClearData() and InitializeEmpty();.
virtual void InitializeViewsByBoundingObjects(const DataStorage *)
Initializes the renderwindows by the aggregated geometry of all objects that are held in the data sto...
static double ComputeFRE(mitk::PointSet::Pointer imageFiducials, mitk::PointSet::Pointer realWorldFiducials, vtkSmartPointer< vtkLandmarkTransform > transform=NULL)
Computes the fiducial registration error out of two sets of fiducials. The two sets must have the sam...
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.