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()));
87 this->toolSelectedSlot();
93 void ToolTipCalibrateWidget::calibrateSlot()
95 ToolPtr refTool = mTools->getTool();
98 if(!refTool || !refTool->hasReferencePointWithId(1))
101 ToolPtr tool = mServices->getToolManager()->getActiveTool();
103 Vector3D P_t = mServices->getSpaceProvider()->getActiveToolTipPoint(to);
109 msgBox.setText(
"Do you want to overwrite "+tool->getName()+
"s calibration file?");
110 msgBox.setInformativeText(
"This cannot be undone.");
111 msgBox.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);
112 msgBox.setDefaultButton(QMessageBox::Ok);
113 int ret = msgBox.exec();
115 if(ret == QMessageBox::Ok)
117 tool->setCalibration_sMt(calibration);
118 mCalibrationLabel->setText(
"Calibration:\n"+
qstring_cast(calibration));
122 void ToolTipCalibrateWidget::testCalibrationSlot()
124 ToolPtr selectedTool = mTools->getTool();
125 if(!selectedTool || !selectedTool->hasReferencePointWithId(1))
128 CoordinateSystem to = mServices->getSpaceProvider()->getT(mServices->getToolManager()->getActiveTool());
129 Vector3D sampledPoint = mServices->getSpaceProvider()->getActiveToolTipPoint(to);
131 ToolTipCalibrationCalculator calc(mServices->getSpaceProvider(), mServices->getToolManager()->getActiveTool(), selectedTool, sampledPoint);
132 Vector3D delta_selectedTool = calc.get_delta_ref();
134 mDeltaLabel->setText(
"<b>Delta:</b> "+
qstring_cast(delta_selectedTool)+
" <br> <b>Length:</b> "+
qstring_cast(delta_selectedTool.length()));
139 void ToolTipCalibrateWidget::toolSelectedSlot()
141 QString text(
"Ref. point: <UNDEFINED POINT>");
142 mCalibrateButton->setEnabled(
false);
144 if(mTools->getTool())
146 ToolPtr tool = mTools->getTool();
147 if(tool && tool->hasReferencePointWithId(1))
149 text =
"Ref. point: "+
qstring_cast(tool->getReferencePoints()[1]);
150 mCalibrateButton->setEnabled(
true);
153 reportWarning(
"Selected tool have no known reference point");
156 mCalibrationLabel->setText(
"Calibration:\n"+
qstring_cast(tool->getCalibration_sMt()));
160 mReferencePointLabel->setText(text);
167 mTool(tool), mRef(ref), mP_t(p_t), mSpaces(spaces)
175 return get_referencePoint_ref() - get_sampledPoint_ref();
180 return this->get_sMt_new();
183 Vector3D ToolTipCalibrationCalculator::get_sampledPoint_t()
188 Vector3D ToolTipCalibrationCalculator::get_sampledPoint_ref()
190 CoordinateSystem csT = mSpaces->getT(mTool);
191 CoordinateSystem csRef = mSpaces->getT(mRef);
193 Transform3D refMt = mSpaces->get_toMfrom(csT, csRef);
200 Vector3D ToolTipCalibrationCalculator::get_referencePoint_ref()
202 return mRef->getReferencePoints()[1];
205 Transform3D ToolTipCalibrationCalculator::get_sMt_new()
209 CoordinateSystem csT = mSpaces->getT(mTool);
210 CoordinateSystem csRef = mSpaces->getT(mRef);
211 Transform3D tMref = mSpaces->get_toMfrom(csRef, csT);
216 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