1 // Copyright 2019-2021 Intel Corporation 2 // SPDX-License-Identifier: Apache-2.0 3 4 #pragma once 5 6 #include "TestingStructuredVolume.h" 7 // std 8 #include <algorithm> 9 #include <fstream> 10 11 using namespace rkcommon; 12 13 namespace openvkl { 14 namespace testing { 15 16 struct RawFileStructuredVolume final : public TestingStructuredVolume 17 { 18 RawFileStructuredVolume(const std::string &filename, 19 const std::string &gridType, 20 const vec3i &dimensions, 21 const vec3f &gridOrigin, 22 const vec3f &gridSpacing, 23 VKLDataType voxelType); 24 25 void generateVoxels(std::vector<unsigned char> &voxels, 26 std::vector<float> &time, 27 std::vector<uint32_t> &tuvIndex) const override final; 28 29 private: 30 std::string filename; 31 }; 32 33 // Inlined definitions //////////////////////////////////////////////////// 34 RawFileStructuredVolume(const std::string & filename,const std::string & gridType,const vec3i & dimensions,const vec3f & gridOrigin,const vec3f & gridSpacing,VKLDataType voxelType)35 inline RawFileStructuredVolume::RawFileStructuredVolume( 36 const std::string &filename, 37 const std::string &gridType, 38 const vec3i &dimensions, 39 const vec3f &gridOrigin, 40 const vec3f &gridSpacing, 41 VKLDataType voxelType) 42 : filename(filename), 43 TestingStructuredVolume(gridType, 44 dimensions, 45 gridOrigin, 46 gridSpacing, 47 TemporalConfig(), 48 voxelType) 49 { 50 } 51 generateVoxels(std::vector<unsigned char> & voxels,std::vector<float> & time,std::vector<uint32_t> & tuvIndex)52 inline void RawFileStructuredVolume::generateVoxels( 53 std::vector<unsigned char> &voxels, 54 std::vector<float> &time, 55 std::vector<uint32_t> &tuvIndex) const 56 { 57 const size_t numValues = this->dimensions.long_product(); 58 const size_t numBytes = numValues * sizeOfVKLDataType(voxelType); 59 60 voxels.resize(numBytes); 61 time.clear(); 62 tuvIndex.clear(); 63 64 std::ifstream input(filename, std::ios::binary); 65 66 if (!input) { 67 throw std::runtime_error("error opening raw volume file"); 68 } 69 70 input.read((char *)voxels.data(), numBytes); 71 72 if (!input.good()) { 73 throw std::runtime_error("error reading raw volume file"); 74 } 75 } 76 77 } // namespace testing 78 } // namespace openvkl 79