Пример #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);
        
    }
Пример #2
0
 bool BSCLib::compressData(uint8 *& out, size_t & outSize, const uint8 * in, size_t inSize)
 {
     Stream::MemoryBlockStream inStream(in, inSize);
     if (out == 0)
     {
         Stream::NullOutputStream outStream;
         if (!compressStream(outStream, inStream)) return false;
         if (outSize) { outSize = (size_t)outStream.fullSize(); return setError(UnexpectedEOD); }
         // Then allocate the output buffer size
         out = new uint8[outStream.fullSize()];
         outSize = (size_t)outStream.fullSize();
         inStream.setPosition(0);
     }
     // Compress the stream now
     Stream::MemoryBlockOutStream finalStream(out, (uint64)outSize);
     return compressStream(finalStream, inStream);
 }
Пример #3
0
void ManipulatorTerrain::Serialize( rapidxml::xml_document<>* doc, rapidxml::xml_node<>* XMLNode )
{
	String strWorldSize = Ogre::StringConverter::toString(GetWorldSize());
	String strTerrainSize = Ogre::StringConverter::toString(GetMapSize());

	float pixelError = ManipulatorSystem.GetScene()->GetTerrainOption()->getMaxPixelError();
	String strPixelError = Ogre::StringConverter::toString(pixelError);

	XMLNode->append_attribute(doc->allocate_attribute("worldSize", doc->allocate_string(strWorldSize.c_str())));
	XMLNode->append_attribute(doc->allocate_attribute("mapSize", doc->allocate_string(strTerrainSize.c_str())));
	XMLNode->append_attribute(doc->allocate_attribute("tuningMaxPixelError", doc->allocate_string(strPixelError.c_str())));

	//保存地形数据
	std::wstring fullPath(ManipulatorSystem.GenerateSceneFullPath());
	fullPath += L"terrain.dat";
	Ogre::DataStreamPtr stream = Ogre::Root::getSingleton().createFileStream(Utility::UnicodeToEngine(fullPath), 
		Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, true);

	Ogre::DataStreamPtr compressStream(new Ogre::DeflateStream(Utility::UnicodeToEngine(fullPath), stream));
	Ogre::StreamSerialiser ser(compressStream);

	ManipulatorSystem.GetScene()->GetTerrain()->save(ser);
}
Пример #4
0
	//----------
	void Sender::compressLoop() {
		uint32_t frameIndex = 0;
		while (this->threadsRunning) {
			Message message;
			while (this->appToCompressor->receive(message)) {
				Packet packet;
				packet.header.packetIndex = 0;
				packet.header.frameIndex = frameIndex;

				struct {
					size_t offset = 0;
					size_t availableBytes = Packet::MaxPayloadSize;
				} payloadState;

				if (!this->getCodec().isValid()) {
					OFXSQUASHBUDDIES_ERROR << "Codec [" << this->getCodec().getName() << "] is not valid. Are you sure you have the plugins installed correctly?";
					continue;
				}
				ofxSquash::Stream compressStream(this->getCodec(), ofxSquash::Direction::Compress, [this, &packet, &payloadState](const ofxSquash::WriteFunctionArguments & args) {
					//copy incoming data and split into packets

					struct {
						uint8_t * readPosition;
						size_t availableBytes;
					} inputState;
					inputState.readPosition = (uint8_t*)args.data;
					inputState.availableBytes = args.size;

					while (inputState.availableBytes > 0) {
						auto bytesToCopy = min<size_t>(inputState.availableBytes, payloadState.availableBytes);

						memcpy(packet.payload + payloadState.offset, inputState.readPosition, bytesToCopy);
						
						inputState.readPosition += bytesToCopy;
						inputState.availableBytes -= bytesToCopy;
						payloadState.offset += bytesToCopy;
						payloadState.availableBytes -= bytesToCopy;

						if (payloadState.availableBytes == 0) {
							//finish off the packet header and send whenever we have a full packet
							{
								if (payloadState.offset > numeric_limits<uint32_t>::max()) {
									OFXSQUASHBUDDIES_ERROR << "Payload is too big! Sorry baby.";
								}
								else {
									packet.header.payloadSize = (uint32_t)payloadState.offset;
									this->compressorToSocket->send(packet);
								}
								
								packet.header.packetIndex++;
								packet.header.payloadSize = 0;
							}

							//reset the packet for next use
							{
								payloadState.offset = 0;
								payloadState.availableBytes = Packet::MaxPayloadSize;
							}
						}
					}
				});

				compressStream << message.getMessageString() << ofxSquash::Stream::Finish();

				//send whatever is left over
				if (payloadState.offset > numeric_limits<uint32_t>::max()) {
					OFXSQUASHBUDDIES_ERROR << "Payload is too big! Sorry baby.";
				}
				else {
					packet.header.payloadSize = (uint32_t) payloadState.offset;
					packet.header.isLastPacket = true;
					this->compressorToSocket->send(packet);
				}

				frameIndex++;
			}
		}
	}
void spec_compress(int in, int out, int lev) {
    blockSize100k           = lev;
    compressStream ( in, out );
}