diff --git a/Plugins/org.mitk.gui.qt.op41.augmentedreality/CMakeLists.txt b/Plugins/org.mitk.gui.qt.op41.augmentedreality/CMakeLists.txt new file mode 100644 index 0000000000..85a52d87d1 --- /dev/null +++ b/Plugins/org.mitk.gui.qt.op41.augmentedreality/CMakeLists.txt @@ -0,0 +1,9 @@ +# The project name must correspond to the directory name of your plug-in +# and must not contain periods. +project(org_mitk_gui_qt_op41_augmentedreality) + +mitk_create_plugin( + EXPORT_DIRECTIVE OP41_EXPORT + EXPORTED_INCLUDE_SUFFIXES src + MODULE_DEPENDS MitkQtWidgetsExt MitkOpenCVVideoSupport MitkOpenCVVideoSupportUI +) diff --git a/Plugins/org.mitk.gui.qt.op41.augmentedreality/files.cmake b/Plugins/org.mitk.gui.qt.op41.augmentedreality/files.cmake new file mode 100644 index 0000000000..3a1ff7a76b --- /dev/null +++ b/Plugins/org.mitk.gui.qt.op41.augmentedreality/files.cmake @@ -0,0 +1,34 @@ +set(SRC_CPP_FILES + +) + +set(INTERNAL_CPP_FILES + QmitkOP41AugmentedRealityView.cpp + mitkPluginActivator.cpp + ) + +set(UI_FILES + src/internal/QmitkOP41AugmentedRealityViewControls.ui +) + +set(MOC_H_FILES + src/internal/QmitkOP41AugmentedRealityView.h + src/internal/mitkPluginActivator.h +) + +set(CACHED_RESOURCE_FILES + resources/QmitkARModule.png + plugin.xml +) + +set(CPP_FILES + +) + +foreach(file ${SRC_CPP_FILES}) + set(CPP_FILES ${CPP_FILES} src/${file}) +endforeach(file ${SRC_CPP_FILES}) + +foreach(file ${INTERNAL_CPP_FILES}) + set(CPP_FILES ${CPP_FILES} src/internal/${file}) +endforeach(file ${INTERNAL_CPP_FILES}) diff --git a/Plugins/org.mitk.gui.qt.op41.augmentedreality/manifest_headers.cmake b/Plugins/org.mitk.gui.qt.op41.augmentedreality/manifest_headers.cmake new file mode 100644 index 0000000000..1a40703ad5 --- /dev/null +++ b/Plugins/org.mitk.gui.qt.op41.augmentedreality/manifest_headers.cmake @@ -0,0 +1,5 @@ +set(Plugin-Name "OP4.1 Augmented Reality") +set(Plugin-Version "0.1") +set(Plugin-Vendor "DKFZ, Medical and Biological Informatics") +set(Plugin-ContactAddress "http://www.mitk.org") +set(Require-Plugin org.mitk.gui.qt.common) diff --git a/Plugins/org.mitk.gui.qt.op41.augmentedreality/plugin.xml b/Plugins/org.mitk.gui.qt.op41.augmentedreality/plugin.xml new file mode 100644 index 0000000000..0e8ded8869 --- /dev/null +++ b/Plugins/org.mitk.gui.qt.op41.augmentedreality/plugin.xml @@ -0,0 +1,14 @@ + + + + + + + + + + diff --git a/Plugins/org.mitk.gui.qt.op41.augmentedreality/resources/QmitkARModule.png b/Plugins/org.mitk.gui.qt.op41.augmentedreality/resources/QmitkARModule.png new file mode 100644 index 0000000000..cb4a99ec17 Binary files /dev/null and b/Plugins/org.mitk.gui.qt.op41.augmentedreality/resources/QmitkARModule.png differ diff --git a/Plugins/org.mitk.gui.qt.op41.augmentedreality/resources/ReadMe_ChangeIcons.txt b/Plugins/org.mitk.gui.qt.op41.augmentedreality/resources/ReadMe_ChangeIcons.txt new file mode 100644 index 0000000000..bd75a511b3 --- /dev/null +++ b/Plugins/org.mitk.gui.qt.op41.augmentedreality/resources/ReadMe_ChangeIcons.txt @@ -0,0 +1 @@ +If you change icons, please change both - svg and png - as one is needed for the documentation and the other as plugin icon. \ No newline at end of file diff --git a/Plugins/org.mitk.gui.qt.op41.augmentedreality/resources/perspectiveIcon1.png b/Plugins/org.mitk.gui.qt.op41.augmentedreality/resources/perspectiveIcon1.png new file mode 100644 index 0000000000..5ac3609e4f Binary files /dev/null and b/Plugins/org.mitk.gui.qt.op41.augmentedreality/resources/perspectiveIcon1.png differ diff --git a/Plugins/org.mitk.gui.qt.op41.augmentedreality/resources/start_rec.png b/Plugins/org.mitk.gui.qt.op41.augmentedreality/resources/start_rec.png new file mode 100644 index 0000000000..21d034ffe5 Binary files /dev/null and b/Plugins/org.mitk.gui.qt.op41.augmentedreality/resources/start_rec.png differ diff --git a/Plugins/org.mitk.gui.qt.op41.augmentedreality/resources/stop_rec.png b/Plugins/org.mitk.gui.qt.op41.augmentedreality/resources/stop_rec.png new file mode 100644 index 0000000000..2ba96cc1ab Binary files /dev/null and b/Plugins/org.mitk.gui.qt.op41.augmentedreality/resources/stop_rec.png differ diff --git a/Plugins/org.mitk.gui.qt.op41.augmentedreality/src/internal/QmitkOP41AugmentedRealityView.cpp b/Plugins/org.mitk.gui.qt.op41.augmentedreality/src/internal/QmitkOP41AugmentedRealityView.cpp new file mode 100644 index 0000000000..1981e644c1 --- /dev/null +++ b/Plugins/org.mitk.gui.qt.op41.augmentedreality/src/internal/QmitkOP41AugmentedRealityView.cpp @@ -0,0 +1,173 @@ +/*=================================================================== + +The Medical Imaging Interaction Toolkit (MITK) + +Copyright (c) German Cancer Research Center, +Division of Medical and Biological Informatics. +All rights reserved. + +This software is distributed WITHOUT ANY WARRANTY; without +even the implied warranty of MERCHANTABILITY or FITNESS FOR +A PARTICULAR PURPOSE. + +See LICENSE.txt or http://www.mitk.org for details. + +===================================================================*/ + + +// Blueberry +#include +#include + +// Qmitk +#include "QmitkOP41AugmentedRealityView.h" + +#include +#include + +#include +#include + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +const std::string QmitkOP41AugmentedRealityView::VIEW_ID = "org.mitk.views.op41.augmentedreality"; + +QmitkOP41AugmentedRealityView::QmitkOP41AugmentedRealityView(): +QmitkAbstractView(), m_Controls(nullptr) { + additionalVideoBackground = false; +} + +QmitkOP41AugmentedRealityView::~QmitkOP41AugmentedRealityView() {} + +void QmitkOP41AugmentedRealityView::CreateQtPartControl(QWidget *parent) +{ + + if (!m_Controls) + { + // create GUI widget + m_Controls = new Ui::QmitkOP41AugmentedRealityViewControls; + m_Controls->setupUi(parent); + this->CreateConnections(); + } + +} + +void QmitkOP41AugmentedRealityView::CreateConnections() +{ + if (m_Controls) + { + connect((QObject *)(m_Controls->m_PlayVideoButton), SIGNAL(clicked()), (QObject *)this, SLOT(OnStartVideo())); + connect((QObject *)(m_Controls->m_StopVideoButton), SIGNAL(clicked()), (QObject *)this, SLOT(OnStopVideo())); + connect((QObject *)(m_Controls->m_OverlayButton), SIGNAL(clicked()), (QObject *)this, SLOT(OnOverlayStuff())); + connect((QObject *)(m_Controls->m_VideoSearchButton), SIGNAL(clicked()), (QObject *)this, SLOT(OnLoadVideo())); + connect((QObject *)(m_Controls->m_ObjectSearch), SIGNAL(clicked()), (QObject *)this, SLOT(OnLoadObject())); + connect((QObject *)(m_Controls->m_AddViewButton), SIGNAL(clicked()), (QObject *)this, SLOT(OnAddView())); + m_Controls->m_OverlayButton->setVisible(false); + m_Controls->m_AddViewButton->setVisible(false); + } + +} + +void QmitkOP41AugmentedRealityView::SetFocus() +{ + m_Controls->cameraInputButton->setFocus(); + m_Controls->cameraInputButton->setChecked(true); +} + +//############################################################################################### +//############################################################################################### +//############################## Slots of CONFIGURATION step #################################### +//############################################################################################### +//############################################################################################### + +void QmitkOP41AugmentedRealityView::OnStartVideo() +{ + m_RenderWindow = this->GetRenderWindowPart()->GetQmitkRenderWindow("3d"); + m_VideoSource = mitk::OpenCVVideoSource::New(); + + if (m_Controls->cameraInputButton->isChecked()) + {// Set a camera as input + + m_VideoSource->SetVideoCameraInput(-1, true); + m_Controls->m_AddViewButton->setVisible(false); + } + else + {// Set a video file as input + + std::string filename; + filename = videoFileName.toStdString(); + m_VideoSource->SetVideoFileInput(filename.c_str(), true); + m_Controls->m_AddViewButton->setVisible(true); + } + + + // Initialize video source and video background + m_VideoSource->StartCapturing(); + m_VideoBackground = new QmitkVideoBackground(); + m_VideoBackground->SetVideoSource(m_VideoSource); + m_VideoSource->GetVideoTexture(); + m_VideoBackground->AddRenderWindow(m_RenderWindow->GetVtkRenderWindow()); + m_VideoBackground->Enable(); + + if (additionalVideoBackground) + { + m_AdditionalVideoBackground = new QmitkVideoBackground(); + m_AdditionalVideoBackground->SetVideoSource(m_VideoSource); + m_AdditionalVideoBackground->AddRenderWindow(m_AdditionalRenderWindow->GetRenderWindow()); + m_AdditionalVideoBackground->Enable(); + } +} + +void QmitkOP41AugmentedRealityView::OnOverlayStuff() +{ + mitk::DataStorage::Pointer dataStorage = this->GetDataStorage(); + m_RenderWindow->GetRenderer()->SetDataStorage(dataStorage); + mitk::IOUtil::Load(objectName.toStdString(), *dataStorage); + m_RenderWindow->update(); + +} + +void QmitkOP41AugmentedRealityView::OnStopVideo() +{ + m_VideoBackground->Disable(); + if (additionalVideoBackground) + {m_AdditionalVideoBackground->Disable(); } + + m_VideoSource->StopCapturing(); +} + +void QmitkOP41AugmentedRealityView::OnLoadVideo() +{ + videoFileName = QFileDialog::getOpenFileName(nullptr, tr("Browse video"), "/", tr("All files(*.*)")); + m_Controls->m_FilePath->setText(videoFileName); +} + +void QmitkOP41AugmentedRealityView::OnLoadObject() +{ + objectName= QFileDialog::getOpenFileName(nullptr, tr("Browse video"), "/", tr("All files(*.*)")); + m_Controls->m_ObjectPath->setText(objectName); + m_Controls->m_OverlayButton->setVisible(true); +} + +void QmitkOP41AugmentedRealityView::OnAddView() +{ + m_AdditionalRenderWindow = this->GetRenderWindowPart()->GetQmitkRenderWindow("axial");; + m_AdditionalVideoBackground = new QmitkVideoBackground(); + m_AdditionalVideoBackground->SetVideoSource(m_VideoSource); + m_VideoSource->GetVideoTexture(); + m_AdditionalVideoBackground->AddRenderWindow(m_AdditionalRenderWindow->GetVtkRenderWindow()); + m_AdditionalVideoBackground->Enable(); + additionalVideoBackground = true; +} \ No newline at end of file diff --git a/Plugins/org.mitk.gui.qt.op41.augmentedreality/src/internal/QmitkOP41AugmentedRealityView.h b/Plugins/org.mitk.gui.qt.op41.augmentedreality/src/internal/QmitkOP41AugmentedRealityView.h new file mode 100644 index 0000000000..e12d7b522f --- /dev/null +++ b/Plugins/org.mitk.gui.qt.op41.augmentedreality/src/internal/QmitkOP41AugmentedRealityView.h @@ -0,0 +1,90 @@ +/*=================================================================== + +The Medical Imaging Interaction Toolkit (MITK) + +Copyright (c) German Cancer Research Center, +Division of Medical and Biological Informatics. +All rights reserved. + +This software is distributed WITHOUT ANY WARRANTY; without +even the implied warranty of MERCHANTABILITY or FITNESS FOR +A PARTICULAR PURPOSE. + +See LICENSE.txt or http://www.mitk.org for details. + +===================================================================*/ + + +#ifndef QmitkOP41AugmentedRealityView_h +#define QmitkOP41AugmentedRealityView_h + +#include + +#include + +#include "ui_QmitkOP41AugmentedRealityViewControls.h" +#include +#include "mitkOpenCVVideoSource.h" +#include +#include + +/** + * \brief QmitkIGTTutorial shows a small typically navigation MITK view + * + * Any kind of navigation application will start with the connection to a tracking system + * and as we do image guided procedures we want to show something on the screen. In this + * tutorial we connect to the NDI Polaris tracking system (or alternatively use a virtual tracking device) + * and we will show the movement of a tool as cone in the render window part. + * + * \sa also take a look at the CMakeLists.txt of this view to see how to + * link to the mitkIGT library. + */ +class QmitkOP41AugmentedRealityView : public QmitkAbstractView +{ + // this is needed for all Qt objects that should have a MOC object (everything that derives from QObject) + Q_OBJECT + +public: + static const std::string VIEW_ID; + + QmitkOP41AugmentedRealityView(); + virtual ~QmitkOP41AugmentedRealityView(); + + virtual void CreateQtPartControl(QWidget *parent) override; + + /// \brief Creation of the connections of main and control widget + virtual void CreateConnections(); + + virtual void SetFocus() override; + +protected slots: + + /** + * \brief Execute MITK-IGT Tutorial + */ + void OnStartVideo(); + + /** + * \brief stop scene and clean up + */ + void OnStopVideo(); + void OnOverlayStuff(); + void OnLoadVideo(); + void OnLoadObject(); + void OnAddView(); + +protected: + Ui::QmitkOP41AugmentedRealityViewControls *m_Controls; + mitk::OpenCVVideoSource::Pointer m_VideoSource; + //mitk::OpenCVVideoSource::Pointer m_AdditionalVideoSource; + cv::Mat m_currentFrame; + QmitkVideoBackground *m_VideoBackground; + QmitkVideoBackground *m_AdditionalVideoBackground; + QmitkRenderWindow *m_RenderWindow; + QmitkRenderWindow *m_AdditionalRenderWindow; + QString videoFileName; + QString objectName; + bool additionalVideoBackground; +}; + +#endif // QmitkOP41AugmentedRealityView_h diff --git a/Plugins/org.mitk.gui.qt.op41.augmentedreality/src/internal/QmitkOP41AugmentedRealityViewControls.ui b/Plugins/org.mitk.gui.qt.op41.augmentedreality/src/internal/QmitkOP41AugmentedRealityViewControls.ui new file mode 100644 index 0000000000..7e2f21e132 --- /dev/null +++ b/Plugins/org.mitk.gui.qt.op41.augmentedreality/src/internal/QmitkOP41AugmentedRealityViewControls.ui @@ -0,0 +1,145 @@ + + + QmitkOP41AugmentedRealityViewControls + + + + 0 + 0 + 271 + 455 + + + + + 0 + 0 + + + + QmitkTemplate + + + + + + Camera input + + + + + + + Video File input + + + + + + + Video path: + + + + + + + + + + Browse + + + + + + + Object to overlay: + + + + + + + + + + Browse + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + + + + + + + Start video + + + + + + + Add Laparoscopic View + + + + + + + Overlay stuff + + + + + + + Stop video + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + QmitkDataStorageComboBox.h + + + + diff --git a/Plugins/org.mitk.gui.qt.op41.augmentedreality/src/internal/mitkPluginActivator.cpp b/Plugins/org.mitk.gui.qt.op41.augmentedreality/src/internal/mitkPluginActivator.cpp new file mode 100644 index 0000000000..c43a1d5f75 --- /dev/null +++ b/Plugins/org.mitk.gui.qt.op41.augmentedreality/src/internal/mitkPluginActivator.cpp @@ -0,0 +1,36 @@ +/*=================================================================== + +The Medical Imaging Interaction Toolkit (MITK) + +Copyright (c) German Cancer Research Center, +Division of Medical and Biological Informatics. +All rights reserved. + +This software is distributed WITHOUT ANY WARRANTY; without +even the implied warranty of MERCHANTABILITY or FITNESS FOR +A PARTICULAR PURPOSE. + +See LICENSE.txt or http://www.mitk.org for details. + +===================================================================*/ +#include "mitkPluginActivator.h" + +#include "QmitkOP41AugmentedRealityView.h" +#include "QmitkOP41Application.h" +#include "TestPerspective.h" + +namespace mitk { + +void PluginActivator::start(ctkPluginContext* context) +{ + BERRY_REGISTER_EXTENSION_CLASS(QmitkOP41AugmentedRealityView, context) + //BERRY_REGISTER_EXTENSION_CLASS(TestPerspective, context) + //BERRY_REGISTER_EXTENSION_CLASS(QmitkOP41Application,context) +} + +void PluginActivator::stop(ctkPluginContext* context) +{ + Q_UNUSED(context) +} + +} diff --git a/Plugins/org.mitk.gui.qt.op41.augmentedreality/src/internal/mitkPluginActivator.h b/Plugins/org.mitk.gui.qt.op41.augmentedreality/src/internal/mitkPluginActivator.h new file mode 100644 index 0000000000..0db208de1d --- /dev/null +++ b/Plugins/org.mitk.gui.qt.op41.augmentedreality/src/internal/mitkPluginActivator.h @@ -0,0 +1,39 @@ +/*=================================================================== + +The Medical Imaging Interaction Toolkit (MITK) + +Copyright (c) German Cancer Research Center, +Division of Medical and Biological Informatics. +All rights reserved. + +This software is distributed WITHOUT ANY WARRANTY; without +even the implied warranty of MERCHANTABILITY or FITNESS FOR +A PARTICULAR PURPOSE. + +See LICENSE.txt or http://www.mitk.org for details. + +===================================================================*/ +#ifndef MITKPLUGINACTIVATOR_H +#define MITKPLUGINACTIVATOR_H + +#include + +namespace mitk { + +class PluginActivator : + public QObject, public ctkPluginActivator +{ + Q_OBJECT + Q_PLUGIN_METADATA(IID "org_mitk_gui_qt_op41_augmentedreality") + Q_INTERFACES(ctkPluginActivator) + +public: + + void start(ctkPluginContext* context) override; + void stop(ctkPluginContext* context) override; + +}; // PluginActivator + +} + +#endif // MITKPLUGINACTIVATOR_H