MCPcopy Create free account
hub / github.com/Kitware/VTK / ParseSparseData

Method ParseSparseData

IO/Infovis/vtkBiomTableReader.cxx:330–394  ·  view source on GitHub ↗

------------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

328
329//------------------------------------------------------------------------------
330void vtkBiomTableReader::ParseSparseData()
331{
332 // find "data":
333 size_t pos1 = this->FileContents.find("\"data\":");
334 if (pos1 == std::string::npos)
335 {
336 vtkErrorMacro(<< "data not found in input file");
337 return;
338 }
339
340 // find first [ (beginning of matrix)
341 size_t pos_start = this->FileContents.find('[', pos1) + 1;
342 if (pos_start == std::string::npos)
343 {
344 vtkErrorMacro(<< "data field not formatted properly");
345 return;
346 }
347
348 while (true)
349 {
350 // find [ (beginning of triplet)
351 pos1 = this->FileContents.find('[', pos_start);
352 if (pos1 == std::string::npos)
353 {
354 vtkErrorMacro(<< "data field not formatted properly");
355 return;
356 }
357 // find first comma
358 size_t pos2 = this->FileContents.find(',', pos1 + 1);
359 if (pos2 == std::string::npos)
360 {
361 vtkErrorMacro(<< "data field not formatted properly");
362 return;
363 }
364 // find second comma
365 size_t pos3 = this->FileContents.find(',', pos2 + 1);
366 if (pos3 == std::string::npos)
367 {
368 vtkErrorMacro(<< "data field not formatted properly");
369 return;
370 }
371 // find ] (end of triplet)
372 size_t pos4 = this->FileContents.find(']', pos3 + 1);
373 if (pos4 == std::string::npos)
374 {
375 vtkErrorMacro(<< "data field not formatted properly");
376 return;
377 }
378 // row is between "[" and ","
379 int row = vtk::scan_int<int>(this->FileContents.substr(pos1 + 1, pos2 - pos1))->value();
380
381 // column is between first and second comma
382 int column =
383 1 + vtk::scan_int<int>(this->FileContents.substr(pos2 + 1, pos3 - pos2 - 1))->value();
384
385 std::string value = this->FileContents.substr(pos3 + 1, pos4 - pos3 - 1);
386 this->InsertValue(row, column, value);
387

Callers 1

ReadMeshSimpleMethod · 0.95

Calls 3

InsertValueMethod · 0.95
findMethod · 0.45
valueMethod · 0.45

Tested by

no test coverage detected