36 #include <QPushButton>
37 #include <QTextStream>
38 #include <QFileDialog>
39 #include <QMessageBox>
58 BaseWidget(parent,
"LapFrameToolCalibrationWidget",
"LapFrame Calibrate"),
60 mCalibrateButton(new QPushButton(
"Calibrate")),
61 mReferencePointLabel(new QLabel(
"Ref. point:")),
62 mTestButton(new QPushButton(
"Test calibration")),
63 mCalibrationLabel(new QLabel(
"Calibration: \n")),
64 mDeltaLabel(new QLabel(
"Delta:"))
66 QVBoxLayout* toplayout =
new QVBoxLayout(
this);
69 "Additional tilt of calibration around tool y-axis,\nfor use with cameras tilted relative to tool direction",
71 mCameraAngleAdapter->setInternal2Display(180.0/
M_PI);
74 mCalibRefTool->setValueName(
"Calibration Frame");
75 mCalibRefTool->setHelp(
"Select Calibration Reference Frame");
78 mCalibratingTool->setValueName(
"Tool");
79 mCalibratingTool->setHelp(
"Select which Tool to calibrate");
85 toplayout->addWidget(mReferencePointLabel);
89 toplayout->addWidget(mCalibrateButton);
90 toplayout->addWidget(mCalibrationLabel);
92 toplayout->addWidget(mTestButton);
93 toplayout->addWidget(mDeltaLabel);
94 toplayout->addStretch();
96 mReferencePointLabel->setText(
"<i> Use only with the special Laparascopic <br>"
97 "calibration frame as reference. </i>");
99 connect(mCalibrateButton, SIGNAL(clicked()),
this, SLOT(calibrateSlot()));
100 connect(mTestButton, SIGNAL(clicked()),
this, SLOT(testCalibrationSlot()));
102 connect(mCalibRefTool.get(), SIGNAL(changed()),
this, SLOT(toolSelectedSlot()));
105 this->toolSelectedSlot();
116 "<h3>Laparascopic tool calibration</h3>"
117 "<p><i>Calibrates a tool by sampling it when it is inserted into the slot of the custom-made calibration frame.</i></br>"
118 "<p><i>The tool to be calibrated will have its calibration set in such a way that the calibrating and calibrated tools"
119 "are in the same position.</i></br>"
120 "<p>By using the test button you can test your calibration by pointing at a known reference point.</br></p>"
124 void LapFrameToolCalibrationWidget::calibrateSlot()
126 ToolPtr refTool = mCalibRefTool->getTool();
127 ToolPtr tool = mCalibratingTool->getTool();
128 double cameraAngle = mCameraAngleAdapter->getValue();
129 if(!refTool || !tool)
131 reportError(QString(
"Calibration prerequisited not met: calref:%1, tool:%2").arg(refTool!=0).arg(tool!=0) );
134 if(!refTool->getVisible() || !tool->getVisible() || !refTool->hasReferencePointWithId(1))
136 reportError(QString(
"Calibration prerequisited not met: calref vis:%1, tool vis :%2, refpoint:%3").arg(refTool->getVisible()).arg(tool->getVisible()).arg(refTool->hasReferencePointWithId(1)) );
140 LapFrameToolCalibrationCalculator calc(tool, refTool, cameraAngle);
141 Transform3D calibration = calc.get_calibration_sMt();
144 msgBox.setText(
"Do you want to overwrite "+tool->getName()+
"'s calibration file?");
145 msgBox.setInformativeText(
"This cannot be undone.");
146 msgBox.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);
147 msgBox.setDefaultButton(QMessageBox::Ok);
148 int ret = msgBox.exec();
150 if(ret == QMessageBox::Ok)
152 tool->setCalibration_sMt(calibration);
155 mCalibrationLabel->setText(QString(
"Calibration matrix for %1:\n%2").arg(tool->getName(),
qstring_cast(calibration)));
159 void LapFrameToolCalibrationWidget::testCalibrationSlot()
161 ToolPtr refTool = mCalibRefTool->getTool();
162 ToolPtr tool = mCalibratingTool->getTool();
163 double cameraAngle = mCameraAngleAdapter->getValue();
165 if(!refTool || !tool || !refTool->hasReferencePointWithId(1))
168 LapFrameToolCalibrationCalculator calc(tool, refTool, cameraAngle);
169 Vector3D delta_selectedTool = calc.get_delta_ref();
171 QString delta = QString(
"%1 mm").arg(delta_selectedTool.length(), 6,
'g', 1);
172 mDeltaLabel->setText(
"<b>Delta "+tool->getName()+
":</b> "+
qstring_cast(delta_selectedTool)+
" <br> <b>Accuracy:</b> " + delta);
174 report(
"Delta "+tool->getName()+
": "+
qstring_cast(delta_selectedTool)+
" Length: "+ delta);
179 void LapFrameToolCalibrationWidget::toolSelectedSlot()
182 mCalibrateButton->setEnabled(
false);
183 mTestButton->setEnabled(
false);
185 if (mCalibRefTool->getTool())
190 mCalibrateButton->setEnabled(
true);
191 mTestButton->setEnabled(
true);
198 void LapFrameToolCalibrationWidget::trackingStartedSlot()
200 ToolPtr ref = mServices->getToolManager()->getTool(
"calibration_tool");
202 mCalibRefTool->setValue(ref->getUid());
213 mTool(tool), mCalibrationRef(calRef), mCameraAngle(cameraAngle)
215 m_sMpr = mTool->getCalibration_sMt() * mTool->get_prMt().inv();
222 m_qMcr = Transform3D::Identity();
223 m_qMpr = m_qMcr * mCalibrationRef->get_prMt().inv();
229 Transform3D qMpr = m_qMcr * mCalibrationRef->get_prMt().inv();
231 Vector3D calibPoint_pr = qMpr.inv().coord(p);
232 Vector3D toolPoint_pr = mTool->get_prMt().coord(p);
233 return calibPoint_pr - toolPoint_pr;
QString qstring_cast(const T &val)
Transform3D createTransformRotateY(const double angle)
void reportError(QString msg)
boost::shared_ptr< class VisServices > VisServicesPtr
Transform3D Transform3D
Transform3D is a representation of an affine 3D transform.
Utility class for describing a bounded numeric range.
Eigen::Vector3d Vector3D
Vector3D is a representation of a point or vector in 3D.
static DoublePropertyPtr initialize(const QString &uid, QString name, QString help, double value, DoubleRange range, int decimals, QDomNode root=QDomNode())
boost::shared_ptr< class Tool > ToolPtr