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");
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()));
87 this->toolSelectedSlot();
96 "<h3>Tool tip calibration.</h3>"
97 "<p><i>Calibrates a tool by sampling it when pointing at a known point on another frame.</i></br>"
98 "By using the test button you can test your calibration by pointing at a known reference point.</br></p>"
102 void ToolTipCalibrateWidget::calibrateSlot()
104 ToolPtr refTool = mTools->getTool();
107 if(!refTool || !refTool->hasReferencePointWithId(1))
110 ToolPtr tool = mServices->getToolManager()->getActiveTool();
112 Vector3D P_t = mServices->getSpaceProvider()->getActiveToolTipPoint(to);
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)
126 tool->setCalibration_sMt(calibration);
127 mCalibrationLabel->setText(
"Calibration:\n"+
qstring_cast(calibration));
131 void ToolTipCalibrateWidget::testCalibrationSlot()
133 ToolPtr selectedTool = mTools->getTool();
134 if(!selectedTool || !selectedTool->hasReferencePointWithId(1))
137 CoordinateSystem to = mServices->getSpaceProvider()->getT(mServices->getToolManager()->getActiveTool());
138 Vector3D sampledPoint = mServices->getSpaceProvider()->getActiveToolTipPoint(to);
140 ToolTipCalibrationCalculator calc(mServices->getSpaceProvider(), mServices->getToolManager()->getActiveTool(), selectedTool, sampledPoint);
141 Vector3D delta_selectedTool = calc.get_delta_ref();
143 mDeltaLabel->setText(
"<b>Delta:</b> "+
qstring_cast(delta_selectedTool)+
" <br> <b>Length:</b> "+
qstring_cast(delta_selectedTool.length()));
148 void ToolTipCalibrateWidget::toolSelectedSlot()
150 QString text(
"Ref. point: <UNDEFINED POINT>");
151 mCalibrateButton->setEnabled(
false);
154 if(mTools->getTool())
156 ToolPtr tool = mTools->getTool();
157 if(tool && tool->hasReferencePointWithId(1))
159 text =
"Ref. point: "+
qstring_cast(tool->getReferencePoints()[1]);
160 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)
Identification of a Coordinate system.
Eigen::Vector3d Vector3D
Vector3D is a representation of a point or vector in 3D.
boost::shared_ptr< class Tool > ToolPtr