Load/activate the currently displayed task. The task must specify an image * or a scene. The segmentation is either created from scratch with an optional * name for the first label, possibly based on a label set preset specified by * the task, or loaded as specified by the task. If a result file does * exist, it is chosen as segmentation instead. */
| 848 | * exist, it is chosen as segmentation instead. |
| 849 | */ |
| 850 | void QmitkSegmentationTaskListWidget::LoadTask(mitk::DataNode::Pointer imageNode) |
| 851 | { |
| 852 | const auto current = m_CurrentTaskIndex.value(); |
| 853 | |
| 854 | mitk::Image::Pointer image; |
| 855 | mitk::MultiLabelSegmentation::Pointer segmentation; |
| 856 | mitk::DataStorage::Pointer scene; |
| 857 | |
| 858 | // If the task has a scene, unload everything from before and load the scene. |
| 859 | // If the task has an image instead, unload everything but the previous image |
| 860 | // if it is the same image and can be reused. Otherwise load the new image. |
| 861 | |
| 862 | if (m_TaskList->HasScene(current)) |
| 863 | { |
| 864 | this->UnloadTasks(); |
| 865 | |
| 866 | try |
| 867 | { |
| 868 | const auto scenePath = m_TaskList->GetAbsolutePath(m_TaskList->GetScene(current).Path); |
| 869 | auto sceneIO = mitk::SceneIO::New(); |
| 870 | |
| 871 | switch (mitk::ClassifyTaskListSceneFile(scenePath)) |
| 872 | { |
| 873 | case mitk::SceneFileForm::Zip: |
| 874 | case mitk::SceneFileForm::JsonStandalone: |
| 875 | scene = sceneIO->LoadScene(scenePath.string()); |
| 876 | break; |
| 877 | |
| 878 | case mitk::SceneFileForm::UnpackedIndex: |
| 879 | scene = sceneIO->LoadSceneUnzipped(scenePath.string()); |
| 880 | break; |
| 881 | } |
| 882 | } |
| 883 | catch (const mitk::Exception& e) |
| 884 | { |
| 885 | QMessageBox::critical(this, "Error while loading scene", e.GetDescription()); |
| 886 | MITK_ERROR << e.GetDescription(); |
| 887 | return; |
| 888 | } |
| 889 | } |
| 890 | else |
| 891 | { |
| 892 | this->UnloadTasks(imageNode); |
| 893 | |
| 894 | if (imageNode.IsNull()) |
| 895 | { |
| 896 | try |
| 897 | { |
| 898 | const auto imagePath = m_TaskList->GetAbsolutePath(m_TaskList->GetImage(current)); |
| 899 | image = mitk::IOUtil::Load<mitk::Image>(imagePath.string()); |
| 900 | } |
| 901 | catch (const mitk::Exception& e) |
| 902 | { |
| 903 | QMessageBox::critical(this, "Error while loading image", e.GetDescription()); |
| 904 | MITK_ERROR << e.GetDescription(); |
| 905 | return; |
| 906 | } |
| 907 | } |
no test coverage detected