CustusX  15.8
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  this->setToolTip("Display current tool tip position");
53  mListener = spaceProvider()->createListener();
54  mListener->setSpace(Space::reference());
55 // mListener.reset(new CoordinateSystemListener(Space(csREF)));
56  connect(mListener.get(), SIGNAL(changed()), this, SLOT(setModified()));
57 
58  mActiveTool = ActiveToolProxy::New(trackingService());
59  connect(mActiveTool.get(), SIGNAL(activeToolChanged(const QString&)), this, SLOT(setModified()));
60  connect(mActiveTool.get(), SIGNAL(toolTransformAndTimestamp(Transform3D, double)), SLOT(setModified()));
61  connect(spaceProvider().get(), &SpaceProvider::spaceAddedOrRemoved, this, &SamplerWidget::spacesChangedSlot);
62 
63  mLayout = new QHBoxLayout(this);
64  mLayout->setMargin(4);
65  mLayout->setSpacing(4);
66 
67  mAdvancedAction = this->createAction(this,
68  QIcon(":/icons/open_icon_library/system-run-5.png"),
69  "Details",
70  "Show Advanced options",
71  SLOT(toggleAdvancedSlot()),
72  mLayout,
73  new CXSmallToolButton());
74 
75  mAdvancedWidget = new QWidget(this);
76  mAdvancedLayout = new QHBoxLayout(mAdvancedWidget);
77  mAdvancedLayout->setMargin(0);
78  mLayout->addWidget(mAdvancedWidget);
79 
80  mSpaceSelector = SpaceProperty::initialize("selectSpace",
81  "Space",
82  "Select coordinate system to store position in.");
83  mSpaceSelector->setSpaceProvider(spaceProvider());
84 
85  connect(mSpaceSelector.get(), &SpaceProperty::valueWasSet, this, &SamplerWidget::spacesChangedSlot);
86  connect(mSpaceSelector.get(), &SpaceProperty::valueWasSet, this, &SamplerWidget::setModified);
87  Space space = Space::fromString(settings()->value("sampler/Space", Space(csREF).toString()).toString());
88  mSpaceSelector->setValue(space);
89  SpaceEditWidget* spaceSelectorWidget = new SpaceEditWidget(this, mSpaceSelector);
90  spaceSelectorWidget->showLabel(false);
91  mAdvancedLayout->addWidget(spaceSelectorWidget);
92  this->spacesChangedSlot();
93 
94  mCoordLineEdit = new QLineEdit(this);
95  mCoordLineEdit->setStyleSheet("QLineEdit { width : 30ex; }"); // enough for "-xxx.x, -xxx.x, -xxx.x - xxxx" plus some slack
96  mCoordLineEdit->setSizePolicy(QSizePolicy::Fixed,
97  mCoordLineEdit->sizePolicy().verticalPolicy());
98  mCoordLineEdit->setReadOnly(true);
99  mLayout->addWidget(mCoordLineEdit);
100 
101  this->showAdvanced();
102  this->setModified();
103 }
104 
106 {}
107 
108 void SamplerWidget::toggleAdvancedSlot()
109 {
110  settings()->setValue("sampler/ShowDetails", !settings()->value("sampler/ShowDetails", "true").toBool());
111  mAdvancedWidget->setVisible(!mAdvancedWidget->isVisible());
112  this->showAdvanced();
113 }
114 
115 void SamplerWidget::showAdvanced()
116 {
117  bool on = settings()->value("sampler/ShowDetails").toBool();
118  mAdvancedWidget->setVisible(on);
119 }
120 
121 void SamplerWidget::spacesChangedSlot()
122 {
123  CoordinateSystem space = mSpaceSelector->getValue();
124  settings()->setValue("sampler/Space", space.toString());
125 
126 // mSpaceSelector->setValueRange(spaceProvider()->getSpacesToPresentInGUI());
127 // mSpaceSelector->setValue(space);
128  mListener->setSpace(space);
129 }
130 
132 {
133  CoordinateSystem space = mSpaceSelector->getValue();
134  Vector3D p = spaceProvider()->getActiveToolTipPoint(space, true);
135  int w=1;
136  QString coord = QString("%1, %2, %3").arg(p[0], w, 'f', 1).arg(p[1], w, 'f', 1).arg(p[2], w, 'f', 1);
137 
138  ImagePtr image = patientService()->getActiveImage();
139  if (image)
140  {
141  Vector3D p = spaceProvider()->getActiveToolTipPoint(Space(csDATA_VOXEL,"active"), true);
142  IntBoundingBox3D bb(Eigen::Vector3i(0,0,0),
143  Eigen::Vector3i(image->getBaseVtkImageData()->GetDimensions())-Eigen::Vector3i(1,1,1));
144  if (bb.contains(p.cast<int>()))
145  {
146  double val = image->getBaseVtkImageData()->GetScalarComponentAsFloat(p[0], p[1], p[2], 0);
147  int intVal = val;
148  coord += QString(" I=%1").arg(intVal);
149  }
150  }
151 
152  mCoordLineEdit->setText(coord);
153  mCoordLineEdit->setStatusTip(QString("Position of active tool tip in %1 space\n"
154  "and the intensity of the active volume in that position").arg(space.toString()));
155  mCoordLineEdit->setToolTip(mCoordLineEdit->statusTip());
156 }
157 
158 
159 } // namespace cx
160 
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:87
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:129
static ActiveToolProxyPtr New(TrackingServicePtr trackingService)
void setValue(const QString &key, const QVariant &value)
Definition: cxSettings.cpp:79
CoordinateSystem Space
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()
cxLogicManager_EXPORT TrackingServicePtr trackingService()
static CoordinateSystem fromString(QString text)