14 #include <QPushButton>
15 #include <QTextStream>
16 #include <QFileDialog>
17 #include <QMessageBox>
33 BaseWidget(parent,
"tool_tip_calibrate_widget",
"ToolTip Calibrate"),
35 mCalibrateButton(new QPushButton(
"Calibrate")),
36 mReferencePointLabel(new QLabel(
"Ref. point:")),
37 mTestButton(new QPushButton(
"Test calibration")),
38 mCalibrationLabel(new QLabel(
"Calibration: \n")),
39 mDeltaLabel(new QLabel(
"Delta:"))
41 QVBoxLayout* toplayout =
new QVBoxLayout(
this);
44 mTools->setValueName(
"Reference tool");
45 mTools->setHelp(
"Select a tool with a known reference point");
47 this->setToolTip(
"Calibrate tool position part of sMt matrix");
50 toplayout->addWidget(mCalibrateToolComboBox);
51 toplayout->addWidget(mReferencePointLabel);
52 toplayout->addWidget(mCalibrateButton);
53 toplayout->addWidget(mCalibrationLabel);
55 toplayout->addWidget(mTestButton);
56 toplayout->addWidget(mDeltaLabel);
57 toplayout->addStretch();
59 connect(mCalibrateButton, SIGNAL(clicked()),
this, SLOT(calibrateSlot()));
60 connect(mTestButton, SIGNAL(clicked()),
this, SLOT(testCalibrationSlot()));
62 connect(mTools.get(), SIGNAL(changed()),
this, SLOT(toolSelectedSlot()));
66 this->toolSelectedSlot();
72 void ToolTipCalibrateWidget::onTrackingSystemStateChanged()
74 if (mServices->tracking()->getTool(mTools->getValue()))
76 if (!mServices->tracking()->getReferenceTool())
79 mTools->setValue(mServices->tracking()->getReferenceTool()->getUid());
82 void ToolTipCalibrateWidget::calibrateSlot()
84 ToolPtr refTool = mTools->getTool();
87 if(!refTool || !refTool->hasReferencePointWithId(
"1"))
90 ToolPtr tool = mServices->tracking()->getActiveTool();
91 CoordinateSystem to = mServices->spaceProvider()->getT(tool);
92 Vector3D P_t = mServices->spaceProvider()->getActiveToolTipPoint(to);
94 ToolTipCalibrationCalculator calc(mServices->spaceProvider(), tool, refTool, P_t);
95 Transform3D calibration = calc.get_calibration_sMt();
98 msgBox.setText(
"Do you want to overwrite "+tool->getName()+
"s calibration file?");
99 msgBox.setInformativeText(
"This cannot be undone.");
100 msgBox.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);
101 msgBox.setDefaultButton(QMessageBox::Ok);
102 int ret = msgBox.exec();
104 if(ret == QMessageBox::Ok)
108 tool->setCalibration_sMt(calibration);
110 catch(std::exception& e)
113 msgBox2.setText(
"Unknown error, could not calibrate the tool: "+tool->getName()+
".");
114 msgBox2.setInformativeText(QString(e.what()));
115 msgBox2.setStandardButtons(QMessageBox::Ok);
116 msgBox2.setDefaultButton(QMessageBox::Ok);
117 int ret2 = msgBox2.exec();
120 mCalibrationLabel->setText(
"Calibration:\n"+
qstring_cast(calibration));
124 void ToolTipCalibrateWidget::testCalibrationSlot()
126 ToolPtr selectedTool = mTools->getTool();
127 if(!selectedTool || !selectedTool->hasReferencePointWithId(
"1"))
130 CoordinateSystem to = mServices->spaceProvider()->getT(mServices->tracking()->getActiveTool());
131 Vector3D sampledPoint = mServices->spaceProvider()->getActiveToolTipPoint(to);
133 ToolTipCalibrationCalculator calc(mServices->spaceProvider(), mServices->tracking()->getActiveTool(), selectedTool, sampledPoint);
134 Vector3D delta_selectedTool = calc.get_delta_ref();
136 mDeltaLabel->setText(
"<b>Delta:</b> "+
qstring_cast(delta_selectedTool)+
" <br> <b>Length:</b> "+
qstring_cast(delta_selectedTool.length()));
141 void ToolTipCalibrateWidget::toolSelectedSlot()
143 QString text(
"Ref. point: <UNDEFINED POINT>");
144 mCalibrateButton->setEnabled(
false);
146 if(mTools->getTool())
148 ToolPtr tool = mTools->getTool();
149 if(tool && tool->hasReferencePointWithId(
"1"))
151 text =
"Ref. point: "+
qstring_cast(tool->getReferencePoints()[
"1"]);
152 mCalibrateButton->setEnabled(
true);
155 reportWarning(
"Selected tool have no known reference point");
158 mCalibrationLabel->setText(
"Calibration:\n"+
qstring_cast(tool->getCalibration_sMt()));
162 mReferencePointLabel->setText(text);
169 mTool(tool), mRef(ref), mP_t(p_t), mSpaces(spaces)
177 return get_referencePoint_ref() - get_sampledPoint_ref();
182 return this->get_sMt_new();
185 Vector3D ToolTipCalibrationCalculator::get_sampledPoint_t()
190 Vector3D ToolTipCalibrationCalculator::get_sampledPoint_ref()
192 CoordinateSystem csT = mSpaces->getT(mTool);
193 CoordinateSystem csRef = mSpaces->getT(mRef);
195 Transform3D refMt = mSpaces->get_toMfrom(csT, csRef);
202 Vector3D ToolTipCalibrationCalculator::get_referencePoint_ref()
204 return mRef->getReferencePoints()[
"1"];
207 Transform3D ToolTipCalibrationCalculator::get_sMt_new()
211 CoordinateSystem csT = mSpaces->getT(mTool);
212 CoordinateSystem csRef = mSpaces->getT(mRef);
213 Transform3D tMref = mSpaces->get_toMfrom(csRef, csT);
218 return sMt_old * T_delta_t;