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