mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
HoloLens: Fixed erroneous size of array payload for the binary packets. Memory for the actual array data ended up being twice as large as needed. Also fixed incorrect array size for texture coordinates.
This commit is contained in:
parent
dc02c9d2a1
commit
22abc52e7a
@ -18,6 +18,7 @@
|
||||
|
||||
#include "VdeArrayDataPacket.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
|
||||
|
||||
@ -107,11 +108,20 @@ VdeArrayDataPacket::ElementType VdeArrayDataPacket::elementType() const
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
size_t VdeArrayDataPacket::elementSize() const
|
||||
{
|
||||
switch (m_elementType)
|
||||
return sizeOfElement(m_elementType);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Size of specified element type in bytes
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
size_t VdeArrayDataPacket::sizeOfElement(ElementType elementType)
|
||||
{
|
||||
switch (elementType)
|
||||
{
|
||||
case Uint32: return sizeof(unsigned int);
|
||||
case Float32: return sizeof(float);
|
||||
case Unknown: return 0;
|
||||
case Float32: return sizeof(float);
|
||||
case Uint32: return sizeof(unsigned int);
|
||||
case Uint8: return sizeof(unsigned char);
|
||||
}
|
||||
|
||||
return 0;
|
||||
@ -235,6 +245,9 @@ VdeArrayDataPacket VdeArrayDataPacket::fromRawPacketBuffer(const char* rawPacket
|
||||
const char* payloadPtr = rawPacketBuffer + VDE_HEADER_SIZE;
|
||||
const size_t payloadSizeInBytes = bufferSize - VDE_HEADER_SIZE;
|
||||
|
||||
const size_t payloadSizeInBytesFromPacketFields = elementCount*sizeOfElement(elementType);
|
||||
assert(payloadSizeInBytes == payloadSizeInBytesFromPacketFields);
|
||||
|
||||
VdeArrayDataPacket packet;
|
||||
packet.assign(packetId, elementType, elementCount, imageWidth, imageHeight, imageCompCount, payloadPtr, payloadSizeInBytes);
|
||||
|
||||
@ -246,6 +259,8 @@ VdeArrayDataPacket VdeArrayDataPacket::fromRawPacketBuffer(const char* rawPacket
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool VdeArrayDataPacket::assign(int arrayId, ElementType elementType, size_t elementCount, unsigned short imageWidth, unsigned short imageHeight, unsigned char imageCompCount, const char* arrayDataPtr, size_t arrayDataSizeInBytes)
|
||||
{
|
||||
assert(arrayDataSizeInBytes > 0);
|
||||
|
||||
const size_t totalSizeBytes = VDE_HEADER_SIZE + arrayDataSizeInBytes;
|
||||
m_packetBytes.resize(totalSizeBytes);
|
||||
|
||||
@ -258,7 +273,11 @@ bool VdeArrayDataPacket::assign(int arrayId, ElementType elementType, size_t ele
|
||||
bufferWriter.setUint16(VDE_BYTEOFFSET_IMAGE_WIDTH, imageWidth);
|
||||
bufferWriter.setUint16(VDE_BYTEOFFSET_IMAGE_HEIGHT, imageHeight);
|
||||
|
||||
m_packetBytes.insert(m_packetBytes.begin() + VDE_HEADER_SIZE, arrayDataPtr, arrayDataPtr + arrayDataSizeInBytes);
|
||||
const size_t calcArraySizeInBytes = elementCount*sizeOfElement(elementType);
|
||||
assert(arrayDataSizeInBytes == calcArraySizeInBytes);
|
||||
|
||||
std::copy(arrayDataPtr, arrayDataPtr + arrayDataSizeInBytes, m_packetBytes.begin() + VDE_HEADER_SIZE);
|
||||
assert(m_packetBytes.size() == totalSizeBytes);
|
||||
|
||||
m_arrayId = arrayId;
|
||||
m_elementType = elementType;
|
||||
|
@ -64,7 +64,8 @@ public:
|
||||
static VdeArrayDataPacket fromRawPacketBuffer(const char* rawPacketBuffer, size_t bufferSize, std::string* errString);
|
||||
|
||||
private:
|
||||
bool assign(int arrayId, ElementType elementType, size_t elementCount, unsigned short imageWidth, unsigned short imageHeight, unsigned char imageCompCount, const char* arrayDataPtr, size_t arrayDataSizeInBytes);
|
||||
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);
|
||||
|
||||
private:
|
||||
int m_arrayId;
|
||||
|
@ -88,6 +88,7 @@ bool VdeFileExporter::exportViewContents(const RimGridView& view)
|
||||
VdeMeshArrayIds meshArrayIds;
|
||||
|
||||
{
|
||||
cvf::Trace::show(" exporting vertices");
|
||||
meshArrayIds.vertexArrId = nextArrayId++;
|
||||
const float* floatArr = reinterpret_cast<const float*>(mesh.vertexArr->ptr());
|
||||
VdeArrayDataPacket dataPacket = VdeArrayDataPacket::fromFloat32Arr(meshArrayIds.vertexArrId, floatArr, 3*mesh.vertexArr->size());
|
||||
@ -97,6 +98,7 @@ bool VdeFileExporter::exportViewContents(const RimGridView& view)
|
||||
//debugComparePackets(dataPacket, VdeArrayDataPacket::fromRawPacketBuffer(dataPacket.fullPacketRawPtr(), dataPacket.fullPacketSize(), nullptr));
|
||||
}
|
||||
{
|
||||
cvf::Trace::show(" exporting connectivities");
|
||||
meshArrayIds.connArrId = nextArrayId++;
|
||||
const unsigned int* uintArr = mesh.connArr.data();
|
||||
VdeArrayDataPacket dataPacket = VdeArrayDataPacket::fromUint32Arr(meshArrayIds.connArrId, uintArr, mesh.connArr.size());
|
||||
@ -109,15 +111,17 @@ bool VdeFileExporter::exportViewContents(const RimGridView& view)
|
||||
if (mesh.texCoordArr.notNull() && mesh.texImage.notNull())
|
||||
{
|
||||
{
|
||||
cvf::Trace::show(" exporting texture coords");
|
||||
meshArrayIds.texCoordsArrId = nextArrayId++;
|
||||
const float* floatArr = reinterpret_cast<const float*>(mesh.texCoordArr->ptr());
|
||||
VdeArrayDataPacket dataPacket = VdeArrayDataPacket::fromFloat32Arr(meshArrayIds.texCoordsArrId, floatArr, 3*mesh.vertexArr->size());
|
||||
VdeArrayDataPacket dataPacket = VdeArrayDataPacket::fromFloat32Arr(meshArrayIds.texCoordsArrId, floatArr, 2*mesh.texCoordArr->size());
|
||||
writeDataPacketToFile(dataPacket.arrayId(), dataPacket);
|
||||
|
||||
// Debug testing of decoding
|
||||
//debugComparePackets(dataPacket, VdeArrayDataPacket::fromRawPacketBuffer(dataPacket.fullPacketRawPtr(), dataPacket.fullPacketSize(), nullptr));
|
||||
}
|
||||
{
|
||||
cvf::Trace::show(" exporting texture image");
|
||||
meshArrayIds.texImageArrId = nextArrayId++;
|
||||
cvf::ref<cvf::UByteArray> byteArr = mesh.texImage->toRgb();
|
||||
VdeArrayDataPacket dataPacket = VdeArrayDataPacket::fromUint8ImageRGBArr(meshArrayIds.texImageArrId, mesh.texImage->width(), mesh.texImage->height(), byteArr->ptr(), byteArr->size());
|
||||
@ -264,7 +268,7 @@ bool VdeFileExporter::writeDataPacketToFile(int arrayId, const VdeArrayDataPacke
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
Loading…
Reference in New Issue
Block a user