Fraxinus  2023.01.05-dev+develop.0da12
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) SINTEF Department of Medical Technology.
5 All rights reserved.
6 
7 CustusX is released under a BSD 3-Clause license.
8 
9 See Lisence.txt (https://github.com/SINTEFMedtek/CustusX/blob/master/License.txt) for details.
10 =========================================================================*/
11 #include "cxSamplerWidget.h"
12 
14 #include <vtkImageData.h>
15 #include "cxTrackingService.h"
16 #include "cxSpaceEditWidget.h"
17 #include "cxTypeConversions.h"
18 #include "cxSettings.h"
19 #include "cxImage.h"
20 #include "cxSpaceProvider.h"
21 #include "cxSpaceListener.h"
22 #include "cxPatientModelService.h"
23 #include "cxActiveData.h"
24 #include "cxVisServices.h"
25 
26 namespace cx
27 {
28 
29 SamplerWidget::SamplerWidget(TrackingServicePtr trackingService, PatientModelServicePtr patientModelService, SpaceProviderPtr spaceProvider, QWidget* parent) :
30  BaseWidget(parent, "sampler_widget", "Point Sampler"),
31  mPatientModelService(patientModelService),
32  mSpaceProvider(spaceProvider)
33 {
34  this->setToolTip("Display current tool tip position");
35  mListener = spaceProvider->createListener();
36  mListener->setSpace(Space::reference());
37 // mListener.reset(new CoordinateSystemListener(Space(csREF)));
38  connect(mListener.get(), SIGNAL(changed()), this, SLOT(setModified()));
39 
40  mActiveTool = ActiveToolProxy::New(trackingService);
41  connect(mActiveTool.get(), SIGNAL(activeToolChanged(const QString&)), this, SLOT(setModified()));
42  connect(mActiveTool.get(), SIGNAL(toolTransformAndTimestamp(Transform3D, double)), SLOT(setModified()));
43  connect(spaceProvider.get(), &SpaceProvider::spaceAddedOrRemoved, this, &SamplerWidget::spacesChangedSlot);
44 
45  mLayout = new QHBoxLayout(this);
46  mLayout->setMargin(4);
47  mLayout->setSpacing(4);
48 
49  mAdvancedAction = this->createAction(this,
50  QIcon(":/icons/open_icon_library/system-run-5.png"),
51  "Details",
52  "Show Advanced options",
53  SLOT(toggleAdvancedSlot()),
54  mLayout,
55  new CXSmallToolButton());
56 
57  mAdvancedWidget = new QWidget(this);
58  mAdvancedLayout = new QHBoxLayout(mAdvancedWidget);
59  mAdvancedLayout->setMargin(0);
60  mLayout->addWidget(mAdvancedWidget);
61 
62  mSpaceSelector = SpaceProperty::initialize("selectSpace",
63  "Space",
64  "Select coordinate system to store position in.");
65  mSpaceSelector->setSpaceProvider(spaceProvider);
66 
67  connect(mSpaceSelector.get(), &SpaceProperty::valueWasSet, this, &SamplerWidget::spacesChangedSlot);
68  connect(mSpaceSelector.get(), &SpaceProperty::valueWasSet, this, &SamplerWidget::setModified);
69  Space space = Space::fromString(settings()->value("sampler/Space", Space(csREF).toString()).toString());
70  mSpaceSelector->setValue(space);
71  SpaceEditWidget* spaceSelectorWidget = new SpaceEditWidget(this, mSpaceSelector);
72  spaceSelectorWidget->showLabel(false);
73  mAdvancedLayout->addWidget(spaceSelectorWidget);
74  this->spacesChangedSlot();
75 
76  mCoordLineEdit = new QLineEdit(this);
77  mCoordLineEdit->setStyleSheet("QLineEdit { width : 30ex; }"); // enough for "-xxx.x, -xxx.x, -xxx.x - xxxx" plus some slack
78  mCoordLineEdit->setSizePolicy(QSizePolicy::Fixed,
79  mCoordLineEdit->sizePolicy().verticalPolicy());
80  mCoordLineEdit->setReadOnly(true);
81  mLayout->addWidget(mCoordLineEdit);
82 
83  this->showAdvanced();
84  this->setModified();
85 }
86 
88 {}
89 
90 void SamplerWidget::toggleAdvancedSlot()
91 {
92  settings()->setValue("sampler/ShowDetails", !settings()->value("sampler/ShowDetails", "true").toBool());
93  mAdvancedWidget->setVisible(!mAdvancedWidget->isVisible());
94  this->showAdvanced();
95 }
96 
97 void SamplerWidget::showAdvanced()
98 {
99  bool on = settings()->value("sampler/ShowDetails").toBool();
100  mAdvancedWidget->setVisible(on);
101 }
102 
103 void SamplerWidget::spacesChangedSlot()
104 {
105  CoordinateSystem space = mSpaceSelector->getValue();
106  settings()->setValue("sampler/Space", space.toString());
107 
108 // mSpaceSelector->setValueRange(spaceProvider()->getSpacesToPresentInGUI());
109 // mSpaceSelector->setValue(space);
110  mListener->setSpace(space);
111 }
112 
114 {
115  CoordinateSystem space = mSpaceSelector->getValue();
116  Vector3D p = mSpaceProvider->getActiveToolTipPoint(space, true);
117  int w=1;
118  QString coord = QString("%1, %2, %3").arg(p[0], w, 'f', 1).arg(p[1], w, 'f', 1).arg(p[2], w, 'f', 1);
119 
120  ActiveDataPtr activeData = mPatientModelService->getActiveData();
121  ImagePtr image = activeData->getActive<Image>();
122  if (image)
123  {
124  Vector3D p = mSpaceProvider->getActiveToolTipPoint(Space(csDATA_VOXEL,"active"), true);
125  //Vector3D p = mSpaceProvider->getActiveToolTipPoint(Space(csDATA_VOXEL, image->getUid()), true);
126  IntBoundingBox3D bb(Eigen::Vector3i(0,0,0),
127  Eigen::Vector3i(image->getBaseVtkImageData()->GetDimensions())-Eigen::Vector3i(1,1,1));
128  if (bb.contains(p.cast<int>()))
129  {
130  double val = image->getBaseVtkImageData()->GetScalarComponentAsFloat(p[0], p[1], p[2], 0);
131  int intVal = val;
132  coord += QString(" I=%1").arg(intVal);
133  }
134  }
135 
136  mCoordLineEdit->setText(coord);
137  mCoordLineEdit->setStatusTip(QString("Position of active tool tip in %1 space\n"
138  "and the intensity of the active volume in that position").arg(space.toString()));
139  mCoordLineEdit->setToolTip(mCoordLineEdit->statusTip());
140 }
141 
142 
143 } // namespace cx
144 
boost::shared_ptr< class SpaceProvider > SpaceProviderPtr
Composite widget for string selection.
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:27
csDATA_VOXEL
the data voxel space (dv)
Definition: cxDefinitions.h:90
void spaceAddedOrRemoved()
csREF
the data reference space (r) using LPS (left-posterior-superior) coordinates.
Definition: cxDefinitions.h:90
boost::shared_ptr< class ActiveData > ActiveDataPtr
Definition: cxColorWidget.h:21
QVariant value(const QString &key, const QVariant &defaultValue=QVariant()) const
Definition: cxSettings.cpp:66
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)
virtual void prePaintEvent()
void setValue(const QString &key, const QVariant &value)
Definition: cxSettings.cpp:58
CoordinateSystem Space
A volumetric data set.
Definition: cxImage.h:45
boost::shared_ptr< class PatientModelService > PatientModelServicePtr
Identification of a Coordinate system.
Settings * settings()
Shortcut for accessing the settings instance.
Definition: cxSettings.cpp:21
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:42
Interface for QWidget which handles widgets uniformly for the system.
Definition: cxBaseWidget.h:88
SamplerWidget(TrackingServicePtr trackingService, PatientModelServicePtr patientModelService, SpaceProviderPtr spaceProvider, QWidget *parent)
static CoordinateSystem fromString(QString text)
Namespace for all CustusX production code.