35 #include <QPushButton>
40 #include <vtkCellArray.h>
59 RegistrationBaseWidget(services, parent,
"org_custusx_registration_method_vessel_seans_widget",
"Seans Vessel Registration"),
60 mLTSRatioSpinBox(new QSpinBox()), mLinearCheckBox(new QCheckBox()), mAutoLTSCheckBox(new QCheckBox()),
61 mRegisterButton(new QPushButton(
"Register"))
63 mRegisterButton->setEnabled(
false);
64 connect(mRegisterButton, &QPushButton::clicked,
this, &SeansVesselRegistrationWidget::registerSlot);
67 this, &SeansVesselRegistrationWidget::inputChanged);
69 this, &SeansVesselRegistrationWidget::inputChanged);
71 QVBoxLayout* topLayout =
new QVBoxLayout(
this);
72 QGridLayout* layout =
new QGridLayout();
73 topLayout->addLayout(layout);
75 mVesselRegOptionsButton =
new QPushButton(
"Options",
this);
76 mVesselRegOptionsButton->setEnabled(
false);
77 mVesselRegOptionsButton->setCheckable(
true);
79 mVesselRegOptionsWidget = this->
createGroupbox(this->createOptionsWidget(),
80 "Vessel registration options");
81 connect(mVesselRegOptionsButton, SIGNAL(clicked(
bool)), mVesselRegOptionsWidget, SLOT(setVisible(
bool)));
82 mVesselRegOptionsWidget->setVisible(mVesselRegOptionsButton->isChecked());
84 QGridLayout* entryLayout =
new QGridLayout;
85 entryLayout->setColumnStretch(1, 1);
92 layout->addLayout(entryLayout, 0, 0, 2, 2);
93 layout->addWidget(mRegisterButton, 2, 0);
94 layout->addWidget(mVesselRegOptionsButton, 2, 1);
95 layout->addWidget(mVesselRegOptionsWidget, 3, 0, 1, 2);
102 void SeansVesselRegistrationWidget::inputChanged()
106 mRegisterButton->setEnabled(
true);
107 mVesselRegOptionsButton->setEnabled(
true);
108 mVesselRegOptionsWidget->setVisible(mVesselRegOptionsButton->isChecked());
112 mRegisterButton->setEnabled(
false);
113 mVesselRegOptionsButton->setEnabled(
false);
114 mVesselRegOptionsWidget->setVisible(
false);
118 void SeansVesselRegistrationWidget::registerSlot()
134 SeansVesselReg vesselReg;
135 vesselReg.mt_auto_lts =
true;
136 vesselReg.mt_ltsRatio = mLTSRatioSpinBox->value();
137 vesselReg.mt_doOnlyLinear = mLinearCheckBox->isChecked();
138 vesselReg.mt_auto_lts = mAutoLTSCheckBox->isChecked();
140 if (vesselReg.mt_auto_lts)
167 Transform3D linearTransform = vesselReg.getLinearResult();
168 std::cout <<
"v2v linear result:\n" << linearTransform << std::endl;
171 vesselReg.checkQuality(linearTransform);
198 mMovingData = mContext->getMovingPoints();
199 mFixedData = mContext->getFixedPoints();
201 MeshPtr moving(
new Mesh(
"v2vreg_moving",
"v2vreg_moving", mMovingData));
202 moving->setColor(QColor(
"red"));
204 MeshPtr fixed(
new Mesh(
"v2vreg_fixed",
"v2vreg_fixed", mFixedData));
205 fixed->setColor(QColor(
"green"));
207 mPolyLines = vtkPolyDataPtr::New();
208 MeshPtr lines(
new Mesh(
"v2vreg_lines",
"v2vreg_lines", mPolyLines));
209 lines->setColor(QColor(
"cornflowerblue"));
214 m_mRep->setMesh(moving);
215 view->addRep(m_mRep);
218 m_fRep->setMesh(fixed);
219 view->addRep(m_fRep);
222 m_lineRep->setMesh(lines);
223 view->addRep(m_lineRep);
227 report(
"Initialized V2V algorithm (debug). Use Step to iterate.");
232 view->removeRep(m_mRep);
233 view->removeRep(m_fRep);
234 view->removeRep(m_lineRep);
235 report(
"Closed V2V algorithm (debug).");
243 report(QString(
"One Linear V2V iteration, metric=%1").arg(mContext->mMetric));
251 report(QString(
"One Nonlinear V2V iteration, metric=%1").arg(mContext->mMetric));
259 std::cout <<
"v2v linear result:\n" << linearTransform << std::endl;
265 report(QString(
"Applied linear registration from debug iteration."));
277 mMovingData->SetPoints(moving->GetPoints());
278 mMovingData->SetVerts(moving->GetVerts());
281 mFixedData->SetPoints(fixed->GetPoints());
282 mFixedData->SetVerts(fixed->GetVerts());
297 mPolyLines->Allocate();
299 for (
int i = 0; i < mContext->mSortedSourcePoints->GetNumberOfPoints(); ++i)
301 verts->InsertNextPoint(mContext->mSortedSourcePoints->GetPoint(i));
302 verts->InsertNextPoint(mContext->mSortedTargetPoints->GetPoint(i));
304 vtkIdType connectivity[2];
305 connectivity[0] = 2 * i;
306 connectivity[1] = 2 * i + 1;
307 mPolyLines->InsertNextCell(VTK_LINE, 2, connectivity);
309 mPolyLines->SetPoints(verts);
322 void SeansVesselRegistrationWidget::debugInit()
324 mDebugger.reset(
new SeansVesselRegistrationDebugger(
mServices, mLTSRatioSpinBox->value(),
325 mLinearCheckBox->isChecked()));
327 void SeansVesselRegistrationWidget::debugRunOneLinearStep()
332 void SeansVesselRegistrationWidget::debugRunOneNonlinearStep()
338 void SeansVesselRegistrationWidget::debugApply()
344 void SeansVesselRegistrationWidget::debugClear()
349 QWidget* SeansVesselRegistrationWidget::createOptionsWidget()
351 QWidget* retval =
new QWidget(
this);
352 QGridLayout* layout =
new QGridLayout(retval);
354 mLTSRatioSpinBox->setSingleStep(1);
355 mLTSRatioSpinBox->setValue(80);
357 mLinearCheckBox->setChecked(
true);
358 mAutoLTSCheckBox->setChecked(
true);
361 layout->addWidget(
new QLabel(
"Auto LTS:"), line, 0);
362 layout->addWidget(mAutoLTSCheckBox, line, 1);
364 layout->addWidget(
new QLabel(
"LTS Ratio:"), line, 0);
365 layout->addWidget(mLTSRatioSpinBox, line, 1);
367 layout->addWidget(
new QLabel(
"Linear:"), line, 0);
368 layout->addWidget(mLinearCheckBox, line, 1);
370 layout->addWidget(
new QLabel(
"Debug"), line, 0);
371 QHBoxLayout* debugLayout =
new QHBoxLayout;
372 layout->addLayout(debugLayout, line, 1, 1, 1);
374 "Initialize the V2V algorithm.\n Display only, registration will not be updated in CustusX (Debug)",
375 SLOT(debugInit()), debugLayout);
376 this->
createAction(
this, QIcon(),
"Lin",
"Run one Linear step in the V2V algorithm. (Debug)",
377 SLOT(debugRunOneLinearStep()), debugLayout);
379 "Run one Nonlinear step in the V2V algorithm. (Should be one at the end only)(Debug)",
380 SLOT(debugRunOneNonlinearStep()), debugLayout);
381 this->
createAction(
this, QIcon(),
"Apply",
"Apply results from the debug iteration", SLOT(debugApply()), debugLayout);
382 this->
createAction(
this, QIcon(),
"Clear",
"Clear debugging of the V2V algorithm.", SLOT(debugClear()), debugLayout);
QString qstring_cast(const T &val)
~SeansVesselRegistrationDebugger()
void performOneRegistration(ContextPtr context, bool linear)
Register the source points to the target point in a single ste.
Transform3D Transform3D
Transform3D is a representation of an affine 3D transform.
boost::shared_ptr< class View > ViewPtr
void fixedDataChanged(QString uid)
vtkSmartPointer< class vtkPolyData > vtkPolyDataPtr
void computeDistances(ContextPtr context)
Compute distances between the two datasets.
void reportWarning(QString msg)
SeansVesselRegistrationDebugger(RegServices services, double ltsRatio, bool linear)
ContextPtr createContext(DataPtr source, DataPtr target)
static GeometricRepPtr New(const QString &uid="")
VisualizationServicePtr visualizationService
void movingDataChanged(QString uid)
void checkQuality(Transform3D linearTransform)
boost::shared_ptr< Context > ContextPtr
PatientModelServicePtr patientModelService
boost::shared_ptr< class Mesh > MeshPtr
Transform3D getLinearResult(ContextPtr context=ContextPtr())
void reportDebug(QString msg)
RegistrationServicePtr registrationService
vtkSmartPointer< class vtkPoints > vtkPointsPtr
boost::shared_ptr< class GeometricRep > GeometricRepPtr