| 83 | } |
| 84 | |
| 85 | bool LabelSuggestionHelper::ParseSuggestions(const std::string& filePath, bool replaceExisting) |
| 86 | { |
| 87 | std::ifstream input(filePath); |
| 88 | if (!input.is_open()) |
| 89 | { |
| 90 | return false; |
| 91 | } |
| 92 | |
| 93 | nlohmann::json fileContent; |
| 94 | try |
| 95 | { |
| 96 | input >> fileContent; |
| 97 | } |
| 98 | catch (const nlohmann::json::parse_error& e) |
| 99 | { |
| 100 | mitkThrow() << "Cannot reader data due to parsing error. Parse error: " << e.what() << '\n'; |
| 101 | } |
| 102 | |
| 103 | //check version |
| 104 | int version = 0; |
| 105 | |
| 106 | if (MultiLabelIOHelper::GetValueFromJson<int>(fileContent, "version", version)) |
| 107 | { |
| 108 | if (version > MULTILABEL_SEGMENTATION_VERSION_VALUE) |
| 109 | { |
| 110 | mitkThrow() << "Suggestion file to parse has unsupported version. Software is to old to ensure correct reading. Please use a compatible version of MITK or store data in another format. Version of data: " << version << "; Supported versions up to: " << MULTILABEL_SEGMENTATION_VERSION_VALUE; |
| 111 | } |
| 112 | } |
| 113 | else |
| 114 | { |
| 115 | MITK_INFO << "Data has unknown version. Assuming that it can be read. Result might be invalid."; |
| 116 | } |
| 117 | |
| 118 | return this->ParseSuggestions(fileContent, replaceExisting); |
| 119 | } |
| 120 | |
| 121 | bool LabelSuggestionHelper::ParseSuggestions(const nlohmann::json& jsonSuggestions, bool replaceExisting) |
| 122 | { |