14 #include <QPushButton> 15 #include <QTextStream> 16 #include <QFileDialog> 17 #include <QMessageBox> 34 BaseWidget(parent,
"tool_tip_calibrate_widget",
"ToolTip Calibrate"),
36 mCalibrateButton(new QPushButton(
"Calibrate")),
37 mReferencePointLabel(new QLabel(
"Ref. point:")),
38 mTestButton(new QPushButton(
"Test calibration")),
39 mCalibrationLabel(new QLabel(
"Calibration: \n")),
40 mDeltaLabel(new QLabel(
"Delta:"))
42 QVBoxLayout* toplayout =
new QVBoxLayout(
this);
45 mTools->setValueName(
"Reference tool");
46 mTools->setHelp(
"Select a tool with a known reference point");
48 this->setToolTip(
"Calibrate tool position part of sMt matrix");
51 toplayout->addWidget(mCalibrateToolComboBox);
52 toplayout->addWidget(mReferencePointLabel);
53 toplayout->addWidget(mCalibrateButton);
54 toplayout->addWidget(mCalibrationLabel);
56 toplayout->addWidget(mTestButton);
57 toplayout->addWidget(mDeltaLabel);
58 toplayout->addStretch();
60 connect(mCalibrateButton, SIGNAL(clicked()),
this, SLOT(calibrateSlot()));
61 connect(mTestButton, SIGNAL(clicked()),
this, SLOT(testCalibrationSlot()));
63 connect(mTools.get(), SIGNAL(changed()),
this, SLOT(toolSelectedSlot()));
67 this->toolSelectedSlot();
73 void ToolTipCalibrateWidget::onTrackingSystemStateChanged()
75 if (mServices->tracking()->getTool(mTools->getValue()))
77 if (!mServices->tracking()->getReferenceTool())
80 mTools->setValue(mServices->tracking()->getReferenceTool()->getUid());
83 void ToolTipCalibrateWidget::calibrateSlot()
85 ToolPtr refTool = mTools->getTool();
88 if(!refTool || !refTool->hasReferencePointWithId(1))
91 ToolPtr tool = mServices->tracking()->getActiveTool();
93 Vector3D P_t = mServices->spaceProvider()->getActiveToolTipPoint(to);
99 msgBox.setText(
"Do you want to overwrite "+tool->getName()+
"s calibration file?");
100 msgBox.setInformativeText(
"This cannot be undone.");
101 msgBox.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);
102 msgBox.setDefaultButton(QMessageBox::Ok);
103 int ret = msgBox.exec();
105 if(ret == QMessageBox::Ok)
109 tool->setCalibration_sMt(calibration);
111 catch(std::exception& e)
114 msgBox2.setText(
"Unknown error, could not calibrate the tool: "+tool->getName()+
".");
115 msgBox2.setInformativeText(QString(e.what()));
116 msgBox2.setStandardButtons(QMessageBox::Ok);
117 msgBox2.setDefaultButton(QMessageBox::Ok);
118 int ret2 = msgBox2.exec();
121 mCalibrationLabel->setText(
"Calibration:\n"+
qstring_cast(calibration));
125 void ToolTipCalibrateWidget::testCalibrationSlot()
127 ToolPtr selectedTool = mTools->getTool();
128 if(!selectedTool || !selectedTool->hasReferencePointWithId(1))
131 CoordinateSystem to = mServices->spaceProvider()->getT(mServices->tracking()->getActiveTool());
132 Vector3D sampledPoint = mServices->spaceProvider()->getActiveToolTipPoint(to);
137 mDeltaLabel->setText(
"<b>Delta:</b> "+
qstring_cast(delta_selectedTool)+
" <br> <b>Length:</b> "+
qstring_cast(delta_selectedTool.length()));
142 void ToolTipCalibrateWidget::toolSelectedSlot()
144 QString text(
"Ref. point: <UNDEFINED POINT>");
145 mCalibrateButton->setEnabled(
false);
147 if(mTools->getTool())
149 ToolPtr tool = mTools->getTool();
150 if(tool && tool->hasReferencePointWithId(1))
152 text =
"Ref. point: "+
qstring_cast(tool->getReferencePoints()[1]);
153 mCalibrateButton->setEnabled(
true);
156 reportWarning(
"Selected tool have no known reference point");
159 mCalibrationLabel->setText(
"Calibration:\n"+
qstring_cast(tool->getCalibration_sMt()));
163 mReferencePointLabel->setText(text);
170 mTool(tool), mRef(ref), mP_t(p_t), mSpaces(spaces)
178 return get_referencePoint_ref() - get_sampledPoint_ref();
183 return this->get_sMt_new();
186 Vector3D ToolTipCalibrationCalculator::get_sampledPoint_t()
191 Vector3D ToolTipCalibrationCalculator::get_sampledPoint_ref()
196 Transform3D refMt = mSpaces->get_toMfrom(csT, csRef);
203 Vector3D ToolTipCalibrationCalculator::get_referencePoint_ref()
205 return mRef->getReferencePoints()[1];
208 Transform3D ToolTipCalibrationCalculator::get_sMt_new()
214 Transform3D tMref = mSpaces->get_toMfrom(csRef, csT);
219 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