34 #include <vtkPolyData.h>
73 "Bronchoscopy Registration"),
77 mVerticalLayout =
new QVBoxLayout(
this);
78 mOptions =
profile()->getXmlSettings().descend(
"bronchoscopyregistrationwidget");
81 mSelectMeshWidget->setValueName(
"Centerline: ");
86 mProcessCenterlineButton =
new QPushButton(
"Process centerline");
87 connect(mProcessCenterlineButton, SIGNAL(clicked()),
this, SLOT(processCenterlineSlot()));
90 mRegisterButton =
new QPushButton(
"Register");
91 connect(mRegisterButton, SIGNAL(clicked()),
this, SLOT(registerSlot()));
94 this->initSessionSelector();
100 mVerticalLayout->setMargin(0);
104 this->selectSubsetOfBranches(mOptions.
getElement());
105 this->createMaxNumberOfGenerations(mOptions.
getElement());
106 this->useLocalRegistration(mOptions.
getElement());
116 mVerticalLayout->addWidget(
new CheckBoxWidget(
this, mUseSubsetOfGenerations));
118 mVerticalLayout->addWidget(mProcessCenterlineButton);
120 mVerticalLayout->addWidget(mRecordSessionWidget.get());
122 mVerticalLayout->addWidget(
new CheckBoxWidget(
this, mUseLocalRegistration));
123 mVerticalLayout->addWidget(mRegisterButton);
125 mVerticalLayout->addStretch();
128 connect(mObscuredListener.get(), SIGNAL(obscured(
bool)),
this, SLOT(obscuredSlot(
bool)));
132 void BronchoscopyRegistrationWidget::initSessionSelector()
134 QStringList sessionUids = getSessionList();
135 QString defaultValue;
136 if(!sessionUids.isEmpty())
137 defaultValue = sessionUids.last();
138 mSessionSelector =
StringProperty::initialize(
"bronchoscopy_session",
"Bronchoscope path",
"Select bronchoscope path for registration", defaultValue, sessionUids, QDomNode());
143 QStringList BronchoscopyRegistrationWidget::getSessionList()
146 std::vector<RecordSessionPtr>::iterator it = sessions.begin();
147 QStringList sessionUids;
149 for(; it != sessions.end(); ++it)
151 QString uid = (*it)->getUid();
164 void BronchoscopyRegistrationWidget::initializeTrackingService()
170 void BronchoscopyRegistrationWidget::processCenterlineSlot()
172 this->initializeTrackingService();
174 if(!mSelectMeshWidget->getMesh())
179 vtkPolyDataPtr centerline = mSelectMeshWidget->getMesh()->getVtkPolyData();
180 Transform3D rMd = mSelectMeshWidget->getMesh()->get_rMd();
182 if (mUseSubsetOfGenerations->getValue())
183 processedCenterline = mBronchoscopyRegistration->processCenterline(centerline, rMd, mMaxNumberOfGenerations->getValue());
185 processedCenterline = mBronchoscopyRegistration->processCenterline(centerline, rMd);
189 QString uid = mSelectMeshWidget->getMesh()->getUid() +
"_cl%1";
190 QString name = mSelectMeshWidget->getMesh()->getName()+
" cl_processed%1";
193 mMesh->setVtkPolyData(processedCenterline);
194 mMesh->setColor(QColor(0, 0, 255, 255));
199 void BronchoscopyRegistrationWidget::registerSlot()
201 if(!mBronchoscopyRegistration->isCenterlineProcessed())
211 mTool = mSelectToolWidget->getTool();
220 std::cout <<
"Tool name: " << mTool->getName() << std::endl;
223 QString sessionUid = mSessionSelector->getValue();
224 if(!sessionUid.isEmpty())
235 if(trackerRecordedData_prMt.size() == 0)
242 double maxDistanceForLocalRegistration = 30;
243 if(mUseLocalRegistration->getValue())
244 new_rMpr =
Transform3D(mBronchoscopyRegistration->runBronchoscopyRegistration(trackerRecordedData_prMt,old_rMpr,maxDistanceForLocalRegistration));
246 new_rMpr =
Transform3D(mBronchoscopyRegistration->runBronchoscopyRegistration(trackerRecordedData_prMt,old_rMpr,0));
248 new_rMpr = new_rMpr*old_rMpr;
249 mServices.
registrationService->applyPatientRegistration(new_rMpr,
"Bronchoscopy centerline to tracking data");
251 Eigen::Matrix4d display_rMpr = Eigen::Matrix4d::Identity();
252 display_rMpr = new_rMpr*display_rMpr;
253 std::cout <<
"New prMt: " << std::endl;
254 for (
int i = 0; i < 4; i++)
255 std::cout << display_rMpr.row(i) << std::endl;
258 if(activeRep3D && activeRep3D->getTracer())
259 activeRep3D->getTracer()->clear();
261 QColor colorGreen = QColor(0, 255, 0, 255);
262 activeRep3D->getTracer()->setColor(colorGreen);
263 activeRep3D->getTracer()->addManyPositions(trackerRecordedData_prMt);
268 void BronchoscopyRegistrationWidget::acquisitionStarted()
270 std::cout <<
"acquisitionStarted" << std::endl;
272 mTool = mSelectToolWidget->getTool();
276 ToolRep3DPtr activeRep3D = this->getToolRepIn3DView(mTool);
280 activeRep3D->getTracer()->start();
282 void BronchoscopyRegistrationWidget::acquisitionStopped()
284 std::cout <<
"acquisitionStopped" << std::endl;
286 this->acquisitionCancelled();
288 QStringList range = mSessionSelector->getValueRange();
290 mSessionSelector->setValueRange(range);
291 mSessionSelector->setValue(newUid);
298 void BronchoscopyRegistrationWidget::acquisitionCancelled()
300 ToolRep3DPtr activeRep3D = this->getToolRepIn3DView(mTool);
304 activeRep3D->getTracer()->stop();
307 void BronchoscopyRegistrationWidget::recordedSessionsChanged()
309 QStringList sessionUids = getSessionList();
310 mSessionSelector->setValueRange(sessionUids);
311 if(mSessionSelector->getValue().isEmpty() && !sessionUids.isEmpty())
312 mSessionSelector->setValue(sessionUids.last());
319 return repContainer->findFirst<ToolRep3D>(tool);
324 void BronchoscopyRegistrationWidget::obscuredSlot(
bool obscured)
342 ToolRep3DPtr activeRep3D = this->getToolRepIn3DView(mTool);
346 activeRep3D->getTracer()->clear();
349 void BronchoscopyRegistrationWidget::createMaxNumberOfGenerations(QDomElement root)
352 "Set max number of generations centerline", 4, DoubleRange(0, 10, 1), 0,
357 void BronchoscopyRegistrationWidget::selectSubsetOfBranches(QDomElement root)
360 "Select branch generations to be used in registration",
false,
364 void BronchoscopyRegistrationWidget::useLocalRegistration(QDomElement root)
367 "Use local registration",
false,
AcquisitionServicePtr acquisitionService
cxResource_EXPORT ProfilePtr profile()
static BoolPropertyPtr initialize(const QString &uid, QString name, QString help, bool value, QDomNode root=QDomNode())
void acquisitionStopped()
void reportError(QString msg)
Transform3D Transform3D
Transform3D is a representation of an affine 3D transform.
QWidget * createDataWidget(VisualizationServicePtr visualizationService, PatientModelServicePtr patientModelService, QWidget *parent, PropertyPtr data, QGridLayout *gridLayout, int row)
Create a widget capable of displaying the input data.
TrackingServicePtr getToolManager()
static TimedTransformMap getToolHistory_prMt(ToolPtr tool, RecordSessionPtr session)
QDomElement getElement()
return the current element
vtkSmartPointer< class vtkPolyData > vtkPolyDataPtr
boost::shared_ptr< class RepContainer > RepContainerPtr
boost::shared_ptr< class RecordSession > RecordSessionPtr
static StringPropertyPtr initialize(const QString &uid, QString name, QString help, QString value, QStringList range, QDomNode root=QDomNode())
VisualizationServicePtr visualizationService
TrackingServicePtr trackingService
static DoublePropertyPtr initialize(const QString &uid, QString name, QString help, double value, DoubleRange range, int decimals, QDomNode root=QDomNode())
void recordedSessionsChanged()
static StringPropertySelectMeshPtr New(PatientModelServicePtr patientModelService)
boost::shared_ptr< class ToolRep3D > ToolRep3DPtr
PatientModelServicePtr patientModelService
std::map< double, Transform3D > TimedTransformMap
RegistrationServicePtr registrationService
boost::shared_ptr< class Tool > ToolPtr