35 #include <QPushButton>
40 #include <vtkCellArray.h>
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);
105 "<h3>Seans Vessel Registration.</h3>"
106 "<p>Select two datasets you want to registere to eachother, adjust the input parameters.</p>"
107 "<p><i>Adjust the parameters and click the register button.</i></p>"
111 void SeansVesselRegistrationWidget::inputChanged()
115 mRegisterButton->setEnabled(
true);
116 mVesselRegOptionsButton->setEnabled(
true);
117 mVesselRegOptionsWidget->setVisible(mVesselRegOptionsButton->isChecked());
121 mRegisterButton->setEnabled(
false);
122 mVesselRegOptionsButton->setEnabled(
false);
123 mVesselRegOptionsWidget->setVisible(
false);
127 void SeansVesselRegistrationWidget::registerSlot()
143 SeansVesselReg vesselReg;
144 vesselReg.mt_auto_lts =
true;
145 vesselReg.mt_ltsRatio = mLTSRatioSpinBox->value();
146 vesselReg.mt_doOnlyLinear = mLinearCheckBox->isChecked();
147 vesselReg.mt_auto_lts = mAutoLTSCheckBox->isChecked();
149 if (vesselReg.mt_auto_lts)
176 Transform3D linearTransform = vesselReg.getLinearResult();
177 std::cout <<
"v2v linear result:\n" << linearTransform << std::endl;
180 vesselReg.checkQuality(linearTransform);
207 mMovingData = mContext->getMovingPoints();
208 mFixedData = mContext->getFixedPoints();
210 MeshPtr moving(
new Mesh(
"v2vreg_moving",
"v2vreg_moving", mMovingData));
211 moving->setColor(QColor(
"red"));
213 MeshPtr fixed(
new Mesh(
"v2vreg_fixed",
"v2vreg_fixed", mFixedData));
214 fixed->setColor(QColor(
"green"));
216 mPolyLines = vtkPolyDataPtr::New();
217 MeshPtr lines(
new Mesh(
"v2vreg_lines",
"v2vreg_lines", mPolyLines));
218 lines->setColor(QColor(
"cornflowerblue"));
223 m_mRep->setMesh(moving);
224 view->addRep(m_mRep);
227 m_fRep->setMesh(fixed);
228 view->addRep(m_fRep);
231 m_lineRep->setMesh(lines);
232 view->addRep(m_lineRep);
236 report(
"Initialized V2V algorithm (debug). Use Step to iterate.");
241 view->removeRep(m_mRep);
242 view->removeRep(m_fRep);
243 view->removeRep(m_lineRep);
244 report(
"Closed V2V algorithm (debug).");
252 report(QString(
"One Linear V2V iteration, metric=%1").arg(mContext->mMetric));
260 report(QString(
"One Nonlinear V2V iteration, metric=%1").arg(mContext->mMetric));
268 std::cout <<
"v2v linear result:\n" << linearTransform << std::endl;
274 report(QString(
"Applied linear registration from debug iteration."));
286 mMovingData->SetPoints(moving->GetPoints());
287 mMovingData->SetVerts(moving->GetVerts());
290 mFixedData->SetPoints(fixed->GetPoints());
291 mFixedData->SetVerts(fixed->GetVerts());
306 mPolyLines->Allocate();
308 for (
int i = 0; i < mContext->mSortedSourcePoints->GetNumberOfPoints(); ++i)
310 verts->InsertNextPoint(mContext->mSortedSourcePoints->GetPoint(i));
311 verts->InsertNextPoint(mContext->mSortedTargetPoints->GetPoint(i));
313 vtkIdType connectivity[2];
314 connectivity[0] = 2 * i;
315 connectivity[1] = 2 * i + 1;
316 mPolyLines->InsertNextCell(VTK_LINE, 2, connectivity);
318 mPolyLines->SetPoints(verts);
331 void SeansVesselRegistrationWidget::debugInit()
333 mDebugger.reset(
new SeansVesselRegistrationDebugger(
mServices, mLTSRatioSpinBox->value(),
334 mLinearCheckBox->isChecked()));
336 void SeansVesselRegistrationWidget::debugRunOneLinearStep()
341 void SeansVesselRegistrationWidget::debugRunOneNonlinearStep()
347 void SeansVesselRegistrationWidget::debugApply()
353 void SeansVesselRegistrationWidget::debugClear()
358 QWidget* SeansVesselRegistrationWidget::createOptionsWidget()
360 QWidget* retval =
new QWidget(
this);
361 QGridLayout* layout =
new QGridLayout(retval);
363 mLTSRatioSpinBox->setSingleStep(1);
364 mLTSRatioSpinBox->setValue(80);
366 mLinearCheckBox->setChecked(
true);
367 mAutoLTSCheckBox->setChecked(
true);
370 layout->addWidget(
new QLabel(
"Auto LTS:"), line, 0);
371 layout->addWidget(mAutoLTSCheckBox, line, 1);
373 layout->addWidget(
new QLabel(
"LTS Ratio:"), line, 0);
374 layout->addWidget(mLTSRatioSpinBox, line, 1);
376 layout->addWidget(
new QLabel(
"Linear:"), line, 0);
377 layout->addWidget(mLinearCheckBox, line, 1);
379 layout->addWidget(
new QLabel(
"Debug"), line, 0);
380 QHBoxLayout* debugLayout =
new QHBoxLayout;
381 layout->addLayout(debugLayout, line, 1, 1, 1);
383 "Initialize the V2V algorithm.\n Display only, registration will not be updated in CustusX (Debug)",
384 SLOT(debugInit()), debugLayout);
385 this->
createAction(
this, QIcon(),
"Lin",
"Run one Linear step in the V2V algorithm. (Debug)",
386 SLOT(debugRunOneLinearStep()), debugLayout);
388 "Run one Nonlinear step in the V2V algorithm. (Should be one at the end only)(Debug)",
389 SLOT(debugRunOneNonlinearStep()), debugLayout);
390 this->
createAction(
this, QIcon(),
"Apply",
"Apply results from the debug iteration", SLOT(debugApply()), debugLayout);
391 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