------------------------------------------------------------------------
| 830 | |
| 831 | //------------------------------------------------------------------------ |
| 832 | bool vtkOpenVDBReader::LoadFile() |
| 833 | { |
| 834 | if (this->FileName == nullptr && this->Stream == nullptr) |
| 835 | { |
| 836 | vtkErrorMacro(<< "No file name or stream has been set."); |
| 837 | return false; |
| 838 | } |
| 839 | |
| 840 | this->Internals->ResetCurrentlyOpenedFile(this->FileName); |
| 841 | |
| 842 | this->DataCorrect = true; |
| 843 | |
| 844 | if (this->Stream) |
| 845 | { |
| 846 | // Encapsulate resource stream into an istream |
| 847 | this->Stream->Seek(0, vtkResourceStream::SeekDirection::Begin); |
| 848 | auto strbuf = this->Stream->ToStreambuf(); |
| 849 | std::istream buffer(strbuf.get()); |
| 850 | |
| 851 | try |
| 852 | { |
| 853 | // Read the istream using OpenVDB |
| 854 | this->Internals->GridsVdbMetadata = openvdb::io::Stream(buffer, false).getGrids(); |
| 855 | } |
| 856 | catch (openvdb::IoError& e) |
| 857 | { |
| 858 | // happens when the strean is not a VDB file |
| 859 | vtkErrorMacro("Error while loading grids from stream: " << e.what()); |
| 860 | return false; |
| 861 | } |
| 862 | } |
| 863 | else |
| 864 | { |
| 865 | vtkOpenVDBReaderInternals::VdbFileContext resCtx = this->Internals->OpenFile(this->FileName); |
| 866 | |
| 867 | if (resCtx.File == nullptr) |
| 868 | { |
| 869 | return false; |
| 870 | } |
| 871 | |
| 872 | // then try to read the metadata |
| 873 | try |
| 874 | { |
| 875 | // it creates the pointers to the metadata of the grids |
| 876 | this->Internals->GridsVdbMetadata = resCtx.File->readAllGridMetadata(); |
| 877 | } |
| 878 | catch (openvdb::IoError& e) |
| 879 | { |
| 880 | vtkErrorMacro(<< "Error while loading metadata from " << this->FileName << ": " << e.what()); |
| 881 | resCtx.File = nullptr; |
| 882 | resCtx.FileName = ""; |
| 883 | return false; |
| 884 | } |
| 885 | |
| 886 | // if everything went well, copy it into CurrentlyOpenedFile |
| 887 | this->Internals->CurrentlyOpenedFile.File = resCtx.File; |
| 888 | this->Internals->CurrentlyOpenedFile.FileName = resCtx.FileName; |
| 889 | } |
no test coverage detected