Exemplo n.º 1
0
    void Source::serialize(const Vector3 &from, const Vector3 &to, float voxelWidth, Real maxClampedAbsoluteDensity, const String &file)
    {
     
        Timer t;

        // Compress
        DataStreamPtr stream = Root::getSingleton().createFileStream(file);
        DataStreamPtr compressStream(OGRE_NEW DeflateStream(file, stream));
        StreamSerialiser ser(compressStream);
        ser.writeChunkBegin(VOLUME_CHUNK_ID, VOLUME_CHUNK_VERSION);

        // Write Metadata
        ser.write(&from);
        ser.write(&to);
        ser.write<float>(&voxelWidth);
        Vector3 diagonal = to - from;
        size_t gridWidth = (size_t)(diagonal.x / voxelWidth);
        size_t gridHeight = (size_t)(diagonal.y / voxelWidth);
        size_t gridDepth = (size_t)(diagonal.z / voxelWidth);
        ser.write<size_t>(&gridWidth);
        ser.write<size_t>(&gridHeight);
        ser.write<size_t>(&gridDepth);

        // Go over the volume and write the density data.
        Vector3 pos;
        Real realVal;
        size_t x;
        size_t y;
        uint16 buffer[SERIALIZATION_CHUNK_SIZE];
        size_t bufferI = 0;
        for (size_t z = 0; z < gridDepth; ++z)
        {
            for (x = 0; x < gridWidth; ++x)
            {
                for (y = 0; y < gridHeight; ++y)
                {
                    pos.x = x * voxelWidth + from.x;
                    pos.y = y * voxelWidth + from.y;
                    pos.z = z * voxelWidth + from.z;
                    realVal = Math::Clamp<Real>(getValue(pos), -maxClampedAbsoluteDensity, maxClampedAbsoluteDensity);
                    buffer[bufferI] = Bitwise::floatToHalf(realVal);
                    bufferI++;
                    if (bufferI == SERIALIZATION_CHUNK_SIZE)
                    {
                        ser.write<uint16>(buffer, SERIALIZATION_CHUNK_SIZE);
                        bufferI = 0;
                    }
                }
            }
        }
        if (bufferI > 0)
        {
            ser.write<uint16>(buffer, bufferI);
        }
        LogManager::getSingleton().stream() << "Time for serialization: " << t.getMilliseconds() << "ms";

        ser.writeChunkEnd(VOLUME_CHUNK_ID);
        
    }
Exemplo n.º 2
0
	void StreamSerialiser::startDeflate(size_t avail_in)
	{
#if OGRE_NO_ZIP_ARCHIVE == 0
		assert( mOriginalStream.isNull() && "Don't start (un)compressing twice!" );
		DataStreamPtr deflateStream(OGRE_NEW DeflateStream(mStream,"",avail_in));
		mOriginalStream = mStream;
		mStream = deflateStream;
#else
        OGRE_EXCEPT(Exception::ERR_NOT_IMPLEMENTED,
                    "Ogre was not built with Zip file support!", "StreamSerialiser::startDeflate");
#endif
	}
HalfFloatGridSource::HalfFloatGridSource(const String &serializedVolumeFile, const bool trilinearValue, const bool trilinearGradient, const bool sobelGradient) :
    GridSource(trilinearValue, trilinearGradient, sobelGradient)
{

    Timer t;
    DataStreamPtr streamRead = Root::getSingleton().openFileStream(serializedVolumeFile);
#if OGRE_NO_ZIP_ARCHIVE == 0
    DataStreamPtr uncompressStream(OGRE_NEW DeflateStream(serializedVolumeFile, streamRead));
    StreamSerialiser ser(uncompressStream);
#else
    StreamSerialiser ser(streamRead);
#endif
    if (!ser.readChunkBegin(VOLUME_CHUNK_ID, VOLUME_CHUNK_VERSION))
    {
        OGRE_EXCEPT(Exception::ERR_INVALID_STATE,
                    "Invalid volume file given!",
                    __FUNCTION__);
    }

    // Read header
    Vector3 readFrom, readTo;
    ser.read(&readFrom);
    ser.read(&readTo);
    float voxelWidth;
    ser.read<float>(&voxelWidth);
    size_t width, height, depth;
    ser.read<size_t>(&width);
    ser.read<size_t>(&height);
    ser.read<size_t>(&depth);
    mWidth = static_cast<int>(width);
    mHeight = static_cast<int>(height);
    mDepth = static_cast<int>(depth);
    mDepthTimesHeight = static_cast<int>(mDepth * mHeight);

    Vector3 worldDimension = readTo - readFrom;
    mPosXScale = (Real)1.0 / (Real)worldDimension.x * (Real)mWidth;
    mPosYScale = (Real)1.0 / (Real)worldDimension.y * (Real)mHeight;
    mPosZScale = (Real)1.0 / (Real)worldDimension.z * (Real)mDepth;

    mVolumeSpaceToWorldSpaceFactor = (Real)worldDimension.x * (Real)mWidth;
    mMaxClampedAbsoluteDensity = 0;

    // Read data
    size_t elementCount = mWidth * mHeight * mDepth;
    mData = OGRE_ALLOC_T(uint16, elementCount, MEMCATEGORY_GENERAL);
    ser.read(mData, elementCount);

    ser.readChunkEnd(VOLUME_CHUNK_ID);

    LogManager::getSingleton().stream() << "Processed serialization in " << t.getMilliseconds() << "ms.";
}
Exemplo n.º 4
0
	void Stream::Deflate()
	{
		std::size_t deflatedLength = 0;
		unsigned char* deflatedBuffer = DeflateStream(buffer, &deflatedLength);
		if (deflatedLength == 0)
		{
			delete[] deflatedBuffer;
			return;
		}
		buffer.resize(deflatedLength);
		std::memcpy(buffer.data(), deflatedBuffer, deflatedLength);
		position = 0;
		delete[] deflatedBuffer;
	}
Exemplo n.º 5
0
ptr<File> DeflateStream::CompressFile(ptr<File> file, CompressionLevel compressionLevel)
{
	try
	{
		//создать выходной поток
		ptr<MemoryStream> outputStream = NEW(MemoryStream);
		//создать поток для сжатия
		ptr<DeflateStream> stream = NEW(DeflateStream(&*outputStream, compressionLevel));

		//сжать данные
		stream->Write(file->GetData(), file->GetSize());
		stream->Flush();
		//вернуть файл
		return outputStream->ToFile();
	}
	catch(Exception* exception)
	{
		THROW_SECONDARY("Can't decompress to file", exception);
	}
}
Exemplo n.º 6
0
ptr<DeflateStream> DeflateStream::CreateMax(ptr<OutputStream> outputStream)
{
	return NEW(DeflateStream(outputStream, compressionMax));
}