diff --git a/Modules/CppRestSdk/files.cmake b/Modules/CppRestSdk/files.cmake index 470b7ecd25..712619726b 100644 --- a/Modules/CppRestSdk/files.cmake +++ b/Modules/CppRestSdk/files.cmake @@ -1,5 +1,6 @@ file(GLOB_RECURSE H_FILES RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}/include/*") set(CPP_FILES mitkRESTServer.cpp + mitkRESTClient.cpp ) diff --git a/Modules/CppRestSdk/include/mitkRESTServer.h b/Modules/CppRestSdk/include/mitkRESTClient.h similarity index 56% copy from Modules/CppRestSdk/include/mitkRESTServer.h copy to Modules/CppRestSdk/include/mitkRESTClient.h index b3149504cc..fd50d9fd50 100644 --- a/Modules/CppRestSdk/include/mitkRESTServer.h +++ b/Modules/CppRestSdk/include/mitkRESTClient.h @@ -1,64 +1,58 @@ /*=================================================================== 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 MITKRESTSERVER_H -#define MITKRESTSERVER_H +#ifndef MITKRESTCLIENT_H +#define MITKRESTCLIENT_H #include "cpprest/asyncrt_utils.h" #include "cpprest/containerstream.h" #include "cpprest/filestream.h" -#include "cpprest/http_listener.h" +#include "cpprest/http_client.h" #include "cpprest/json.h" #include "cpprest/producerconsumerstream.h" #include "cpprest/uri.h" // hm.. maybe go after that warning at some time? seems like a nasty hack, but works so far :) #pragma warning(disable : 4251) #include "MitkCppRestSdkExports.h" -typedef web::http::experimental::listener::http_listener MitkListener; +typedef web::http::client::http_client MitkClient; typedef web::http::http_request MitkRequest; +typedef web::http::http_response MitkResponse; typedef web::http::methods MitkRESTMethods; +typedef web::http::uri_builder MitkUriBuilder; typedef web::http::status_codes MitkRestStatusCodes; typedef web::json::json_exception MitkJsonException; namespace mitk { - class MITKCPPRESTSDK_EXPORT RESTServer + class MITKCPPRESTSDK_EXPORT RESTClient { - public: - RESTServer(); - RESTServer(utility::string_t url); - virtual ~RESTServer(); + public:; + RESTClient(utility::string_t url); + virtual ~RESTClient(); - pplx::task open() { return m_Listener.open(); } - pplx::task close() { return m_Listener.close(); } + void executeGETRequest(utility::string_t uri); + void executeWADOGET(std::string studyUID, std::string seriesUID, std::string instanceUID); + + private: + MitkClient m_Client; - static std::string convertToUtf8(utility::string_t stringT) { return utility::conversions::to_utf8string(stringT); } - - protected: - virtual void HandleGet(MitkRequest message){}; - virtual void HandlePut(MitkRequest message){}; - virtual void HandlePost(MitkRequest message){}; - virtual void HandleDelete(MitkRequest message){}; - void HandleError(pplx::task &t); - - MitkListener m_Listener; }; }; -#endif // MITKRESTSERVER_H \ No newline at end of file +#endif // MITKRESTCLIENT_H \ No newline at end of file diff --git a/Modules/CppRestSdk/include/mitkRESTServer.h b/Modules/CppRestSdk/include/mitkRESTServer.h index b3149504cc..5228554fc3 100644 --- a/Modules/CppRestSdk/include/mitkRESTServer.h +++ b/Modules/CppRestSdk/include/mitkRESTServer.h @@ -1,64 +1,65 @@ /*=================================================================== 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 MITKRESTSERVER_H #define MITKRESTSERVER_H #include "cpprest/asyncrt_utils.h" #include "cpprest/containerstream.h" #include "cpprest/filestream.h" #include "cpprest/http_listener.h" #include "cpprest/json.h" #include "cpprest/producerconsumerstream.h" #include "cpprest/uri.h" // hm.. maybe go after that warning at some time? seems like a nasty hack, but works so far :) #pragma warning(disable : 4251) #include "MitkCppRestSdkExports.h" typedef web::http::experimental::listener::http_listener MitkListener; typedef web::http::http_request MitkRequest; +typedef web::http::http_response MitkResponse; typedef web::http::methods MitkRESTMethods; typedef web::http::status_codes MitkRestStatusCodes; typedef web::json::json_exception MitkJsonException; namespace mitk { class MITKCPPRESTSDK_EXPORT RESTServer { public: RESTServer(); RESTServer(utility::string_t url); virtual ~RESTServer(); pplx::task open() { return m_Listener.open(); } pplx::task close() { return m_Listener.close(); } static std::string convertToUtf8(utility::string_t stringT) { return utility::conversions::to_utf8string(stringT); } protected: virtual void HandleGet(MitkRequest message){}; virtual void HandlePut(MitkRequest message){}; virtual void HandlePost(MitkRequest message){}; virtual void HandleDelete(MitkRequest message){}; void HandleError(pplx::task &t); MitkListener m_Listener; }; }; #endif // MITKRESTSERVER_H \ No newline at end of file diff --git a/Modules/CppRestSdk/src/mitkRESTClient.cpp b/Modules/CppRestSdk/src/mitkRESTClient.cpp new file mode 100644 index 0000000000..812b1db1af --- /dev/null +++ b/Modules/CppRestSdk/src/mitkRESTClient.cpp @@ -0,0 +1,77 @@ +/*=================================================================== + +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 "mitkRESTClient.h" + +#include + +mitk::RESTClient::RESTClient(utility::string_t url) : m_Client(url) {} + +mitk::RESTClient::~RESTClient() {} + +void mitk::RESTClient::executeGETRequest(utility::string_t uri) +{ + MITK_INFO << "Calling GET with " << utility::conversions::to_utf8string(uri) << " on client " << utility::conversions::to_utf8string(m_Client.base_uri().to_string()); + + auto fileBuffer = std::make_shared>(); + const utility::string_t outputFileName = U("downloadWADO.dcm"); + + concurrency::streams::file_buffer::open(outputFileName, std::ios::out).then([=](concurrency::streams::streambuf outFile) -> pplx::task + { + *fileBuffer = outFile; + + return m_Client.request(MitkRESTMethods::GET, uri); + }) + // Write the response body into the file buffer. + .then([=](MitkResponse response) -> pplx::task + { + printf("Response status code %u returned.\n", response.status_code()); + + return response.body().read_to_end(*fileBuffer); + }) + // Close the file buffer. + .then([=](size_t) + { + return fileBuffer->close(); + }) + // Wait for the entire response body to be written into the file. + .wait(); + + //m_Client.request(MitkRESTMethods::GET, uri).then([=](MitkResponse response) + //{ + + // if (response.status_code() == MitkRestStatusCodes::OK) { + // auto fileStream = std::make_shared(); + // MITK_INFO << "Received response status code: " << response.status_code(); + // response.body().read_to_end(fileStream->streambuf()); + + // return; + // } + + //}); + return; +} + +void mitk::RESTClient::executeWADOGET(std::string studyUID, std::string seriesUID, std::string instanceUID) +{ + MitkUriBuilder builder(U("wado")); + builder.append_query(U("requestType"), U("WADO")); + builder.append_query(U("studyUID"), utility::conversions::to_string_t(studyUID)); + builder.append_query(U("seriesUID"), utility::conversions::to_string_t(seriesUID)); + builder.append_query(U("objectUID"), utility::conversions::to_string_t(instanceUID)); + builder.append_query(U("contentType"), U("application/dicom")); + executeGETRequest(builder.to_string()); +} diff --git a/Plugins/org.mitk.gui.qt.segmentation.rework/CMakeLists.txt b/Plugins/org.mitk.gui.qt.segmentation.rework/CMakeLists.txt index 7e332cbaf7..fb79d2b4b1 100644 --- a/Plugins/org.mitk.gui.qt.segmentation.rework/CMakeLists.txt +++ b/Plugins/org.mitk.gui.qt.segmentation.rework/CMakeLists.txt @@ -1,7 +1,7 @@ project(org_mitk_gui_qt_segmentation_rework) mitk_create_plugin( EXPORT_DIRECTIVE REWORK_EXPORT EXPORTED_INCLUDE_SUFFIXES src - MODULE_DEPENDS MitkQtWidgetsExt MitkCppRestSdk + MODULE_DEPENDS MitkQtWidgetsExt MitkCppRestSdk MitkChart ) diff --git a/Plugins/org.mitk.gui.qt.segmentation.rework/src/internal/SegmentationReworkREST.cpp b/Plugins/org.mitk.gui.qt.segmentation.rework/src/internal/SegmentationReworkREST.cpp index 415911f64a..3c36e598ac 100644 --- a/Plugins/org.mitk.gui.qt.segmentation.rework/src/internal/SegmentationReworkREST.cpp +++ b/Plugins/org.mitk.gui.qt.segmentation.rework/src/internal/SegmentationReworkREST.cpp @@ -1,58 +1,63 @@ /*=================================================================== 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 "SegmentationReworkREST.h" #include SegmentationReworkREST::SegmentationReworkREST(utility::string_t url) : mitk::RESTServer(url) { m_Listener.support(MitkRESTMethods::PUT, std::bind(&SegmentationReworkREST::HandlePut, this, std::placeholders::_1)); } SegmentationReworkREST::~SegmentationReworkREST() {} void SegmentationReworkREST::HandlePut(MitkRequest message) { auto messageString = message.to_string(); MITK_INFO << "Message PUT incoming..."; MITK_INFO << convertToUtf8(messageString); std::string imageSeriesUID = ""; try { auto jsonMessage = message.extract_json().get(); auto messageTypeKey = jsonMessage.at(U("messageType")); if (messageTypeKey.as_string() == U("downloadData")) { auto imageSeriesUIDKey = jsonMessage.at(U("imageSeriesUID")); imageSeriesUID = convertToUtf8(imageSeriesUIDKey.as_string()); MITK_INFO << "value of imageSeriesUID " << imageSeriesUID; // trigger download function } else { message.reply(MitkRestStatusCodes::BadRequest, "Oh man, i can only deal with 'messageType' = 'downloadData'..."); } } catch (MitkJsonException &e) { MITK_ERROR << e.what() << ".. oh man, that was not expected"; + message.reply(MitkRestStatusCodes::BadRequest, "oh man, that was not expected"); + return; } - message.reply(MitkRestStatusCodes::OK, "Sure, i got you.. have an awesome day"); + MitkResponse response(MitkRestStatusCodes::OK); + response.headers().add(U("Access-Control-Allow-Origin"), U("localhost:9000/*")); + response.set_body("Sure, i got you.. have an awesome day"); + message.reply(response); return; -} +} \ No newline at end of file diff --git a/Plugins/org.mitk.gui.qt.segmentation.rework/src/internal/SegmentationReworkREST.h b/Plugins/org.mitk.gui.qt.segmentation.rework/src/internal/SegmentationReworkREST.h index 6e99c20d7d..5418dface2 100644 --- a/Plugins/org.mitk.gui.qt.segmentation.rework/src/internal/SegmentationReworkREST.h +++ b/Plugins/org.mitk.gui.qt.segmentation.rework/src/internal/SegmentationReworkREST.h @@ -1,32 +1,30 @@ /*=================================================================== 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 SegmentationReworkREST_h #define SegmentationReworkREST_h #include class SegmentationReworkREST : public mitk::RESTServer { public: SegmentationReworkREST(utility::string_t url); ~SegmentationReworkREST(); void HandlePut(MitkRequest message); }; - - #endif // SegmentationReworkREST_h \ No newline at end of file diff --git a/Plugins/org.mitk.gui.qt.segmentation.rework/src/internal/SegmentationReworkView.cpp b/Plugins/org.mitk.gui.qt.segmentation.rework/src/internal/SegmentationReworkView.cpp index 70bff2c088..8b208d2ed3 100644 --- a/Plugins/org.mitk.gui.qt.segmentation.rework/src/internal/SegmentationReworkView.cpp +++ b/Plugins/org.mitk.gui.qt.segmentation.rework/src/internal/SegmentationReworkView.cpp @@ -1,111 +1,138 @@ /*=================================================================== 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 "SegmentationReworkView.h" // Qt #include // mitk image #include const std::string SegmentationReworkView::VIEW_ID = "org.mitk.views.segmentationreworkview"; void SegmentationReworkView::SetFocus() { - m_Controls.buttonPerformImageProcessing->setFocus(); + } void SegmentationReworkView::CreateQtPartControl(QWidget *parent) { // create GUI widgets from the Qt Designer's .ui file m_Controls.setupUi(parent); - connect( - m_Controls.buttonPerformImageProcessing, &QPushButton::clicked, this, &SegmentationReworkView::DoImageProcessing); + + connect(m_Controls.buttonUpload, &QPushButton::clicked, this, &SegmentationReworkView::UploadNewSegmentation); + + std::map map; + map.insert(std::map::value_type(0,0.92)); + map.insert(std::map::value_type(1, 0.32)); + map.insert(std::map::value_type(2, 0.52)); + + m_Controls.chartWidget->AddData2D(map, "similarity score"); + m_Controls.chartWidget->SetChartType("similarity score", QmitkChartWidget::ChartType::line); + m_Controls.chartWidget->SetXAxisLabel("slice number"); + m_Controls.chartWidget->SetYAxisLabel("similarity score"); +#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0) + m_Controls.chartWidget->Show(); +#endif + utility::string_t port = U("2020"); utility::string_t address = U("http://127.0.0.1:"); address.append(port); m_HttpHandler = std::unique_ptr(new SegmentationReworkREST(address)); m_HttpHandler->open().wait(); MITK_INFO << "Listening for requests at: " << utility::conversions::to_utf8string(address); + + utility::string_t pacsHost = U("http://193.174.48.78:8090/dcm4chee-arc/aets/DCM4CHEE"); + m_RestClient = new mitk::RESTClient(pacsHost); + + + auto studyUID = "1.2.840.113654.2.70.1.212389164178151513355109725184839174882"; + auto seriesUID = "1.2.276.0.7230010.3.1.3.296485376.9.1536581245.922469"; + auto instanceUID = "1.2.276.0.7230010.3.1.4.296485376.9.1536581245.922470"; + + m_RestClient->executeWADOGET(studyUID, seriesUID, instanceUID); } void SegmentationReworkView::OnSelectionChanged(berry::IWorkbenchPart::Pointer /*source*/, const QList &nodes) { // iterate all selected objects, adjust warning visibility foreach (mitk::DataNode::Pointer node, nodes) { if (node.IsNotNull() && dynamic_cast(node->GetData())) { m_Controls.labelWarning->setVisible(false); - m_Controls.buttonPerformImageProcessing->setEnabled(true); return; } } m_Controls.labelWarning->setVisible(true); - m_Controls.buttonPerformImageProcessing->setEnabled(false); +} + +void SegmentationReworkView::UploadNewSegmentation() +{ + } void SegmentationReworkView::DoImageProcessing() { QList nodes = this->GetDataManagerSelection(); if (nodes.empty()) return; mitk::DataNode *node = nodes.front(); if (!node) { // Nothing selected. Inform the user and return QMessageBox::information(nullptr, "Template", "Please load and select an image before starting image processing."); return; } // here we have a valid mitk::DataNode // a node itself is not very useful, we need its data item (the image) mitk::BaseData *data = node->GetData(); if (data) { // test if this data item is an image or not (could also be a surface or something totally different) mitk::Image *image = dynamic_cast(data); if (image) { std::stringstream message; std::string name; message << "Performing image processing for image "; if (node->GetName(name)) { // a property called "name" was found for this DataNode message << "'" << name << "'"; } message << "."; MITK_INFO << message.str(); // actually do something here... } } } diff --git a/Plugins/org.mitk.gui.qt.segmentation.rework/src/internal/SegmentationReworkView.h b/Plugins/org.mitk.gui.qt.segmentation.rework/src/internal/SegmentationReworkView.h index 36f4b22c5b..566303f2a8 100644 --- a/Plugins/org.mitk.gui.qt.segmentation.rework/src/internal/SegmentationReworkView.h +++ b/Plugins/org.mitk.gui.qt.segmentation.rework/src/internal/SegmentationReworkView.h @@ -1,63 +1,67 @@ /*=================================================================== 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 SegmentationReworkView_h #define SegmentationReworkView_h #include #include #include "ui_SegmentationReworkViewControls.h" #include "SegmentationReworkRest.h" +#include /** \brief SegmentationReworkView \warning This class is not yet documented. Use "git blame" and ask the author to provide basic documentation. \sa QmitkAbstractView \ingroup ${plugin_target}_internal */ class SegmentationReworkView : public QmitkAbstractView { // this is needed for all Qt objects that should have a Qt meta-object // (everything that derives from QObject and wants to have signal/slots) Q_OBJECT public: static const std::string VIEW_ID; protected: virtual void CreateQtPartControl(QWidget *parent) override; virtual void SetFocus() override; /// \brief called by QmitkFunctionality when DataManager's selection has changed virtual void OnSelectionChanged(berry::IWorkbenchPart::Pointer source, const QList &nodes) override; /// \brief Called when the user clicks the GUI button void DoImageProcessing(); + void UploadNewSegmentation(); + Ui::SegmentationReworkViewControls m_Controls; private: std::unique_ptr m_HttpHandler; + mitk::RESTClient* m_RestClient; }; #endif // SegmentationReworkView_h diff --git a/Plugins/org.mitk.gui.qt.segmentation.rework/src/internal/SegmentationReworkViewControls.ui b/Plugins/org.mitk.gui.qt.segmentation.rework/src/internal/SegmentationReworkViewControls.ui index b33e4d5ba6..55f1d26631 100644 --- a/Plugins/org.mitk.gui.qt.segmentation.rework/src/internal/SegmentationReworkViewControls.ui +++ b/Plugins/org.mitk.gui.qt.segmentation.rework/src/internal/SegmentationReworkViewControls.ui @@ -1,64 +1,126 @@ SegmentationReworkViewControls 0 0 - 222 - 161 + 465 + 673 0 0 QmitkTemplate + + true + QLabel { color: rgb(255, 0, 0) } Please select an image! - + + + Segmentation A: + + + + + + + Segmentation B: + + + + + + + ground truth: + + + + + + + Qt::Horizontal + + + + + + + + 0 + 300 + + + + + 16777215 + 300 + + + + + + + + Qt::Horizontal + + + + + Do image processing - Do Something + Upload new Segmentation C Qt::Vertical QSizePolicy::Expanding 20 220 + + + QmitkChartWidget + QWidget +
QmitkChartWidget.h
+ 1 +
+