CustusX  2023.01.05-dev+develop.0da12
An IGT application
cxDataMetricWrappers.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) SINTEF Department of Medical Technology.
5 All rights reserved.
6 
7 CustusX is released under a BSD 3-Clause license.
8 
9 See Lisence.txt (https://github.com/SINTEFMedtek/CustusX/blob/master/License.txt) for details.
10 =========================================================================*/
11 #include <cxDataMetricWrappers.h>
12 
13 #include <QTreeWidget>
14 #include <QTreeWidgetItem>
15 #include <QStringList>
16 #include <QVBoxLayout>
17 #include <QHeaderView>
18 
19 #include "cxLogger.h"
20 #include "cxTypeConversions.h"
22 #include "cxTrackingService.h"
23 #include "cxPointMetric.h"
24 #include "cxDistanceMetric.h"
26 #include "cxVector3DWidget.h"
28 #include "cxHelperWidgets.h"
29 #include "cxBaseWidget.h"
30 #include "cxBoolProperty.h"
31 #include "cxSpaceProvider.h"
32 #include "cxPatientModelService.h"
33 #include "cxSpaceEditWidget.h"
34 #include "cxSpaceProperty.h"
35 #include "cxStringListProperty.h"
37 #include "cxVisServices.h"
38 #include "cxImage.h"
39 
40 namespace cx
41 {
42 
44  mServices(services)
45 {
46 }
47 
48 void MetricBase::colorSelected()
49 {
50  this->getData()->setColor(mColorSelector->getValue());
51 }
52 
53 QString MetricBase::getValue() const
54 {
55  QString retval = this->getData()->getValueAsString();
56  if (retval.isEmpty())
57  return "NA";
58  return retval;
59 }
60 
61 void MetricBase::addColorWidget(QVBoxLayout* layout)
62 {
63  mColorSelector = ColorProperty::initialize("color", "Color",
64  "Set color of metric",
65  this->getData()->getColor(), QDomNode());
66  QHBoxLayout* line = new QHBoxLayout;
67  line->addWidget(createDataWidget(mServices->view(), mServices->patient(), NULL, mColorSelector));
68  line->addStretch();
69  line->setMargin(0);
70  layout->addLayout(line);
71  connect(mColorSelector.get(), SIGNAL(valueWasSet()), this, SLOT(colorSelected()));
72 }
73 
74 QWidget *cx::MetricBase::newWidget(QString objectName)
75 {
76  QWidget* widget = new QWidget;
77  widget->setFocusPolicy(Qt::StrongFocus); // needed for help system: focus is used to display help text
78  widget->setObjectName(objectName);
79  return widget;
80 }
81 //---------------------------------------------------------
82 //---------------------------------------------------------
83 //---------------------------------------------------------
84 
86  mServices(services)
87 {
88  mModified = true;
89  mInternalUpdate = false;
90 }
91 
93 {
94  mArguments = arguments;
95  connect(mArguments.get(), SIGNAL(argumentsChanged()), this, SLOT(dataChangedSlot()));
96 }
97 
99 {
100  QString value;
101 
102  mPSelector.resize(mArguments->getCount());
103  for (unsigned i=0; i<mPSelector.size(); ++i)
104  {
105  mPSelector[i] = StringProperty::initialize(QString("p%1").arg(i),
106  QString("p%1").arg(i),
107  mArguments->getDescription(i),
108  mArguments->get(i) ? mArguments->get(i)->getUid() : "",
109  QStringList(),
110  QDomNode());
111 // mPSelector[i]->setDisplayNames(names);
112  layout->addWidget(new LabeledComboBoxWidget(NULL, mPSelector[i]));
113  connect(mPSelector[i].get(), SIGNAL(valueWasSet()), this, SLOT(pointSelected()));
114  }
115 
116  this->dataChangedSlot();
117 }
118 
119 void MetricReferenceArgumentListGui::getAvailableArgumentMetrics(QStringList* uid, std::map<QString,QString>* namemap)
120 {
121  std::map<QString, DataPtr> data = mServices->patient()->getDatas();
122  for (std::map<QString, DataPtr>::iterator iter=data.begin(); iter!=data.end(); ++iter)
123  {
124  if (mArguments->validArgument(iter->second))
125  {
126  *uid << iter->first;
127  (*namemap)[iter->first] = iter->second->getName();
128  }
129  }
130 }
131 
133 {
134  QStringList data;
135  for (unsigned i=0; i<mArguments->getCount(); ++i)
136  data << (mArguments->get(i) ? mArguments->get(i)->getName() : QString("*"));
137  return data.join("-");
138 }
139 
140 void MetricReferenceArgumentListGui::pointSelected()
141 {
142  if (mInternalUpdate)
143  return;
144  for (unsigned i=0; i<mPSelector.size(); ++i)
145  {
146  DataPtr data = mServices->patient()->getData(mPSelector[i]->getValue());
147  if (mArguments->validArgument(data))
148  mArguments->set(i, data);
149  else
150  reportWarning(QString("Failed to set data [%1] in metric, invalid argument.").arg(data?data->getName():"NULL"));
151  }
152 }
153 
154 void MetricReferenceArgumentListGui::dataChangedSlot()
155 {
156 // mModified = true;
157 }
158 
160 {
161  if (!mModified)
162  return;
163  mInternalUpdate = true;
164 
165  QStringList range;
166  std::map<QString,QString> names;
167  this->getAvailableArgumentMetrics(&range, &names);
168 
169  for (unsigned i=0; i<mPSelector.size(); ++i)
170  {
171  if (!mArguments->get(i))
172  continue;
173  mPSelector[i]->setValue(mArguments->get(i)->getUid());
174  mPSelector[i]->setDisplayNames(names);
175  mPSelector[i]->setValueRange(range);
176  }
177 
178  mInternalUpdate = false;
179  mModified = true;
180 }
181 
182 
183 //---------------------------------------------------------
184 //---------------------------------------------------------
185 //---------------------------------------------------------
186 
188  MetricBase(services),
189  mData(data)
190 {
191  mInternalUpdate = false;
192 // connect(mData.get(), SIGNAL(transformChanged()), this, SLOT(dataChangedSlot()));
193 // connect(mPatientModelService.get(), SIGNAL(dataAddedOrRemoved()), this, SLOT(dataChangedSlot()));
194 }
195 
197 {
198 // disconnect(mPatientModelService.get(), SIGNAL(dataAddedOrRemoved()), this, SLOT(dataChangedSlot()));
199 }
200 
202 {
203  QWidget* widget = this->newWidget("point_metric");
204  QVBoxLayout* topLayout = new QVBoxLayout(widget);
205  QHBoxLayout* hLayout = new QHBoxLayout;
206  hLayout->setMargin(0);
207  topLayout->setMargin(0);
208  topLayout->addLayout(hLayout);
209 
210  mSpaceSelector = this->createSpaceSelector();
211  hLayout->addWidget(new SpaceEditWidget(widget, mSpaceSelector));
212 
213  mCoordinate = this->createCoordinateSelector();
214  topLayout->addWidget(Vector3DWidget::createSmallHorizontal(widget, mCoordinate));
215 
216  QWidget* sampleButton = this->createSampleButton(widget);
217  hLayout->addWidget(sampleButton);
218 
219  this->addColorWidget(topLayout);
220  topLayout->addStretch();
221 // this->dataChangedSlot();
222 
223  return widget;
224 }
225 
226 SpacePropertyPtr PointMetricWrapper::createSpaceSelector() const
227 {
228  SpacePropertyPtr retval;
229  retval = SpaceProperty::initialize("selectSpace",
230  "Space",
231  "Select coordinate system to store position in.");
232  connect(retval.get(), SIGNAL(valueWasSet()), this, SLOT(spaceSelected()));
233  retval->setSpaceProvider(mServices->spaceProvider());
234  return retval;
235 }
236 
237 Vector3DPropertyPtr PointMetricWrapper::createCoordinateSelector() const
238 {
239  Vector3DPropertyPtr retval;
240  retval = Vector3DProperty::initialize("selectCoordinate",
241  "Coord",
242  "Coordinate values.",
243  Vector3D(0,0,0),
244  DoubleRange(-1000,1000,1),
245  1,
246  QDomNode());
247 
248  connect(retval.get(), SIGNAL(valueWasSet()), this, SLOT(coordinateChanged()));
249  return retval;
250 }
251 
252 QWidget* PointMetricWrapper::createSampleButton(QWidget* parent) const
253 {
254  QAction* sampleAction = new QAction("Sample", parent);
255  QString sampleTip("Set the position equal to the current tool tip position.");
256  sampleAction->setStatusTip(sampleTip);
257  sampleAction->setWhatsThis(sampleTip);
258  sampleAction->setToolTip(sampleTip);
259  connect(sampleAction, SIGNAL(triggered()), this, SLOT(moveToToolPosition()));
260 
261  CXToolButton* sampleButton = new CXToolButton(parent);
262  sampleButton->setDefaultAction(sampleAction);
263  return sampleButton;
264 }
265 
267 {
268  return mData;
269 }
270 
272 {
273  return "point";
274 }
275 
277 {
278  Vector3D p = mData->getCoordinate();
279  QString coord = prettyFormat(p, 1, 1);
280  if (mData->getSpace().mId==csREF)
281  coord = ""; // ignore display of coord if in ref space
282 
283  return mData->getSpace().toString() + " " + coord;
284 }
285 
286 void PointMetricWrapper::moveToToolPosition()
287 {
288  Vector3D p = mServices->spaceProvider()->getActiveToolTipPoint(mData->getSpace(), true);
289  mData->setCoordinate(p);
290 }
291 
292 void PointMetricWrapper::spaceSelected()
293 {
294  if (mInternalUpdate)
295  return;
296  CoordinateSystem space = mSpaceSelector->getValue();
297  if (!space.isValid())
298  return;
299  mData->setSpace(space);
300 }
301 
302 void PointMetricWrapper::coordinateChanged()
303 {
304  if (mInternalUpdate)
305  return;
306  mData->setCoordinate(mCoordinate->getValue());
307 }
308 
309 //void PointMetricWrapper::dataChangedSlot()
310 //{
311 //}
312 
314 {
315  mInternalUpdate = true;
316  mSpaceSelector->setValue(mData->getSpace());
317  mCoordinate->setValue(mData->getCoordinate());
318  mInternalUpdate = false;
319 }
320 
321 //---------------------------------------------------------
322 //---------------------------------------------------------
323 //---------------------------------------------------------
324 
326  MetricBase(services),
327  mData(data),
328  mArguments(services)
329 {
330  mArguments.setArguments(data->getArguments());
331  mInternalUpdate = false;
332  connect(mData.get(), SIGNAL(transformChanged()), this, SLOT(dataChangedSlot()));
333  connect(mData.get(), SIGNAL(propertiesChanged()), this, SLOT(dataChangedSlot()));
334  connect(mServices->patient().get(), SIGNAL(dataAddedOrRemoved()), this, SLOT(dataChangedSlot()));
335 }
336 
338 {
339  disconnect(mServices->patient().get(), SIGNAL(dataAddedOrRemoved()), this, SLOT(dataChangedSlot()));
340 }
341 
343 {
344  QWidget* widget = this->newWidget("plane_metric");
345  QVBoxLayout* topLayout = new QVBoxLayout(widget);
346  QHBoxLayout* hLayout = new QHBoxLayout;
347  hLayout->setMargin(0);
348  topLayout->setMargin(0);
349  topLayout->addLayout(hLayout);
350 
351  mArguments.addWidgets(hLayout);
352  this->addColorWidget(topLayout);
353  topLayout->addStretch();
354 
355  this->dataChangedSlot();
356 
357  return widget;
358 }
359 
361 {
362  return mData;
363 }
364 
366 {
367  return "plane";
368 }
369 
371 {
372  return mArguments.getAsString();
373 }
374 
375 void PlaneMetricWrapper::dataChangedSlot()
376 {
377 // mInternalUpdate = true;
378  mInternalUpdate = false;
379 }
380 
382 {
383  mArguments.update();
384 }
385 
386 //---------------------------------------------------------
387 //---------------------------------------------------------
388 //---------------------------------------------------------
389 
391  MetricBase(services),
392  mData(data),
393  mArguments(services)
394 {
395  mArguments.setArguments(data->getArguments());
396  mInternalUpdate = false;
397  connect(mData.get(), SIGNAL(transformChanged()), this, SLOT(dataChangedSlot()));
398  connect(mServices->patient().get(), SIGNAL(dataAddedOrRemoved()), this, SLOT(dataChangedSlot()));
399 }
400 
402 {
403  QWidget* widget = this->newWidget("distance_metric");
404  QVBoxLayout* topLayout = new QVBoxLayout(widget);
405  QHBoxLayout* hLayout = new QHBoxLayout;
406  hLayout->setMargin(0);
407  topLayout->setMargin(0);
408  topLayout->addLayout(hLayout);
409 
410  mArguments.addWidgets(hLayout);
411  this->addColorWidget(topLayout);
412  topLayout->addStretch();
413 
414  this->dataChangedSlot();
415  return widget;
416 }
417 
419 {
420  return mData;
421 }
422 
424 {
425  return "distance";
426 }
427 
429 {
430  return mArguments.getAsString();
431 }
432 
433 void DistanceMetricWrapper::dataChangedSlot()
434 {
435 // mInternalUpdate = true;
436  mInternalUpdate = false;
437 }
438 
440 {
441  mArguments.update();
442 }
443 
444 
445 //---------------------------------------------------------
446 //---------------------------------------------------------
447 //---------------------------------------------------------
448 
450  MetricBase(services),
451  mData(data),
452  mArguments(services)
453 {
454  mArguments.setArguments(data->getArguments());
455  mInternalUpdate = false;
456  connect(mData.get(), SIGNAL(transformChanged()), this, SLOT(dataChangedSlot()));
457  connect(mServices->patient().get(), SIGNAL(dataAddedOrRemoved()), this, SLOT(dataChangedSlot()));
458 }
459 
461 {
462  disconnect(mServices->patient().get(), SIGNAL(dataAddedOrRemoved()), this, SLOT(dataChangedSlot()));
463 }
464 
466 {
467  QWidget* widget = this->newWidget("angle_metric");
468  QVBoxLayout* topLayout = new QVBoxLayout(widget);
469  QHBoxLayout* hLayout = new QHBoxLayout;
470  hLayout->setMargin(0);
471  topLayout->setMargin(0);
472  topLayout->addLayout(hLayout);
473 
474  mArguments.addWidgets(hLayout);
475 
476  mUseSimpleVisualization = this->createUseSimpleVisualizationSelector();
477  topLayout->addWidget(createDataWidget(mServices->view(), mServices->patient(), widget, mUseSimpleVisualization));
478 
479  this->addColorWidget(topLayout);
480  topLayout->addStretch();
481 
482  this->dataChangedSlot();
483  return widget;
484 }
485 
487 {
488  return mData;
489 }
491 {
492  return "angle";
493 }
494 
496 {
497  return mArguments.getAsString();
498 }
499 
500 void AngleMetricWrapper::dataChangedSlot()
501 {
502  mInternalUpdate = true;
503  mUseSimpleVisualization->setValue(mData->getUseSimpleVisualization());
504  mInternalUpdate = false;
505 }
506 
507 void AngleMetricWrapper::guiChanged()
508 {
509  if (mInternalUpdate)
510  return;
511  mData->setUseSimpleVisualization(mUseSimpleVisualization->getValue());
512 }
513 
514 BoolPropertyPtr AngleMetricWrapper::createUseSimpleVisualizationSelector() const
515 {
516  BoolPropertyPtr retval;
517  retval = BoolProperty::initialize("Simple Visualization", "",
518  "Simple Visualization",
519  mData->getUseSimpleVisualization());
520 
521  connect(retval.get(), SIGNAL(valueWasSet()), this, SLOT(guiChanged()));
522  return retval;
523 }
524 
526 {
527  mArguments.update();
528 }
529 
530 //---------------------------------------------------------
531 //---------------------------------------------------------
532 //---------------------------------------------------------
533 
535  MetricBase(services),
536  mData(data),
537  mArguments(services)
538 {
539  mArguments.setArguments(data->getArguments());
540  mInternalUpdate = false;
541  connect(mData.get(), SIGNAL(propertiesChanged()), this, SLOT(dataChangedSlot()));
542 }
543 
545 {
546  QWidget* widget = this->newWidget("donut_metric");
547  QVBoxLayout* topLayout = new QVBoxLayout(widget);
548  QHBoxLayout* hLayout = new QHBoxLayout;
549  hLayout->setMargin(0);
550  topLayout->setMargin(0);
551  topLayout->addLayout(hLayout);
552 
553  mArguments.addWidgets(hLayout);
554 
555  mRadius = this->createRadiusSelector();
556  topLayout->addWidget(createDataWidget(mServices->view(), mServices->patient(), widget, mRadius));
557  mThickness = this->createThicknessSelector();
558  topLayout->addWidget(createDataWidget(mServices->view(), mServices->patient(), widget, mThickness));
559  mFlat = this->createFlatSelector();
560  topLayout->addWidget(createDataWidget(mServices->view(), mServices->patient(), widget, mFlat));
561  mHeight = this->createHeightSelector();
562  topLayout->addWidget(createDataWidget(mServices->view(), mServices->patient(), widget, mHeight));
563 
564  this->addColorWidget(topLayout);
565  topLayout->addStretch();
566 
567  this->dataChangedSlot();
568  return widget;
569 }
570 
572 {
573  return mData;
574 }
576 {
577  return "donut";
578 }
579 
581 {
582  return mArguments.getAsString();
583 }
584 
586 {
587  mArguments.update();
588 
589  if (mInternalUpdate)
590  return;
591  mInternalUpdate = true;
592  mRadius->setValue(mData->getRadius());
593  mThickness->setValue(mData->getThickness());
594  mHeight->setValue(mData->getHeight());
595  mFlat->setValue(mData->getFlat());
596  mInternalUpdate = false;
597 }
598 
599 void DonutMetricWrapper::dataChangedSlot()
600 {
601 // if (mInternalUpdate)
602 // return;
603 // mInternalUpdate = true;
604 // mRadius->setValue(mData->getRadius());
605 // mThickness->setValue(mData->getThickness());
606 // mFlat->setValue(mData->getFlat());
607 // mInternalUpdate = false;
608 }
609 
610 void DonutMetricWrapper::guiChanged()
611 {
612  if (mInternalUpdate)
613  return;
614  mInternalUpdate = true;
615  mData->setRadius(mRadius->getValue());
616  mData->setThickness(mThickness->getValue());
617  mData->setHeight(mHeight->getValue());
618  mData->setFlat(mFlat->getValue());
619  mInternalUpdate = false;
620 }
621 
622 
623 DoublePropertyPtr DonutMetricWrapper::createRadiusSelector() const
624 {
625  DoublePropertyPtr retval;
626  retval = DoubleProperty::initialize("selectRadius",
627  "Radius",
628  "Donut Radius",
629  mData->getRadius(),
630  DoubleRange(0, 50, 1),
631  1,
632  QDomNode());
633 
634  connect(retval.get(), SIGNAL(valueWasSet()), this, SLOT(guiChanged()));
635  return retval;
636 }
637 
638 DoublePropertyPtr DonutMetricWrapper::createThicknessSelector() const
639 {
640  DoublePropertyPtr retval;
641  retval = DoubleProperty::initialize("selectThickness",
642  "Thickness",
643  "Donut Thickness",
644  mData->getThickness(),
645  DoubleRange(0.05, 1, 0.05),
646  2,
647  QDomNode());
648 
649  connect(retval.get(), SIGNAL(valueWasSet()), this, SLOT(guiChanged()));
650  return retval;
651 }
652 
653 DoublePropertyPtr DonutMetricWrapper::createHeightSelector() const
654 {
655  DoublePropertyPtr retval;
656  retval = DoubleProperty::initialize("selectHeight",
657  "Height",
658  "Disc height, NA to torus",
659  mData->getHeight(),
660  DoubleRange(0.0, 100, 1),
661  1,
662  QDomNode());
663 
664  connect(retval.get(), SIGNAL(valueWasSet()), this, SLOT(guiChanged()));
665  return retval;
666 }
667 
668 BoolPropertyPtr DonutMetricWrapper::createFlatSelector() const
669 {
670  BoolPropertyPtr retval;
671  retval = BoolProperty::initialize("selectFlat",
672  "Flat",
673  "Flat disk or torus",
674  mData->getFlat(),
675  QDomNode());
676 
677  connect(retval.get(), SIGNAL(valueWasSet()), this, SLOT(guiChanged()));
678  return retval;
679 }
680 //---------------------------------------------------------
681 //---------------------------------------------------------
682 //---------------------------------------------------------
683 
685  MetricBase(services),
686  mData(data),
687  mScaleToP1Widget(NULL),
688  mArguments(services)
689 {
690  mArguments.setArguments(data->getArguments());
691  mInternalUpdate = false;
692  connect(mData.get(), SIGNAL(propertiesChanged()), this, SLOT(dataChangedSlot()));
693 }
694 
696 {
697  QWidget* widget = this->newWidget("custom_metric");
698  QVBoxLayout* topLayout = new QVBoxLayout(widget);
699  QHBoxLayout* hLayout = new QHBoxLayout;
700  hLayout->setMargin(0);
701  topLayout->setMargin(0);
702  topLayout->addLayout(hLayout);
703 
704  mArguments.addWidgets(hLayout);
705 
706  mDefineVectorUpMethod = this->createDefineVectorUpMethodSelector();
707  topLayout->addWidget(createDataWidget(mServices->view(), mServices->patient(), widget, mDefineVectorUpMethod));
708  mModel = this->createModelSelector();
709  topLayout->addWidget(createDataWidget(mServices->view(), mServices->patient(), widget, mModel));
710 
711  mOffsetFromP0 = this->createOffsetFromP0();
712  topLayout->addWidget(createDataWidget(mServices->view(), mServices->patient(), widget, mOffsetFromP0));
713  mOffsetFromP1 = this->createOffsetFromP1();
714  topLayout->addWidget(createDataWidget(mServices->view(), mServices->patient(), widget, mOffsetFromP1));
715  mRepeatDistance = this->createRepeatDistance();
716  topLayout->addWidget(createDataWidget(mServices->view(), mServices->patient(), widget, mRepeatDistance));
717 
718  mShowDistanceMarkers = this->createShowDistanceMarkers();
719  topLayout->addWidget(createDataWidget(mServices->view(), mServices->patient(), widget, mShowDistanceMarkers));
720  mDistanceMarkerVisibility = this->createDistanceMarkerVisibility();
721  mDistanceMarkerVisibilityWidget = createDataWidget(mServices->view(), mServices->patient(), widget, mDistanceMarkerVisibility);
722  topLayout->addWidget(mDistanceMarkerVisibilityWidget);
723 
724  mScaleToP1 = this->createScaletoP1();
725  mScaleToP1Widget = createDataWidget(mServices->view(), mServices->patient(), widget, mScaleToP1);
726  topLayout->addWidget(mScaleToP1Widget);
727 
728  mTranslationOnly= this->createTranslationOnly();
729  topLayout->addWidget(createDataWidget(mServices->view(), mServices->patient(), widget, mTranslationOnly));
730 
731  mTextureFollowTool= this->createTextureFollowTool();
732  topLayout->addWidget(createDataWidget(mServices->view(), mServices->patient(), widget, mTextureFollowTool));
733 
734  this->addColorWidget(topLayout);
735  topLayout->addStretch();
736 
737  this->dataChangedSlot();
738  return widget;
739 }
740 
742 {
743  return mData;
744 }
746 {
747  return "Custom";
748 }
749 
751 {
752  return mArguments.getAsString();
753 }
754 
756 {
757  mArguments.update();
758 
759  if (mInternalUpdate)
760  return;
761  mInternalUpdate = true;
762  mDefineVectorUpMethod->setValue(mData->getDefineVectorUpMethod());
763  mModel->setValue(mData->getModelUid());
764  mInternalUpdate = false;
765  guiChanged();
766 }
767 
768 void CustomMetricWrapper::dataChangedSlot()
769 {
770 // if (mInternalUpdate)
771 // return;
772 // mInternalUpdate = true;
773 // mRadius->setValue(mData->getRadius());
774 // mThickness->setValue(mData->getThickness());
775 // mFlat->setValue(mData->getFlat());
776 // mInternalUpdate = false;
777 }
778 
779 void CustomMetricWrapper::guiChanged()
780 {
781  if (mInternalUpdate)
782  return;
783 
784  if(mModel->getData() && mModel->getData()->getType() == Image::getTypeName())
785  mScaleToP1Widget->setEnabled(false);
786  else
787  mScaleToP1Widget->setEnabled(true);
788 
789  if(mShowDistanceMarkers->getValue())
790  mDistanceMarkerVisibilityWidget->setEnabled(true);
791  else
792  mDistanceMarkerVisibilityWidget->setEnabled(false);
793 
794  mInternalUpdate = true;
795  mData->setDefineVectorUpMethod(mDefineVectorUpMethod->getValue());
796  mData->setModelUid(mModel->getValue());
797  mData->setOffsetFromP0(mOffsetFromP0->getValue());
798  mData->setOffsetFromP1(mOffsetFromP1->getValue());
799  mData->setRepeatDistance(mRepeatDistance->getValue());
800  mData->setScaleToP1(mScaleToP1->getValue());
801  mData->setShowDistanceMarkers(mShowDistanceMarkers->getValue());
802  mData->setDistanceMarkerVisibility(mDistanceMarkerVisibility->getValue());
803  mData->setTranslationOnly(mTranslationOnly->getValue());
804  mData->setTextureFollowTool(mTextureFollowTool->getValue());
805 
806  mInternalUpdate = false;
807 }
808 
809 BoolPropertyPtr CustomMetricWrapper::createScaletoP1() const
810 {
811  BoolPropertyPtr retval;
812  retval = BoolProperty::initialize("Scale to P1", "",
813  "Scale model so that it fits between P0 and P1",
814  mData->getScaleToP1());
815  connect(retval.get(), SIGNAL(valueWasSet()), this, SLOT(guiChanged()));
816  return retval;
817 }
818 
819 BoolPropertyPtr CustomMetricWrapper::createShowDistanceMarkers() const
820 {
821  BoolPropertyPtr retval;
822  retval = BoolProperty::initialize("Show distance markers", "",
823  "Show distance to P0 for each repeated model",
824  mData->getShowDistanceMarkers());
825  connect(retval.get(), SIGNAL(valueWasSet()), this, SLOT(guiChanged()));
826  return retval;
827 }
828 
829 BoolPropertyPtr CustomMetricWrapper::createTranslationOnly() const
830 {
831  BoolPropertyPtr retval;
832  retval = BoolProperty::initialize("Translation Only", "",
833  "Ignore scale and rotate",
834  mData->getTranslationOnly());
835  connect(retval.get(), SIGNAL(valueWasSet()), this, SLOT(guiChanged()));
836  return retval;
837 }
838 
839 BoolPropertyPtr CustomMetricWrapper::createTextureFollowTool() const
840 {
841  BoolPropertyPtr retval;
842  retval = BoolProperty::initialize("Texture Follow Tool", "",
843  "Any texture on the model will move with the tool",
844  mData->getTextureFollowTool());
845  connect(retval.get(), SIGNAL(valueWasSet()), this, SLOT(guiChanged()));
846  return retval;
847 }
848 
849 DoublePropertyPtr CustomMetricWrapper::createOffsetFromP0() const
850 {
851  DoublePropertyPtr retval;
852  retval = DoubleProperty::initialize("Offset from P0", "",
853  "Position model an offset from P0 towards P1",
854  mData->getOffsetFromP0(), DoubleRange(-100, 100, 1), 0);
855  connect(retval.get(), SIGNAL(valueWasSet()), this, SLOT(guiChanged()));
856  return retval;
857 }
858 
859 DoublePropertyPtr CustomMetricWrapper::createOffsetFromP1() const
860 {
861  DoublePropertyPtr retval;
862  retval = DoubleProperty::initialize("Offset from P1", "",
863  "When scaling to P1, scale to a point offset from P1 towards P0",
864  mData->getOffsetFromP1(), DoubleRange(-100, 100, 1), 0);
865  connect(retval.get(), SIGNAL(valueWasSet()), this, SLOT(guiChanged()));
866  return retval;
867 }
868 
869 DoublePropertyPtr CustomMetricWrapper::createRepeatDistance() const
870 {
871  DoublePropertyPtr retval;
872  retval = DoubleProperty::initialize("Repeat Distance", "",
873  "Repeat model with this distance",
874  mData->getRepeatDistance(), DoubleRange(0, 100, 1), 0);
875  connect(retval.get(), SIGNAL(valueWasSet()), this, SLOT(guiChanged()));
876  return retval;
877 }
878 
879 DoublePropertyPtr CustomMetricWrapper::createDistanceMarkerVisibility() const
880 {
881  DoublePropertyPtr retval;
882  retval = DoubleProperty::initialize("Distance markers visibility threshold", "",
883  "Hide the markers if the distance to the camera exceeds this threshold",
884  mData->getDistanceMarkerVisibility(), DoubleRange(0, 1000, 1), 0);
885  connect(retval.get(), SIGNAL(valueWasSet()), this, SLOT(guiChanged()));
886  return retval;
887 }
888 
889 StringPropertyPtr CustomMetricWrapper::createDefineVectorUpMethodSelector() const
890 {
891  StringPropertyPtr retval;
892  retval = StringProperty::initialize("selectDefineVectorUp",
893  "Use to define the vector up",
894  "The vector up of the metric will be connected to one of:\n"
895  "- a) The static up vector of the operating table\n"
896  "- b) To a frame in p1, which might well be connected "
897  "to a tool giving a dynamic up vector.\n"
898  "- c) The tool up (tool negative x)",
899  mData->getDefineVectorUpMethod(),
900  mData->getDefineVectorUpMethods().getAvailableDefineVectorUpMethods(),
901  QDomNode());
902  retval->setDisplayNames(mData->getDefineVectorUpMethods().getAvailableDefineVectorUpMethodsDisplayNames());
903 
904 
905  connect(retval.get(), SIGNAL(valueWasSet()), this, SLOT(guiChanged()));
906  return retval;
907 }
908 
909 StringPropertySelectDataPtr CustomMetricWrapper::createModelSelector() const
910 {
912  retval = StringPropertySelectData::New(mServices->patient(), "image|mesh");
913  retval->setOnly2DImagesFilter(true);
914  retval->setValueName("Model");
915  retval->setHelp("Model can be mesh or 2D image");
916  connect(retval.get(), &StringPropertySelectData::changed, this, &CustomMetricWrapper::guiChanged);
917  return retval;
918 }
919 
920 //---------------------------------------------------------
921 //---------------------------------------------------------
922 //---------------------------------------------------------
923 
925  MetricBase(services),
926  mData(data),
927  mArguments(services)
928 {
929  mArguments.setArguments(data->getArguments());
930  mInternalUpdate = false;
931  connect(mData.get(), SIGNAL(propertiesChanged()), this, SLOT(dataChangedSlot()));
932 }
933 
935 {
936  QWidget* widget = this->newWidget("sphere_metric");
937  QVBoxLayout* topLayout = new QVBoxLayout(widget);
938  QHBoxLayout* hLayout = new QHBoxLayout;
939  hLayout->setMargin(0);
940  topLayout->setMargin(0);
941  topLayout->addLayout(hLayout);
942 
943  mArguments.addWidgets(hLayout);
944 
945  mRadius = this->createRadiusSelector();
946  topLayout->addWidget(createDataWidget(mServices->view(), mServices->patient(), widget, mRadius));
947 
948  this->addColorWidget(topLayout);
949  topLayout->addStretch();
950 
951  this->dataChangedSlot();
952  return widget;
953 }
954 
956 {
957  return mData;
958 }
960 {
961  return "sphere";
962 }
963 
965 {
966  return mArguments.getAsString();
967 }
968 
969 void SphereMetricWrapper::dataChangedSlot()
970 {
971 
972 }
973 
975 {
976  mArguments.update();
977  mInternalUpdate = true;
978  mRadius->setValue(mData->getRadius());
979  mInternalUpdate = false;
980 }
981 
982 void SphereMetricWrapper::guiChanged()
983 {
984  if (mInternalUpdate)
985  return;
986  mData->setRadius(mRadius->getValue());
987 }
988 
989 DoublePropertyPtr SphereMetricWrapper::createRadiusSelector() const
990 {
991  DoublePropertyPtr retval;
992  retval = DoubleProperty::initialize("selectRadius",
993  "Radius",
994  "Sphere Radius",
995  mData->getRadius(),
996  DoubleRange(0, 50, 0.5),
997  1,
998  QDomNode());
999 
1000  connect(retval.get(), SIGNAL(valueWasSet()), this, SLOT(guiChanged()));
1001  return retval;
1002 }
1003 
1004 //---------------------------------------------------------
1005 //---------------------------------------------------------
1006 //---------------------------------------------------------
1007 
1009  MetricBase(services),
1010  mData(data)
1011 {
1012  mInternalUpdate = false;
1013  connect(mData.get(), SIGNAL(propertiesChanged()), this, SLOT(dataChangedSlot()));
1014 }
1015 
1017 {
1018  QWidget* widget = this->newWidget("region_of_interest_metric");
1019  QVBoxLayout* topLayout = new QVBoxLayout(widget);
1020  QHBoxLayout* hLayout = new QHBoxLayout;
1021  hLayout->setMargin(0);
1022  topLayout->setMargin(0);
1023  topLayout->addLayout(hLayout);
1024 
1025  mDataListProperty = this->createDataListProperty();
1026  StringListSelectWidget* datalistwidget = new StringListSelectWidget(widget, mDataListProperty);
1027  topLayout->addWidget(datalistwidget);
1028 
1029  mUseActiveTooltipProperty = this->createUseActiveTooltipSelector();
1030  topLayout->addWidget(createDataWidget(mServices->view(), mServices->patient(), widget, mUseActiveTooltipProperty));
1031 
1032  mMaxBoundsDataProperty = this->createMaxBoundsDataSelector();
1033  topLayout->addWidget(createDataWidget(mServices->view(), mServices->patient(), widget, mMaxBoundsDataProperty));
1034 
1035  mMarginProperty = this->createMarginSelector();
1036  topLayout->addWidget(createDataWidget(mServices->view(), mServices->patient(), widget, mMarginProperty));
1037 
1038  this->addColorWidget(topLayout);
1039  topLayout->addStretch();
1040 
1041  this->dataChangedSlot();
1042  return widget;
1043 }
1044 
1046 {
1047  return mData;
1048 }
1050 {
1051  return "roi";
1052 }
1053 
1055 {
1056  return "";
1057 }
1058 
1059 void RegionOfInterestMetricWrapper::dataChangedSlot()
1060 {
1061 
1062 }
1063 
1064 StringListPropertyPtr RegionOfInterestMetricWrapper::createDataListProperty()
1065 {
1067  "Data",
1068  "Select data to define ROI",
1069  QStringList(),
1070  QStringList());
1071  connect(retval.get(), &Property::changed, this, &RegionOfInterestMetricWrapper::guiChanged);
1072  return retval;
1073 }
1074 
1075 StringPropertyPtr RegionOfInterestMetricWrapper::createMaxBoundsDataSelector()
1076 {
1077  StringPropertyPtr retval;
1078  retval = StringProperty::initialize("max_bounds_data",
1079  "Max Bounds",
1080  "Select data to define maximal extent of ROI",
1081  "",
1082  QStringList(),
1083  QDomNode());
1084  connect(retval.get(), &Property::changed, this, &RegionOfInterestMetricWrapper::guiChanged);
1085  return retval;
1086 }
1087 
1088 DoublePropertyPtr RegionOfInterestMetricWrapper::createMarginSelector() const
1089 {
1090  DoublePropertyPtr retval;
1091  retval = DoubleProperty::initialize("margin",
1092  "Margin",
1093  "Margin added outside the data",
1094  0,
1095  DoubleRange(0, 100, 1),
1096  1,
1097  QDomNode());
1098 
1099  connect(retval.get(), SIGNAL(valueWasSet()), this, SLOT(guiChanged()));
1100  return retval;
1101 }
1102 
1103 BoolPropertyPtr RegionOfInterestMetricWrapper::createUseActiveTooltipSelector() const
1104 {
1105  BoolPropertyPtr retval;
1106  retval = BoolProperty::initialize("Use Tool Tip", "",
1107  "Include tool tip in the roi",
1108  false);
1109 
1110  connect(retval.get(), &Property::changed, this, &RegionOfInterestMetricWrapper::guiChanged);
1111  return retval;
1112 }
1113 
1114 
1116 {
1117  mInternalUpdate = true;
1118 
1119  QStringList data;
1120  std::map<QString, QString> names;
1121  std::map<QString, DataPtr> alldata = mServices->patient()->getDatas();
1122  for (std::map<QString, DataPtr>::iterator i=alldata.begin(); i!=alldata.end(); ++i)
1123  {
1124  if (i->first == mData->getUid())
1125  continue;
1126  data << i->first;
1127  names[i->first] = i->second->getName();
1128  }
1129 
1130  mDataListProperty->setValue(mData->getDataList());
1131  mDataListProperty->setValueRange(data);
1132  mDataListProperty->setDisplayNames(names);
1133 
1134  mMaxBoundsDataProperty->setValue(mData->getMaxBoundsData());
1135  mMaxBoundsDataProperty->setValueRange(data);
1136  mMaxBoundsDataProperty->setDisplayNames(names);
1137 
1138  mMarginProperty->setValue(mData->getMargin());
1139  mUseActiveTooltipProperty->setValue(mData->getUseActiveTooltip());
1140 
1141  mInternalUpdate = false;
1142 }
1143 
1144 void RegionOfInterestMetricWrapper::guiChanged()
1145 {
1146  if (mInternalUpdate)
1147  return;
1148  mData->setDataList(mDataListProperty->getValue());
1149  mData->setUseActiveTooltip(mUseActiveTooltipProperty->getValue());
1150  mData->setMargin(mMarginProperty->getValue());
1151  mData->setMaxBoundsData(mMaxBoundsDataProperty->getValue());
1152 }
1153 
1154 }
virtual QString getArguments() const
static BoolPropertyPtr initialize(const QString &uid, QString name, QString help, bool value, QDomNode root=QDomNode())
boost::shared_ptr< class DistanceMetric > DistanceMetricPtr
void setArguments(MetricReferenceArgumentListPtr arguments)
virtual QString getArguments() const
Composite widget for string selection.
virtual DataMetricPtr getData() const
virtual DataMetricPtr getData() const
virtual QWidget * createWidget()
virtual DataMetricPtr getData() const
boost::shared_ptr< class VisServices > VisServicesPtr
Definition: cxMainWindow.h:40
boost::shared_ptr< class DonutMetric > DonutMetricPtr
boost::shared_ptr< DataMetric > DataMetricPtr
Definition: cxDataMetric.h:73
void addColorWidget(QVBoxLayout *layout)
static StringPropertySelectDataPtr New(PatientModelServicePtr patientModelService, QString typeRegexp=".*")
static SpacePropertyPtr initialize(const QString &uid, QString name, QString help, Space value=Space(), std::vector< Space > range=std::vector< Space >(), QDomNode root=QDomNode())
Utility class for describing a bounded numeric range.
Definition: cxDoubleRange.h:32
Composite widget for string list selection.
CustomMetricWrapper(VisServicesPtr services, CustomMetricPtr data)
virtual QString getType() const
QString prettyFormat(Vector3D val, int decimals, int fieldWidth)
Definition: cxVector3D.cpp:98
boost::shared_ptr< class SpaceProperty > SpacePropertyPtr
csREF
the data reference space (r) using LPS (left-posterior-superior) coordinates.
Definition: cxDefinitions.h:90
boost::shared_ptr< class SphereMetric > SphereMetricPtr
PlaneMetricWrapper(VisServicesPtr services, PlaneMetricPtr data)
virtual DataMetricPtr getData() const =0
virtual DataMetricPtr getData() const
virtual QString getArguments() const
virtual DataMetricPtr getData() const
virtual QWidget * createWidget()
Composite widget for string selection.
boost::shared_ptr< class AngleMetric > AngleMetricPtr
Definition: cxAngleMetric.h:33
SphereMetricWrapper(VisServicesPtr services, SphereMetricPtr data)
virtual QString getType() const
virtual QString getArguments() const
virtual QString getArguments() const
static StringListPropertyPtr initialize(const QString &uid, QString name, QString help, QStringList value, QStringList range, QDomNode root=QDomNode())
QWidget * createDataWidget(ViewServicePtr viewService, PatientModelServicePtr patientModelService, QWidget *parent, PropertyPtr data, QGridLayout *gridLayout, int row)
Create a widget capable of displaying the input data.
ColorPropertyPtr mColorSelector
MetricBase(VisServicesPtr services)
virtual QString getArguments() const
boost::shared_ptr< class PlaneMetric > PlaneMetricPtr
Definition: cxPlaneMetric.h:34
boost::shared_ptr< class Data > DataPtr
boost::shared_ptr< class StringProperty > StringPropertyPtr
virtual QString getType() const
virtual QWidget * createWidget()
static Vector3DWidget * createSmallHorizontal(QWidget *parent, Vector3DPropertyBasePtr data)
virtual QString getType() const
void reportWarning(QString msg)
Definition: cxLogger.cpp:70
static Vector3DPropertyPtr initialize(const QString &uid, QString name, QString help, Vector3D value, DoubleRange range, int decimals, QDomNode root=QDomNode())
virtual QString getType() const
DonutMetricWrapper(VisServicesPtr services, DonutMetricPtr data)
virtual QWidget * createWidget()
boost::shared_ptr< class MetricReferenceArgumentList > MetricReferenceArgumentListPtr
static QString getTypeName()
Definition: cxImage.h:126
AngleMetricWrapper(VisServicesPtr services, AngleMetricPtr data)
PointMetricWrapper(VisServicesPtr services, PointMetricPtr data)
Identification of a Coordinate system.
virtual DataMetricPtr getData() const
boost::shared_ptr< class RegionOfInterestMetric > RegionOfInterestMetricPtr
void changed()
emit when the underlying data value is changed: The user interface will be updated.
static StringPropertyPtr initialize(const QString &uid, QString name, QString help, QString value, QStringList range, QDomNode root=QDomNode())
DistanceMetricWrapper(VisServicesPtr services, DistanceMetricPtr data)
virtual QString getType() const
boost::shared_ptr< class DoubleProperty > DoublePropertyPtr
Eigen::Vector3d Vector3D
Vector3D is a representation of a point or vector in 3D.
Definition: cxVector3D.h:42
boost::shared_ptr< class StringListProperty > StringListPropertyPtr
virtual QWidget * createWidget()
boost::shared_ptr< class Vector3DProperty > Vector3DPropertyPtr
VisServicesPtr mServices
virtual DataMetricPtr getData() const
static DoublePropertyPtr initialize(const QString &uid, QString name, QString help, double value, DoubleRange range, int decimals, QDomNode root=QDomNode())
virtual QString getType() const
RegionOfInterestMetricWrapper(VisServicesPtr services, RegionOfInterestMetricPtr data)
boost::shared_ptr< class StringPropertySelectData > StringPropertySelectDataPtr
static ColorPropertyPtr initialize(const QString &uid, QString name, QString help, QColor value, QDomNode root=QDomNode())
virtual QString getArguments() const
boost::shared_ptr< class BoolProperty > BoolPropertyPtr
MetricReferenceArgumentListGui(VisServicesPtr services)
QWidget * newWidget(QString objectName)
virtual QString getValue() const
virtual QWidget * createWidget()
boost::shared_ptr< class CustomMetric > CustomMetricPtr
virtual DataMetricPtr getData() const
Namespace for all CustusX production code.
boost::shared_ptr< class PointMetric > PointMetricPtr