15 #include <QVBoxLayout> 16 #include <QPushButton> 17 #include <QTableWidget> 18 #include <QTableWidgetItem> 19 #include <QHeaderView> 23 #include <vtkDoubleArray.h> 24 #include <vtkImageData.h> 39 LandmarkRegistrationWidget::LandmarkRegistrationWidget(
RegServicesPtr services, QWidget* parent, QString objectName, QString windowTitle,
bool showAccuracy) :
41 mLandmarkTableWidget(new QTableWidget(this)), mAvarageAccuracyLabel(new QLabel(QString(
" "), this)),
43 mLandmarkListener(new
LandmarkListener(services)), mShowAccuracy(showAccuracy),
44 mMouseClickSample(nullptr)
52 mMouseClickSample =
new QCheckBox(
"Resample with mouse clicks in anyplane view.",
this);
53 mMouseClickSample->setToolTip(
"Allow mouse clicks in 2D anyplane view to sample patient landmarks.");
63 if (row < 0 || column < 0)
86 Vector3D p_pr = rMpr.inv().coord(p_r);
90 Vector3D offset = tool->get_prMt().vector(
Vector3D(0, 0, tool->getTooltipOffset()));
92 p_r = rMpr.coord(p_pr);
103 QWidget::showEvent(event);
113 mServices->registration()->setLastRegistrationTime(QDateTime::currentDateTime());
123 if(landmarks.size() > 0)
125 QString firstLandmarkUid = landmarks[0].getUid();
135 QWidget::hideEvent(event);
150 DataPtr fixedData = boost::dynamic_pointer_cast<
Data>(
mServices->registration()->getFixedData());
152 fixedName = fixedData->
getName();
160 QStringList headerItems(QStringList() <<
"Name" <<
"Status" <<
"Coordinates");
164 headerItems.append(
"Accuracy (mm)");
173 for (
unsigned i = 0; i < landmarks.size(); ++i)
175 std::vector<QTableWidgetItem*> items(4);
178 Vector3D coord = landmarks[i].getCoord();
179 coord = rMtarget.coord(coord);
182 items[0]->setToolTip(QString(
"Landmark name. Double-click to rename."));
184 items[1] =
new QTableWidgetItem;
187 items[1]->setCheckState(Qt::Checked);
189 items[1]->setCheckState(Qt::Unchecked);
190 items[1]->setToolTip(QString(
"Check to use landmark in current registration."));
192 QString coordText =
"Not sampled";
193 if (targetData.count(prop.
getUid()))
197 coordText = tr(
"(%1, %2, %3)").arg(coord[0], width,
'f', prec).arg(coord[1], width,
'f', prec).arg(
198 coord[2], width,
'f', prec);
201 items[2] =
new QTableWidgetItem(coordText);
202 items[2]->setToolTip(QString(
"Landmark coordinates of target [%1] in reference space.").arg(this->
getTargetName()));
204 items[3] =
new QTableWidgetItem(tr(
"%1").arg(this->
getAccuracy(landmarks[i].getUid())));
205 items[3]->setToolTip(QString(
"Distance from target [%1] to fixed [%2].").arg(this->
getTargetName()).arg(fixedName));
207 for (
unsigned j = 0; j < items.size(); ++j)
238 int size = int(lm.size());
239 for (
unsigned i=0; int(i) < size-1; ++i)
243 return lm[i+1].getUid();
252 std::vector<Landmark> retval;
254 std::map<QString, LandmarkProperty> dataData =
mServices->patient()->getLandmarkProperties();
255 std::map<QString, LandmarkProperty>::iterator iter;
257 for (iter = dataData.begin(); iter != dataData.end(); ++iter)
259 if (targetData.count(iter->first))
260 retval.push_back(targetData[iter->first]);
262 retval.push_back(
Landmark(iter->first));
265 std::sort(retval.begin(), retval.end());
273 QString uid = item->data(Qt::UserRole).toString();
277 QString name = item->text();
278 mServices->patient()->setLandmarkName(uid, name);
282 Qt::CheckState state = item->checkState();
283 mServices->patient()->setLandmarkActive(uid, state == Qt::Checked);
288 QString val = item->text();
290 val = val.replace(
'(',
" ");
291 val = val.replace(
')',
" ");
292 val = val.replace(
',',
" ");
296 Vector3D p_r = Vector3D::fromString(val);
297 Vector3D p_target = rMtarget.inv().coord(p_r);
315 DataPtr fixedData = boost::dynamic_pointer_cast<
Data>(
mServices->registration()->getFixedData());
317 fixedName = fixedData->
getName();
331 bool LandmarkRegistrationWidget::isAverageAccuracyValid()
333 int numActiveLandmarks = 0;
335 if(numActiveLandmarks < 3)
342 int numActiveLandmarks = 0;
348 std::map<QString, LandmarkProperty> props =
mServices->patient()->getLandmarkProperties();
351 numActiveLandmarks = 0;
352 std::map<QString, LandmarkProperty>::iterator it = props.begin();
353 for (; it != props.end(); ++it)
355 if (!it->second.getActive())
357 QString uid = it->first;
362 numActiveLandmarks++;
365 if (numActiveLandmarks == 0)
367 return sum / numActiveLandmarks;
376 Landmark masterLandmark = fixedData->getLandmarks()->getLandmarks()[uid];
378 if (masterLandmark.
getUid().isEmpty() || targetLandmark.
getUid().isEmpty())
386 Vector3D p_target_r = rMtarget.coord(p_target_target);
387 Vector3D p_master_r = rMmaster.coord(p_master_master);
389 return (p_target_r - p_master_r).length();
QString qstring_cast(const T &val)
void landmarkPropertiesChanged()
emitted when global info about a landmark changed
One landmark, or fiducial, coordinate.
Transform3D Transform3D
Transform3D is a representation of an affine 3D transform.
void landmarkAdded(QString uid)
void pointSampled(Vector3D p_r)
boost::shared_ptr< class Data > DataPtr
virtual QString getName() const
boost::shared_ptr< class RegServices > RegServicesPtr
Transform3D createTransformTranslate(const Vector3D &translation)
Vector3D getCoord() const
void activeLayoutChanged()
emitted when the active layout changes
Eigen::Vector3d Vector3D
Vector3D is a representation of a point or vector in 3D.
Superclass for all data objects.
std::map< QString, class Landmark > LandmarkMap
bool similar(const CameraInfo &lhs, const CameraInfo &rhs, double tol)
void landmarkRemoved(QString uid)
void reportDebug(QString msg)
Namespace for all CustusX production code.
boost::shared_ptr< class Tool > ToolPtr