diff --git a/Modules/REST/test/mitkRESTClientHttpLibTest.cpp b/Modules/REST/test/mitkRESTClientHttpLibTest.cpp index a33b437a7f..b9d8d128ba 100644 --- a/Modules/REST/test/mitkRESTClientHttpLibTest.cpp +++ b/Modules/REST/test/mitkRESTClientHttpLibTest.cpp @@ -1,39 +1,123 @@ /*============================================================================ The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center (DKFZ) All rights reserved. Use of this source code is governed by a 3-clause BSD license that can be found in the LICENSE file. ============================================================================*/ #include #include #include #include class mitkRESTClientHttpLibTestSuite : public mitk::TestFixture { CPPUNIT_TEST_SUITE(mitkRESTClientHttpLibTestSuite); - MITK_TEST(GetRequestValidURI_ReturnsExpectedJSON); + // MITK_TEST(GetRequestValidURI_ReturnsExpectedJSON); + MITK_TEST(PostMONAI); CPPUNIT_TEST_SUITE_END(); public: void GetRequestValidURI_ReturnsExpectedJSON() { httplib::Client cli("http://eu.httpbin.org"); auto response = cli.Get("/get"); if (response->status == 200) { auto js = nlohmann::json::parse(response->body); std::string userAgentWithVersion = js["headers"]["User-Agent"]; - std::string userAgent = userAgentWithVersion.substr(0, userAgentWithVersion.find("/")); + std::string userAgent = userAgentWithVersion.substr(0, userAgentWithVersion.find("/")); CPPUNIT_ASSERT_MESSAGE("Result is the expected JSON value", userAgent == "cpp-httplib"); } } + + void PostMONAI() + { + std::string filePath = "C://data//dataset//Task02_Heart//imagesTr//la_016.nii.gz"; + std::ifstream input(filePath, std::ios::binary); + if (!input) + { + MITK_WARN << "could not read file to POST"; + } + std::stringstream buffer_lf_img; + buffer_lf_img << input.rdbuf(); + input.close(); + + httplib::Client cli("localhost", 8000); + + httplib::MultipartFormDataItems items = { + {"file", buffer_lf_img.str(), "spleen_58.nii.gz", "application/octet-stream"}}; + + // httplib::MultipartFormDataMap itemMap = {{"file", {"file", buffer_lf_img.str(), "spleen_58.nii.gz", + // "application/octet-stream"}}}; + + auto response = cli.Post("/infer/deepedit_seg", items); + if (response->status == 200) + { + MITK_INFO << response->body; + auto h = response->headers; + std::string contentType = h.find("content-type")->second; + std::string delimiter = "boundary="; + std::string boundaryString = + contentType.substr(contentType.find(delimiter) + delimiter.length(), std::string::npos); + boundaryString.insert(0, "--"); + MITK_INFO << "boundary hash: " << boundaryString; + + std::string resBody = response->body; + std::vector multiPartResponse = getStringInBoundary(resBody, boundaryString); + + std::string metaData = multiPartResponse[0]; + std::string contentTypeJson = "Content-Type: application/json"; + size_t ctPos = metaData.find(contentTypeJson) + contentTypeJson.length(); + std::string metaDataPart = metaData.substr(ctPos); + MITK_INFO << metaDataPart; + auto jsonObj = nlohmann::json::parse(metaDataPart); + if (jsonObj.is_discarded() || !jsonObj.is_object()) + { + MITK_ERROR << "Could not parse \"" << /* jsonPath.toStdString() << */ "\" as JSON object!"; + return; + } + + std::string imagePart = multiPartResponse[1]; + std::string contentTypeStream = "Content-Type: application/octet-stream"; + ctPos = imagePart.find(contentTypeStream) + contentTypeStream.length(); + std::string imageDataPart = imagePart.substr(ctPos); + MITK_INFO << imageDataPart; + + + int size1 = imageDataPart.size(); + std::ofstream output("C://Users//a178n//Desktop//output.nii.gz", std::ios::out | std::ios::binary); + output.write(reinterpret_cast(&size1), sizeof(int)); + output.write(imageDataPart.c_str(), size1); + output.flush(); + output.close(); + + } + } + + std::vector getStringInBoundary(const std::string &body, std::string boundary) + { + std::vector retVal; + std::string master = body; + size_t found = master.find(boundary); + size_t beginPos = 0; + while (found != std::string::npos) + { + std::string part = master.substr(beginPos, found); + if (!part.empty()) + { + retVal.push_back(part); + } + master.erase(beginPos, found + boundary.length()); + found = master.find(boundary); + } + return retVal; + } }; MITK_TEST_SUITE_REGISTRATION(mitkRESTClientHttpLib) diff --git a/Modules/Segmentation/Interactions/mitkMonaiLabelTool.cpp b/Modules/Segmentation/Interactions/mitkMonaiLabelTool.cpp index 564c819d8f..2fb6b0437b 100644 --- a/Modules/Segmentation/Interactions/mitkMonaiLabelTool.cpp +++ b/Modules/Segmentation/Interactions/mitkMonaiLabelTool.cpp @@ -1,292 +1,391 @@ /*============================================================================ The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center (DKFZ) All rights reserved. Use of this source code is governed by a 3-clause BSD license that can be found in the LICENSE file. ============================================================================*/ // MITK #include "mitkMonaiLabelTool.h" // us #include "mitkIOUtil.h" #include "mitkRESTUtil.h" #include #include #include #include #include #include #include #include #include "cpprest/asyncrt_utils.h" #include "cpprest/http_client.h" +#include + namespace mitk { MITK_TOOL_MACRO(MITKSEGMENTATION_EXPORT, MonaiLabelTool, "MonaiLabel"); } mitk::MonaiLabelTool::MonaiLabelTool() { InitializeRESTManager(); } void mitk::MonaiLabelTool::Activated() { Superclass::Activated(); this->SetLabelTransferMode(LabelTransferMode::AllLabels); } const char **mitk::MonaiLabelTool::GetXPM() const { return nullptr; } us::ModuleResource mitk::MonaiLabelTool::GetIconResource() const { us::Module *module = us::GetModuleContext()->GetModule(); us::ModuleResource resource = module->GetResource("Otsu_48x48.png"); return resource; } const char *mitk::MonaiLabelTool::GetName() const { return "MonaiLabel"; } void mitk::MonaiLabelTool::DoUpdatePreview(const Image *inputAtTimeStep, const Image * /*oldSegAtTimeStep*/, LabelSetImage *previewImage, TimeStepType timeStep) { std::string outputImagePath = "Z:/dataset/Task05_Prostate/labelsTr/prostate_00.nii.gz"; try { Image::Pointer outputImage = IOUtil::Load(outputImagePath); previewImage->InitializeByLabeledImage(outputImage); previewImage->SetGeometry(inputAtTimeStep->GetGeometry()); } catch (const mitk::Exception &e) { /* Can't throw mitk exception to the caller. Refer: T28691 */ MITK_ERROR << e.GetDescription(); return; } } void mitk::MonaiLabelTool::InitializeRESTManager() // Don't call from constructor --ashis { auto serviceRef = us::GetModuleContext()->GetServiceReference(); if (serviceRef) { m_RESTManager = us::GetModuleContext()->GetService(serviceRef); } } void mitk::MonaiLabelTool::GetOverallInfo(std::string url) { - if (m_RESTManager != nullptr) + MITK_INFO << "URL..." << url; + httplib::Client cli("localhost", 8000); + auto response = cli.Get("/info/"); + if (response->status == 200) { - PostSegmentationRequest(); - std::string jsonString; - bool fetched = false; - web::json::value result; - m_RESTManager->SendRequest(mitk::RESTUtil::convertToTString(url)) - .then( - [&](pplx::task resultTask) /*It is important to use task-based continuation*/ - { - try - { - result = resultTask.get(); - fetched = true; - } - catch (const mitk::Exception &exception) - { - MITK_ERROR << exception.what(); - return; - } - }) - .wait(); - if (fetched) + auto jsonObj = nlohmann::json::parse(response->body); + if (jsonObj.is_discarded() || !jsonObj.is_object()) + { + MITK_ERROR << "Could not parse \"" << /* jsonPath.toStdString() << */ "\" as JSON object!"; + return; + } + m_Parameters = DataMapper(jsonObj); + } + + //if (m_RESTManager != nullptr) + //{ + // //PostSegmentationRequest(); + // std::string jsonString; + // bool fetched = false; + // web::json::value result; + // m_RESTManager->SendRequest(mitk::RESTUtil::convertToTString(url)) + // .then( + // [&](pplx::task resultTask) /*It is important to use task-based continuation*/ + // { + // try + // { + // result = resultTask.get(); + // fetched = true; + // } + // catch (const mitk::Exception &exception) + // { + // MITK_ERROR << exception.what(); + // return; + // } + // }) + // .wait(); + /* if (fetched) { m_Parameters = DataMapper(result); + }*/ + //} +} + +void mitk::MonaiLabelTool::PostSegmentationRequest() +{ + std::string url = "http://localhost:8000/infer/deepedit_seg"; // + m_ModelName; + // std::string filePath = "//vmware-host//Shared Folders//Downloads//spleen_58.nii.gz"; + std::string filePath = "C://data//dataset//Task02_Heart//imagesTr//la_016.nii.gz"; + std::ifstream input(filePath, std::ios::binary); + if (!input) + { + MITK_WARN << "could not read file to POST"; + } + std::stringstream buffer_lf_img; + buffer_lf_img << input.rdbuf(); + httplib::Client cli("localhost", 8000); + + httplib::MultipartFormDataItems items = { + {"file", buffer_lf_img.str(), "spleen_58.nii.gz", "application/octet-stream"}}; + + // httplib::MultipartFormDataMap itemMap = {{"file", {"file", buffer_lf_img.str(), "spleen_58.nii.gz", + // "application/octet-stream"}}}; + + auto response = cli.Post("/infer/deepedit_seg", items); + if (response->status == 200) + { + MITK_INFO<body; + auto h = response->headers; + std::string contentType = h.find("content-type")->second; + std::string delimiter = "boundary="; + std::string boundaryString = contentType.substr(contentType.find(delimiter)+delimiter.length(), std::string::npos); + boundaryString.insert(0, "--"); + MITK_INFO << "boundary hash: " << boundaryString; + + std::string resBody = response->body; + resBody.erase(0, boundaryString.length()); + std::string metaData = resBody.substr(0, resBody.find(boundaryString)); + MITK_INFO << metaData; + auto jsonObj = nlohmann::json::parse(metaData); + if (jsonObj.is_discarded() || !jsonObj.is_object()) + { + MITK_ERROR << "Could not parse \"" << /* jsonPath.toStdString() << */ "\" as JSON object!"; + return; } } } +std::unique_ptr mitk::MonaiLabelTool::DataMapper(nlohmann::json &jsonObj) +{ + auto object = std::make_unique(); + object->name = jsonObj["name"].get(); + object->description = jsonObj["description"].get(); + object->labels = jsonObj["labels"].get>(); + + auto modelJsonMap = jsonObj["models"].get>(); + for (const auto &[_name, _jsonObj] : modelJsonMap) + { + if (_jsonObj.is_discarded() || !_jsonObj.is_object()) + { + MITK_ERROR << "Could not parse JSON object."; + } + MonaiModelInfo modelInfo; + modelInfo.name = _name; + try + { + auto labels = _jsonObj["labels"].get>(); + modelInfo.labels = labels; + } + catch (const std::exception &) + { + auto labels = _jsonObj["labels"].get>(); + for (const auto &label : labels) + { + modelInfo.labels[label] = -1; // Hardcode -1 as label id + } + } + modelInfo.type = _jsonObj["type"].get(); + modelInfo.dimension = _jsonObj["dimension"].get(); + modelInfo.description = _jsonObj["description"].get(); + + object->models.push_back(modelInfo); + } + return object; +} + + std::unique_ptr mitk::MonaiLabelTool::DataMapper(web::json::value &result) { auto object = std::make_unique(); utility::string_t stringT = result.to_string(); std::string jsonString(stringT.begin(), stringT.end()); auto jsonObj = nlohmann::json::parse(jsonString); if (jsonObj.is_discarded() || !jsonObj.is_object()) { MITK_ERROR << "Could not parse \"" << jsonString << "\" as JSON object!"; } //MITK_INFO << jsonString; MITK_INFO << "ashis inside mapper " << jsonObj["name"].get(); // remove object->name = jsonObj["name"].get(); object->description = jsonObj["description"].get(); object->labels = jsonObj["labels"].get>(); auto modelJsonMap = jsonObj["models"].get>(); for (const auto &[_name, _jsonObj] : modelJsonMap) { if (_jsonObj.is_discarded() || !_jsonObj.is_object()) { MITK_ERROR << "Could not parse JSON object."; } MonaiModelInfo modelInfo; modelInfo.name = _name; try { auto labels = _jsonObj["labels"].get>(); modelInfo.labels = labels; } catch (const std::exception &) { auto labels = _jsonObj["labels"].get>(); for (const auto &label : labels) { modelInfo.labels[label] = -1; // Hardcode -1 as label id } } modelInfo.type = _jsonObj["type"].get(); modelInfo.dimension = _jsonObj["dimension"].get(); modelInfo.description = _jsonObj["description"].get(); object->models.push_back(modelInfo); } return object; } std::vector mitk::MonaiLabelTool::GetAutoSegmentationModels() { std::vector autoModels; if (nullptr != m_Parameters) { for (mitk::MonaiModelInfo &model : m_Parameters->models) { if (m_AUTO_SEG_TYPE_NAME.find(model.type) != m_AUTO_SEG_TYPE_NAME.end()) { autoModels.push_back(model); } } } return autoModels; } std::vector mitk::MonaiLabelTool::GetInteractiveSegmentationModels() { std::vector interactiveModels; if (nullptr != m_Parameters) { for (mitk::MonaiModelInfo &model : m_Parameters->models) { if (m_INTERACTIVE_SEG_TYPE_NAME.find(model.type) != m_INTERACTIVE_SEG_TYPE_NAME.end()) { interactiveModels.push_back(model); } } } return interactiveModels; } std::vector mitk::MonaiLabelTool::GetScribbleSegmentationModels() { std::vector scribbleModels; if (nullptr != m_Parameters) { for (mitk::MonaiModelInfo &model : m_Parameters->models) { if (m_SCRIBBLE_SEG_TYPE_NAME.find(model.type) != m_SCRIBBLE_SEG_TYPE_NAME.end()) { scribbleModels.push_back(model); } } } return scribbleModels; } -void mitk::MonaiLabelTool::PostSegmentationRequest() // return LabelSetImage ?? -{ - // web::json::value result; - // web::json::value data; - - std::string url = "http://localhost:8000/infer/deepedit_seg"; // + m_ModelName; - std::string filePath = "//vmware-host//Shared Folders//Downloads//spleen_58.nii.gz"; - std::ifstream input(filePath, std::ios::binary); - if (!input) - { - MITK_WARN << "could not read file to POST"; - } - - std::vector result; - std::vector buffer; - - // Stop eating new lines in binary mode!!! - input.unsetf(std::ios::skipws); - - input.seekg(0, std::ios::end); - const std::streampos fileSize = input.tellg(); - input.seekg(0, std::ios::beg); - - MITK_INFO << fileSize << " bytes will be sent."; - buffer.reserve(fileSize); // file size - std::copy( - std::istream_iterator(input), std::istream_iterator(), std::back_inserter(buffer)); - - - mitk::RESTUtil::ParamMap headers; - headers.insert(mitk::RESTUtil::ParamMap::value_type(U("accept"), U("application/json"))); - // headers.insert(mitk::RESTUtil::ParamMap::value_type(U("Accept-Encoding"), U("gzip, deflate"))); - headers.insert(mitk::RESTUtil::ParamMap::value_type( - // U("Content-Type"), U("multipart/related; type=\"application/dicom\"; boundary=boundary"))); - U("Content-Type"), U("multipart/form-data; boundary=boundary"))); - - // in future more than one file should also be supported.. - std::string head = ""; - head += "\r\n--boundary"; - head += "\r\nContent-Disposition: form-data; name=\"params\"\r\n\r\n{}"; - head += "\r\n--boundary"; - head += "\r\nContent-Disposition: form-data; name=\"file\"; filename=\"spleen_58.nii.gz\"\r\n\r\n"; - - std::vector bodyVector(head.begin(), head.end()); - - std::string tail = ""; - tail += "\r\n--boundary"; - tail += "\r\nContent-Disposition: form-data; name=\"label\"\r\n\r\n"; - tail += "\r\n--boundary--\r\n"; - - result.insert(result.end(), bodyVector.begin(), bodyVector.end()); - result.insert(result.end(), buffer.begin(), buffer.end()); - result.insert(result.end(), tail.begin(), tail.end()); - - try - { - m_RESTManager - ->SendBinaryRequest(mitk::RESTUtil::convertToTString(url), mitk::IRESTManager::RequestType::Post, &result, headers) - .then( - [=](pplx::task result) /* (web::json::value result)*/ - { - MITK_INFO << "after send"; - //MITK_INFO << mitk::RESTUtil::convertToUtf8(result.serialize()); - //result.is_null(); - }) - .wait(); - } - catch (std::exception &e) - { - MITK_WARN << e.what(); - } -} \ No newline at end of file +//void mitk::MonaiLabelTool::PostSegmentationRequest() // return LabelSetImage ?? +//{ +// // web::json::value result; +// // web::json::value data; +// +// std::string url = "http://localhost:8000/infer/deepedit_seg"; // + m_ModelName; +// std::string filePath = "//vmware-host//Shared Folders//Downloads//spleen_58.nii.gz"; +// std::ifstream input(filePath, std::ios::binary); +// if (!input) +// { +// MITK_WARN << "could not read file to POST"; +// } +// +// std::vector result; +// std::vector buffer; +// +// // Stop eating new lines in binary mode!!! +// input.unsetf(std::ios::skipws); +// +// input.seekg(0, std::ios::end); +// const std::streampos fileSize = input.tellg(); +// input.seekg(0, std::ios::beg); +// +// MITK_INFO << fileSize << " bytes will be sent."; +// buffer.reserve(fileSize); // file size +// std::copy( +// std::istream_iterator(input), std::istream_iterator(), std::back_inserter(buffer)); +// +// +// mitk::RESTUtil::ParamMap headers; +// headers.insert(mitk::RESTUtil::ParamMap::value_type(U("accept"), U("application/json"))); +// // headers.insert(mitk::RESTUtil::ParamMap::value_type(U("Accept-Encoding"), U("gzip, deflate"))); +// headers.insert(mitk::RESTUtil::ParamMap::value_type( +// // U("Content-Type"), U("multipart/related; type=\"application/dicom\"; boundary=boundary"))); +// U("Content-Type"), U("multipart/form-data; boundary=boundary"))); +// +// // in future more than one file should also be supported.. +// std::string head = ""; +// head += "\r\n--boundary"; +// head += "\r\nContent-Disposition: form-data; name=\"params\"\r\n\r\n{}"; +// head += "\r\n--boundary"; +// head += "\r\nContent-Disposition: form-data; name=\"file\"; filename=\"spleen_58.nii.gz\"\r\n\r\n"; +// +// std::vector bodyVector(head.begin(), head.end()); +// +// std::string tail = ""; +// tail += "\r\n--boundary"; +// tail += "\r\nContent-Disposition: form-data; name=\"label\"\r\n\r\n"; +// tail += "\r\n--boundary--\r\n"; +// +// result.insert(result.end(), bodyVector.begin(), bodyVector.end()); +// result.insert(result.end(), buffer.begin(), buffer.end()); +// result.insert(result.end(), tail.begin(), tail.end()); +// +// try +// { +// m_RESTManager +// ->SendBinaryRequest(mitk::RESTUtil::convertToTString(url), mitk::IRESTManager::RequestType::Post, &result, headers) +// .then( +// [=](pplx::task result) /* (web::json::value result)*/ +// { +// MITK_INFO << "after send"; +// //MITK_INFO << mitk::RESTUtil::convertToUtf8(result.serialize()); +// //result.is_null(); +// }) +// .wait(); +// } +// catch (std::exception &e) +// { +// MITK_WARN << e.what(); +// } +//} \ No newline at end of file diff --git a/Modules/Segmentation/Interactions/mitkMonaiLabelTool.h b/Modules/Segmentation/Interactions/mitkMonaiLabelTool.h index b6fefa9e9c..a850ae13b9 100644 --- a/Modules/Segmentation/Interactions/mitkMonaiLabelTool.h +++ b/Modules/Segmentation/Interactions/mitkMonaiLabelTool.h @@ -1,98 +1,102 @@ /*============================================================================ The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center (DKFZ) All rights reserved. Use of this source code is governed by a 3-clause BSD license that can be found in the LICENSE file. ============================================================================*/ #ifndef MITKMONAILABELTOOL_H #define MITKMONAILABELTOOL_H #include "mitkSegWithPreviewTool.h" #include #include #include #include #include +#include +#include + namespace us { class ModuleResource; } namespace mitk { // class Image; struct MonaiModelInfo { std::string name; std::string type; std::unordered_map labels; int dimension; std::string description; std::unordered_map config; //TODO: find the full extent }; struct MonaiAppMetadata { std::string URL; unsigned short port; std::string origin; std::string name; std::string description; std::string version; std::vector labels; std::vector models; }; class MITKSEGMENTATION_EXPORT MonaiLabelTool : public SegWithPreviewTool { public: mitkClassMacro(MonaiLabelTool, SegWithPreviewTool); itkFactorylessNewMacro(Self); itkCloneMacro(Self); const char *GetName() const override; const char **GetXPM() const override; us::ModuleResource GetIconResource() const override; void Activated() override; void GetOverallInfo(std::string); std::unique_ptr m_Parameters; //contains all parameters from Server to serve the GUI std::vector GetAutoSegmentationModels(); std::vector GetInteractiveSegmentationModels(); std::vector GetScribbleSegmentationModels(); void PostSegmentationRequest(); itkSetMacro(ModelName, std::string); itkGetConstMacro(ModelName, std::string); itkSetMacro(URL, std::string); itkGetConstMacro(URL, std::string); protected: MonaiLabelTool(); ~MonaiLabelTool() = default; void DoUpdatePreview(const Image* inputAtTimeStep, const Image* oldSegAtTimeStep, LabelSetImage* previewImage, TimeStepType timeStep) override; private: void InitializeRESTManager(); std::unique_ptr DataMapper(web::json::value&); + std::unique_ptr mitk::MonaiLabelTool::DataMapper(nlohmann::json&); mitk::IRESTManager *m_RESTManager; const std::set m_AUTO_SEG_TYPE_NAME = {"segmentation"}; const std::set m_SCRIBBLE_SEG_TYPE_NAME = {"scribbles"}; const std::set m_INTERACTIVE_SEG_TYPE_NAME = {"deepedit", "deepgrow"}; std::string m_ModelName; std::string m_URL; }; // class } // namespace #endif diff --git a/Modules/SegmentationUI/Qmitk/QmitkMonaiLabelToolGUI.cpp b/Modules/SegmentationUI/Qmitk/QmitkMonaiLabelToolGUI.cpp index ecb3f78beb..40648c039f 100644 --- a/Modules/SegmentationUI/Qmitk/QmitkMonaiLabelToolGUI.cpp +++ b/Modules/SegmentationUI/Qmitk/QmitkMonaiLabelToolGUI.cpp @@ -1,92 +1,92 @@ #include "QmitkMonaiLabelToolGUI.h" #include "mitkMonaiLabelTool.h" #include #include #include #include "usServiceReference.h" #include #include #include MITK_TOOL_GUI_MACRO(MITKSEGMENTATIONUI_EXPORT, QmitkMonaiLabelToolGUI, "") QmitkMonaiLabelToolGUI::QmitkMonaiLabelToolGUI() : QmitkMultiLabelSegWithPreviewToolGUIBase(), m_SuperclassEnableConfirmSegBtnFnc(m_EnableConfirmSegBtnFnc) { m_EnableConfirmSegBtnFnc = [this](bool enabled) { return !m_FirstPreviewComputation ? m_SuperclassEnableConfirmSegBtnFnc(enabled) : false; }; } void QmitkMonaiLabelToolGUI::ConnectNewTool(mitk::SegWithPreviewTool* newTool) { Superclass::ConnectNewTool(newTool); newTool->IsTimePointChangeAwareOff(); m_FirstPreviewComputation = true; } void QmitkMonaiLabelToolGUI::InitializeUI(QBoxLayout* mainLayout) { m_Controls.setupUi(this); mainLayout->addLayout(m_Controls.verticalLayout); connect(m_Controls.previewButton, SIGNAL(clicked()), this, SLOT(OnPreviewBtnClicked())); connect(m_Controls.fetchUrl, SIGNAL(clicked()), this, SLOT(OnFetchBtnClicked())); QIcon refreshIcon = QmitkStyleManager::ThemeIcon(QStringLiteral(":/org_mitk_icons/icons/awesome/scalable/actions/view-refresh.svg")); m_Controls.fetchUrl->setIcon(refreshIcon); Superclass::InitializeUI(mainLayout); } void QmitkMonaiLabelToolGUI::EnableWidgets(bool enabled) { Superclass::EnableWidgets(enabled); } void QmitkMonaiLabelToolGUI::OnFetchBtnClicked() { auto tool = this->GetConnectedToolAs(); if (nullptr != tool) { QString urlString = m_Controls.urlBox->text(); QUrl url(urlString); if (url.isValid() && !url.isLocalFile() && !url.hasFragment() && !url.hasQuery()) // sanity check { tool->GetOverallInfo(urlString.toStdString()); // tool->GetOverallInfo("http://localhost:8000/info"); if (nullptr != tool->m_Parameters) { std::string response = tool->m_Parameters->name; std::vector autoModels = tool->GetAutoSegmentationModels(); m_Controls.responseNote->setText(QString::fromStdString(response)); m_Controls.appBox->addItem(QString::fromStdString(response)); for (auto &model : autoModels) { m_Controls.modelBox->addItem(QString::fromStdString(model.name)); } } } else { MITK_ERROR << "Invalid URL entered: " << urlString.toStdString(); } } } void QmitkMonaiLabelToolGUI::OnPreviewBtnClicked() { auto tool = this->GetConnectedToolAs(); if (nullptr != tool) { /* QString url = m_Controls.url->text(); MITK_INFO << "tool found" << url.toStdString();*/ //tool->GetOverallInfo("https://httpbin.org/get"); - + tool->PostSegmentationRequest(); } //tool->UpdatePreview(); }