35 #include <QPushButton>
36 #include <QTextStream>
37 #include <QFileDialog>
38 #include <QMessageBox>
55 BaseWidget(parent,
"ToolTipCalibrateWidget",
"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();
113 CoordinateSystem to = mServices->spaceProvider()->getT(tool);
114 Vector3D P_t = mServices->spaceProvider()->getActiveToolTipPoint(to);
116 ToolTipCalibrationCalculator calc(mServices->spaceProvider(), tool, refTool, P_t);
117 Transform3D calibration = calc.get_calibration_sMt();
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)
128 tool->setCalibration_sMt(calibration);
129 mCalibrationLabel->setText(
"Calibration:\n"+
qstring_cast(calibration));
133 void ToolTipCalibrateWidget::testCalibrationSlot()
135 ToolPtr selectedTool = mTools->getTool();
136 if(!selectedTool || !selectedTool->hasReferencePointWithId(1))
139 CoordinateSystem to = mServices->spaceProvider()->getT(mServices->tracking()->getActiveTool());
140 Vector3D sampledPoint = mServices->spaceProvider()->getActiveToolTipPoint(to);
142 ToolTipCalibrationCalculator calc(mServices->spaceProvider(), mServices->tracking()->getActiveTool(), selectedTool, sampledPoint);
143 Vector3D delta_selectedTool = calc.get_delta_ref();
145 mDeltaLabel->setText(
"<b>Delta:</b> "+
qstring_cast(delta_selectedTool)+
" <br> <b>Length:</b> "+
qstring_cast(delta_selectedTool.length()));
150 void ToolTipCalibrateWidget::toolSelectedSlot()
152 QString text(
"Ref. point: <UNDEFINED POINT>");
153 mCalibrateButton->setEnabled(
false);
155 if(mTools->getTool())
157 ToolPtr tool = mTools->getTool();
158 if(tool && tool->hasReferencePointWithId(1))
160 text =
"Ref. point: "+
qstring_cast(tool->getReferencePoints()[1]);
161 mCalibrateButton->setEnabled(
true);
164 reportWarning(
"Selected tool have no known reference point");
167 mCalibrationLabel->setText(
"Calibration:\n"+
qstring_cast(tool->getCalibration_sMt()));
171 mReferencePointLabel->setText(text);
178 mTool(tool), mRef(ref), mP_t(p_t), mSpaces(spaces)
186 return get_referencePoint_ref() - get_sampledPoint_ref();
191 return this->get_sMt_new();
194 Vector3D ToolTipCalibrationCalculator::get_sampledPoint_t()
199 Vector3D ToolTipCalibrationCalculator::get_sampledPoint_ref()
201 CoordinateSystem csT = mSpaces->getT(mTool);
202 CoordinateSystem csRef = mSpaces->getT(mRef);
204 Transform3D refMt = mSpaces->get_toMfrom(csT, csRef);
211 Vector3D ToolTipCalibrationCalculator::get_referencePoint_ref()
213 return mRef->getReferencePoints()[1];
216 Transform3D ToolTipCalibrationCalculator::get_sMt_new()
220 CoordinateSystem csT = mSpaces->getT(mTool);
221 CoordinateSystem csRef = mSpaces->getT(mRef);
222 Transform3D tMref = mSpaces->get_toMfrom(csRef, csT);
227 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)
Eigen::Vector3d Vector3D
Vector3D is a representation of a point or vector in 3D.
boost::shared_ptr< class Tool > ToolPtr