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