diff --git a/Modules/CppRestSdk/include/mitkRESTClient.h b/Modules/CppRestSdk/include/mitkRESTClient.h index f6fa93ea41..2e989c21d7 100644 --- a/Modules/CppRestSdk/include/mitkRESTClient.h +++ b/Modules/CppRestSdk/include/mitkRESTClient.h @@ -1,65 +1,62 @@ /*=================================================================== 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 MITKRESTCLIENT_H #define MITKRESTCLIENT_H #include "cpprest/asyncrt_utils.h" #include "cpprest/containerstream.h" #include "cpprest/filestream.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::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 RESTClient { public:; RESTClient(utility::string_t url); virtual ~RESTClient(); pplx::task Post(utility::string_t uri, utility::string_t contentType, concurrency::streams::basic_istream fileStream); pplx::task Post(utility::string_t uri, utility::string_t contentType, utility::string_t filePath); pplx::task Get(const utility::string_t filePath, utility::string_t uri); pplx::task WadoRS(const utility::string_t filePath, std::string studyUID, std::string seriesUID, std::string instanceUID); pplx::task WadoRS(const utility::string_t filePath, std::string studyUID, std::string seriesUID); pplx::task StowRS(utility::string_t filePath, std::string studyUID); private: - MitkClient m_Client; + MitkClient* m_Client; }; }; #endif // MITKRESTCLIENT_H diff --git a/Modules/CppRestSdk/include/mitkRESTServer.h b/Modules/CppRestSdk/include/mitkRESTServer.h index 1bb89f6d2c..b51a07a4dc 100644 --- a/Modules/CppRestSdk/include/mitkRESTServer.h +++ b/Modules/CppRestSdk/include/mitkRESTServer.h @@ -1,68 +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. ===================================================================*/ #ifndef MITKRESTSERVER_H #define MITKRESTSERVER_H #include #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 QObject { 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 diff --git a/Modules/CppRestSdk/include/mitkRESTUtil.h b/Modules/CppRestSdk/include/mitkRESTUtil.h new file mode 100644 index 0000000000..24cba4c452 --- /dev/null +++ b/Modules/CppRestSdk/include/mitkRESTUtil.h @@ -0,0 +1,38 @@ +/*=================================================================== + +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 MITKRESTUTIL_H +#define MITKRESTUTIL_H + +#include "MitkCppRestSdkExports.h" + +#include +#include "cpprest/asyncrt_utils.h" + +namespace mitk +{ + class MITKCPPRESTSDK_EXPORT RESTUtil + { + + public: + + static std::string convertToUtf8(utility::string_t stringT) { return utility::conversions::to_utf8string(stringT); } + static utility::string_t convertToTString(std::string string) { return utility::conversions::to_string_t(string); } + + }; +}; + +#endif // MITKRESTUTIL_H diff --git a/Modules/CppRestSdk/src/mitkRESTClient.cpp b/Modules/CppRestSdk/src/mitkRESTClient.cpp index 6004f4ddae..ee568a7307 100644 --- a/Modules/CppRestSdk/src/mitkRESTClient.cpp +++ b/Modules/CppRestSdk/src/mitkRESTClient.cpp @@ -1,209 +1,214 @@ /*=================================================================== 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 "mitkRestUtil.h" #include #include -mitk::RESTClient::RESTClient(utility::string_t url) : m_Client(url) { +mitk::RESTClient::RESTClient(utility::string_t url) +{ + m_Client = new MitkClient(url); } -mitk::RESTClient::~RESTClient() {} +mitk::RESTClient::~RESTClient() +{ + delete m_Client; +} pplx::task mitk::RESTClient::Get(utility::string_t filePath, utility::string_t uri) { MITK_DEBUG << "Calling GET with " << utility::conversions::to_utf8string(uri) << " on client " - << utility::conversions::to_utf8string(m_Client.base_uri().to_string()) << " save into " - << utility::conversions::to_utf8string(filePath); + << mitk::RESTUtil::convertToUtf8(m_Client->base_uri().to_string()) << " save into " + << mitk::RESTUtil::convertToUtf8(filePath); auto fileBuffer = std::make_shared>(); return concurrency::streams::file_buffer::open(filePath, std::ios::out).then([=](concurrency::streams::streambuf outFile) -> pplx::task { *fileBuffer = outFile; - return m_Client.request(MitkRESTMethods::GET, uri); + return m_Client->request(MitkRESTMethods::GET, uri); }) // Write the response body into the file buffer. .then([=](MitkResponse response) -> pplx::task { MITK_DEBUG << "Status code: " << response.status_code(); return response.body().read_to_end(*fileBuffer); }) // Close the file buffer. .then([=](size_t) { return fileBuffer->close(); }); } pplx::task mitk::RESTClient::Post(utility::string_t uri, utility::string_t contentType, concurrency::streams::basic_istream fileStream) { - MITK_INFO << "Calling POST with " << utility::conversions::to_utf8string(uri) << " on client " - << utility::conversions::to_utf8string(m_Client.base_uri().to_string()); + MITK_INFO << "Calling POST with " << mitk::RESTUtil::convertToUtf8(uri) << " on client " + << mitk::RESTUtil::convertToUtf8(m_Client->base_uri().to_string()); // currently not working, but stream approach may be useful for later.. don't use string streams for dcm files... concurrency::streams::container_buffer inStringBuffer; return fileStream.read(inStringBuffer, fileStream.streambuf().size()).then([=](size_t bytesRead) -> pplx::task { const std::string &text = inStringBuffer.collection(); std::string body = ""; body += "\r\n--boundary"; - body += "\r\nContentType: " + utility::conversions::to_utf8string("application/dicom") + "\r\n\r\n"; + body += "\r\nContentType: " + mitk::RESTUtil::convertToUtf8(L"application/dicom") + "\r\n\r\n"; body += text; body += "\r\n--boundary--"; auto utf8String = utility::conversions::to_utf8string(body); auto binaryVector = std::vector(utf8String.begin(), utf8String.end()); MitkRequest postRequest(MitkRESTMethods::POST); postRequest.set_request_uri(uri); postRequest.headers().add(U("Content-Type"), contentType); postRequest.set_body(binaryVector); - MITK_INFO << "Request: " << utility::conversions::to_utf8string(postRequest.to_string()); + MITK_INFO << "Request: " << mitk::RESTUtil::convertToUtf8(postRequest.to_string()); - return m_Client.request(postRequest).then([fileStream](MitkResponse response) + return m_Client->request(postRequest).then([fileStream](MitkResponse response) { fileStream.close(); - MITK_INFO << "Response: " << utility::conversions::to_utf8string(response.to_string()); + MITK_INFO << "Response: " << mitk::RESTUtil::convertToUtf8(response.to_string()); }); }); } pplx::task mitk::RESTClient::Post(utility::string_t uri, utility::string_t contentType, utility::string_t filePath) { // this is the working stow-rs request which supports just one dicom file packed into a multipart message std::basic_ifstream input(filePath, std::ios::binary); std::vector result; std::vector buffer((std::istreambuf_iterator(input)),(std::istreambuf_iterator())); + // reuse 'content-type' variable or struct to be more flexible, in future more than one file should also be supported.. std::string head = ""; head += "\r\n--boundary"; - head += "\r\nContent-Type: " + utility::conversions::to_utf8string("application/dicom") + "\r\n\r\n"; + head += "\r\nContent-Type: " + mitk::RESTUtil::convertToUtf8(L"application/dicom") + "\r\n\r\n"; std::vector bodyVector(head.begin(), head.end()); std::string tail = ""; tail += "\r\n--boundary--"; result.insert(result.end(), bodyVector.begin(), bodyVector.end()); result.insert(result.end(), buffer.begin(), buffer.end()); result.insert(result.end(), tail.begin(), tail.end()); MitkRequest postRequest(MitkRESTMethods::POST); postRequest.set_request_uri(uri); postRequest.headers().add(U("Content-Type"), "multipart/related; type=\"application/dicom\"; boundary=boundary"); postRequest.set_body(result); - MITK_INFO << "Request: " << utility::conversions::to_utf8string(postRequest.to_string()); - return m_Client.request(postRequest).then([](MitkResponse response) + MITK_INFO << "Request: " << mitk::RESTUtil::convertToUtf8(postRequest.to_string()); + return m_Client->request(postRequest).then([](MitkResponse response) { - MITK_INFO << "Response: " << utility::conversions::to_utf8string(response.to_string()); + MITK_INFO << "Response: " << mitk::RESTUtil::convertToUtf8(response.to_string()); }); } pplx::task mitk::RESTClient::WadoRS(utility::string_t filePath, 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("studyUID"), mitk::RESTUtil::convertToTString(studyUID)); + builder.append_query(U("seriesUID"), mitk::RESTUtil::convertToTString(seriesUID)); + builder.append_query(U("objectUID"), mitk::RESTUtil::convertToTString(instanceUID)); builder.append_query(U("contentType"), U("application/dicom")); return Get(filePath, builder.to_string()); } pplx::task mitk::RESTClient::WadoRS(const utility::string_t folderPath, std::string studyUID, std::string seriesUID) { // this is actually a quido-rs request, should be packed into a seperate method.. at some time.. //but there are many possible requests to support: http://dicom.nema.org/medical/dicom/current/output/chtml/part18/sect_6.7.html MitkUriBuilder builder(U("rs/instances")); - builder.append_query(U("StudyInstanceUID"), utility::conversions::to_string_t(studyUID)); - builder.append_query(U("SeriesInstanceUID"), utility::conversions::to_string_t(seriesUID)); + builder.append_query(U("StudyInstanceUID"), mitk::RESTUtil::convertToTString(studyUID)); + builder.append_query(U("SeriesInstanceUID"), mitk::RESTUtil::convertToTString(seriesUID)); MITK_INFO << utility::conversions::to_utf8string(builder.to_string()); MitkRequest getSeries(MitkRESTMethods::GET); getSeries.set_request_uri(builder.to_string()); getSeries.headers().add(U("Accept"), U("application/json")); - return m_Client.request(getSeries).then([=](MitkResponse response) -> pplx::task + return m_Client->request(getSeries).then([=](MitkResponse response) -> pplx::task { MITK_INFO << "search for instances in series with uid " << seriesUID << " status: " << response.status_code(); auto jsonListResult = response.extract_json().get(); auto resultArray = jsonListResult.as_array(); auto firstFileName = std::string(); std::vector> tasks; for (unsigned short i = 0; i < resultArray.size(); i++) { try { auto firstResult = resultArray[i]; auto sopInstanceUIDKey = firstResult.at(U("00080018")); auto sopInstanceObject = sopInstanceUIDKey.as_object(); auto valueKey = sopInstanceObject.at(U("Value")); auto valueArray = valueKey.as_array(); auto sopInstanceUID = valueArray[0].as_string(); auto fileName = utility::string_t(sopInstanceUID).append(U(".dcm")); // save first file name as result to load series if (i == 0) { firstFileName = utility::conversions::to_utf8string(fileName); } auto filePath = utility::string_t(folderPath).append(fileName); - auto task = WadoRS(filePath, studyUID, seriesUID, utility::conversions::to_utf8string(sopInstanceUID)); + auto task = WadoRS(filePath, studyUID, seriesUID, mitk::RESTUtil::convertToUtf8(sopInstanceUID)); tasks.push_back(task); } catch (const web::json::json_exception& e) { MITK_ERROR << e.what(); } } auto joinTask = pplx::when_all(begin(tasks), end(tasks)); return joinTask.then([=](void) { return utility::conversions::to_utf8string(folderPath).append(firstFileName); }); }); } pplx::task mitk::RESTClient::StowRS(utility::string_t filePath, std::string studyUID) { // TODO: add data MitkUriBuilder builder(U("rs/studies")); - builder.append_path(utility::conversions::to_string_t(studyUID)); + builder.append_path(mitk::RESTUtil::convertToTString(studyUID)); - //return concurrency::streams::file_stream::open_istream(filePath).then([=](concurrency::streams::basic_istream fileStream) { - return Post(builder.to_string(), U("multipart/related; type='application/dicom'; boundary='boundary'"), filePath); - //}); + return Post(builder.to_string(), U("multipart/related; type='application/dicom'; boundary='boundary'"), filePath); } \ No newline at end of file diff --git a/Plugins/org.mitk.gui.qt.segmentation.rework/CMakeLists.txt b/Plugins/org.mitk.gui.qt.segmentation.rework/CMakeLists.txt index fb79d2b4b1..880cd32f30 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 MitkChart + MODULE_DEPENDS MitkQtWidgetsExt MitkCppRestSdk MitkChart MitkSegmentationUI ) 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 c7edc3fa09..7cba7e9434 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,126 +1,129 @@ /*=================================================================== 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 +#include SegmentationReworkREST::SegmentationReworkREST() {} SegmentationReworkREST::SegmentationReworkREST(utility::string_t url) : mitk::RESTServer(url) { m_Listener.support(MitkRESTMethods::PUT, std::bind(&SegmentationReworkREST::HandlePut, this, std::placeholders::_1)); m_Listener.support(MitkRESTMethods::GET, std::bind(&SegmentationReworkREST::HandleGet, this, std::placeholders::_1)); } SegmentationReworkREST::~SegmentationReworkREST() {} void SegmentationReworkREST::HandleGet(MitkRequest message) { auto messageString = message.to_string(); MITK_INFO << "Message GET incoming..."; - MITK_INFO << convertToUtf8(messageString); + MITK_INFO << mitk::RESTUtil::convertToUtf8(messageString); auto httpParams = web::uri::split_query(message.request_uri().query()); // IHE Invoke Image Display style auto requestType = httpParams.find(L"requestType"); if (requestType != httpParams.end() && requestType->second == L"IMAGE_SEG") { try { auto studyUID = httpParams.at(L"studyUID"); auto imageSeriesUID = httpParams.at(L"imageSeriesUID"); auto segSeriesUID = httpParams.at(L"segSeriesUID"); DicomDTO dto; - dto.imageSeriesUID = convertToUtf8(imageSeriesUID); - dto.studyUID = convertToUtf8(studyUID); - dto.segSeriesUIDA = convertToUtf8(segSeriesUID); + dto.imageSeriesUID = mitk::RESTUtil::convertToUtf8(imageSeriesUID); + dto.studyUID = mitk::RESTUtil::convertToUtf8(studyUID); + dto.segSeriesUIDA = mitk::RESTUtil::convertToUtf8(segSeriesUID); m_GetCallback(dto); MitkResponse response(MitkRestStatusCodes::OK); response.set_body("Sure, i got you.. have an awesome day"); message.reply(response); } catch (std::out_of_range& e) { message.reply(MitkRestStatusCodes::BadRequest, "oh man, that was not expected: " + std::string(e.what())); } } else { message.reply(MitkRestStatusCodes::BadRequest, "Oh man, i can only deal with 'requestType' = 'IMAGE+SEG'..."); } } void SegmentationReworkREST::HandlePut(MitkRequest message) { auto messageString = message.to_string(); MITK_INFO << "Message PUT incoming..."; - MITK_INFO << convertToUtf8(messageString); + MITK_INFO << mitk::RESTUtil::convertToUtf8(messageString); try { auto jsonMessage = message.extract_json().get(); auto messageTypeKey = jsonMessage.at(U("messageType")); if (messageTypeKey.as_string() == U("downloadData")) { auto imageStudyUIDKey = jsonMessage.at(U("studyUID")); auto imageSeriesUIDKey = jsonMessage.at(U("imageSeriesUID")); auto segSeriesUIDAKey = jsonMessage.at(U("segSeriesUIDA")); auto segSeriesUIDBKey = jsonMessage.at(U("segSeriesUIDB")); + auto groundTruthKey = jsonMessage.at(U("groundTruth")); auto simScoreKey = jsonMessage.at(U("simScoreArray")); auto minSliceStartKey = jsonMessage.at(U("minSliceStart")); DicomDTO dto; - dto.segSeriesUIDA = convertToUtf8(segSeriesUIDAKey.as_string()); - dto.segSeriesUIDB = convertToUtf8(segSeriesUIDBKey.as_string()); - dto.imageSeriesUID = convertToUtf8(imageSeriesUIDKey.as_string()); + dto.segSeriesUIDA = mitk::RESTUtil::convertToUtf8(segSeriesUIDAKey.as_string()); + dto.segSeriesUIDB = mitk::RESTUtil::convertToUtf8(segSeriesUIDBKey.as_string()); + dto.imageSeriesUID = mitk::RESTUtil::convertToUtf8(imageSeriesUIDKey.as_string()); + dto.groundTruth = mitk::RESTUtil::convertToUtf8(groundTruthKey.as_string()); - dto.studyUID = convertToUtf8(imageStudyUIDKey.as_string()); + dto.studyUID = mitk::RESTUtil::convertToUtf8(imageStudyUIDKey.as_string()); dto.minSliceStart = minSliceStartKey.as_integer(); std::vector vec; web::json::array simArray = simScoreKey.as_array(); for (web::json::value score : simArray) { vec.push_back(score.as_double()); } dto.simScoreArray = vec; m_PutCallback(dto); emit InvokeUpdateChartWidget(); } 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; } 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 642fca7949..1ee83e0ac5 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,63 +1,64 @@ /*=================================================================== 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 { Q_OBJECT public: struct DicomDTO { std::string segSeriesUIDA; std::string segSeriesUIDB; std::string imageSeriesUID; std::string studyUID; std::string segInstanceUIDA; std::string segInstanceUIDB; std::vector simScoreArray; int minSliceStart; + std::string groundTruth; }; SegmentationReworkREST(); SegmentationReworkREST(utility::string_t url); ~SegmentationReworkREST(); void HandlePut(MitkRequest message); void HandleGet(MitkRequest message); void SetPutCallback(std::function callback) { m_PutCallback = callback; } void SetGetCallback(std::function callback) { m_GetCallback = callback; } signals: void InvokeUpdateChartWidget(); private: std::function m_PutCallback; std::function m_GetCallback; }; #endif // SegmentationReworkREST_h 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 f5eadbbaa4..8b295f8fd7 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,224 +1,257 @@ /*=================================================================== 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 #include +#include "QmitkNewSegmentationDialog.h" +#include "mitkSegTool2D.h" +#include "mitkToolManagerProvider.h" #include // uuid class #include // generators #include #include -#include const std::string SegmentationReworkView::VIEW_ID = "org.mitk.views.segmentationreworkview"; void SegmentationReworkView::SetFocus() {} void SegmentationReworkView::CreateQtPartControl(QWidget *parent) { // create GUI widgets from the Qt Designer's .ui file m_Controls.setupUi(parent); qRegisterMetaType< std::vector >("std::vector"); connect(m_Controls.buttonUpload, &QPushButton::clicked, this, &SegmentationReworkView::UploadNewSegmentation); + connect(m_Controls.buttonNewSeg, &QPushButton::clicked, this, &SegmentationReworkView::CreateNewSegmentationC); + connect(m_Controls.cleanDicomBtn, &QPushButton::clicked, this, &SegmentationReworkView::CleanDicomFolder); + + m_downloadBaseDir = std::experimental::filesystem::path("/temp/"); + + if (!std::experimental::filesystem::exists(m_downloadBaseDir)) + { + std::experimental::filesystem::create_directory(m_downloadBaseDir); + } + 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)); connect(m_HttpHandler.get(), &SegmentationReworkREST::InvokeUpdateChartWidget, this, &SegmentationReworkView::UpdateChartWidget); connect(this, &SegmentationReworkView::InvokeLoadData, this, &SegmentationReworkView::LoadData); m_HttpHandler->SetPutCallback(std::bind(&SegmentationReworkView::RESTPutCallback, this, std::placeholders::_1)); m_HttpHandler->SetGetCallback(std::bind(&SegmentationReworkView::RESTGetCallback, this, std::placeholders::_1)); 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); } void SegmentationReworkView::RESTPutCallback(const SegmentationReworkREST::DicomDTO &dto) { SetSimilarityGraph(dto.simScoreArray, dto.minSliceStart); MITK_INFO << "Load related dicom series ..."; boost::uuids::random_generator generator; - std::string folderPathSeries = m_downloadBaseDir + boost::uuids::to_string(generator()) + "/"; + std::string folderPathSeries = std::experimental::filesystem::path(m_downloadBaseDir).append(boost::uuids::to_string(generator())).string() + "/"; std::experimental::filesystem::create_directory(folderPathSeries); - std::string pathSegA = m_downloadBaseDir + boost::uuids::to_string(generator()) + "/"; - std::string pathSegB = m_downloadBaseDir + boost::uuids::to_string(generator()) + "/"; + std::string pathSegA = std::experimental::filesystem::path(m_downloadBaseDir).append(boost::uuids::to_string(generator())).string() + "/"; + std::string pathSegB = std::experimental::filesystem::path(m_downloadBaseDir).append(boost::uuids::to_string(generator())).string() + "/"; auto folderPathSegA = utility::conversions::to_string_t(pathSegA); auto folderPathSegB = utility::conversions::to_string_t(pathSegB); std::experimental::filesystem::create_directory(pathSegA); std::experimental::filesystem::create_directory(pathSegB); m_CurrentStudyUID = dto.studyUID; std::vector> tasks; auto imageSeriesTask = m_RestClient->WadoRS(utility::conversions::to_string_t(folderPathSeries), dto.studyUID, dto.imageSeriesUID); auto segATask = m_RestClient->WadoRS(folderPathSegA, dto.studyUID, dto.segSeriesUIDA); auto segBTask = m_RestClient->WadoRS(folderPathSegB, dto.studyUID, dto.segSeriesUIDB); tasks.push_back(imageSeriesTask); tasks.push_back(segATask); tasks.push_back(segBTask); auto joinTask = pplx::when_all(begin(tasks), end(tasks)); auto filePathList = joinTask.then([&](std::vector filePathList) { + auto fileNameA = std::experimental::filesystem::path(filePathList[1]).filename(); + auto fileNameB = std::experimental::filesystem::path(filePathList[2]).filename(); + m_Controls.labelSegA->setText(m_Controls.labelSegA->text() + " " + QString::fromUtf8(fileNameA.string().c_str())); + m_Controls.labelSegB->setText(m_Controls.labelSegB->text() + " " + QString::fromUtf8(fileNameB.string().c_str())); InvokeLoadData(filePathList); }); } void SegmentationReworkView::RESTGetCallback(const SegmentationReworkREST::DicomDTO &dto) { boost::uuids::random_generator generator; - std::string folderPathSeries = m_downloadBaseDir + boost::uuids::to_string(generator()) + "/"; + std::string folderPathSeries = std::experimental::filesystem::path(m_downloadBaseDir).append(boost::uuids::to_string(generator())).string() + "/"; std::experimental::filesystem::create_directory(folderPathSeries); - std::string pathSeg = m_downloadBaseDir + boost::uuids::to_string(generator()) + "/"; + std::string pathSeg = std::experimental::filesystem::path(m_downloadBaseDir).append(boost::uuids::to_string(generator())).string() + "/"; auto folderPathSeg = utility::conversions::to_string_t(pathSeg); std::experimental::filesystem::create_directory(pathSeg); std::vector> tasks; auto imageSeriesTask = m_RestClient->WadoRS(utility::conversions::to_string_t(folderPathSeries), dto.studyUID, dto.imageSeriesUID); auto segATask = m_RestClient->WadoRS(folderPathSeg, dto.studyUID, dto.segSeriesUIDA); tasks.push_back(imageSeriesTask); tasks.push_back(segATask); auto joinTask = pplx::when_all(begin(tasks), end(tasks)); auto filePathList = joinTask.then([&](std::vector filePathList) { InvokeLoadData(filePathList); }); } void SegmentationReworkView::LoadData(std::vector filePathList) { MITK_INFO << "Loading finished. Pushing data to data storage ..."; auto ds = GetDataStorage(); mitk::IOUtil::Load(filePathList, *ds); // reinit view mitk::RenderingManager::GetInstance()->InitializeViewsByBoundingObjects(ds); + + // find data nodes + //auto allNodes = ds->GetAll(); + } void SegmentationReworkView::UpdateChartWidget() { m_Controls.chartWidget->Show(); } void SegmentationReworkView::SetSimilarityGraph(std::vector simScoreArray, int sliceMinStart) { std::map map; double sliceIndex = sliceMinStart; for (double score : simScoreArray) { map.insert(std::map::value_type(sliceIndex, score)); sliceIndex++; } 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"); } 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); return; } } m_Controls.labelWarning->setVisible(true); } void SegmentationReworkView::UploadNewSegmentation() { auto filePath = U("1.2.276.0.7230010.3.1.4.296485376.8.1533635734.141264.dcm"); m_CurrentStudyUID = "1.2.840.113654.2.70.1.159145727925405623564217141386659468090"; try { m_RestClient->StowRS(filePath, m_CurrentStudyUID).wait(); } catch (const std::exception &exception) { std::cout << exception.what() << std::endl; } } +void SegmentationReworkView::CreateNewSegmentationC() +{ + mitk::ToolManager* toolManager = mitk::ToolManagerProvider::GetInstance()->GetToolManager(); + //toolManager->SetReferenceData(const_cast(referenceData)); + //toolManager->SetWorkingData(const_cast(workingData)); +} + +void SegmentationReworkView::CleanDicomFolder() +{ + std::experimental::filesystem::remove_all(m_downloadBaseDir); + std::experimental::filesystem::create_directory(m_downloadBaseDir); +} + 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 428dd59330..560862dc38 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,83 +1,86 @@ /*=================================================================== 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 +#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; void RESTPutCallback(const SegmentationReworkREST::DicomDTO& dto); void RESTGetCallback(const SegmentationReworkREST::DicomDTO& dto); void UpdateChartWidget(); void LoadData(std::vector filePathList); signals: void InvokeLoadData(std::vector filePathList); 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 CreateNewSegmentationC(); + void CleanDicomFolder(); void UploadNewSegmentation(); Ui::SegmentationReworkViewControls m_Controls; private: void SetSimilarityGraph(std::vector simScoreArray, int sliceMinStart); std::unique_ptr m_HttpHandler; mitk::RESTClient* m_RestClient; std::string m_CurrentStudyUID; // use filesystem::path later... - std::string m_downloadBaseDir = "/temp/"; + std::experimental::filesystem::path m_downloadBaseDir; }; #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 e058f1edb6..e9649e297e 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,126 +1,140 @@ SegmentationReworkViewControls 0 0 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 400 16777215 400 Qt::Horizontal + + + + Create new Segmentation C + + + Do image processing - Upload new Segmentation C + Upload Segmentation C Qt::Vertical QSizePolicy::Expanding 20 220 + + + + clean dicom download folder + + + QmitkChartWidget QWidget
QmitkChartWidget.h
1