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);
223 SeansVesselReg vesselReg;
224 vesselReg.mt_auto_lts =
true;
225 vesselReg.mt_ltsRatio = 80;
226 vesselReg.mt_doOnlyLinear =
true;
227 QString logPath =
mServices->patient()->getActivePatientFolder() +
"/Logs/";
230 bool success = vesselReg.initialize(
mServices->registration()->getMovingData(),
mServices->registration()->getFixedData(), logPath);
231 success = success && vesselReg.execute();
238 Transform3D linearTransform = vesselReg.getLinearResult();
239 std::cout <<
"v2v linear result:\n" << linearTransform << std::endl;
241 vesselReg.checkQuality(linearTransform);
242 mLastRegistration = linearTransform;
249 mServices->registration()->setLastRegistrationTime(QDateTime::currentDateTime());
250 mServices->registration()->applyImage2ImageRegistration(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);
312 p1 =
mServices->patient()->createSpecificData<PointMetric>(
"cross_nominal");
314 p1->get_rMd_History()->setParentSpace(
mServices->registration()->getFixedData()->getUid());
315 p1->setSpace(
mServices->spaceProvider()->getD(
mServices->registration()->getFixedData()));
316 p1->setCoordinate(cross_r);
323 p2 =
mServices->patient()->createSpecificData<PointMetric>(
"cross_us");
325 p2->get_rMd_History()->setParentSpace(
mServices->registration()->getMovingData()->getUid());
326 p2->setSpace(
mServices->spaceProvider()->getD(
mServices->registration()->getMovingData()));
327 p2->setCoordinate(cross_us);
334 d0 =
mServices->patient()->createSpecificData<DistanceMetric>(
"accuracy");
336 d0->get_rMd_History()->setParentSpace(
"reference");
337 d0->getArguments()->set(0, p1);
338 d0->getArguments()->set(1, p2);
350 std::pair<QString, Transform3D> WirePhantomWidget::getLastProbePosition()
353 USReconstructInputData usData = mUsReconstructionService->getSelectedFileData();
355 if (usData.mPositions.empty())
356 return std::make_pair(
"", Transform3D::Identity());
357 prMt_us = usData.mPositions[usData.mPositions.size()/2].mPos;
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.");
374 USReconstructInputData usData = mUsReconstructionService->getSelectedFileData();
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)
Transform3D Transform3D
Transform3D is a representation of an affine 3D transform.
boost::shared_ptr< class Data > DataPtr
vtkSmartPointer< class vtkPolyData > vtkPolyDataPtr
boost::shared_ptr< class Filter > FilterPtr
void reportWarning(QString msg)
boost::shared_ptr< FilterGroup > FilterGroupPtr
Transform3D createTransformTranslate(const Vector3D &translation)
boost::shared_ptr< class DistanceMetric > DistanceMetricPtr
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()
boost::shared_ptr< class Mesh > MeshPtr
Helper class for xml files used to store ssc/cx data.
vtkSmartPointer< class vtkPoints > vtkPointsPtr
boost::shared_ptr< class Tool > ToolPtr
boost::shared_ptr< class PointMetric > PointMetricPtr