Medical Imaging Interaction Toolkit  2018.4.99-3e3f1a6e
Medical Imaging Interaction Toolkit
QmitkNPOptitrackWidget.cpp
Go to the documentation of this file.
1 /*============================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
13 #include "QmitkNPOptitrackWidget.h"
14 
17 #include "QmitkIGTCommonHelper.h"
18 
19 #include <QFileDialog>
20 #include <QScrollBar>
21 #include <Poco/Path.h>
22 
23 const std::string QmitkNPOptitrackWidget::VIEW_ID = "org.mitk.views.NPOptitrackWidget";
24 
25 QmitkNPOptitrackWidget::QmitkNPOptitrackWidget(QWidget* parent, Qt::WindowFlags f)
27  , m_Controls(nullptr)
28 {
29 }
30 
32 {
34  CreateQtPartControl(this);
35  CreateConnections();
36 }
37 
39 {
40  delete m_Controls;
41 }
42 
43 void QmitkNPOptitrackWidget::CreateQtPartControl(QWidget *parent)
44 {
45  if (!m_Controls)
46  {
47  // create GUI widgets
48  m_Controls = new Ui::QmitkNPOptitrackWidget;
49  m_Controls->setupUi(parent);
50  }
51 }
52 
53 void QmitkNPOptitrackWidget::CreateConnections()
54 {
55  if (m_Controls)
56  {
57  connect((QObject*)(m_Controls->m_testConnectionOptitrack), SIGNAL(clicked()), this, SLOT(TestConnection()));
58  connect((QObject*)(m_Controls->m_SetOptitrackCalibrationFile), SIGNAL(clicked()), this, SLOT(SetOptitrackCalibrationFileClicked()));
59  }
60 }
61 
63 {
64  m_Controls->m_outputTextOptitrack->setHtml("<body style=\" font-family:\'MS Shell Dlg 2\'; font-size:7pt; font-weight:400; font-style:normal;\" bgcolor=black><span style=\"color:#ffffff;\"><u>output:</u>");
65 }
66 
68 {
69  m_Controls->m_outputTextOptitrack->setHtml(QString(s.c_str()));
70  m_Controls->m_outputTextOptitrack->verticalScrollBar()->setValue(m_Controls->m_outputTextOptitrack->verticalScrollBar()->maximum());
71 }
72 
73 mitk::TrackingDevice::Pointer QmitkNPOptitrackWidget::GetTrackingDevice()
74 {
75  // Create the Tracking Device
76  mitk::OptitrackTrackingDevice::Pointer tempTrackingDevice = mitk::OptitrackTrackingDevice::New();
77  // Set the calibration File
78  tempTrackingDevice->SetCalibrationPath(m_OptitrackCalibrationFile);
79 
80  //Set the camera parameters
81  tempTrackingDevice->SetExp(m_Controls->m_OptitrackExp->value());
82  tempTrackingDevice->SetLed(m_Controls->m_OptitrackLed->value());
83  tempTrackingDevice->SetThr(m_Controls->m_OptitrackThr->value());
84 
86  return static_cast<mitk::TrackingDevice::Pointer>(tempTrackingDevice);
87 }
88 
90 {
91  return mitk::OptitrackTrackingDevice::New()->IsDeviceInstalled();
92 }
93 
95 {
96  std::string filename = QFileDialog::getOpenFileName(nullptr, tr("Open Calibration File"), QmitkIGTCommonHelper::GetLastFileLoadPath(), "*.*").toLatin1().data();
97  if (filename == "") { return; }
98  else
99  {
100  QmitkIGTCommonHelper::SetLastFileLoadPathByFileName(QString::fromStdString(filename));
101  m_OptitrackCalibrationFile = filename;
102  Poco::Path myPath = Poco::Path(m_OptitrackCalibrationFile.c_str());
103  m_Controls->m_OptitrackCalibrationFile->setText("Calibration File: " + QString(myPath.getFileName().c_str()));
104  }
105 }
106 
108 {
109  QmitkNPOptitrackWidget* clonedWidget = new QmitkNPOptitrackWidget(parent);
110  clonedWidget->Initialize();
112  clonedWidget->m_Controls->m_OptitrackCalibrationFile->setText(m_Controls->m_OptitrackCalibrationFile->text());
113 
114  clonedWidget->m_Controls->m_OptitrackExp->setValue(m_Controls->m_OptitrackExp->value());
115  clonedWidget->m_Controls->m_OptitrackLed->setValue(m_Controls->m_OptitrackLed->value());
116  clonedWidget->m_Controls->m_OptitrackThr->setValue(m_Controls->m_OptitrackThr->value());
117  return clonedWidget;
118 }
static const QString GetLastFileLoadPath()
bool IsDeviceInstalled() override
Optional method to investigate if drivers etc for your device are installed. The default value is "tr...
static void SetLastFileLoadPathByFileName(const QString &str)
void ResetOutput() override
Optional method to add output to a small screen in the trackingToolbox (see QmitkNDIPolarisWidget) ...
Ui::QmitkNPOptitrackWidget * m_Controls
void Initialize() override
Subclass must implement this method to return a pointer to a copy of the object. Please don&#39;t forget ...
Implementation of a configuration widget for NP Optitrack Tracking Devices.
QmitkNPOptitrackWidget(QWidget *parent=nullptr, Qt::WindowFlags f=nullptr)
QmitkNPOptitrackWidget * Clone(QWidget *parent) const override
Subclass must implement this method to return a pointer to a copy of the object. Please don&#39;t forget ...
PERSISTENCE_GET_SERVICE_METHOD_MACRO void InitializeSuperclassWidget()
mitk::TrackingDevice::Pointer GetTrackingDevice() override
Abstract class to configure a tracking device. Inherited widgets should be registered in the Microser...
static const std::string VIEW_ID
void AddOutput(std::string s) override
Optional method to add output to a small screen in the trackingToolbox (see QmitkNDIPolarisWidget) ...