From ae3f1498381d22ea6d7d585525bd3eb1c4c79d1e Mon Sep 17 00:00:00 2001 From: David Williams Date: Thu, 26 Aug 2010 21:16:52 +0000 Subject: [PATCH] Reverted what looks like a previous accidental serialization commit. --- library/PolyVoxUtil/include/Serialization.h | 264 +----------------- library/PolyVoxUtil/include/Serialization.inl | 261 +++++++++++++++++ 2 files changed, 262 insertions(+), 263 deletions(-) diff --git a/library/PolyVoxUtil/include/Serialization.h b/library/PolyVoxUtil/include/Serialization.h index 52d1ee22..02a4a84f 100644 --- a/library/PolyVoxUtil/include/Serialization.h +++ b/library/PolyVoxUtil/include/Serialization.h @@ -52,268 +52,6 @@ namespace PolyVox void saveVolumeRle(std::ostream& stream, Volume& volume, VolumeSerializationProgressListener* progressListener = 0); } -/******************************************************************************* -Copyright (c) 2005-2009 David Williams - -This software is provided 'as-is', without any express or implied -warranty. In no event will the authors be held liable for any damages -arising from the use of this software. - -Permission is granted to anyone to use this software for any purpose, -including commercial applications, and to alter it and redistribute it -freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - - 3. This notice may not be removed or altered from any source - distribution. -*******************************************************************************/ - -#include "Serialization.h" - -#include "Volume.h" -#include "VolumeSampler.h" -#include "PolyVoxImpl/Utility.h" - -using namespace std; - -namespace PolyVox -{ - //Note: we don't do much error handling in here - exceptions will simply be propergated up to the caller. - //FIXME - think about pointer ownership issues. Or could return volume by value if the copy constructor is shallow - template - shared_ptr< Volume > loadVolumeRaw(istream& stream, VolumeSerializationProgressListener* progressListener) - { - //Read volume dimensions - uint8_t volumeWidthPower = 0; - uint8_t volumeHeightPower = 0; - uint8_t volumeDepthPower = 0; - stream.read(reinterpret_cast(&volumeWidthPower), sizeof(volumeWidthPower)); - stream.read(reinterpret_cast(&volumeHeightPower), sizeof(volumeHeightPower)); - stream.read(reinterpret_cast(&volumeDepthPower), sizeof(volumeDepthPower)); - - uint16_t volumeWidth = 0x0001 << volumeWidthPower; - uint16_t volumeHeight = 0x0001 << volumeHeightPower; - uint16_t volumeDepth = 0x0001 << volumeDepthPower; - - //FIXME - need to support non cubic volumes - shared_ptr< Volume > volume(new Volume(volumeWidth, volumeHeight, volumeDepth)); - - //Read data - for(uint16_t z = 0; z < volumeDepth; ++z) - { - //Update progress once per slice. - if(progressListener) - { - float fProgress = static_cast(z) / static_cast(volumeDepth); - progressListener->onProgressUpdated(fProgress); - } - - for(uint16_t y = 0; y < volumeHeight; ++y) - { - for(uint16_t x = 0; x < volumeWidth; ++x) - { - VoxelType value; - stream.read(reinterpret_cast(&value), sizeof(value)); - - volume->setVoxelAt(x,y,z,value); - } - } - } - - //Finished - if(progressListener) - { - progressListener->onProgressUpdated(1.0f); - } - - return volume; - } - - template - void saveVolumeRaw(std::ostream& stream, Volume& volume, VolumeSerializationProgressListener* progressListener) - { - //Write volume dimensions - uint16_t volumeWidth = volume.getWidth(); - uint16_t volumeHeight = volume.getHeight(); - uint16_t volumeDepth = volume.getDepth(); - - uint8_t volumeWidthPower = logBase2(volumeWidth); - uint8_t volumeHeightPower = logBase2(volumeHeight); - uint8_t volumeDepthPower = logBase2(volumeDepth); - - stream.write(reinterpret_cast(&volumeWidthPower), sizeof(volumeWidthPower)); - stream.write(reinterpret_cast(&volumeHeightPower), sizeof(volumeHeightPower)); - stream.write(reinterpret_cast(&volumeDepthPower), sizeof(volumeDepthPower)); - - //Write data - VolumeSampler volIter(&volume); - for(uint16_t z = 0; z < volumeDepth; ++z) - { - //Update progress once per slice. - if(progressListener) - { - float fProgress = static_cast(z) / static_cast(volumeDepth); - progressListener->onProgressUpdated(fProgress); - } - - for(uint16_t y = 0; y < volumeHeight; ++y) - { - for(uint16_t x = 0; x < volumeWidth; ++x) - { - volIter.setPosition(x,y,z); - VoxelType value = volIter.getVoxel(); - stream.write(reinterpret_cast(&value), sizeof(value)); - } - } - } - - //Finished - if(progressListener) - { - progressListener->onProgressUpdated(1.0f); - } - } - - //Note: we don't do much error handling in here - exceptions will simply be propergated up to the caller. - //FIXME - think about pointer ownership issues. Or could return volume by value if the copy constructor is shallow - template - shared_ptr< Volume > loadVolumeRle(istream& stream, VolumeSerializationProgressListener* progressListener) - { - //Read volume dimensions - uint8_t volumeWidthPower = 0; - uint8_t volumeHeightPower = 0; - uint8_t volumeDepthPower = 0; - stream.read(reinterpret_cast(&volumeWidthPower), sizeof(volumeWidthPower)); - stream.read(reinterpret_cast(&volumeHeightPower), sizeof(volumeHeightPower)); - stream.read(reinterpret_cast(&volumeDepthPower), sizeof(volumeDepthPower)); - - uint16_t volumeWidth = 0x0001 << volumeWidthPower; - uint16_t volumeHeight = 0x0001 << volumeHeightPower; - uint16_t volumeDepth = 0x0001 << volumeDepthPower; - - //FIXME - need to support non cubic volumes - shared_ptr< Volume > volume(new Volume(volumeWidth, volumeHeight, volumeDepth)); - - //Read data - bool firstTime = true; - uint32_t runLength = 0; - VoxelType value; - stream.read(reinterpret_cast(&value), sizeof(value)); - stream.read(reinterpret_cast(&runLength), sizeof(runLength)); - for(uint16_t z = 0; z < volumeDepth; ++z) - { - //Update progress once per slice. - if(progressListener) - { - float fProgress = static_cast(z) / static_cast(volumeDepth); - progressListener->onProgressUpdated(fProgress); - } - - for(uint16_t y = 0; y < volumeHeight; ++y) - { - for(uint16_t x = 0; x < volumeWidth; ++x) - { - if(runLength != 0) - { - volume->setVoxelAt(x,y,z,value); - runLength--; - } - else - { - stream.read(reinterpret_cast(&value), sizeof(value)); - stream.read(reinterpret_cast(&runLength), sizeof(runLength)); - - volume->setVoxelAt(x,y,z,value); - runLength--; - } - } - } - } - - //Finished - if(progressListener) - { - progressListener->onProgressUpdated(1.0f); - } - - return volume; - } - - template - void saveVolumeRle(std::ostream& stream, Volume& volume, VolumeSerializationProgressListener* progressListener) - { - //Write volume dimensions - uint16_t volumeWidth = volume.getWidth(); - uint16_t volumeHeight = volume.getHeight(); - uint16_t volumeDepth = volume.getDepth(); - - uint8_t volumeWidthPower = logBase2(volumeWidth); - uint8_t volumeHeightPower = logBase2(volumeHeight); - uint8_t volumeDepthPower = logBase2(volumeDepth); - - stream.write(reinterpret_cast(&volumeWidthPower), sizeof(volumeWidthPower)); - stream.write(reinterpret_cast(&volumeHeightPower), sizeof(volumeHeightPower)); - stream.write(reinterpret_cast(&volumeDepthPower), sizeof(volumeDepthPower)); - - //Write data - VolumeSampler volIter(&volume); - VoxelType current; - uint32_t runLength = 0; - bool firstTime = true; - for(uint16_t z = 0; z < volumeDepth; ++z) - { - //Update progress once per slice. - if(progressListener) - { - float fProgress = static_cast(z) / static_cast(volumeDepth); - progressListener->onProgressUpdated(fProgress); - } - - for(uint16_t y = 0; y < volumeHeight; ++y) - { - for(uint16_t x = 0; x < volumeWidth; ++x) - { - volIter.setPosition(x,y,z); - VoxelType value = volIter.getVoxel(); - if(firstTime) - { - current = value; - runLength = 1; - firstTime = false; - } - else - { - if(value == current) - { - runLength++; - } - else - { - stream.write(reinterpret_cast(¤t), sizeof(current)); - stream.write(reinterpret_cast(&runLength), sizeof(runLength)); - current = value; - runLength = 1; - } - } - } - } - } - stream.write(reinterpret_cast(¤t), sizeof(current)); - stream.write(reinterpret_cast(&runLength), sizeof(runLength)); - - //Finished - if(progressListener) - { - progressListener->onProgressUpdated(1.0f); - } - } -} +#include "Serialization.inl" #endif diff --git a/library/PolyVoxUtil/include/Serialization.inl b/library/PolyVoxUtil/include/Serialization.inl index e69de29b..835635a5 100644 --- a/library/PolyVoxUtil/include/Serialization.inl +++ b/library/PolyVoxUtil/include/Serialization.inl @@ -0,0 +1,261 @@ +/******************************************************************************* +Copyright (c) 2005-2009 David Williams + +This software is provided 'as-is', without any express or implied +warranty. In no event will the authors be held liable for any damages +arising from the use of this software. + +Permission is granted to anyone to use this software for any purpose, +including commercial applications, and to alter it and redistribute it +freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + + 3. This notice may not be removed or altered from any source + distribution. +*******************************************************************************/ + +#include "Volume.h" +#include "VolumeSampler.h" +#include "PolyVoxImpl/Utility.h" + +using namespace std; + +namespace PolyVox +{ + //Note: we don't do much error handling in here - exceptions will simply be propergated up to the caller. + //FIXME - think about pointer ownership issues. Or could return volume by value if the copy constructor is shallow + template + shared_ptr< Volume > loadVolumeRaw(istream& stream, VolumeSerializationProgressListener* progressListener) + { + //Read volume dimensions + uint8_t volumeWidthPower = 0; + uint8_t volumeHeightPower = 0; + uint8_t volumeDepthPower = 0; + stream.read(reinterpret_cast(&volumeWidthPower), sizeof(volumeWidthPower)); + stream.read(reinterpret_cast(&volumeHeightPower), sizeof(volumeHeightPower)); + stream.read(reinterpret_cast(&volumeDepthPower), sizeof(volumeDepthPower)); + + uint16_t volumeWidth = 0x0001 << volumeWidthPower; + uint16_t volumeHeight = 0x0001 << volumeHeightPower; + uint16_t volumeDepth = 0x0001 << volumeDepthPower; + + //FIXME - need to support non cubic volumes + shared_ptr< Volume > volume(new Volume(volumeWidth, volumeHeight, volumeDepth)); + + //Read data + for(uint16_t z = 0; z < volumeDepth; ++z) + { + //Update progress once per slice. + if(progressListener) + { + float fProgress = static_cast(z) / static_cast(volumeDepth); + progressListener->onProgressUpdated(fProgress); + } + + for(uint16_t y = 0; y < volumeHeight; ++y) + { + for(uint16_t x = 0; x < volumeWidth; ++x) + { + VoxelType value; + stream.read(reinterpret_cast(&value), sizeof(value)); + + volume->setVoxelAt(x,y,z,value); + } + } + } + + //Finished + if(progressListener) + { + progressListener->onProgressUpdated(1.0f); + } + + return volume; + } + + template + void saveVolumeRaw(std::ostream& stream, Volume& volume, VolumeSerializationProgressListener* progressListener) + { + //Write volume dimensions + uint16_t volumeWidth = volume.getWidth(); + uint16_t volumeHeight = volume.getHeight(); + uint16_t volumeDepth = volume.getDepth(); + + uint8_t volumeWidthPower = logBase2(volumeWidth); + uint8_t volumeHeightPower = logBase2(volumeHeight); + uint8_t volumeDepthPower = logBase2(volumeDepth); + + stream.write(reinterpret_cast(&volumeWidthPower), sizeof(volumeWidthPower)); + stream.write(reinterpret_cast(&volumeHeightPower), sizeof(volumeHeightPower)); + stream.write(reinterpret_cast(&volumeDepthPower), sizeof(volumeDepthPower)); + + //Write data + VolumeSampler volIter(&volume); + for(uint16_t z = 0; z < volumeDepth; ++z) + { + //Update progress once per slice. + if(progressListener) + { + float fProgress = static_cast(z) / static_cast(volumeDepth); + progressListener->onProgressUpdated(fProgress); + } + + for(uint16_t y = 0; y < volumeHeight; ++y) + { + for(uint16_t x = 0; x < volumeWidth; ++x) + { + volIter.setPosition(x,y,z); + VoxelType value = volIter.getVoxel(); + stream.write(reinterpret_cast(&value), sizeof(value)); + } + } + } + + //Finished + if(progressListener) + { + progressListener->onProgressUpdated(1.0f); + } + } + + //Note: we don't do much error handling in here - exceptions will simply be propergated up to the caller. + //FIXME - think about pointer ownership issues. Or could return volume by value if the copy constructor is shallow + template + shared_ptr< Volume > loadVolumeRle(istream& stream, VolumeSerializationProgressListener* progressListener) + { + //Read volume dimensions + uint8_t volumeWidthPower = 0; + uint8_t volumeHeightPower = 0; + uint8_t volumeDepthPower = 0; + stream.read(reinterpret_cast(&volumeWidthPower), sizeof(volumeWidthPower)); + stream.read(reinterpret_cast(&volumeHeightPower), sizeof(volumeHeightPower)); + stream.read(reinterpret_cast(&volumeDepthPower), sizeof(volumeDepthPower)); + + uint16_t volumeWidth = 0x0001 << volumeWidthPower; + uint16_t volumeHeight = 0x0001 << volumeHeightPower; + uint16_t volumeDepth = 0x0001 << volumeDepthPower; + + //FIXME - need to support non cubic volumes + shared_ptr< Volume > volume(new Volume(volumeWidth, volumeHeight, volumeDepth)); + + //Read data + bool firstTime = true; + uint32_t runLength = 0; + VoxelType value; + stream.read(reinterpret_cast(&value), sizeof(value)); + stream.read(reinterpret_cast(&runLength), sizeof(runLength)); + for(uint16_t z = 0; z < volumeDepth; ++z) + { + //Update progress once per slice. + if(progressListener) + { + float fProgress = static_cast(z) / static_cast(volumeDepth); + progressListener->onProgressUpdated(fProgress); + } + + for(uint16_t y = 0; y < volumeHeight; ++y) + { + for(uint16_t x = 0; x < volumeWidth; ++x) + { + if(runLength != 0) + { + volume->setVoxelAt(x,y,z,value); + runLength--; + } + else + { + stream.read(reinterpret_cast(&value), sizeof(value)); + stream.read(reinterpret_cast(&runLength), sizeof(runLength)); + + volume->setVoxelAt(x,y,z,value); + runLength--; + } + } + } + } + + //Finished + if(progressListener) + { + progressListener->onProgressUpdated(1.0f); + } + + return volume; + } + + template + void saveVolumeRle(std::ostream& stream, Volume& volume, VolumeSerializationProgressListener* progressListener) + { + //Write volume dimensions + uint16_t volumeWidth = volume.getWidth(); + uint16_t volumeHeight = volume.getHeight(); + uint16_t volumeDepth = volume.getDepth(); + + uint8_t volumeWidthPower = logBase2(volumeWidth); + uint8_t volumeHeightPower = logBase2(volumeHeight); + uint8_t volumeDepthPower = logBase2(volumeDepth); + + stream.write(reinterpret_cast(&volumeWidthPower), sizeof(volumeWidthPower)); + stream.write(reinterpret_cast(&volumeHeightPower), sizeof(volumeHeightPower)); + stream.write(reinterpret_cast(&volumeDepthPower), sizeof(volumeDepthPower)); + + //Write data + VolumeSampler volIter(&volume); + VoxelType current; + uint32_t runLength = 0; + bool firstTime = true; + for(uint16_t z = 0; z < volumeDepth; ++z) + { + //Update progress once per slice. + if(progressListener) + { + float fProgress = static_cast(z) / static_cast(volumeDepth); + progressListener->onProgressUpdated(fProgress); + } + + for(uint16_t y = 0; y < volumeHeight; ++y) + { + for(uint16_t x = 0; x < volumeWidth; ++x) + { + volIter.setPosition(x,y,z); + VoxelType value = volIter.getVoxel(); + if(firstTime) + { + current = value; + runLength = 1; + firstTime = false; + } + else + { + if(value == current) + { + runLength++; + } + else + { + stream.write(reinterpret_cast(¤t), sizeof(current)); + stream.write(reinterpret_cast(&runLength), sizeof(runLength)); + current = value; + runLength = 1; + } + } + } + } + } + stream.write(reinterpret_cast(¤t), sizeof(current)); + stream.write(reinterpret_cast(&runLength), sizeof(runLength)); + + //Finished + if(progressListener) + { + progressListener->onProgressUpdated(1.0f); + } + } +}