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

Method DoRead

Modules/Segmentation/autoload/IO/mitkSegmentationTaskListIO.cpp:157–269  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

155}
156
157std::vector<mitk::BaseData::Pointer> mitk::SegmentationTaskListIO::DoRead()
158{
159 auto* stream = this->GetInputStream();
160 std::ifstream fileStream;
161
162 if (nullptr == stream)
163 {
164 auto filename = this->GetInputLocation();
165
166 if (filename.empty() || !fs::exists(filename))
167 mitkThrow() << "Invalid or nonexistent filename: \"" << filename << "\"!";
168
169 fileStream.open(filename);
170
171 if (!fileStream.is_open())
172 mitkThrow() << "Could not open file \"" << filename << "\" for reading!";
173
174 stream = &fileStream;
175 }
176
177 nlohmann::json json;
178
179 try
180 {
181 json = nlohmann::json::parse(*stream);
182 }
183 catch (const nlohmann::json::exception& e)
184 {
185 mitkThrow() << e.what();
186 }
187
188 if (!json.is_object())
189 mitkThrow() << "Unknown file format (expected JSON object as root)!";
190
191 if ("MITK Segmentation Task List" != json.value("FileFormat", ""))
192 mitkThrow() << "Unknown file format (expected \"MITK Segmentation Task List\")!";
193
194 int version;
195
196 if (version = json.value<int>("Version", 0); version < 1 || version > 3)
197 mitkThrow() << "Unknown file format version (expected \"1\", \"2\", or \"3\")!";
198
199 if (!json.contains("Tasks") || !json["Tasks"].is_array())
200 mitkThrow() << "Tasks array not found!";
201
202 auto segmentationTaskList = SegmentationTaskList::New();
203
204 try
205 {
206 if (json.contains("Name"))
207 segmentationTaskList->SetProperty("name", StringProperty::New(json["Name"].get<std::string>()));
208
209 if (json.contains("Defaults"))
210 {
211 segmentationTaskList->SetDefaults(json["Defaults"].get<SegmentationTaskList::Task>());
212
213 if (segmentationTaskList->GetDefaults().HasResult())
214 mitkThrow() << "Defaults must not contain \"Result\"!";

Callers

nothing calls this directly

Calls 15

ResolvePathMethod · 0.95
GetInputStreamMethod · 0.80
GetInputLocationMethod · 0.80
whatMethod · 0.80
containsMethod · 0.80
SetDefaultsMethod · 0.80
AddTaskMethod · 0.80
GetFormMethod · 0.80
GetPointerMethod · 0.80
NewFunction · 0.50
emptyMethod · 0.45
openMethod · 0.45

Tested by

no test coverage detected