diff --git a/Modules/CppRestSdk/src/mitkRESTClient.cpp b/Modules/CppRestSdk/src/mitkRESTClient.cpp index c9ba9c6387..db91239c53 100644 --- a/Modules/CppRestSdk/src/mitkRESTClient.cpp +++ b/Modules/CppRestSdk/src/mitkRESTClient.cpp @@ -1,93 +1,97 @@ /*=================================================================== 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 filePath, 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()); + MITK_INFO << "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); auto fileBuffer = std::make_shared>(); 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); }) // Write the response body into the file buffer. .then([=](MitkResponse response) -> pplx::task { - printf("Response status code %u returned.\n", response.status_code()); + MITK_INFO << "Status code: " << 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(); return; } void mitk::RESTClient::executeWADOGET(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("contentType"), U("application/dicom")); executeGETRequest(filePath, builder.to_string()); } void mitk::RESTClient::executeWADOGET(const utility::string_t folderPath, std::string studyUID, std::string seriesUID) { MitkUriBuilder builder(U("instances")); builder.append_query(U("studyUID"), utility::conversions::to_string_t(studyUID)); builder.append_query(U("seriesUID"), utility::conversions::to_string_t(seriesUID)); - m_Client.request(MitkRESTMethods::GET, builder.to_string()).then([=](MitkResponse response) -> pplx::task + m_Client.request(MitkRESTMethods::GET, builder.to_string()).then([=](MitkResponse response) { + 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(); - for(unsigned short i = 0; i < resultArray.size(); i++) { + for (unsigned short i = 0; i < resultArray.size(); i++) + { auto firstResult = resultArray[i]; auto sopInstanceUIDKey = firstResult.at(U("00080018")); auto sopInstanceObject = sopInstanceUIDKey.as_object(); auto valueKey = sopInstanceObject.at(U("Value")); auto sopInstanceUID = valueKey.as_string(); - - utility::string_t fileName = U("/" + sopInstanceUID); - auto filePath = folderPath.substr().append(fileName); + + auto filePath = utility::string_t(folderPath) + .append(sopInstanceUID) + .append(U(".dcm")); executeWADOGET(filePath, studyUID, seriesUID, utility::conversions::to_utf8string(sopInstanceUID)); } - }).then([] { - - }) - .wait(); + }); } 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 1796f68927..0f7e65ab54 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,88 +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. ===================================================================*/ #include "SegmentationReworkREST.h" #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)); } SegmentationReworkREST::~SegmentationReworkREST() {} void SegmentationReworkREST::SetPutCallback(std::function callback) { m_PutCallback = callback; } -void SegmentationReworkREST::InvokeUpdateChartWidget(){} - void SegmentationReworkREST::HandlePut(MitkRequest message) { auto messageString = message.to_string(); MITK_INFO << "Message PUT incoming..."; MITK_INFO << convertToUtf8(messageString); 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")); auto imageStudyUIDKey = jsonMessage.at(U("imageStudyUID")); auto imageInstanceUIDKey = jsonMessage.at(U("imageInstanceUID")); auto simScoreKey = jsonMessage.at(U("simScoreArray")); auto minSliceStartKey = jsonMessage.at(U("minSliceStart")); DicomDTO dto; dto.instanceUID = convertToUtf8(imageInstanceUIDKey.as_string()); dto.seriesUID = convertToUtf8(imageSeriesUIDKey.as_string()); dto.studyUID = 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); - InvokeUpdateChartWidget(); + 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 9913fd0f10..c502cecd85 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,48 +1,50 @@ /*=================================================================== 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 { +class SegmentationReworkREST : public mitk::RESTServer +{ Q_OBJECT public: struct DicomDTO { std::string seriesUID; std::string studyUID; std::string instanceUID; std::vector simScoreArray; int minSliceStart; }; SegmentationReworkREST(); SegmentationReworkREST(utility::string_t url); ~SegmentationReworkREST(); void HandlePut(MitkRequest message); void SetPutCallback(std::function callback); +signals: void InvokeUpdateChartWidget(); private: std::function m_PutCallback; }; #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 c490efed01..abbda47838 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,156 +1,158 @@ /*=================================================================== 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 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); connect(m_Controls.buttonUpload, &QPushButton::clicked, this, &SegmentationReworkView::UploadNewSegmentation); - //connect(m_HttpHandler.get(), &SegmentationReworkREST::InvokeUpdateChartWidget, this, &SegmentationReworkView::UpdateChartWidget); + 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); + m_HttpHandler->SetPutCallback(std::bind(&SegmentationReworkView::RESTPutCallback, 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); + m_RestClient = new mitk::RESTClient(U("http://www.officesupplyuae.com")); - m_RestClient->executeWADOGET(U("/temp/downloadSeries/"), "1.2.840.113654.2.70.1.311779127785374989361829772874593461506", "1.2.840.113654.2.70.1.182762555335754050396179618615436313390"); + m_RestClient->executeWADOGET(U("/tmp/"), "1.2.840.113654.2.70.1.311779127785374989361829772874593461506", "1.2.840.113654.2.70.1.182762555335754050396179618615436313390"); } void SegmentationReworkView::RESTPutCallback(const SegmentationReworkREST::DicomDTO& dto) { MITK_INFO << "callback! " << dto.studyUID << dto.seriesUID << dto.instanceUID; SetSimilarityGraph(dto.simScoreArray, dto.minSliceStart); auto filePath = U("/temp/downloadWADO.dcm"); - m_RestClient->executeWADOGET(filePath, dto.studyUID, dto.seriesUID, dto.instanceUID).wait(); + // m_RestClient->executeWADOGET(filePath, dto.studyUID, dto.seriesUID, dto.instanceUID); MITK_INFO << "load file into data storage"; - mitk::IOUtil::Load(utility::conversions::to_utf8string(filePath), *this->GetDataStorage()); + //mitk::IOUtil::Load(utility::conversions::to_utf8string(filePath), *this->GetDataStorage()); this->GetDataStorage()->GetAll()->at(0)->Update(); } void SegmentationReworkView::UpdateChartWidget() { m_Controls.chartWidget->Show(); } void SegmentationReworkView::SetSimilarityGraph(std::vector simScoreArray, int sliceMinStart) { std::map map; MITK_INFO << simScoreArray.size(); 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() { } 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 da888ba450..b24a7a8e16 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,75 +1,74 @@ /*=================================================================== 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; void RESTPutCallback(const SegmentationReworkREST::DicomDTO& dto); -public slots: void UpdateChartWidget(); 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: void SetSimilarityGraph(std::vector simScoreArray, int sliceMinStart); std::unique_ptr m_HttpHandler; mitk::RESTClient* m_RestClient; }; #endif // SegmentationReworkView_h