Fraxinus  17.12-rc1
An IGT application
cxMetricManager.cpp
Go to the documentation of this file.
1 /*=========================================================================
2 This file is part of CustusX, an Image Guided Therapy Application.
3 
4 Copyright (c) 2008-2014, SINTEF Department of Medical Technology
5 All rights reserved.
6 
7 Redistribution and use in source and binary forms, with or without
8 modification, are permitted provided that the following conditions are met:
9 
10 1. Redistributions of source code must retain the above copyright notice,
11  this list of conditions and the following disclaimer.
12 
13 2. Redistributions in binary form must reproduce the above copyright notice,
14  this list of conditions and the following disclaimer in the documentation
15  and/or other materials provided with the distribution.
16 
17 3. Neither the name of the copyright holder nor the names of its contributors
18  may be used to endorse or promote products derived from this software
19  without specific prior written permission.
20 
21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
25 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 =========================================================================*/
32 
33 #include "cxMetricManager.h"
34 #include "cxManualTool.h"
35 #include "cxViewGroupData.h"
36 #include "cxTrackingService.h"
37 #include <QFile>
38 #include <QTextStream>
39 #include <QDialog>
40 #include <QVBoxLayout>
41 #include <QPushButton>
42 #include <QLabel>
43 #include <vtkMNITagPointReader.h>
44 #include <vtkStringArray.h>
45 #include "vtkForwardDeclarations.h"
46 #include "cxDataReaderWriter.h"
47 #include "cxLogger.h"
49 #include "cxPointMetric.h"
50 #include "cxDistanceMetric.h"
51 #include "cxFrameMetric.h"
52 #include "cxToolMetric.h"
53 #include "cxPlaneMetric.h"
54 #include "cxShapedMetric.h"
55 #include "cxCustomMetric.h"
56 #include "cxAngleMetric.h"
57 #include "cxSphereMetric.h"
59 #include "cxDataFactory.h"
60 #include "cxSpaceProvider.h"
61 #include "cxTypeConversions.h"
62 #include "cxPatientModelService.h"
63 #include "cxViewService.h"
64 #include "cxOrderedQDomDocument.h"
65 #include "cxXmlFileHandler.h"
66 #include "cxTime.h"
67 #include "cxErrorObserver.h"
68 #include "cxHelperWidgets.h"
69 #include "cxFileHelpers.h"
70 #include "cxSpaceProperty.h"
71 #include "cxSpaceEditWidget.h"
72 
73 namespace cx
74 {
75 
76 MetricManager::MetricManager(ViewServicePtr viewService, PatientModelServicePtr patientModelService, TrackingServicePtr trackingService, SpaceProviderPtr spaceProvider) :
77  QObject(NULL),
78  mViewService(viewService),
79  mPatientModelService(patientModelService),
80  mTrackingService(trackingService),
81  mSpaceProvider(spaceProvider)
82 {
83  connect(trackingService.get(), &TrackingService::stateChanged, this, &MetricManager::metricsChanged);
84  connect(patientModelService.get(), SIGNAL(dataAddedOrRemoved()), this, SIGNAL(metricsChanged()));
85 }
86 
88 {
89  DataPtr data = mPatientModelService->getData(uid);
90  DataMetricPtr metric = boost::dynamic_pointer_cast<DataMetric>(data);
91  return metric;
92 }
93 
95 {
96  return this->getAllMetrics().size();
97 }
98 
99 std::vector<DataMetricPtr> MetricManager::getAllMetrics() const
100 {
101  std::vector<DataMetricPtr> retval;
102  std::map<QString, DataPtr> all = mPatientModelService->getDatas();
103  for (std::map<QString, DataPtr>::iterator iter=all.begin(); iter!=all.end(); ++iter)
104  {
105  DataMetricPtr metric = boost::dynamic_pointer_cast<DataMetric>(iter->second);
106  if (metric)
107  retval.push_back(metric);
108  }
109  return retval;
110 }
111 
112 void MetricManager::setSelection(std::set<QString> selection)
113 {
114  mSelection = selection;
115 }
116 
118 {
119  mActiveLandmark = uid;
120  emit activeMetricChanged();
121 }
122 
124 {
125  DataMetricPtr metric = this->getMetric(uid);
126  if (!metric)
127  return;
128  Vector3D p_r = metric->getRefCoord();;
129  this->setManualToolPosition(p_r);
130 }
131 
132 void MetricManager::setManualToolPosition(Vector3D p_r)
133 {
134  Transform3D rMpr = mPatientModelService->get_rMpr();
135  Vector3D p_pr = rMpr.inv().coord(p_r);
136 
137  // set the picked point as offset tip
138  ToolPtr tool = mTrackingService->getManualTool();
139  Vector3D offset = tool->get_prMt().vector(Vector3D(0, 0, tool->getTooltipOffset()));
140  p_pr -= offset;
141  p_r = rMpr.coord(p_pr);
142 
143  // TODO set center here will not do: must handle
144  mPatientModelService->setCenter(p_r);
145  Vector3D p0_pr = tool->get_prMt().coord(Vector3D(0, 0, 0));
146  tool->set_prMt(createTransformTranslate(p_pr - p0_pr) * tool->get_prMt());
147 }
148 
149 PointMetricPtr MetricManager::addPoint(Vector3D point, CoordinateSystem space, QString uid, QColor color)
150 {
151  PointMetricPtr p1 = mPatientModelService->createSpecificData<PointMetric>(uid);
152  p1->get_rMd_History()->setParentSpace("reference");
153  p1->setSpace(space);
154  p1->setCoordinate(point);
155  p1->setColor(color);
156  mPatientModelService->insertData(p1);
157 
158  mViewService->getGroup(0)->addData(p1->getUid());
159  this->setActiveUid(p1->getUid());
160 
161  return p1;
162 }
163 
165 {
166  DistanceMetricPtr d0 = mPatientModelService->createSpecificData<DistanceMetric>(uid);
167  d0->get_rMd_History()->setParentSpace("reference");
168 
169  std::vector<DataPtr> args = this->getSpecifiedNumberOfValidArguments(d0->getArguments());
170  for (unsigned i=0; i<args.size(); ++i)
171  d0->getArguments()->set(i, args[i]);
172 
173  this->installNewMetric(d0);
174 
175  return d0;
176 }
177 
179 {
180  this->addPointInDefaultPosition();
181 }
182 
183 PointMetricPtr MetricManager::addPointInDefaultPosition()
184 {
186  QColor color = QColor(240, 170, 255, 255);
187  Vector3D p_ref = mSpaceProvider->getActiveToolTipPoint(ref, true);
188 
189  DataPtr data = mPatientModelService->getData(mActiveLandmark);
190  if(!data)
191 
192  return this->addPoint(p_ref, ref,"point%1", color);
193 
194  PointMetricPtr pointMetric = boost::dynamic_pointer_cast<PointMetric>(data);
195  if(pointMetric)
196  {
197  ref = pointMetric->getSpace();
198  p_ref = mSpaceProvider->getActiveToolTipPoint(ref, true);
199  }
200 
201  DataMetricPtr metric = boost::dynamic_pointer_cast<DataMetric>(data);
202  if(metric)
203  color = metric->getColor();
204 
205 
206 
207  return this->addPoint(p_ref, ref,"point%1", color);
208 }
209 
211 {
212  FrameMetricPtr frame = mPatientModelService->createSpecificData<FrameMetric>("frame%1");
213  frame->get_rMd_History()->setParentSpace("reference");
214 
216  Transform3D rMt = mSpaceProvider->getActiveToolTipTransform(ref, true);
217 
218  frame->setSpace(ref);
219  frame->setFrame(rMt);
220 
221  this->installNewMetric(frame);
222 }
223 
225 {
226  ToolMetricPtr frame = mPatientModelService->createSpecificData<ToolMetric>("tool%1");
227  frame->get_rMd_History()->setParentSpace("reference");
228 
230  Transform3D rMt = mSpaceProvider->getActiveToolTipTransform(ref, true);
231 
232  frame->setSpace(ref);
233  frame->setFrame(rMt);
234  frame->setToolName(mTrackingService->getActiveTool()->getName());
235  frame->setToolOffset(mTrackingService->getActiveTool()->getTooltipOffset());
236 
237  this->installNewMetric(frame);
238 }
239 
241 {
242  PlaneMetricPtr p1 = mPatientModelService->createSpecificData<PlaneMetric>("plane%1");
243  p1->get_rMd_History()->setParentSpace("reference");
244 
245  std::vector<DataPtr> args = this->getSpecifiedNumberOfValidArguments(p1->getArguments());
246  for (unsigned i=0; i<args.size(); ++i)
247  p1->getArguments()->set(i, args[i]);
248 
249  this->installNewMetric(p1);
250 }
251 
256 std::vector<DataPtr> MetricManager::refinePointArguments(std::vector<DataPtr> args, unsigned argNo)
257 {
258  // erase non-selected arguments if we have more than enough
259  //std::set<QString> selectedUids = this->getSelectedUids();
260  for (unsigned i=0; i<args.size();)
261  {
262  if (args.size() <= argNo)
263  break;
264  if (!mSelection.count(args[i]->getUid()))
265  args.erase(args.begin()+i);
266  else
267  ++i;
268  }
269 
270  while (args.size() > argNo)
271  args.erase(args.begin());
272 
273  while (args.size() < argNo)
274  {
275  PointMetricPtr p0 = this->addPointInDefaultPosition();
276  args.push_back(p0);
277  }
278 
279  return args;
280 }
281 
283 {
284  RegionOfInterestMetricPtr d0 = mPatientModelService->createSpecificData<RegionOfInterestMetric>("roi%1");
285  d0->get_rMd_History()->setParentSpace("reference");
286  this->installNewMetric(d0);
287 }
288 
290 {
291  this->addDistance();
292 }
293 
295 {
296  AngleMetricPtr d0 = mPatientModelService->createSpecificData<AngleMetric>("angle%1");
297  d0->get_rMd_History()->setParentSpace("reference");
298 
299  std::vector<DataPtr> args = this->getSpecifiedNumberOfValidArguments(d0->getArguments(), 3);
300  d0->getArguments()->set(0, args[0]);
301  d0->getArguments()->set(1, args[1]);
302  d0->getArguments()->set(2, args[1]);
303  d0->getArguments()->set(3, args[2]);
304 
305  this->installNewMetric(d0);
306 }
307 
308 std::vector<DataPtr> MetricManager::getSpecifiedNumberOfValidArguments(MetricReferenceArgumentListPtr arguments, int numberOfRequiredArguments)
309 {
310  // first try to reuse existing points as distance arguments, otherwise create new ones.
311 
312  std::vector<DataMetricPtr> metrics = this->getAllMetrics();
313 
314  std::vector<DataPtr> args;
315  for (unsigned i=0; i<metrics.size(); ++i)
316  {
317  if (arguments->validArgument(metrics[i]))
318  args.push_back(metrics[i]);
319  }
320 
321  if (numberOfRequiredArguments<0)
322  numberOfRequiredArguments = arguments->getCount();
323  args = this->refinePointArguments(args, numberOfRequiredArguments);
324 
325  return args;
326 }
327 
329 {
330  SphereMetricPtr d0 = mPatientModelService->createSpecificData<SphereMetric>("sphere%1");
331  d0->get_rMd_History()->setParentSpace("reference");
332  std::vector<DataPtr> args = this->getSpecifiedNumberOfValidArguments(d0->getArguments());
333  d0->getArguments()->set(0, args[0]);
334 
335  this->installNewMetric(d0);
336 }
337 
339 {
340  DonutMetricPtr d0 = mPatientModelService->createSpecificData<DonutMetric>("donut%1");
341  d0->get_rMd_History()->setParentSpace("reference");
342  std::vector<DataPtr> args = this->getSpecifiedNumberOfValidArguments(d0->getArguments());
343  d0->getArguments()->set(0, args[0]);
344  d0->getArguments()->set(1, args[1]);
345 
346  this->installNewMetric(d0);
347 }
348 
350 {
351  CustomMetricPtr d0 = mPatientModelService->createSpecificData<CustomMetric>("Custom%1");
352  d0->get_rMd_History()->setParentSpace("reference");
353  std::vector<DataPtr> args = this->getSpecifiedNumberOfValidArguments(d0->getArguments());
354  d0->getArguments()->set(0, args[0]);
355  d0->getArguments()->set(1, args[1]);
356 
357  this->installNewMetric(d0);
358 }
359 
360 void MetricManager::installNewMetric(DataMetricPtr metric)
361 {
362  DataMetricPtr prevMetric = this->getMetric(mActiveLandmark);
363  if(prevMetric)
364  {
365  metric->setColor(prevMetric->getColor());
366  }
367 
368  mPatientModelService->insertData(metric);
369  this->setActiveUid(metric->getUid());
370  mViewService->getGroup(0)->addData(metric->getUid());
371 }
372 
374 {
375  ToolPtr refTool = mTrackingService->getReferenceTool();
376  if(!refTool) // we only load reference points from reference tools
377  {
378  reportDebug("No reference tool, cannot load reference points into the pointsampler");
379  return;
380  }
381 
382  std::map<int, Vector3D> referencePoints_s = refTool->getReferencePoints();
383  if(referencePoints_s.empty())
384  {
385  reportWarning("No referenceppoints in reference tool "+refTool->getName());
386  return;
387  }
388 
390  CoordinateSystem sensor = mSpaceProvider->getS(refTool);
391 
392  std::map<int, Vector3D>::iterator it = referencePoints_s.begin();
393  for(; it != referencePoints_s.end(); ++it)
394  {
395  Vector3D P_ref = mSpaceProvider->get_toMfrom(sensor, ref).coord(it->second);
396  this->addPoint(P_ref, CoordinateSystem(csREF), "ref%1");
397  }
398 }
399 
401 {
402  OrderedQDomDocument orderedDoc;
403  QDomDocument& doc = orderedDoc.doc();
404  doc.appendChild(doc.createProcessingInstruction("xml version =", "'1.0'"));
405  QDomElement patientNode = doc.createElement("patient");
406  doc.appendChild(patientNode);
407  QDomElement managersNode = doc.createElement("managers");
408  patientNode.appendChild(managersNode);
409  QDomElement datamanagerNode = doc.createElement("datamanager");
410  managersNode.appendChild(datamanagerNode);
411  std::map<QString, DataPtr> dataMap = mPatientModelService->getDatas();
412 
413  std::map<QString, DataPtr>::iterator iter;
414  for (iter = dataMap.begin(); iter != dataMap.end(); ++iter)
415  {
416  DataMetricPtr metric = boost::dynamic_pointer_cast<DataMetric>(iter->second);
417  if(metric)
418  {
419  QDomElement dataNode = doc.createElement("data");
420  metric->addXml(dataNode);
421  datamanagerNode.appendChild(dataNode);
422  }
423  }
424 
425  XmlFileHandler::writeXmlFile(doc, filename);
426 }
427 
428 void MetricManager::resolveUnknownParentSpacesForPointMetrics(QDomNode dataNode, std::map<QString, QString> mapping_of_unknown_to_known_spaces, DataPtr data)
429 {
430  QString uid = data->getUid();
431  PointMetricPtr point_metric = boost::static_pointer_cast<PointMetric>(data);
432  if(!point_metric)
433  return;
434 
435  QString string_space = dataNode.toElement().attribute("space");
436  CoordinateSystem parentSpace = CoordinateSystem::fromString(string_space);
437  bool need_parent = parentSpace.isValid() && (parentSpace.mId == csDATA);
438  bool parent_found = mPatientModelService->getData(parentSpace.mRefObject) != DataPtr();
439  if(need_parent && !parent_found)
440  {
441  if(mapping_of_unknown_to_known_spaces.find(string_space) == mapping_of_unknown_to_known_spaces.end())
442  {
443  SpacePropertyPtr space_property;
444  space_property = SpaceProperty::initialize("selectSpace",
445  "Space",
446  "Select parent coordinate system of metric with uid: "+uid);
447  space_property->setSpaceProvider(mSpaceProvider);
448  QWidget* widget = new QWidget;
449  widget->setFocusPolicy(Qt::StrongFocus); // needed for help system: focus is used to display help text
450  QVBoxLayout *layout = new QVBoxLayout();
451  layout->addWidget(new QLabel("Select parent space for Point metric: "+uid+"."));
452  layout->addWidget(new SpaceEditWidget(widget, space_property));
453  QDialog dialog;
454  dialog.setWindowTitle("Space "+string_space+" does not exist.");
455  dialog.setLayout(layout);
456  QPushButton *okButton = new QPushButton(tr("Ok"));
457  layout->addWidget(okButton);
458  connect(okButton, &QAbstractButton::clicked, &dialog, &QWidget::close);
459  dialog.exec();
460  CX_LOG_DEBUG() << "New space is now: " << space_property->getValue().mId << " " << space_property->getValue().mRefObject;
461  CoordinateSystem new_parentspace = space_property->getValue();
462  mapping_of_unknown_to_known_spaces[string_space] = new_parentspace.toString();
463  }
464  parentSpace = CoordinateSystem::fromString(mapping_of_unknown_to_known_spaces[string_space]);
465  point_metric->setSpace(parentSpace);
466  point_metric->setCoordinate(Vector3D::fromString(dataNode.toElement().attribute("coord")));
467  dataNode.toElement().setAttribute("space", parentSpace.toString());
468  }
469 }
470 
472 {
473  QDomDocument xml = XmlFileHandler::readXmlFile(filename);
474  QDomElement patientNode = xml.documentElement();
475 
476  std::map<DataPtr, QDomNode> datanodes;
477 
478  QDomNode managersNode = patientNode.firstChildElement("managers");
479  QDomNode datamanagerNode = managersNode.firstChildElement("datamanager");
480  QDomNode dataNode = datamanagerNode.firstChildElement("data");
481 
482 
483  std::map<QString, QString> mapping_of_unknown_to_known_spaces;
484 
485  for (; !dataNode.isNull(); dataNode = dataNode.nextSibling())
486  {
487  QDomNamedNodeMap attributes = dataNode.attributes();
488  QDomNode typeAttribute = attributes.namedItem("type");
489  bool isMetric = false;
490  if(typeAttribute.isAttr())
491  {
492  isMetric = typeAttribute.toAttr().value().contains("Metric");
493  }
494 
495  if (dataNode.nodeName() == "data" && isMetric)
496  {
497 
498  QString uid = dataNode.toElement().attribute("uid");
499  if(mPatientModelService->getData(uid))
500  {
501  QString name = dataNode.toElement().attribute("name");
502  reportWarning("Metric: " + name + ", is already in the model with Uid: " + uid + ". Import skipped.");
503  continue;
504  }
505 
506  DataPtr data = this->loadDataFromXMLNode(dataNode.toElement());
507  if (data)
508  datanodes[data] = dataNode.toElement();
509 
510  //If point metrics space is uknown to the system, user needs to select a new parent -> POPUP DIALOG
511  this->resolveUnknownParentSpacesForPointMetrics(dataNode, mapping_of_unknown_to_known_spaces, data);
512  }
513  }
514 
515  // parse xml data separately: we want to first load all data
516  // because there might be interdependencies (cx::DistanceMetric)
517  for (std::map<DataPtr, QDomNode>::iterator iter = datanodes.begin(); iter != datanodes.end(); ++iter)
518  {
519  iter->first->parseXml(iter->second);
520  }
521 }
522 
523 QColor MetricManager::getRandomColor()
524 {
525  QStringList colorNames = QColor::colorNames();
526  int random_int = rand() % colorNames.size();
527  QColor color(colorNames[random_int]);
528  if(color == QColor("black"))
529  color = getRandomColor();
530 
531  return color;
532 }
533 
534 std::vector<QString> MetricManager::dialogForSelectingVolumesForImportedMNITagFile( int number_of_volumes, QString description)
535 {
536  std::vector<QString> data_uid;
537 
538  QDialog selectVolumeDialog;
539  selectVolumeDialog.setWindowTitle("Select volume(s) related to points in MNI Tag Point file.");
540 
541  QVBoxLayout *layout = new QVBoxLayout();
542  QLabel *description_label = new QLabel(description);
543  layout->addWidget(description_label);
544 
545  std::map<int, StringPropertySelectImagePtr> selectedImageProperties;
546  for(int i=0; i < number_of_volumes; ++i)
547  {
548  StringPropertySelectImagePtr image_property = StringPropertySelectImage::New(mPatientModelService);
549  QWidget *widget = createDataWidget(mViewService, mPatientModelService, NULL, image_property);
550  layout->addWidget(widget);
551  selectedImageProperties[i] = image_property;
552  }
553 
554  QPushButton *okButton = new QPushButton(tr("Ok"));
555  layout->addWidget(okButton);
556  connect(okButton, &QAbstractButton::clicked, &selectVolumeDialog, &QWidget::close);
557  selectVolumeDialog.setLayout(layout);
558  selectVolumeDialog.exec();
559  for(int i=0; i < number_of_volumes; ++i)
560  {
561  StringPropertySelectImagePtr image_property = selectedImageProperties[i];
562  data_uid.push_back(image_property->getValue());
563  }
564  return data_uid;
565 }
566 
567 void MetricManager::importMetricsFromMNITagFile(QString &filename, bool testmode)
568 {
569  //--- HACK to be able to read *.tag files with missing newline before eof
570  forceNewlineBeforeEof(filename);
571 
572  //--- Reader for MNI Tag Point files
573  vtkMNITagPointReaderPtr reader = vtkMNITagPointReader::New();
574  reader->SetFileName(filename.toStdString().c_str());
575  reader->Update();
576  if (!ErrorObserver::checkedRead(reader, filename))
577  CX_LOG_ERROR() << "Error reading MNI Tag Point file.";
578 
579 
580  //--- Prompt user to select the volume(s) that is(are) related to the points in the file
581  int number_of_volumes = reader->GetNumberOfVolumes();
582  QString description(reader->GetComments());
583  std::vector<QString> data_uid;
584  data_uid.push_back("");
585  data_uid.push_back("");
586  if(!testmode)
587  data_uid = dialogForSelectingVolumesForImportedMNITagFile(number_of_volumes, description);
588 
589  //--- Create the point metrics
590  QString type = "pointMetric";
591  QString uid = "";
592  QString name = "";
593  vtkStringArray *labels = reader->GetLabelText();
594 
595  for(int i=0; i< number_of_volumes; ++i)
596  {
597  QColor color = getRandomColor();
598 
599  vtkPoints *points = reader->GetPoints(i);
600  if(points != NULL)
601  {
602  unsigned int number_of_points = points->GetNumberOfPoints();
603  //CX_LOG_DEBUG() << "Number of points: " << number_of_points;
604 
605  for(int j=0; j < number_of_points; ++j)
606  {
607  vtkStdString label = labels->GetValue(j);
608  name = QString(*label); //NB: name never used, using j+1 as name to be able to correlate two sets of points from MNI import
609  uid = QDateTime::currentDateTime().toString(timestampMilliSecondsFormat()) + "_" + QString::number(i)+ QString::number(j);
610 
611  double *point = points->GetPoint(j);
612  DataPtr data = this->createData(type, uid, QString::number(j+1));
613  PointMetricPtr point_metric = boost::static_pointer_cast<PointMetric>(data);
614 
615  CoordinateSystem space(csDATA, data_uid[i]);
616  Vector3D vector_ras(point[0], point[1], point[2]);
617  //CX_LOG_DEBUG() << "POINTS: " << vector_ras;
618 
619  //Convert from RAS (MINC) to LPS (CX)
621  Vector3D vector_lps = sMr.inv() * vector_ras;
622 
623  point_metric->setCoordinate(vector_lps);
624  point_metric->setSpace(space);
625  point_metric->setColor(color);
626  }
627  }
628 
629  }
630 }
631 
632 DataPtr MetricManager::loadDataFromXMLNode(QDomElement node)
633 {
634  QString uid = node.toElement().attribute("uid");
635  QString name = node.toElement().attribute("name");
636  QString type = node.toElement().attribute("type");
637 
638  return this->createData(type, uid, name);
639 
640 }
641 
642 DataPtr MetricManager::createData(QString type, QString uid, QString name)
643 {
644  DataPtr data = mPatientModelService->createData(type, uid, name);
645  if (!data)
646  {
647  reportError(QString("Not able to create metric with name: %1, uid: %2, type: %3").arg(name).arg(uid).arg(type));
648  return DataPtr();
649  }
650 
651  if (!name.isEmpty())
652  data->setName(name);
653 
654  mPatientModelService->insertData(data);
655 
656  return data;
657 
658 }
659 
660 
661 } // namespace cx
662 
663 
boost::shared_ptr< class SpaceProvider > SpaceProviderPtr
static void writeXmlFile(QDomDocument &doc, QString &filename)
pcsRAS
Right-Anterior-Superior, used by Slicer3D, ITK-Snap, nifti, MINC.
void reportError(QString msg)
Definition: cxLogger.cpp:92
void exportMetricsToXMLFile(QString &filename)
boost::shared_ptr< class DistanceMetric > DistanceMetricPtr
void addXml(QDomNode &dataNode)
adds xml information about the data and its variabels
Composite widget for string selection.
boost::shared_ptr< class FrameMetric > FrameMetricPtr
Definition: cxFrameMetric.h:44
boost::shared_ptr< class ToolMetric > ToolMetricPtr
Definition: cxToolMetric.h:45
boost::shared_ptr< class DonutMetric > DonutMetricPtr
Transform3D Transform3D
Transform3D is a representation of an affine 3D transform.
boost::shared_ptr< DataMetric > DataMetricPtr
Definition: cxDataMetric.h:94
cxResource_EXPORT Transform3D createTransformFromReferenceToExternal(PATIENT_COORDINATE_SYSTEM external)
boost::shared_ptr< class TrackingService > TrackingServicePtr
QString timestampMilliSecondsFormat()
Definition: cxTime.cpp:43
static SpacePropertyPtr initialize(const QString &uid, QString name, QString help, Space value=Space(), std::vector< Space > range=std::vector< Space >(), QDomNode root=QDomNode())
boost::shared_ptr< class SpaceProperty > SpacePropertyPtr
csREF
the data reference space (r) using LPS (left-posterior-superior) coordinates.
boost::shared_ptr< class SphereMetric > SphereMetricPtr
DistanceMetricPtr addDistance(QString uid="distance%1")
Data class that represents a single frame (transform).
Definition: cxFrameMetric.h:54
boost::shared_ptr< class ViewService > ViewServicePtr
Data class representing a plane.
Definition: cxPlaneMetric.h:69
static CoordinateSystem reference()
MetricManager(ViewServicePtr viewService, PatientModelServicePtr patientModelService, TrackingServicePtr trackingService, SpaceProviderPtr spaceProvider)
boost::shared_ptr< class AngleMetric > AngleMetricPtr
Definition: cxAngleMetric.h:54
csDATA
a datas space (d)
QWidget * createDataWidget(ViewServicePtr viewService, PatientModelServicePtr patientModelService, QWidget *parent, PropertyPtr data, QGridLayout *gridLayout, int row)
Create a widget capable of displaying the input data.
COORDINATE_SYSTEM mId
the type of coordinate system
Data class that represents a donut.
boost::shared_ptr< class PlaneMetric > PlaneMetricPtr
Definition: cxPlaneMetric.h:55
boost::shared_ptr< class Data > DataPtr
void setSelection(std::set< QString > selection)
virtual RegistrationHistoryPtr get_rMd_History()
Definition: cxData.cpp:112
void importMetricsFromMNITagFile(QString &filename, bool testmode=false)
Note: testmode is available to skip dialog popup for running automatic tests.
void reportWarning(QString msg)
Definition: cxLogger.cpp:91
#define CX_LOG_ERROR
Definition: cxLogger.h:120
Data class that represents a custom.
Data class that represents a donut.
boost::shared_ptr< class PatientModelService > PatientModelServicePtr
boost::shared_ptr< class MetricReferenceArgumentList > MetricReferenceArgumentListPtr
DataMetricPtr getMetric(QString uid)
Transform3D createTransformTranslate(const Vector3D &translation)
Identification of a Coordinate system.
QColor getColor()
Data class that represents a distance between two points, or a point and a plane. ...
boost::shared_ptr< class RegionOfInterestMetric > RegionOfInterestMetricPtr
QString mRefObject
for tool, sensor and data we need a object uid to define the coordinate system
boost::shared_ptr< class StringPropertySelectImage > StringPropertySelectImagePtr
Data class that represents a single point.
Definition: cxPointMetric.h:63
void importMetricsFromXMLFile(QString &filename)
Eigen::Vector3d Vector3D
Vector3D is a representation of a point or vector in 3D.
Definition: cxVector3D.h:63
void forceNewlineBeforeEof(QString path)
#define CX_LOG_DEBUG
Definition: cxLogger.h:116
static QDomDocument readXmlFile(QString &filename)
static bool checkedRead(vtkSmartPointer< vtkAlgorithm > reader, QString filename)
PointMetricPtr addPoint(Vector3D point, CoordinateSystem space=CoordinateSystem(csREF), QString uid="point%1", QColor color=QColor(240, 170, 255, 255))
static StringPropertySelectImagePtr New(PatientModelServicePtr patientModelService)
void activeMetricChanged()
void addDistanceButtonClickedSlot()
int getNumberOfMetrics() const
Base class for all Data Metrics.
Definition: cxDataMetric.h:64
boost::shared_ptr< class CustomMetric > CustomMetricPtr
vtkSmartPointer< class vtkMNITagPointReader > vtkMNITagPointReaderPtr
Data class that represents an angle between two lines.
Definition: cxAngleMetric.h:67
void moveToMetric(QString uid)
static CoordinateSystem fromString(QString text)
void reportDebug(QString msg)
Definition: cxLogger.cpp:89
void setActiveUid(QString uid)
Namespace for all CustusX production code.
boost::shared_ptr< class PointMetric > PointMetricPtr
boost::shared_ptr< class Tool > ToolPtr