NorMIT-nav  2023.01.05-dev+develop.0da12
An IGT application
cxFrameMetricWrapper.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 
12 #include "cxFrameMetricWrapper.h"
13 
14 #include <QHBoxLayout>
16 #include "cxSpaceProvider.h"
17 #include "cxSpaceEditWidget.h"
18 #include "cxVisServices.h"
19 
20 namespace cx {
21 
23  MetricBase(services),
24  mData(data)
25 {
26  mInternalUpdate = false;
27 }
28 
30 {
31 }
32 
34 {
35  QWidget* widget = this->newWidget("frame_metric");
36  QVBoxLayout* topLayout = new QVBoxLayout(widget);
37  QHBoxLayout* hLayout = new QHBoxLayout;
38  hLayout->setMargin(0);
39  topLayout->setMargin(0);
40  topLayout->addLayout(hLayout);
41 
42  mSpaceSelector = SpaceProperty::initialize("selectSpace",
43  "Space",
44  "Select coordinate system to store position in.");
45  mSpaceSelector->setSpaceProvider(mServices->spaceProvider());
46  hLayout->addWidget(new SpaceEditWidget(widget, mSpaceSelector));
47 
48  mFrameWidget = new Transform3DWidget(widget);
49  connect(mFrameWidget, SIGNAL(changed()), this, SLOT(frameWidgetChangedSlot()));
50  topLayout->addWidget(mFrameWidget);
51 
52  QPushButton* sampleButton = new QPushButton("Sample");
53  sampleButton->setToolTip("Set the position equal to the current tool tip position.");
54  hLayout->addWidget(sampleButton);
55 
56  connect(mSpaceSelector.get(), SIGNAL(valueWasSet()), this, SLOT(spaceSelected()));
57  connect(sampleButton, SIGNAL(clicked()), this, SLOT(moveToToolPosition()));
58 
59  this->addColorWidget(topLayout);
60 
61  return widget;
62 }
63 
65 {
66  return prettyFormat(mData->getRefCoord(), 1, 3);
67 }
68 
70 {
71  return mData;
72 }
73 
75 {
76  return "frame";
77 }
78 
80 {
81  return mData->getSpace().toString();
82 }
83 
84 
85 void FrameMetricWrapper::moveToToolPosition()
86 {
87 // CoordinateSystem ref = CoordinateSystem::reference()
88  Transform3D qMt = mServices->spaceProvider()->getActiveToolTipTransform(mData->getSpace(), true);
89  mData->setFrame(qMt);
90 }
91 
92 void FrameMetricWrapper::spaceSelected()
93 {
94  if (mInternalUpdate)
95  return;
96  CoordinateSystem space = mSpaceSelector->getValue();
97  if (space.isValid())
98  mData->setSpace(space);
99 }
100 
101 void FrameMetricWrapper::frameWidgetChangedSlot()
102 {
103  if (mInternalUpdate)
104  return;
105  Transform3D matrix = mFrameWidget->getMatrix();
106  mData->setFrame(matrix);
107 }
108 
110 {
111  mInternalUpdate = true;
112  mSpaceSelector->setValue(mData->getSpace());
113  mFrameWidget->setMatrix(mData->getFrame());
114  mInternalUpdate = false;
115 }
116 
117 
118 
119 } //namespace cx
cx::FrameMetricWrapper::FrameMetricWrapper
FrameMetricWrapper(VisServicesPtr services, FrameMetricPtr data)
Definition: cxFrameMetricWrapper.cpp:22
cx::FrameMetricPtr
boost::shared_ptr< class FrameMetric > FrameMetricPtr
Definition: cxFrameMetric.h:23
cx::Transform3DWidget
Widget for displaying and manipulating an affine matrix, i.e. a rotation+translation matrix.
Definition: cxTransform3DWidget.h:38
cx
Namespace for all CustusX production code.
Definition: cx_dev_group_definitions.h:13
cx::MetricBase
Definition: cxDataMetricWrappers.h:53
cx::DataMetricPtr
boost::shared_ptr< DataMetric > DataMetricPtr
Definition: cxDataMetric.h:73
cx::VisServicesPtr
boost::shared_ptr< class VisServices > VisServicesPtr
Definition: cxMainWindow.h:40
cxLabeledComboBoxWidget.h
cxFrameMetricWrapper.h
cx::SpaceProperty::initialize
static SpacePropertyPtr initialize(const QString &uid, QString name, QString help, Space value=Space(), std::vector< Space > range=std::vector< Space >(), QDomNode root=QDomNode())
Definition: cxSpaceProperty.cpp:30
cx::FrameMetricWrapper::createWidget
virtual QWidget * createWidget()
Definition: cxFrameMetricWrapper.cpp:33
cx::Transform3D
Transform3D Transform3D
Transform3D is a representation of an affine 3D transform.
Definition: cxLandmarkPatientRegistrationWidget.h:33
cx::FrameMetricWrapper::getData
virtual DataMetricPtr getData() const
Definition: cxFrameMetricWrapper.cpp:69
cx::MetricBase::newWidget
QWidget * newWidget(QString objectName)
Definition: cxDataMetricWrappers.cpp:74
cx::FrameMetricWrapper::~FrameMetricWrapper
virtual ~FrameMetricWrapper()
Definition: cxFrameMetricWrapper.cpp:29
cx::FrameMetricWrapper::update
virtual void update()
Definition: cxFrameMetricWrapper.cpp:109
cx::MetricBase::addColorWidget
void addColorWidget(QVBoxLayout *layout)
Definition: cxDataMetricWrappers.cpp:61
cx::Transform3DWidget::setMatrix
void setMatrix(const Transform3D &M)
Definition: cxTransform3DWidget.cpp:267
cx::FrameMetricWrapper::getValue
virtual QString getValue() const
Definition: cxFrameMetricWrapper.cpp:64
cx::Transform3DWidget::getMatrix
Transform3D getMatrix() const
Definition: cxTransform3DWidget.cpp:272
cx::FrameMetricWrapper::getType
virtual QString getType() const
Definition: cxFrameMetricWrapper.cpp:74
cx::FrameMetricWrapper::getArguments
virtual QString getArguments() const
Definition: cxFrameMetricWrapper.cpp:79
cx::SpaceEditWidget
Composite widget for string selection.
Definition: cxSpaceEditWidget.h:35
cxSpaceEditWidget.h
cxSpaceProvider.h
cx::MetricBase::mServices
VisServicesPtr mServices
Definition: cxDataMetricWrappers.h:72
cx::prettyFormat
QString prettyFormat(Vector3D val, int decimals, int fieldWidth)
Definition: cxVector3D.cpp:98
cxVisServices.h