15 #include <QPushButton> 16 #include <QTextStream> 17 #include <QFileDialog> 18 #include <QMessageBox> 39 BaseWidget(parent,
"ebus_calibration_widget",
"EBUS Calibrate"),
41 mCalibrateButton(new QPushButton(
"Calibrate")),
42 mReferencePointLabel(new QLabel(
"Ref. point:")),
43 mCalibrationLabel(new QLabel(
"Calibration: \n")),
44 mDeltaLabel(new QLabel(
"Delta:"))
46 QVBoxLayout* toplayout =
new QVBoxLayout(
this);
49 mCalibRefTool->setValueName(
"Calibration Adapter");
50 mCalibRefTool->setHelp(
"Select Calibration Adapter sensor");
53 mCalibratingTool->setValueName(
"Tool");
54 mCalibratingTool->setHelp(
"Select which Tool to calibrate");
57 mAdapterCalibrationPath =
settings()->
value(
"EBUScalibration/path").toString();
59 QLabel* adapterCalibrationPathLabel =
new QLabel(tr(
"EBUS adapter calibration matrix path:"));
60 mAdapterCalibrationPathComboBox =
new QComboBox();
61 mAdapterCalibrationPathComboBox->addItem(mAdapterCalibrationPath);
62 mAdapterCalibrationPathComboBox->setMaximumWidth(500);
63 QAction* browseAdapterCalibrationPathAction =
new QAction(QIcon(
":/icons/open.png"), tr(
"Browse for EBUS adapter calibration matrix..."),
this);
64 connect(browseAdapterCalibrationPathAction, &QAction::triggered,
this, &EBUSCalibrationWidget::browseAdapterCalibrationPathSlot);
65 QToolButton* browseAdapterCalibrationPathButton =
new QToolButton(
this);
66 browseAdapterCalibrationPathButton->setDefaultAction(browseAdapterCalibrationPathAction);
68 QGridLayout* gridLayout =
new QGridLayout();
70 gridLayout->addWidget(adapterCalibrationPathLabel, 0, 0);
71 gridLayout->addWidget(mAdapterCalibrationPathComboBox, 1, 0);
72 gridLayout->addWidget(browseAdapterCalibrationPathButton, 1, 1);
74 toplayout->addWidget(mReferencePointLabel);
77 toplayout->addLayout(gridLayout);
78 toplayout->addWidget(mCalibrateButton);
79 toplayout->addWidget(mCalibrationLabel);
81 toplayout->addStretch();
83 mReferencePointLabel->setText(
"<b>EBUS calibration adapter - Use sensor on adapter as reference</b>");
85 connect(mCalibrateButton, SIGNAL(clicked()),
this, SLOT(calibrateSlot()));
87 connect(mCalibRefTool.get(), SIGNAL(changed()),
this, SLOT(toolSelectedSlot()));
90 this->toolSelectedSlot();
98 void EBUSCalibrationWidget::calibrateSlot()
100 ToolPtr refTool = mCalibRefTool->getTool();
101 ToolPtr tool = mCalibratingTool->getTool();
102 if(!refTool || !tool)
104 reportError(QString(
"Calibration prerequisited not met: calref:%1, tool:%2").arg(refTool!=0).arg(tool!=0) );
107 if(!refTool->getVisible() || !tool->getVisible())
109 reportError(QString(
"Calibration prerequisited not met: calref vis:%1, tool vis :%2").arg(refTool->getVisible()).arg(tool->getVisible()) );
114 Transform3D adapterCalibration = readCalibrationFile(mAdapterCalibrationPath);
118 msgBox.setText(
"Do you want to overwrite "+tool->getName()+
"'s calibration file?");
119 msgBox.setInformativeText(
"This cannot be undone.");
120 msgBox.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);
121 msgBox.setDefaultButton(QMessageBox::Ok);
122 int ret = msgBox.exec();
124 if(ret == QMessageBox::Ok)
128 tool->setCalibration_sMt(calibration);
130 catch(std::exception& e)
133 msgBox2.setText(
"Unknown error, could not calibrate the tool: "+tool->getName()+
".");
134 msgBox2.setInformativeText(QString(e.what()));
135 msgBox2.setStandardButtons(QMessageBox::Ok);
136 msgBox2.setDefaultButton(QMessageBox::Ok);
137 int ret2 = msgBox2.exec();
140 mCalibrationLabel->setText(QString(
"Calibration matrix for %1:\n%2").arg(tool->getName(),
qstring_cast(calibration)));
144 void EBUSCalibrationWidget::toolSelectedSlot()
147 mCalibrateButton->setEnabled(
false);
149 if (mCalibRefTool->getTool())
154 mCalibrateButton->setEnabled(
true);
160 void EBUSCalibrationWidget::browseAdapterCalibrationPathSlot()
162 QFileInfo fileInfo(mAdapterCalibrationPath);
163 mAdapterCalibrationPath = QFileDialog::getOpenFileName(
this, tr(
"Find adapter calibration matrix file"), fileInfo.absolutePath());
167 if(!mAdapterCalibrationPath.isEmpty())
169 mAdapterCalibrationPathComboBox->addItem( mAdapterCalibrationPath );
170 mAdapterCalibrationPathComboBox->setCurrentIndex( mAdapterCalibrationPathComboBox->currentIndex() + 1 );
174 Transform3D EBUSCalibrationWidget::readCalibrationFile(QString absoluteFilePath)
189 void EBUSCalibrationWidget::trackingStartedSlot()
191 ToolPtr ref = mServices->tracking()->getTool(
"calibration_tool");
193 mCalibRefTool->setValue(ref->getUid());
204 mTool(tool), mCalibrationRef(calRef)
206 m_sMpr = mTool->getCalibration_sMt() * mTool->get_prMt().inv();
208 m_qMcr = Transform3D::Identity();
209 m_qMpr = m_qMcr * mCalibrationRef->get_prMt().inv();
214 Transform3D tool_prMs = mTool->get_prMt() * mTool->getCalibration_sMt().inverse();
216 Transform3D calibration = tool_prMs.inverse() * adapterCalibration;
QString qstring_cast(const T &val)
void reportError(QString msg)
Transform3D get_calibration_sMt(Transform3D adapterCalibration)
new calibration matrix for the input tool.
boost::shared_ptr< class VisServices > VisServicesPtr
Transform3D Transform3D
Transform3D is a representation of an affine 3D transform.
Transform3D transform() const
QVariant value(const QString &key, const QVariant &defaultValue=QVariant()) const
void setValue(const QString &key, const QVariant &value)
static Frame3D create(const Transform3D &transform)
Settings * settings()
Shortcut for accessing the settings instance.
EBUSCalibrationCalculator(ToolPtr tool, ToolPtr calRef)
Namespace for all CustusX production code.
boost::shared_ptr< class Tool > ToolPtr