2018-09-18 08:39:24 -05:00
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
2019-01-09 08:21:38 -06:00
|
|
|
// Copyright (C) 2018- Equinor ASA
|
2018-09-18 08:39:24 -05:00
|
|
|
//
|
|
|
|
// ResInsight is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
|
|
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
// FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
//
|
|
|
|
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
|
|
|
// for more details.
|
|
|
|
//
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2018-09-18 09:23:58 -05:00
|
|
|
#include <cstddef>
|
2018-12-19 05:31:44 -06:00
|
|
|
#include <memory>
|
2019-09-06 03:40:57 -05:00
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
2018-09-18 08:39:24 -05:00
|
|
|
|
|
|
|
//==================================================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//==================================================================================================
|
|
|
|
class VdeArrayDataPacket
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
enum ElementType
|
|
|
|
{
|
|
|
|
Unknown = 0,
|
2018-09-19 02:04:09 -05:00
|
|
|
Float32 = 1,
|
|
|
|
Uint32 = 2,
|
2018-09-19 02:58:24 -05:00
|
|
|
Uint8 = 4,
|
2018-09-18 08:39:24 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
public:
|
2018-09-18 16:32:20 -05:00
|
|
|
VdeArrayDataPacket();
|
2018-09-18 08:39:24 -05:00
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
bool isValid() const;
|
|
|
|
int arrayId() const;
|
2018-09-18 08:39:24 -05:00
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
ElementType elementType() const;
|
|
|
|
size_t elementSize() const;
|
|
|
|
size_t elementCount() const;
|
|
|
|
const char* arrayData() const;
|
2018-09-18 08:39:24 -05:00
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
unsigned short imageWidth() const;
|
|
|
|
unsigned short imageHeight() const;
|
|
|
|
unsigned char imageComponentCount() const;
|
2018-09-19 05:42:19 -05:00
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
size_t fullPacketSize() const;
|
|
|
|
const char* fullPacketRawPtr() const;
|
2018-09-18 08:39:24 -05:00
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
static std::unique_ptr<VdeArrayDataPacket>
|
|
|
|
fromFloat32Arr( int arrayId, const float* srcArr, size_t srcArrElementCount );
|
|
|
|
static std::unique_ptr<VdeArrayDataPacket>
|
|
|
|
fromUint32Arr( int arrayId, const unsigned int* srcArr, size_t srcArrElementCount );
|
|
|
|
static std::unique_ptr<VdeArrayDataPacket> fromUint8ImageRGBArr( int arrayId,
|
|
|
|
unsigned short imageWidth,
|
|
|
|
unsigned short imageHeight,
|
|
|
|
const unsigned char* srcArr,
|
|
|
|
size_t srcArrElementCount );
|
2018-09-18 16:32:20 -05:00
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
static VdeArrayDataPacket fromRawPacketBuffer( const char* rawPacketBuffer, size_t bufferSize, std::string* errString );
|
2018-09-18 08:39:24 -05:00
|
|
|
|
2018-09-18 16:32:20 -05:00
|
|
|
private:
|
2019-09-06 03:40:57 -05:00
|
|
|
bool assign( int arrayId,
|
|
|
|
ElementType elementType,
|
|
|
|
size_t elementCount,
|
|
|
|
unsigned short imageWidth,
|
|
|
|
unsigned short imageHeight,
|
|
|
|
unsigned char imageCompCount,
|
|
|
|
const char* arrayDataPtr,
|
|
|
|
size_t arrayDataSizeInBytes );
|
|
|
|
static size_t sizeOfElement( ElementType elementType );
|
2018-09-18 08:39:24 -05:00
|
|
|
|
|
|
|
private:
|
2019-09-06 03:40:57 -05:00
|
|
|
int m_arrayId;
|
|
|
|
ElementType m_elementType;
|
|
|
|
size_t m_elementCount;
|
2018-09-18 08:39:24 -05:00
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
unsigned short m_imageWidth;
|
|
|
|
unsigned short m_imageHeight;
|
|
|
|
unsigned char m_imageComponentCount;
|
2018-09-19 05:42:19 -05:00
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
std::vector<char> m_packetBytes;
|
2018-09-18 16:32:20 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
//==================================================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//==================================================================================================
|
|
|
|
class VdeBufferReader
|
|
|
|
{
|
|
|
|
public:
|
2019-09-06 03:40:57 -05:00
|
|
|
VdeBufferReader( const char* buffer, size_t bufferSize );
|
2018-09-18 16:32:20 -05:00
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
unsigned int getUint32( size_t byteOffset ) const;
|
|
|
|
unsigned short getUint16( size_t byteOffset ) const;
|
|
|
|
unsigned char getUint8( size_t byteOffset ) const;
|
2018-09-18 16:32:20 -05:00
|
|
|
|
|
|
|
private:
|
2019-09-06 03:40:57 -05:00
|
|
|
const char* m_buffer;
|
|
|
|
const size_t m_bufferSize;
|
2018-09-18 16:32:20 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
//==================================================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//==================================================================================================
|
|
|
|
class VdeBufferWriter
|
|
|
|
{
|
|
|
|
public:
|
2019-09-06 03:40:57 -05:00
|
|
|
VdeBufferWriter( char* buffer, size_t bufferSize );
|
2018-09-18 16:32:20 -05:00
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
void setUint32( size_t byteOffset, unsigned int val );
|
|
|
|
void setUint16( size_t byteOffset, unsigned short val );
|
|
|
|
void setUint8( size_t byteOffset, unsigned char val );
|
2018-09-18 16:32:20 -05:00
|
|
|
|
|
|
|
private:
|
2019-09-06 03:40:57 -05:00
|
|
|
char* m_buffer;
|
|
|
|
const size_t m_bufferSize;
|
2018-09-18 08:39:24 -05:00
|
|
|
};
|