MCPcopy Create free account
hub / github.com/MITK/MITK / DoUpdatePreview

Method DoUpdatePreview

Modules/Segmentation/src/Interactions/mitkMonaiLabelTool.cpp:382–437  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

380}
381
382void mitk::MonaiLabelTool::DoUpdatePreview(const Image *inputAtTimeStep,
383 const Image * /*oldSegAtTimeStep*/,
384 MultiLabelSegmentation *previewImage,
385 TimeStepType timeStep)
386{
387 if (nullptr == m_RequestParameters || (m_RequestParameters->model.IsInteractive() && !this->HasPicks()))
388 {
389 this->ResetPreviewContentAtTimeStep(timeStep);
390 RenderingManager::GetInstance()->ForceImmediateUpdateAll();
391 return;
392 }
393 const std::string &hostName = m_RequestParameters->hostName;
394 const int port = m_RequestParameters->port;
395 if (!IsMonaiServerOn(hostName, port))
396 {
397 mitkThrow() << m_SERVER_503_ERROR_TEXT;
398 }
399 if (this->m_TempDir.empty())
400 {
401 this->SetTempDir(IOUtil::CreateTemporaryDirectory("mitk-XXXXXX"));
402 }
403
404 std::string inputImagePath, outputImagePath;
405 std::tie(inputImagePath, outputImagePath) = this->CreateTempDirs(m_TEMPLATE_FILENAME);
406
407 try
408 {
409 mitk::Image::Pointer filteredImage = this->ApplyLevelWindowEffect(inputAtTimeStep);
410 this->WriteImage(filteredImage, inputImagePath);
411 this->PostInferRequest(hostName, port, inputImagePath, outputImagePath, inputAtTimeStep->GetGeometry());
412 auto outputImage = IOUtil::Load<Image>(outputImagePath);
413 auto outputBuffer = mitk::MultiLabelSegmentation::New();
414 outputBuffer->InitializeByLabeledImage(outputImage);
415 std::map<std::string, mitk::Label::PixelType> labelMap; // empty map
416 if (m_RequestParameters->model.IsInteractive())
417 {
418 this->SetLabelTransferMode(LabelTransferMode::MapLabel);
419 this->SetSelectedLabels({MASK_VALUE});
420 }
421 else
422 {
423 outputBuffer->SetGeometry(inputAtTimeStep->GetGeometry());
424 labelMap = m_ResultMetadata["label_names"];
425 this->SetLabelTransferMode(LabelTransferMode::AddLabel);
426 }
427 ::MapLabelsToSegmentation(outputBuffer, previewImage, labelMap);
428 this->WriteBackResults(previewImage, outputBuffer.GetPointer(), timeStep);
429 MonaiStatusEvent.Send(true);
430 }
431 catch (const mitk::Exception &e)
432 {
433 MITK_ERROR << e.GetDescription();
434 mitkThrow() << e.GetDescription();
435 MonaiStatusEvent.Send(false);
436 }
437}
438
439void mitk::MonaiLabelTool::FetchOverallInfo(const std::string &hostName, const int &port)

Callers

nothing calls this directly

Calls 15

HasPicksMethod · 0.95
CreateTempDirsMethod · 0.95
PostInferRequestMethod · 0.95
MapLabelsToSegmentationFunction · 0.85
IsInteractiveMethod · 0.80
GetGeometryMethod · 0.80
SetLabelTransferModeMethod · 0.80
GetPointerMethod · 0.80
NewFunction · 0.50

Tested by

no test coverage detected