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

Method WriteData

IO/CellGrid/vtkCellGridWriter.cxx:392–441  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

390}
391
392void vtkCellGridWriter::WriteData()
393{
394 if (!this->FileName || !this->FileName[0])
395 {
396 vtkErrorMacro("No filename set.");
397 return;
398 }
399
400 auto* grid = this->GetInput();
401 if (!grid)
402 {
403 vtkErrorMacro("No input dataset to write to \"" << this->FileName << "\"");
404 return;
405 }
406
407 std::ofstream output(this->FileName);
408 if (!output.good())
409 {
410 vtkErrorMacro("Could not open \"" << this->FileName << "\" for writing.");
411 return;
412 }
413
414 nlohmann::json data;
415 if (this->ToJSON(data, grid))
416 {
417 switch (this->FileFormat)
418 {
419 default:
420 case Format::PlainText:
421 output << data;
422 break;
423 case Format::MessagePack:
424 {
425 output << "vtkCellGrid\nMessagePack\nv1\n";
426 std::vector<char> mpack;
427 nlohmann::json::to_msgpack(data, mpack);
428 auto writeSize = mpack.size() / sizeof(std::istream::char_type) +
429 (mpack.size() % sizeof(std::istream::char_type) ? 1 : 0);
430 output.write(reinterpret_cast<std::ostream::char_type*>(mpack.data()), writeSize);
431 }
432 break;
433 }
434 output.close();
435 }
436 else
437 {
438 vtkErrorMacro("Could not write JSON to \"" << this->FileName << "\".");
439 return; /* 0 */
440 }
441}
442
443VTK_ABI_NAMESPACE_END

Callers

nothing calls this directly

Calls 8

GetInputMethod · 0.95
ToJSONMethod · 0.95
to_msgpackFunction · 0.85
goodMethod · 0.45
sizeMethod · 0.45
writeMethod · 0.45
dataMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected