35 #include <QPushButton> 36 #include <QTextStream> 37 #include <QFileDialog> 38 #include <QMessageBox> 55 BaseWidget(parent,
"tool_tip_calibrate_widget",
"ToolTip Calibrate"),
57 mCalibrateButton(new QPushButton(
"Calibrate")),
58 mReferencePointLabel(new QLabel(
"Ref. point:")),
59 mTestButton(new QPushButton(
"Test calibration")),
60 mCalibrationLabel(new QLabel(
"Calibration: \n")),
61 mDeltaLabel(new QLabel(
"Delta:"))
63 QVBoxLayout* toplayout =
new QVBoxLayout(
this);
66 mTools->setValueName(
"Reference tool");
67 mTools->setHelp(
"Select a tool with a known reference point");
69 this->setToolTip(
"Calibrate tool position part of sMt matrix");
72 toplayout->addWidget(mCalibrateToolComboBox);
73 toplayout->addWidget(mReferencePointLabel);
74 toplayout->addWidget(mCalibrateButton);
75 toplayout->addWidget(mCalibrationLabel);
77 toplayout->addWidget(mTestButton);
78 toplayout->addWidget(mDeltaLabel);
79 toplayout->addStretch();
81 connect(mCalibrateButton, SIGNAL(clicked()),
this, SLOT(calibrateSlot()));
82 connect(mTestButton, SIGNAL(clicked()),
this, SLOT(testCalibrationSlot()));
84 connect(mTools.get(), SIGNAL(changed()),
this, SLOT(toolSelectedSlot()));
88 this->toolSelectedSlot();
94 void ToolTipCalibrateWidget::onTrackingSystemStateChanged()
96 if (mServices->tracking()->getTool(mTools->getValue()))
98 if (!mServices->tracking()->getReferenceTool())
101 mTools->setValue(mServices->tracking()->getReferenceTool()->getUid());
104 void ToolTipCalibrateWidget::calibrateSlot()
106 ToolPtr refTool = mTools->getTool();
109 if(!refTool || !refTool->hasReferencePointWithId(1))
112 ToolPtr tool = mServices->tracking()->getActiveTool();
114 Vector3D P_t = mServices->spaceProvider()->getActiveToolTipPoint(to);
120 msgBox.setText(
"Do you want to overwrite "+tool->getName()+
"s calibration file?");
121 msgBox.setInformativeText(
"This cannot be undone.");
122 msgBox.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);
123 msgBox.setDefaultButton(QMessageBox::Ok);
124 int ret = msgBox.exec();
126 if(ret == QMessageBox::Ok)
130 tool->setCalibration_sMt(calibration);
132 catch(std::exception& e)
135 msgBox2.setText(
"Unknown error, could not calibrate the tool: "+tool->getName()+
".");
136 msgBox2.setInformativeText(QString(e.what()));
137 msgBox2.setStandardButtons(QMessageBox::Ok);
138 msgBox2.setDefaultButton(QMessageBox::Ok);
139 int ret2 = msgBox2.exec();
142 mCalibrationLabel->setText(
"Calibration:\n"+
qstring_cast(calibration));
146 void ToolTipCalibrateWidget::testCalibrationSlot()
148 ToolPtr selectedTool = mTools->getTool();
149 if(!selectedTool || !selectedTool->hasReferencePointWithId(1))
152 CoordinateSystem to = mServices->spaceProvider()->getT(mServices->tracking()->getActiveTool());
153 Vector3D sampledPoint = mServices->spaceProvider()->getActiveToolTipPoint(to);
158 mDeltaLabel->setText(
"<b>Delta:</b> "+
qstring_cast(delta_selectedTool)+
" <br> <b>Length:</b> "+
qstring_cast(delta_selectedTool.length()));
163 void ToolTipCalibrateWidget::toolSelectedSlot()
165 QString text(
"Ref. point: <UNDEFINED POINT>");
166 mCalibrateButton->setEnabled(
false);
168 if(mTools->getTool())
170 ToolPtr tool = mTools->getTool();
171 if(tool && tool->hasReferencePointWithId(1))
173 text =
"Ref. point: "+
qstring_cast(tool->getReferencePoints()[1]);
174 mCalibrateButton->setEnabled(
true);
177 reportWarning(
"Selected tool have no known reference point");
180 mCalibrationLabel->setText(
"Calibration:\n"+
qstring_cast(tool->getCalibration_sMt()));
184 mReferencePointLabel->setText(text);
191 mTool(tool), mRef(ref), mP_t(p_t), mSpaces(spaces)
199 return get_referencePoint_ref() - get_sampledPoint_ref();
204 return this->get_sMt_new();
207 Vector3D ToolTipCalibrationCalculator::get_sampledPoint_t()
212 Vector3D ToolTipCalibrationCalculator::get_sampledPoint_ref()
217 Transform3D refMt = mSpaces->get_toMfrom(csT, csRef);
224 Vector3D ToolTipCalibrationCalculator::get_referencePoint_ref()
226 return mRef->getReferencePoints()[1];
229 Transform3D ToolTipCalibrationCalculator::get_sMt_new()
235 Transform3D tMref = mSpaces->get_toMfrom(csRef, csT);
240 return sMt_old * T_delta_t;
boost::shared_ptr< class SpaceProvider > SpaceProviderPtr
QString qstring_cast(const T &val)
boost::shared_ptr< class VisServices > VisServicesPtr
Transform3D Transform3D
Transform3D is a representation of an affine 3D transform.
void reportWarning(QString msg)
Transform3D createTransformTranslate(const Vector3D &translation)
Identification of a Coordinate system.
Eigen::Vector3d Vector3D
Vector3D is a representation of a point or vector in 3D.
Namespace for all CustusX production code.
boost::shared_ptr< class Tool > ToolPtr