Fraxinus  17.12
An IGT application
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 "cxSpaceProvider.h"
42 #include "cxSpaceListener.h"
43 #include "cxPatientModelService.h"
44 #include "cxActiveData.h"
45 #include "cxVisServices.h"
46 
47 namespace cx
48 {
49 
50 SamplerWidget::SamplerWidget(TrackingServicePtr trackingService, PatientModelServicePtr patientModelService, SpaceProviderPtr spaceProvider, QWidget* parent) :
51  BaseWidget(parent, "sampler_widget", "Point Sampler"),
52  mPatientModelService(patientModelService),
53  mSpaceProvider(spaceProvider)
54 {
55  this->setToolTip("Display current tool tip position");
56  mListener = spaceProvider->createListener();
57  mListener->setSpace(Space::reference());
58 // mListener.reset(new CoordinateSystemListener(Space(csREF)));
59  connect(mListener.get(), SIGNAL(changed()), this, SLOT(setModified()));
60 
61  mActiveTool = ActiveToolProxy::New(trackingService);
62  connect(mActiveTool.get(), SIGNAL(activeToolChanged(const QString&)), this, SLOT(setModified()));
63  connect(mActiveTool.get(), SIGNAL(toolTransformAndTimestamp(Transform3D, double)), SLOT(setModified()));
64  connect(spaceProvider.get(), &SpaceProvider::spaceAddedOrRemoved, this, &SamplerWidget::spacesChangedSlot);
65 
66  mLayout = new QHBoxLayout(this);
67  mLayout->setMargin(4);
68  mLayout->setSpacing(4);
69 
70  mAdvancedAction = this->createAction(this,
71  QIcon(":/icons/open_icon_library/system-run-5.png"),
72  "Details",
73  "Show Advanced options",
74  SLOT(toggleAdvancedSlot()),
75  mLayout,
76  new CXSmallToolButton());
77 
78  mAdvancedWidget = new QWidget(this);
79  mAdvancedLayout = new QHBoxLayout(mAdvancedWidget);
80  mAdvancedLayout->setMargin(0);
81  mLayout->addWidget(mAdvancedWidget);
82 
83  mSpaceSelector = SpaceProperty::initialize("selectSpace",
84  "Space",
85  "Select coordinate system to store position in.");
86  mSpaceSelector->setSpaceProvider(spaceProvider);
87 
88  connect(mSpaceSelector.get(), &SpaceProperty::valueWasSet, this, &SamplerWidget::spacesChangedSlot);
89  connect(mSpaceSelector.get(), &SpaceProperty::valueWasSet, this, &SamplerWidget::setModified);
90  Space space = Space::fromString(settings()->value("sampler/Space", Space(csREF).toString()).toString());
91  mSpaceSelector->setValue(space);
92  SpaceEditWidget* spaceSelectorWidget = new SpaceEditWidget(this, mSpaceSelector);
93  spaceSelectorWidget->showLabel(false);
94  mAdvancedLayout->addWidget(spaceSelectorWidget);
95  this->spacesChangedSlot();
96 
97  mCoordLineEdit = new QLineEdit(this);
98  mCoordLineEdit->setStyleSheet("QLineEdit { width : 30ex; }"); // enough for "-xxx.x, -xxx.x, -xxx.x - xxxx" plus some slack
99  mCoordLineEdit->setSizePolicy(QSizePolicy::Fixed,
100  mCoordLineEdit->sizePolicy().verticalPolicy());
101  mCoordLineEdit->setReadOnly(true);
102  mLayout->addWidget(mCoordLineEdit);
103 
104  this->showAdvanced();
105  this->setModified();
106 }
107 
109 {}
110 
111 void SamplerWidget::toggleAdvancedSlot()
112 {
113  settings()->setValue("sampler/ShowDetails", !settings()->value("sampler/ShowDetails", "true").toBool());
114  mAdvancedWidget->setVisible(!mAdvancedWidget->isVisible());
115  this->showAdvanced();
116 }
117 
118 void SamplerWidget::showAdvanced()
119 {
120  bool on = settings()->value("sampler/ShowDetails").toBool();
121  mAdvancedWidget->setVisible(on);
122 }
123 
124 void SamplerWidget::spacesChangedSlot()
125 {
126  CoordinateSystem space = mSpaceSelector->getValue();
127  settings()->setValue("sampler/Space", space.toString());
128 
129 // mSpaceSelector->setValueRange(spaceProvider()->getSpacesToPresentInGUI());
130 // mSpaceSelector->setValue(space);
131  mListener->setSpace(space);
132 }
133 
135 {
136  CoordinateSystem space = mSpaceSelector->getValue();
137  Vector3D p = mSpaceProvider->getActiveToolTipPoint(space, true);
138  int w=1;
139  QString coord = QString("%1, %2, %3").arg(p[0], w, 'f', 1).arg(p[1], w, 'f', 1).arg(p[2], w, 'f', 1);
140 
141  ActiveDataPtr activeData = mPatientModelService->getActiveData();
142  ImagePtr image = activeData->getActive<Image>();
143  if (image)
144  {
145  Vector3D p = mSpaceProvider->getActiveToolTipPoint(Space(csDATA_VOXEL,"active"), true);
146  IntBoundingBox3D bb(Eigen::Vector3i(0,0,0),
147  Eigen::Vector3i(image->getBaseVtkImageData()->GetDimensions())-Eigen::Vector3i(1,1,1));
148  if (bb.contains(p.cast<int>()))
149  {
150  double val = image->getBaseVtkImageData()->GetScalarComponentAsFloat(p[0], p[1], p[2], 0);
151  int intVal = val;
152  coord += QString(" I=%1").arg(intVal);
153  }
154  }
155 
156  mCoordLineEdit->setText(coord);
157  mCoordLineEdit->setStatusTip(QString("Position of active tool tip in %1 space\n"
158  "and the intensity of the active volume in that position").arg(space.toString()));
159  mCoordLineEdit->setToolTip(mCoordLineEdit->statusTip());
160 }
161 
162 
163 } // namespace cx
164 
boost::shared_ptr< class SpaceProvider > SpaceProviderPtr
Composite widget for string selection.
std::string toString(T const &value)
converts any type to a string
Definition: catch.hpp:755
Transform3D Transform3D
Transform3D is a representation of an affine 3D transform.
boost::shared_ptr< class TrackingService > TrackingServicePtr
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) using LPS (left-posterior-superior) coordinates.
boost::shared_ptr< class ActiveData > ActiveDataPtr
Definition: cxColorWidget.h:42
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:150
static ActiveToolProxyPtr New(TrackingServicePtr trackingService)
virtual void prePaintEvent()
void setValue(const QString &key, const QVariant &value)
Definition: cxSettings.cpp:79
CoordinateSystem Space
A volumetric data set.
Definition: cxImage.h:66
boost::shared_ptr< class PatientModelService > PatientModelServicePtr
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.
Eigen::Vector3d Vector3D
Vector3D is a representation of a point or vector in 3D.
Definition: cxVector3D.h:63
Interface for QWidget which handles widgets uniformly for the system.
Definition: cxBaseWidget.h:109
SamplerWidget(TrackingServicePtr trackingService, PatientModelServicePtr patientModelService, SpaceProviderPtr spaceProvider, QWidget *parent)
static CoordinateSystem fromString(QString text)
Namespace for all CustusX production code.