35 #include <QPushButton> 37 #include <vtkPolyData.h> 38 #include <vtkPoints.h> 72 mLastRegistration = Transform3D::Identity();
76 XmlOptionFile options =
profile()->getXmlSettings().descend(
"registration").descend(
"WirePhantomWidget");
81 mPipeline->initialize(filters);
83 mPipeline->getNodes()[0]->setValueName(
"US Image:");
84 mPipeline->getNodes()[0]->setHelp(
"Select an US volume acquired from the wire phantom.");
85 mPipeline->setOption(
"Color", QVariant(QColor(
"red")));
87 mLayout =
new QVBoxLayout(
this);
91 QPushButton* showCrossButton =
new QPushButton(
"Show Cross");
92 showCrossButton->setToolTip(
"Load the centerline description of the wire cross");
93 connect(showCrossButton, SIGNAL(clicked()),
this, SLOT(loadNominalCross()));
95 mMeasureButton =
new QPushButton(
"Execute");
96 mMeasureButton->setToolTip(
"Measure deviation of input volume from nominal wire cross.");
97 connect(mMeasureButton, SIGNAL(clicked()),
this, SLOT(measureSlot()));
99 mCalibrationButton =
new QPushButton(
"Probe calib");
100 mCalibrationButton->setToolTip(
"" 101 "Estimate probe calibration sMt\n" 102 "based on last accuracy test and\n" 103 "the current probe orientation");
104 connect(mCalibrationButton, SIGNAL(clicked()),
this, SLOT(generate_sMt()));
106 QLayout* buttonsLayout =
new QHBoxLayout;
107 buttonsLayout->addWidget(mMeasureButton);
108 buttonsLayout->addWidget(mCalibrationButton);
110 mResults =
new QTextEdit;
112 mLayout->addWidget(showCrossButton);
113 mLayout->addWidget(mPipelineWidget);
114 mLayout->addLayout(buttonsLayout);
115 mLayout->addWidget(mResults, 1);
126 "<h3>Measure US accuracy using the wire phantom.</h3>" 128 "Select a US recording of the wire phantom, then press" 129 "the register button to find deviation from the nominal" 130 "data. The output is given as a distance from measured" 136 MeshPtr WirePhantomWidget::loadNominalCross()
141 std::map<QString, MeshPtr> meshes =
mServices->patient()->getDataOfType<
Mesh>();
142 for (std::map<QString, MeshPtr>::iterator iter=meshes.begin(); iter!=meshes.end(); ++iter)
143 if (iter->first.contains(
"wire_phantom_cross_pts"))
144 retval = iter->second;
149 retval = boost::dynamic_pointer_cast<
Mesh>(
mServices->patient()->importData(nominalCrossFilename, infoText));
154 reportError(QString(
"failed to load %s.").arg(nominalCrossFilename));
157 retval->setColor(QColor(
"green"));
158 this->showData(retval);
163 void WirePhantomWidget::showData(
DataPtr data)
165 mServices->view()->getGroup(0)->addData(data->getUid());
168 void WirePhantomWidget::measureSlot()
170 if (mPipeline->getPipelineTimedAlgorithm()->isRunning())
172 connect(mPipeline->getPipelineTimedAlgorithm().get(), SIGNAL(finished()),
this, SLOT(registration()));
173 mPipeline->execute();
182 int N = points->GetNumberOfPoints();
187 for (
int i = 0; i < N; ++i)
188 acc +=
Vector3D(points->GetPoint(i));
192 void WirePhantomWidget::registration()
195 disconnect(mPipeline->getPipelineTimedAlgorithm().get(), SIGNAL(finished()),
this, SLOT(registration()));
209 DataPtr measuredCross = mPipeline->getNodes().back()->getData();
210 MeshPtr nominalCross = this->loadNominalCross();
211 if (!nominalCross || !measuredCross)
213 reportError(
"Missing fixed/moving data. WirePhantom measurement failed.");
217 mServices->registration()->setFixedData(nominalCross);
218 mServices->registration()->setMovingData(measuredCross);
220 this->showData(nominalCross);
221 this->showData(measuredCross);
227 QString logPath =
mServices->patient()->getActivePatientFolder() +
"/Logs/";
231 success = success && vesselReg.
execute();
239 std::cout <<
"v2v linear result:\n" << linearTransform << std::endl;
242 mLastRegistration = linearTransform;
249 mServices->registration()->setLastRegistrationTime(QDateTime::currentDateTime());
250 mServices->registration()->addImage2ImageRegistration(delta,
"Wire Phantom Measurement");
253 Vector3D t_delta = linearTransform.matrix().block<3, 1>(0, 3);
254 Eigen::AngleAxisd angleAxis = Eigen::AngleAxisd(linearTransform.matrix().block<3, 3>(0, 0));
255 double angle = angleAxis.angle();
260 Vector3D cross_r = this->findCentroid(nominalCross);
267 std::pair<QString, Transform3D> probePos = this->getLastProbePosition();
270 Vector3D cross_moving_r = linearTransform.coord(cross_r);
271 Vector3D diff_r = (cross_r - cross_moving_r);
272 Vector3D diff_tus = rMt_us.inv().vector(diff_r);
276 QString operator()(
double val)
278 return QString(
"%1").arg(val, 2,
'f', 2);
284 result += QString(
"Results for: %1\n").arg(
mServices->registration()->getMovingData()->getName());
285 result += QString(
"Shift vector (r): \t%1\t%2\t%3\n").arg(fmt(diff_r[0])).arg(fmt(diff_r[1])).arg(fmt(diff_r[2]));
286 if (!probePos.first.isEmpty())
287 result += QString(
"Shift vector (probe): \t%1\t%2\t%3\t(used tracking data from %4)\n").arg(fmt(diff_tus[0])).arg(fmt(diff_tus[1])).arg(fmt(diff_tus[2])).arg(probePos.first);
288 result += QString(
"Accuracy |v|: \t%1\tmm\n").arg(fmt(diff_r.length()));
289 result += QString(
"Angle: \t%1\t*\n").arg(fmt(angle /
M_PI * 180.0));
291 mResults->append(result);
292 report(
"Wire Phantom Test Results:\n"+result);
294 this->showDataMetrics(cross_r);
302 void WirePhantomWidget::showDataMetrics(
Vector3D cross_r)
308 Vector3D cross_us = usMnom.coord(cross_r);
315 p1->setSpace(
mServices->spaceProvider()->getD(
mServices->registration()->getFixedData()));
316 p1->setCoordinate(cross_r);
326 p2->setSpace(
mServices->spaceProvider()->getD(
mServices->registration()->getMovingData()));
327 p2->setCoordinate(cross_us);
337 d0->getArguments()->set(0, p1);
338 d0->getArguments()->set(1, p2);
350 std::pair<QString, Transform3D> WirePhantomWidget::getLastProbePosition()
356 return std::make_pair(
"", Transform3D::Identity());
358 return std::make_pair(usData.
mFilename, prMt_us);
361 void WirePhantomWidget::generate_sMt()
363 bool translateOnly =
true;
366 std::pair<QString, Transform3D> probePos = this->getLastProbePosition();
368 if (probePos.first.isEmpty())
370 reportWarning(
"Cannot find probe position from last recording, aborting calibration test.");
378 reportWarning(
"Cannot find probe, aborting calibration test.");
388 if (!
mServices->registration()->getMovingData())
390 reportWarning(
"Cannot find moving data, aborting calibration test.");
397 Vector3D cross_r = this->findCentroid(this->loadNominalCross());
407 Vector3D cross_moving_r = mLastRegistration.coord(cross_r);
408 Vector3D diff_r = (cross_r - cross_moving_r);
409 Vector3D diff_tus = rMt_us.inv().vector(diff_r);
417 "Calculated new calibration matrix\n" 418 "adding only translation " 419 "from last accuracy test\n" 438 sQt = usMs.inv() * nomMus * usMs * sMt;
441 "Calculated new calibration matrix\n" 442 "from last accuracy test\n" 444 "Old calibration matrix sMt:\n" 446 "New calibration matrix sQt:\n"
QString qstring_cast(const T &val)
cxResource_EXPORT ProfilePtr profile()
void reportError(QString msg)
boost::shared_ptr< class DistanceMetric > DistanceMetricPtr
Transform3D Transform3D
Transform3D is a representation of an affine 3D transform.
vtkSmartPointer< vtkPoints > vtkPointsPtr
boost::shared_ptr< class Data > DataPtr
virtual RegistrationHistoryPtr get_rMd_History()
boost::shared_ptr< class Filter > FilterPtr
void reportWarning(QString msg)
boost::shared_ptr< FilterGroup > FilterGroupPtr
Transform3D createTransformTranslate(const Vector3D &translation)
Data class that represents a distance between two points, or a point and a plane. ...
Data class that represents a single point.
vtkSmartPointer< vtkPolyData > vtkPolyDataPtr
Eigen::Vector3d Vector3D
Vector3D is a representation of a point or vector in 3D.
static QString getRootConfigPath()
return path to root config folder. May be replaced with getExistingConfigPath()
void checkQuality(Transform3D linearTransform)
boost::shared_ptr< class Mesh > MeshPtr
Transform3D getLinearResult(ContextPtr context=ContextPtr())
Helper class for xml files used to store ssc/cx data.
bool initialize(DataPtr source, DataPtr target, QString logPath)
Namespace for all CustusX production code.
boost::shared_ptr< class Tool > ToolPtr
boost::shared_ptr< class PointMetric > PointMetricPtr