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