CustusX  15.3.3-beta
An IGT application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
cxSamplerWidget.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 "cxSamplerWidget.h"
33 
35 #include <vtkImageData.h>
36 #include "cxTrackingService.h"
37 #include "cxSpaceEditWidget.h"
38 #include "cxTypeConversions.h"
39 #include "cxSettings.h"
40 #include "cxImage.h"
41 #include "cxLegacySingletons.h"
42 #include "cxSpaceProvider.h"
43 #include "cxSpaceListener.h"
44 #include "cxPatientModelService.h"
45 
46 namespace cx
47 {
48 
49 SamplerWidget::SamplerWidget(QWidget* parent) :
50  BaseWidget(parent, "SamplerWidget", "Point Sampler")
51 {
52  mListener = spaceProvider()->createListener();
53  mListener->setSpace(Space::reference());
54 // mListener.reset(new CoordinateSystemListener(Space(csREF)));
55  connect(mListener.get(), SIGNAL(changed()), this, SLOT(setModified()));
56 
57  mActiveTool = ActiveToolProxy::New(trackingService());
58  connect(mActiveTool.get(), SIGNAL(activeToolChanged(const QString&)), this, SLOT(setModified()));
59  connect(mActiveTool.get(), SIGNAL(toolTransformAndTimestamp(Transform3D, double)), SLOT(setModified()));
60  connect(spaceProvider().get(), &SpaceProvider::spaceAddedOrRemoved, this, &SamplerWidget::spacesChangedSlot);
61 
62  mLayout = new QHBoxLayout(this);
63  mLayout->setMargin(4);
64  mLayout->setSpacing(4);
65 
66  mAdvancedAction = this->createAction(this,
67  QIcon(":/icons/open_icon_library/system-run-5.png"),
68  "Details",
69  "Show Advanced options",
70  SLOT(toggleAdvancedSlot()),
71  mLayout,
72  new CXSmallToolButton());
73 
74  mAdvancedWidget = new QWidget(this);
75  mAdvancedLayout = new QHBoxLayout(mAdvancedWidget);
76  mAdvancedLayout->setMargin(0);
77  mLayout->addWidget(mAdvancedWidget);
78 
79  mSpaceSelector = SpaceProperty::initialize("selectSpace",
80  "Space",
81  "Select coordinate system to store position in.");
82  mSpaceSelector->setSpaceProvider(spaceProvider());
83 
84  connect(mSpaceSelector.get(), &SpaceProperty::valueWasSet, this, &SamplerWidget::spacesChangedSlot);
85  connect(mSpaceSelector.get(), &SpaceProperty::valueWasSet, this, &SamplerWidget::setModified);
86  Space space = Space::fromString(settings()->value("sampler/Space", Space(csREF).toString()).toString());
87  mSpaceSelector->setValue(space);
88  SpaceEditWidget* spaceSelectorWidget = new SpaceEditWidget(this, mSpaceSelector);
89  spaceSelectorWidget->showLabel(false);
90  mAdvancedLayout->addWidget(spaceSelectorWidget);
91  this->spacesChangedSlot();
92 
93  mCoordLineEdit = new QLineEdit(this);
94  mCoordLineEdit->setStyleSheet("QLineEdit { width : 30ex; }"); // enough for "-xxx.x, -xxx.x, -xxx.x - xxxx" plus some slack
95  mCoordLineEdit->setSizePolicy(QSizePolicy::Fixed,
96  mCoordLineEdit->sizePolicy().verticalPolicy());
97  mCoordLineEdit->setReadOnly(true);
98  mLayout->addWidget(mCoordLineEdit);
99 
100  this->showAdvanced();
101  this->setModified();
102 }
103 
105 {}
106 
108 {
109  return "<html>"
110  "<h3>Utility for sampling the current tool point</h3>"
111  "<p>Displays the current tool tip position in a selected coordinate system.</p>"
112  "<p><i></i></p>"
113  "</html>";
114 }
115 
116 void SamplerWidget::toggleAdvancedSlot()
117 {
118  settings()->setValue("sampler/ShowDetails", !settings()->value("sampler/ShowDetails", "true").toBool());
119  mAdvancedWidget->setVisible(!mAdvancedWidget->isVisible());
120  this->showAdvanced();
121 }
122 
123 void SamplerWidget::showAdvanced()
124 {
125  bool on = settings()->value("sampler/ShowDetails").toBool();
126  mAdvancedWidget->setVisible(on);
127 }
128 
129 void SamplerWidget::spacesChangedSlot()
130 {
131  CoordinateSystem space = mSpaceSelector->getValue();
132  settings()->setValue("sampler/Space", space.toString());
133 
134 // mSpaceSelector->setValueRange(spaceProvider()->getSpacesToPresentInGUI());
135 // mSpaceSelector->setValue(space);
136  mListener->setSpace(space);
137 }
138 
140 {
141  CoordinateSystem space = mSpaceSelector->getValue();
142  Vector3D p = spaceProvider()->getActiveToolTipPoint(space, true);
143  int w=1;
144  QString coord = QString("%1, %2, %3").arg(p[0], w, 'f', 1).arg(p[1], w, 'f', 1).arg(p[2], w, 'f', 1);
145 
146  ImagePtr image = patientService()->getActiveImage();
147  if (image)
148  {
149  Vector3D p = spaceProvider()->getActiveToolTipPoint(Space(csDATA_VOXEL,"active"), true);
150  IntBoundingBox3D bb(Eigen::Vector3i(0,0,0),
151  Eigen::Vector3i(image->getBaseVtkImageData()->GetDimensions())-Eigen::Vector3i(1,1,1));
152  if (bb.contains(p.cast<int>()))
153  {
154  double val = image->getBaseVtkImageData()->GetScalarComponentAsFloat(p[0], p[1], p[2], 0);
155  int intVal = val;
156  coord += QString(" I=%1").arg(intVal);
157  }
158  }
159 
160  mCoordLineEdit->setText(coord);
161  mCoordLineEdit->setStatusTip(QString("Position of active tool tip in %1 space\n"
162  "and the intensity of the active volume in that position").arg(space.toString()));
163  mCoordLineEdit->setToolTip(mCoordLineEdit->statusTip());
164 }
165 
166 
167 } // namespace cx
168 
Composite widget for string selection.
Transform3D Transform3D
Transform3D is a representation of an affine 3D transform.
static SpacePropertyPtr initialize(const QString &uid, QString name, QString help, Space value=Space(), std::vector< Space > range=std::vector< Space >(), QDomNode root=QDomNode())
boost::shared_ptr< class Image > ImagePtr
Definition: cxDicomWidget.h:48
csDATA_VOXEL
the data voxel space (dv)
void spaceAddedOrRemoved()
csREF
the data reference space (r)
QVariant value(const QString &key, const QVariant &defaultValue=QVariant()) const
Definition: cxSettings.cpp:99
static CoordinateSystem reference()
QAction * createAction(QObject *parent, QIcon iconName, QString text, QString tip, T slot, QLayout *layout=NULL, QToolButton *button=new QToolButton())
Definition: cxBaseWidget.h:130
static ActiveToolProxyPtr New(TrackingServicePtr trackingService)
void setValue(const QString &key, const QVariant &value)
Definition: cxSettings.cpp:91
CoordinateSystem Space
Vector3d coord(const Vector3d &v) const
transform a coordinate [x,y,z,1].
Identification of a Coordinate system.
Settings * settings()
Shortcut for accessing the settings instance.
Definition: cxSettings.cpp:42
Representation of an integer bounding box in 3D. The data are stored as {xmin,xmax,ymin,ymax,zmin,zmax}, in order to simplify communication with vtk.
cxLogicManager_EXPORT SpaceProviderPtr spaceProvider()
Eigen::Vector3d Vector3D
Vector3D is a representation of a point or vector in 3D.
Definition: cxVector3D.h:63
SamplerWidget(QWidget *parent)
Interface for QWidget which handles widgets uniformly for the system.
Definition: cxBaseWidget.h:108
cxLogicManager_EXPORT PatientModelServicePtr patientService()
virtual QString defaultWhatsThis() const
Returns a short description of what this widget will do for you.
cxLogicManager_EXPORT TrackingServicePtr trackingService()
static CoordinateSystem fromString(QString text)