36 #include <QVBoxLayout>
37 #include <QPushButton>
38 #include <QTableWidget>
39 #include <QTableWidgetItem>
40 #include <QHeaderView>
43 #include <vtkDoubleArray.h>
44 #include <vtkImageData.h>
59 LandmarkRegistrationWidget::LandmarkRegistrationWidget(
RegServicesPtr services, QWidget* parent,
60 QString objectName, QString windowTitle) :
62 mLandmarkTableWidget(new QTableWidget(this)), mAvarageAccuracyLabel(new QLabel(QString(
" "), this)),
78 if (row < 0 || column < 0)
101 Vector3D p_pr = rMpr.inv().coord(p_r);
105 Vector3D offset = tool->get_prMt().vector(
Vector3D(0, 0, tool->getTooltipOffset()));
107 p_r = rMpr.coord(p_pr);
117 QWidget::showEvent(event);
126 mServices->registration()->setLastRegistrationTime(QDateTime::currentDateTime());
133 QWidget::hideEvent(event);
147 DataPtr fixedData = boost::dynamic_pointer_cast<
Data>(
mServices->registration()->getFixedData());
149 fixedName = fixedData->
getName();
158 QStringList headerItems(QStringList() <<
"Name" <<
"Status" <<
"Coordinates" <<
"Accuracy (mm)");
163 for (
unsigned i = 0; i < landmarks.size(); ++i)
165 std::vector<QTableWidgetItem*> items(4);
168 Vector3D coord = landmarks[i].getCoord();
169 coord = rMtarget.coord(coord);
172 items[0]->setToolTip(QString(
"Landmark name. Double-click to rename."));
174 items[1] =
new QTableWidgetItem;
177 items[1]->setCheckState(Qt::Checked);
179 items[1]->setCheckState(Qt::Unchecked);
180 items[1]->setToolTip(QString(
"Check to use landmark in current registration."));
182 QString coordText =
"Not sampled";
183 if (targetData.count(prop.
getUid()))
187 coordText = tr(
"(%1, %2, %3)").arg(coord[0], width,
'f', prec).arg(coord[1], width,
'f', prec).arg(
188 coord[2], width,
'f', prec);
191 items[2] =
new QTableWidgetItem(coordText);
192 items[2]->setToolTip(QString(
"Landmark coordinates of target [%1] in reference space.").arg(this->
getTargetName()));
194 items[3] =
new QTableWidgetItem(tr(
"%1").arg(this->
getAccuracy(landmarks[i].getUid())));
195 items[3]->setToolTip(QString(
"Distance from target [%1] to fixed [%2].").arg(this->
getTargetName()).arg(fixedName));
197 for (
unsigned j = 0; j < items.size(); ++j)
227 for (
int i=0; i<lm.size()-1; ++i)
231 return lm[i+1].getUid();
240 std::vector<Landmark> retval;
242 std::map<QString, LandmarkProperty> dataData =
mServices->patient()->getLandmarkProperties();
243 std::map<QString, LandmarkProperty>::iterator iter;
245 for (iter = dataData.begin(); iter != dataData.end(); ++iter)
247 if (targetData.count(iter->first))
248 retval.push_back(targetData[iter->first]);
250 retval.push_back(
Landmark(iter->first));
253 std::sort(retval.begin(), retval.end());
261 QString uid = item->data(Qt::UserRole).toString();
265 QString name = item->text();
266 mServices->patient()->setLandmarkName(uid, name);
270 Qt::CheckState state = item->checkState();
271 mServices->patient()->setLandmarkActive(uid, state == Qt::Checked);
276 QString val = item->text();
278 val = val.replace(
'(',
" ");
279 val = val.replace(
')',
" ");
280 val = val.replace(
',',
" ");
284 Vector3D p_r = Vector3D::fromString(val);
285 Vector3D p_target = rMtarget.inv().coord(p_r);
302 DataPtr fixedData = boost::dynamic_pointer_cast<
Data>(
mServices->registration()->getFixedData());
304 fixedName = fixedData->
getName();
306 if(this->isAverageAccuracyValid())
318 bool LandmarkRegistrationWidget::isAverageAccuracyValid()
320 int numActiveLandmarks = 0;
322 if(numActiveLandmarks < 3)
329 int numActiveLandmarks = 0;
335 std::map<QString, LandmarkProperty> props =
mServices->patient()->getLandmarkProperties();
338 numActiveLandmarks = 0;
339 std::map<QString, LandmarkProperty>::iterator it = props.begin();
340 for (; it != props.end(); ++it)
342 if (!it->second.getActive())
344 QString uid = it->first;
349 numActiveLandmarks++;
352 if (numActiveLandmarks == 0)
354 return sum / numActiveLandmarks;
363 Landmark masterLandmark = fixedData->getLandmarks()->getLandmarks()[uid];
365 if (masterLandmark.
getUid().isEmpty() || targetLandmark.
getUid().isEmpty())
373 Vector3D p_target_r = rMtarget.coord(p_target_target);
374 Vector3D p_master_r = rMmaster.coord(p_master_master);
376 return (p_target_r - p_master_r).length();
QString qstring_cast(const T &val)
boost::shared_ptr< class RegServices > RegServicesPtr
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)
bool similar(const DoubleBoundingBox3D &a, const DoubleBoundingBox3D &b, double tol)
boost::shared_ptr< class Data > DataPtr
virtual QString getName() const
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
void landmarkRemoved(QString uid)
void reportDebug(QString msg)
boost::shared_ptr< class Tool > ToolPtr