Fraxinus  17.12
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) 2008-2014, SINTEF Department of Medical Technology
5 All rights reserved.
6 
7 Redistribution and use in source and binary forms, with or without
8 modification, are permitted provided that the following conditions are met:
9 
10 1. Redistributions of source code must retain the above copyright notice,
11  this list of conditions and the following disclaimer.
12 
13 2. Redistributions in binary form must reproduce the above copyright notice,
14  this list of conditions and the following disclaimer in the documentation
15  and/or other materials provided with the distribution.
16 
17 3. Neither the name of the copyright holder nor the names of its contributors
18  may be used to endorse or promote products derived from this software
19  without specific prior written permission.
20 
21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
25 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 =========================================================================*/
32 
33 #include "cxFrameMetricWrapper.h"
34 
35 #include <QHBoxLayout>
37 #include "cxSpaceProvider.h"
38 #include "cxSpaceEditWidget.h"
39 #include "cxVisServices.h"
40 
41 namespace cx {
42 
44  MetricBase(services),
45  mData(data)
46 {
47  mInternalUpdate = false;
48 }
49 
51 {
52 }
53 
55 {
56  QWidget* widget = this->newWidget("frame_metric");
57  QVBoxLayout* topLayout = new QVBoxLayout(widget);
58  QHBoxLayout* hLayout = new QHBoxLayout;
59  hLayout->setMargin(0);
60  topLayout->setMargin(0);
61  topLayout->addLayout(hLayout);
62 
63  mSpaceSelector = SpaceProperty::initialize("selectSpace",
64  "Space",
65  "Select coordinate system to store position in.");
66  mSpaceSelector->setSpaceProvider(mServices->spaceProvider());
67  hLayout->addWidget(new SpaceEditWidget(widget, mSpaceSelector));
68 
69  mFrameWidget = new Transform3DWidget(widget);
70  connect(mFrameWidget, SIGNAL(changed()), this, SLOT(frameWidgetChangedSlot()));
71  topLayout->addWidget(mFrameWidget);
72 
73  QPushButton* sampleButton = new QPushButton("Sample");
74  sampleButton->setToolTip("Set the position equal to the current tool tip position.");
75  hLayout->addWidget(sampleButton);
76 
77  connect(mSpaceSelector.get(), SIGNAL(valueWasSet()), this, SLOT(spaceSelected()));
78  connect(sampleButton, SIGNAL(clicked()), this, SLOT(moveToToolPosition()));
79 
80  this->addColorWidget(topLayout);
81 
82  return widget;
83 }
84 
86 {
87  return prettyFormat(mData->getRefCoord(), 1, 3);
88 }
89 
91 {
92  return mData;
93 }
94 
96 {
97  return "frame";
98 }
99 
101 {
102  return mData->getSpace().toString();
103 }
104 
105 
106 void FrameMetricWrapper::moveToToolPosition()
107 {
108 // CoordinateSystem ref = CoordinateSystem::reference()
109  Transform3D qMt = mServices->spaceProvider()->getActiveToolTipTransform(mData->getSpace(), true);
110  mData->setFrame(qMt);
111 }
112 
113 void FrameMetricWrapper::spaceSelected()
114 {
115  if (mInternalUpdate)
116  return;
117  CoordinateSystem space = mSpaceSelector->getValue();
118  if (space.isValid())
119  mData->setSpace(space);
120 }
121 
122 void FrameMetricWrapper::frameWidgetChangedSlot()
123 {
124  if (mInternalUpdate)
125  return;
126  Transform3D matrix = mFrameWidget->getMatrix();
127  mData->setFrame(matrix);
128 }
129 
131 {
132  mInternalUpdate = true;
133  mSpaceSelector->setValue(mData->getSpace());
134  mFrameWidget->setMatrix(mData->getFrame());
135  mInternalUpdate = false;
136 }
137 
138 
139 
140 } //namespace cx
Widget for displaying and manipulating an affine matrix, i.e. a rotation+translation matrix...
Composite widget for string selection.
boost::shared_ptr< class FrameMetric > FrameMetricPtr
Definition: cxFrameMetric.h:44
boost::shared_ptr< class VisServices > VisServicesPtr
Definition: cxMainWindow.h:61
Transform3D Transform3D
Transform3D is a representation of an affine 3D transform.
boost::shared_ptr< DataMetric > DataMetricPtr
Definition: cxDataMetric.h:94
void addColorWidget(QVBoxLayout *layout)
static SpacePropertyPtr initialize(const QString &uid, QString name, QString help, Space value=Space(), std::vector< Space > range=std::vector< Space >(), QDomNode root=QDomNode())
QString prettyFormat(Vector3D val, int decimals, int fieldWidth)
Definition: cxVector3D.cpp:119
FrameMetricWrapper(VisServicesPtr services, FrameMetricPtr data)
void setMatrix(const Transform3D &M)
virtual QString getType() const
virtual DataMetricPtr getData() const
virtual QString getArguments() const
virtual QWidget * createWidget()
Identification of a Coordinate system.
virtual QString getValue() const
VisServicesPtr mServices
Transform3D getMatrix() const
QWidget * newWidget(QString objectName)
Namespace for all CustusX production code.