15 #include <QPushButton> 16 #include <QTextStream> 17 #include <QFileDialog> 18 #include <QMessageBox> 37 BaseWidget(parent,
"lap_frame_tool_calibration_widget",
"LapFrame Calibrate"),
39 mCalibrateButton(new QPushButton(
"Calibrate")),
40 mReferencePointLabel(new QLabel(
"Ref. point:")),
41 mTestButton(new QPushButton(
"Test calibration")),
42 mCalibrationLabel(new QLabel(
"Calibration: \n")),
43 mDeltaLabel(new QLabel(
"Delta:"))
45 QVBoxLayout* toplayout =
new QVBoxLayout(
this);
48 "Additional tilt of calibration around tool y-axis,\nfor use with cameras tilted relative to tool direction",
50 mCameraAngleAdapter->setInternal2Display(180.0/
M_PI);
53 mCalibRefTool->setValueName(
"Calibration Frame");
54 mCalibRefTool->setHelp(
"Select Calibration Reference Frame");
57 mCalibratingTool->setValueName(
"Tool");
58 mCalibratingTool->setHelp(
"Select which Tool to calibrate");
60 this->setToolTip(
"Calibrate tool matrix using a custom frame");
64 toplayout->addWidget(mReferencePointLabel);
68 toplayout->addWidget(mCalibrateButton);
69 toplayout->addWidget(mCalibrationLabel);
71 toplayout->addWidget(mTestButton);
72 toplayout->addWidget(mDeltaLabel);
73 toplayout->addStretch();
75 mReferencePointLabel->setText(
"<i> Use only with the special Laparascopic <br>" 76 "calibration frame as reference. </i>");
78 connect(mCalibrateButton, SIGNAL(clicked()),
this, SLOT(calibrateSlot()));
79 connect(mTestButton, SIGNAL(clicked()),
this, SLOT(testCalibrationSlot()));
81 connect(mCalibRefTool.get(), SIGNAL(changed()),
this, SLOT(toolSelectedSlot()));
84 this->toolSelectedSlot();
92 void LapFrameToolCalibrationWidget::calibrateSlot()
94 ToolPtr refTool = mCalibRefTool->getTool();
95 ToolPtr tool = mCalibratingTool->getTool();
96 double cameraAngle = mCameraAngleAdapter->getValue();
99 reportError(QString(
"Calibration prerequisited not met: calref:%1, tool:%2").arg(refTool!=0).arg(tool!=0) );
102 if(!refTool->getVisible() || !tool->getVisible() || !refTool->hasReferencePointWithId(1))
104 reportError(QString(
"Calibration prerequisited not met: calref vis:%1, tool vis :%2, refpoint:%3").arg(refTool->getVisible()).arg(tool->getVisible()).arg(refTool->hasReferencePointWithId(1)) );
112 msgBox.setText(
"Do you want to overwrite "+tool->getName()+
"'s calibration file?");
113 msgBox.setInformativeText(
"This cannot be undone.");
114 msgBox.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);
115 msgBox.setDefaultButton(QMessageBox::Ok);
116 int ret = msgBox.exec();
118 if(ret == QMessageBox::Ok)
122 tool->setCalibration_sMt(calibration);
124 catch(std::exception& e)
127 msgBox2.setText(
"Unknown error, could not calibrate the tool: "+tool->getName()+
".");
128 msgBox2.setInformativeText(QString(e.what()));
129 msgBox2.setStandardButtons(QMessageBox::Ok);
130 msgBox2.setDefaultButton(QMessageBox::Ok);
131 int ret2 = msgBox2.exec();
134 mCalibrationLabel->setText(QString(
"Calibration matrix for %1:\n%2").arg(tool->getName(),
qstring_cast(calibration)));
138 void LapFrameToolCalibrationWidget::testCalibrationSlot()
140 ToolPtr refTool = mCalibRefTool->getTool();
141 ToolPtr tool = mCalibratingTool->getTool();
142 double cameraAngle = mCameraAngleAdapter->getValue();
144 if(!refTool || !tool || !refTool->hasReferencePointWithId(1))
150 QString delta = QString(
"%1 mm").arg(delta_selectedTool.length(), 6,
'g', 1);
151 mDeltaLabel->setText(
"<b>Delta "+tool->getName()+
":</b> "+
qstring_cast(delta_selectedTool)+
" <br> <b>Accuracy:</b> " + delta);
153 report(
"Delta "+tool->getName()+
": "+
qstring_cast(delta_selectedTool)+
" Length: "+ delta);
158 void LapFrameToolCalibrationWidget::toolSelectedSlot()
161 mCalibrateButton->setEnabled(
false);
162 mTestButton->setEnabled(
false);
164 if (mCalibRefTool->getTool())
169 mCalibrateButton->setEnabled(
true);
170 mTestButton->setEnabled(
true);
177 void LapFrameToolCalibrationWidget::trackingStartedSlot()
179 ToolPtr ref = mServices->tracking()->getTool(
"calibration_tool");
181 mCalibRefTool->setValue(ref->getUid());
192 mTool(tool), mCalibrationRef(calRef), mCameraAngle(cameraAngle)
194 m_sMpr = mTool->getCalibration_sMt() * mTool->get_prMt().inv();
201 m_qMcr = Transform3D::Identity();
202 m_qMpr = m_qMcr * mCalibrationRef->get_prMt().inv();
208 Transform3D qMpr = m_qMcr * mCalibrationRef->get_prMt().inv();
210 Vector3D calibPoint_pr = qMpr.inv().coord(p);
211 Vector3D toolPoint_pr = mTool->get_prMt().coord(p);
212 return calibPoint_pr - toolPoint_pr;
218 this->useOnlyRotationalPart(&calibration);
234 Transform3D::LinearMatrixType rotationalPart = transform->rotation();
235 transform->linear() = rotationalPart;
QString qstring_cast(const T &val)
DoubleBoundingBox3D transform(const Transform3D &m, const DoubleBoundingBox3D &bb)
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())
Namespace for all CustusX production code.
boost::shared_ptr< class Tool > ToolPtr