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

Method ReadUncompressedData

IO/XMLParser/vtkXMLDataParser.cxx:632–701  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

630
631//------------------------------------------------------------------------------
632size_t vtkXMLDataParser::ReadUncompressedData(
633 unsigned char* data, vtkTypeUInt64 startWord, size_t numWords, size_t wordSize)
634{
635 // First read the length of the data.
636 std::unique_ptr<vtkXMLDataHeader> uh(vtkXMLDataHeader::New(this->HeaderType, 1));
637
638 size_t const headerSize = uh->DataSize();
639 size_t r = this->DataStream->Read(uh->Data(), headerSize);
640 if (r < headerSize)
641 {
642 vtkErrorMacro("Error reading uncompressed binary data header. "
643 "Read "
644 << r << " of " << headerSize << " bytes.");
645 return 0;
646 }
647 this->PerformByteSwap(uh->Data(), uh->WordCount(), uh->WordSize());
648 vtkTypeUInt64 rsize = uh->Get(0);
649
650 // Adjust the size to be a multiple of the wordSize by taking
651 // advantage of integer division. This will only change the value
652 // when the input file is invalid.
653 vtkTypeUInt64 size = (rsize / wordSize) * wordSize;
654
655 // Convert the start/length into bytes.
656 vtkTypeUInt64 offset = startWord * wordSize;
657 size_t length = numWords * wordSize;
658
659 // Make sure the begin/end offsets fall within total size.
660 if (offset > size)
661 {
662 return 0;
663 }
664 vtkTypeUInt64 end = offset + length;
665 end = std::min(end, size);
666 length = end - offset;
667
668 // Read the data.
669 if (!this->DataStream->Seek(headerSize + offset))
670 {
671 return 0;
672 }
673
674 // Read data in 2MB blocks and report progress.
675 constexpr size_t blockSize = 2097152;
676 size_t left = length;
677 unsigned char* p = data;
678 this->UpdateProgress(0);
679 while (left > 0 && !this->Abort)
680 {
681 // Read this block.
682 size_t n = (blockSize < left) ? blockSize : left;
683 if (!this->DataStream->Read(p, n))
684 {
685 return 0;
686 }
687
688 // Byte swap this block. Note that n will always be an integer
689 // multiple of the word size.

Callers 1

ReadBinaryDataMethod · 0.95

Calls 10

PerformByteSwapMethod · 0.95
UpdateProgressMethod · 0.95
WordCountMethod · 0.80
WordSizeMethod · 0.80
NewFunction · 0.50
minFunction · 0.50
ReadMethod · 0.45
DataMethod · 0.45
GetMethod · 0.45
SeekMethod · 0.45

Tested by

no test coverage detected