From b17fe8a7fc903b02a9f40e16652408759ac92d0e Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Sun, 12 Oct 2014 23:14:25 +0300 Subject: [PATCH] impl/voxel_volume: Voxel data compression --- src/impl/voxel_volume.cpp | 57 +++++++++++++++++++++++++++++++++------ src/interface/compress.h | 2 +- 2 files changed, 50 insertions(+), 9 deletions(-) diff --git a/src/impl/voxel_volume.cpp b/src/impl/voxel_volume.cpp index ba3dc0f..130ce3c 100644 --- a/src/impl/voxel_volume.cpp +++ b/src/impl/voxel_volume.cpp @@ -1,8 +1,10 @@ // http://www.apache.org/licenses/LICENSE-2.0 // Copyright 2014 Perttu Ahola #include "interface/voxel_volume.h" +#include "interface/compress.h" #include "core/log.h" #include +#include #define MODULE "voxel_volume" namespace interface { @@ -19,8 +21,7 @@ ss_ serialize_volume_simple(const pv::RawVolume &volume) auto region = volume.getEnclosingRegion(); auto lc = region.getLowerCorner(); auto uc = region.getUpperCorner(); - size_t size = volume.getWidth() * volume.getHeight() * volume.getDepth(); - for(size_t i=0; i &volume) ss_ serialize_volume_compressed(const pv::RawVolume &volume) { std::ostringstream os(std::ios::binary); - os<<(uint8_t)3; // Format - // TODO - log_w(MODULE, "serialize_volume_compressed: Not implemented"); + { + cereal::PortableBinaryOutputArchive ar(os); + ar((uint8_t)3); // Format + ar((int32_t)volume.getWidth()); + ar((int32_t)volume.getHeight()); + ar((int32_t)volume.getDepth()); + std::ostringstream raw_os(std::ios::binary); + { + cereal::PortableBinaryOutputArchive ar(raw_os); + auto region = volume.getEnclosingRegion(); + auto lc = region.getLowerCorner(); + auto uc = region.getUpperCorner(); + for(size_t i=0; i> deserialize_volume(const ss_ &data) pv::Region region(0, 0, 0, w-1, h-1, d-1); up_> volume( new pv::RawVolume(region)); - size_t size = volume->getWidth() * volume->getHeight() * volume->getDepth(); - for(size_t i=0; im_dataSize; i++){ uint32_t v; ar(v); volume->m_pData[i].data = v; } return volume; } - log_w(MODULE, "deserialize_volume(): Unknown format %i", format); + if(format == 3){ + int32_t w = 0; + int32_t h = 0; + int32_t d = 0; + ar(w, h, d); + pv::Region region(0, 0, 0, w-1, h-1, d-1); + up_> volume( + new pv::RawVolume(region)); + ss_ compressed_data; + ar(compressed_data); + std::istringstream compressed_is(compressed_data, std::ios::binary); + std::ostringstream raw_os(std::ios::binary); + decompress_zlib(compressed_is, raw_os); + { + std::istringstream raw_is(raw_os.str(), std::ios::binary); + cereal::PortableBinaryInputArchive ar(raw_is); + for(size_t i=0; im_dataSize; i++){ + uint32_t v; + ar(v); + volume->m_pData[i].data = v; + } + } + return volume; + } return up_>();; } diff --git a/src/interface/compress.h b/src/interface/compress.h index b02c632..8635556 100644 --- a/src/interface/compress.h +++ b/src/interface/compress.h @@ -5,7 +5,7 @@ namespace interface { - void compress_zlib(const ss_ &data_in, std::ostream &os, int level); + void compress_zlib(const ss_ &data_in, std::ostream &os, int level=6); void decompress_zlib(std::istream &is, std::ostream &os); } // vim: set noet ts=4 sw=4: