mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
#3345 HoloLens: Opacity, refactor and preparations for export of results
This commit is contained in:
@@ -18,6 +18,8 @@
|
|||||||
|
|
||||||
#include "VdeArrayDataPacket.h"
|
#include "VdeArrayDataPacket.h"
|
||||||
|
|
||||||
|
#include <cassert>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//==================================================================================================
|
//==================================================================================================
|
||||||
@@ -194,11 +196,12 @@ VdeArrayDataPacket VdeArrayDataPacket::fromUint32Arr(int arrayId, const unsigned
|
|||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
VdeArrayDataPacket VdeArrayDataPacket::fromUint8ImageRGBArr(int arrayId, unsigned short imageWidth, unsigned short imageHeight, const unsigned char* srcArr, size_t srcArrElementCount)
|
VdeArrayDataPacket VdeArrayDataPacket::fromUint8ImageRGBArr(int arrayId, unsigned short imageWidth, unsigned short imageHeight, const unsigned char* srcArr, size_t srcArrElementCount)
|
||||||
{
|
{
|
||||||
size_t payloadByteCount = srcArrElementCount*sizeof(unsigned int);
|
|
||||||
const char* rawSrcPtr = reinterpret_cast<const char*>(srcArr);
|
const char* rawSrcPtr = reinterpret_cast<const char*>(srcArr);
|
||||||
|
|
||||||
|
assert(3*imageWidth*imageHeight == srcArrElementCount);
|
||||||
|
|
||||||
VdeArrayDataPacket packet;
|
VdeArrayDataPacket packet;
|
||||||
packet.assign(arrayId, Uint8, srcArrElementCount, imageWidth, imageHeight, 3, rawSrcPtr, payloadByteCount);
|
packet.assign(arrayId, Uint8, srcArrElementCount, imageWidth, imageHeight, 3, rawSrcPtr, srcArrElementCount);
|
||||||
return packet;
|
return packet;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -30,6 +30,9 @@
|
|||||||
#include "cvfDrawableGeo.h"
|
#include "cvfDrawableGeo.h"
|
||||||
#include "cvfPrimitiveSet.h"
|
#include "cvfPrimitiveSet.h"
|
||||||
#include "cvfTransform.h"
|
#include "cvfTransform.h"
|
||||||
|
#include "cvfRenderStateTextureBindings.h"
|
||||||
|
#include "cvfTexture.h"
|
||||||
|
#include "cvfEffect.h"
|
||||||
#include "cvfTrace.h"
|
#include "cvfTrace.h"
|
||||||
|
|
||||||
#include <QString>
|
#include <QString>
|
||||||
@@ -57,101 +60,95 @@ VdeFileExporter::VdeFileExporter(QString absOutputFolder)
|
|||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
bool VdeFileExporter::exportViewContents(const RimGridView& view)
|
bool VdeFileExporter::exportViewContents(const RimGridView& view)
|
||||||
{
|
{
|
||||||
|
std::vector<VdeExportPart> exportPartsArr = RicHoloLensExportImpl::partsForExport(view);
|
||||||
std::vector<VdeMesh> meshArr;
|
std::vector<VdeMesh> meshArr;
|
||||||
|
for (const auto& exportPart : exportPartsArr)
|
||||||
{
|
{
|
||||||
std::vector<VdeExportPart> exportParts = RicHoloLensExportImpl::partsForExport(view);
|
VdeMesh mesh;
|
||||||
for (const auto& exportPart : exportParts)
|
if (extractMeshFromExportPart(exportPart, &mesh))
|
||||||
{
|
{
|
||||||
const cvf::Part* part = exportPart.part();
|
meshArr.push_back(mesh);
|
||||||
if (part)
|
|
||||||
{
|
|
||||||
VdeMesh mesh;
|
|
||||||
if (extractMeshFromPart(view, *part, &mesh))
|
|
||||||
{
|
|
||||||
QString srcObjType = "unknown";
|
|
||||||
if (exportPart.sourceObjectType() == VdeExportPart::OBJ_TYPE_GRID) srcObjType = "grid";
|
|
||||||
else if (exportPart.sourceObjectType() == VdeExportPart::OBJ_TYPE_PIPE) srcObjType = "pipe";
|
|
||||||
mesh.meshSourceObjTypeStr = srcObjType;
|
|
||||||
|
|
||||||
mesh.meshSourceObjName = exportPart.sourceObjectName();
|
|
||||||
mesh.color = exportPart.color();
|
|
||||||
|
|
||||||
meshArr.push_back(mesh);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<VdeMeshContentIds> meshContentIdsArr;
|
std::vector<VdeMeshArrayIds> meshArrayIdsArr;
|
||||||
|
|
||||||
|
const size_t meshCount = meshArr.size();
|
||||||
|
cvf::Trace::show("Exporting %d meshes", meshCount);
|
||||||
|
size_t totNumPrimitives = 0;
|
||||||
int nextArrayId = 0;
|
int nextArrayId = 0;
|
||||||
for (size_t i = 0; i < meshArr.size(); i++)
|
for (size_t i = 0; i < meshCount; i++)
|
||||||
{
|
{
|
||||||
const VdeMesh& mesh = meshArr[i];
|
const VdeMesh& mesh = meshArr[i];
|
||||||
const size_t primCount = mesh.connArr.size()/3;
|
|
||||||
cvf::Trace::show("%d: primCount=%d meshSourceObjName='%s'", i, primCount, mesh.meshSourceObjName.toLatin1().constData());
|
|
||||||
|
|
||||||
VdeMeshContentIds meshContentIds;
|
const size_t primCount = mesh.connArr.size()/mesh.verticesPerPrimitive;
|
||||||
|
totNumPrimitives += primCount;
|
||||||
|
cvf::Trace::show(" %2d: primCount=%d meshSourceObjName='%s'", i, primCount, mesh.meshSourceObjName.toLatin1().constData());
|
||||||
|
|
||||||
|
VdeMeshArrayIds meshArrayIds;
|
||||||
|
|
||||||
{
|
{
|
||||||
meshContentIds.vertexArrId = nextArrayId++;
|
meshArrayIds.vertexArrId = nextArrayId++;
|
||||||
const float* floatArr = reinterpret_cast<const float*>(mesh.vertexArr->ptr());
|
const float* floatArr = reinterpret_cast<const float*>(mesh.vertexArr->ptr());
|
||||||
VdeArrayDataPacket dataPacket = VdeArrayDataPacket::fromFloat32Arr(meshContentIds.vertexArrId, floatArr, 3*mesh.vertexArr->size());
|
VdeArrayDataPacket dataPacket = VdeArrayDataPacket::fromFloat32Arr(meshArrayIds.vertexArrId, floatArr, 3*mesh.vertexArr->size());
|
||||||
writeDataPacketToFile(dataPacket.arrayId(), dataPacket);
|
writeDataPacketToFile(dataPacket.arrayId(), dataPacket);
|
||||||
|
|
||||||
// Debug testing of decoding
|
// Debug testing of decoding
|
||||||
debugComparePackets(dataPacket, VdeArrayDataPacket::fromRawPacketBuffer(dataPacket.fullPacketRawPtr(), dataPacket.fullPacketSize(), nullptr));
|
//debugComparePackets(dataPacket, VdeArrayDataPacket::fromRawPacketBuffer(dataPacket.fullPacketRawPtr(), dataPacket.fullPacketSize(), nullptr));
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
meshContentIds.connArrId = nextArrayId++;
|
meshArrayIds.connArrId = nextArrayId++;
|
||||||
const unsigned int* uintArr = mesh.connArr.data();
|
const unsigned int* uintArr = mesh.connArr.data();
|
||||||
VdeArrayDataPacket dataPacket = VdeArrayDataPacket::fromUint32Arr(meshContentIds.connArrId, uintArr, mesh.connArr.size());
|
VdeArrayDataPacket dataPacket = VdeArrayDataPacket::fromUint32Arr(meshArrayIds.connArrId, uintArr, mesh.connArr.size());
|
||||||
writeDataPacketToFile(dataPacket.arrayId(), dataPacket);
|
writeDataPacketToFile(dataPacket.arrayId(), dataPacket);
|
||||||
|
|
||||||
// Debug testing of decoding
|
// Debug testing of decoding
|
||||||
debugComparePackets(dataPacket, VdeArrayDataPacket::fromRawPacketBuffer(dataPacket.fullPacketRawPtr(), dataPacket.fullPacketSize(), nullptr));
|
//debugComparePackets(dataPacket, VdeArrayDataPacket::fromRawPacketBuffer(dataPacket.fullPacketRawPtr(), dataPacket.fullPacketSize(), nullptr));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mesh.texCoordArr.notNull() && mesh.texImage.notNull())
|
if (mesh.texCoordArr.notNull() && mesh.texImage.notNull())
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
meshContentIds.texCoordsArrId = nextArrayId++;
|
meshArrayIds.texCoordsArrId = nextArrayId++;
|
||||||
const float* floatArr = reinterpret_cast<const float*>(mesh.texCoordArr->ptr());
|
const float* floatArr = reinterpret_cast<const float*>(mesh.texCoordArr->ptr());
|
||||||
VdeArrayDataPacket dataPacket = VdeArrayDataPacket::fromFloat32Arr(meshContentIds.texCoordsArrId, floatArr, 3*mesh.vertexArr->size());
|
VdeArrayDataPacket dataPacket = VdeArrayDataPacket::fromFloat32Arr(meshArrayIds.texCoordsArrId, floatArr, 3*mesh.vertexArr->size());
|
||||||
writeDataPacketToFile(dataPacket.arrayId(), dataPacket);
|
writeDataPacketToFile(dataPacket.arrayId(), dataPacket);
|
||||||
|
|
||||||
// Debug testing of decoding
|
// Debug testing of decoding
|
||||||
debugComparePackets(dataPacket, VdeArrayDataPacket::fromRawPacketBuffer(dataPacket.fullPacketRawPtr(), dataPacket.fullPacketSize(), nullptr));
|
//debugComparePackets(dataPacket, VdeArrayDataPacket::fromRawPacketBuffer(dataPacket.fullPacketRawPtr(), dataPacket.fullPacketSize(), nullptr));
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
meshContentIds.texImageArrId = nextArrayId++;
|
meshArrayIds.texImageArrId = nextArrayId++;
|
||||||
cvf::ref<cvf::UByteArray> byteArr = mesh.texImage->toRgb();
|
cvf::ref<cvf::UByteArray> byteArr = mesh.texImage->toRgb();
|
||||||
VdeArrayDataPacket dataPacket = VdeArrayDataPacket::fromUint8ImageRGBArr(meshContentIds.texImageArrId, mesh.texImage->width(), mesh.texImage->height(), byteArr->ptr(), byteArr->size());
|
VdeArrayDataPacket dataPacket = VdeArrayDataPacket::fromUint8ImageRGBArr(meshArrayIds.texImageArrId, mesh.texImage->width(), mesh.texImage->height(), byteArr->ptr(), byteArr->size());
|
||||||
writeDataPacketToFile(dataPacket.arrayId(), dataPacket);
|
writeDataPacketToFile(dataPacket.arrayId(), dataPacket);
|
||||||
|
|
||||||
// Debug testing of decoding
|
// Debug testing of decoding
|
||||||
debugComparePackets(dataPacket, VdeArrayDataPacket::fromRawPacketBuffer(dataPacket.fullPacketRawPtr(), dataPacket.fullPacketSize(), nullptr));
|
//debugComparePackets(dataPacket, VdeArrayDataPacket::fromRawPacketBuffer(dataPacket.fullPacketRawPtr(), dataPacket.fullPacketSize(), nullptr));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
meshContentIdsArr.push_back(meshContentIds);
|
meshArrayIdsArr.push_back(meshArrayIds);
|
||||||
}
|
}
|
||||||
|
|
||||||
QString jsonFileName = m_absOutputFolder + "/modelMeta.json";
|
QString jsonFileName = m_absOutputFolder + "/modelMeta.json";
|
||||||
if (!writeModelMetaJsonFile(meshArr, meshContentIdsArr, jsonFileName))
|
if (!writeModelMetaJsonFile(meshArr, meshArrayIdsArr, jsonFileName))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cvf::Trace::show("Total number of primitives exported: %d", totNumPrimitives);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
///
|
///
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
bool VdeFileExporter::extractMeshFromPart(const RimGridView& view, const cvf::Part& part, VdeMesh* mesh)
|
bool VdeFileExporter::extractMeshFromExportPart(const VdeExportPart& exportPart, VdeMesh* mesh)
|
||||||
{
|
{
|
||||||
const cvf::DrawableGeo* geo = dynamic_cast<const cvf::DrawableGeo*>(part.drawable());
|
const cvf::Part* cvfPart = exportPart.part();
|
||||||
|
const cvf::DrawableGeo* geo = dynamic_cast<const cvf::DrawableGeo*>(cvfPart ? cvfPart->drawable() : nullptr);
|
||||||
if (!geo)
|
if (!geo)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
@@ -173,19 +170,19 @@ bool VdeFileExporter::extractMeshFromPart(const RimGridView& view, const cvf::Pa
|
|||||||
|
|
||||||
if (primSet->primitiveType() != cvf::PT_TRIANGLES)
|
if (primSet->primitiveType() != cvf::PT_TRIANGLES)
|
||||||
{
|
{
|
||||||
RiaLogging::debug("Currently only triangle primitive sets are supported");
|
RiaLogging::debug(QString("Currently only triangle primitive sets are supported (saw primitive type: %1)").arg(primSet->primitiveType()));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
mesh->verticesPerPrimitive = 3;
|
mesh->verticesPerPrimitive = 3;
|
||||||
|
|
||||||
// Possibly transform the vertices
|
// Possibly transform the vertices
|
||||||
if (part.transform())
|
if (cvfPart->transform())
|
||||||
{
|
{
|
||||||
const size_t vertexCount = vertexArr->size();
|
const size_t vertexCount = vertexArr->size();
|
||||||
cvf::ref<cvf::Vec3fArray> transVertexArr = new cvf::Vec3fArray(vertexArr->size());
|
cvf::ref<cvf::Vec3fArray> transVertexArr = new cvf::Vec3fArray(vertexArr->size());
|
||||||
|
|
||||||
cvf::Mat4f m = cvf::Mat4f(part.transform()->worldTransform());
|
cvf::Mat4f m = cvf::Mat4f(cvfPart->transform()->worldTransform());
|
||||||
for (size_t i = 0; i < vertexCount; i++)
|
for (size_t i = 0; i < vertexCount; i++)
|
||||||
{
|
{
|
||||||
transVertexArr->set(i, vertexArr->get(i).getTransformedPoint(m));
|
transVertexArr->set(i, vertexArr->get(i).getTransformedPoint(m));
|
||||||
@@ -213,6 +210,36 @@ bool VdeFileExporter::extractMeshFromPart(const RimGridView& view, const cvf::Pa
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// !!!!
|
||||||
|
// Experiment with texture fringes
|
||||||
|
//if (geo->textureCoordArray())
|
||||||
|
//{
|
||||||
|
// cvf::Part* nonConstPart = const_cast<cvf::Part*>(cvfPart);
|
||||||
|
// cvf::Effect* eff = nonConstPart->effect();
|
||||||
|
// cvf::RenderStateTextureBindings* rsTexBindings = dynamic_cast<cvf::RenderStateTextureBindings*>(eff->renderStateOfType(cvf::RenderState::TEXTURE_BINDINGS));
|
||||||
|
// if (rsTexBindings && rsTexBindings->bindingCount() > 0)
|
||||||
|
// {
|
||||||
|
// cvf::TextureImage* texImg = rsTexBindings->texture(0)->image();
|
||||||
|
// if (texImg)
|
||||||
|
// {
|
||||||
|
// mesh->texCoordArr = geo->textureCoordArray();
|
||||||
|
// mesh->texImage = texImg;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//}
|
||||||
|
|
||||||
|
|
||||||
|
QString srcObjType = "unknown";
|
||||||
|
if (exportPart.sourceObjectType() == VdeExportPart::OBJ_TYPE_GRID) srcObjType = "grid";
|
||||||
|
else if (exportPart.sourceObjectType() == VdeExportPart::OBJ_TYPE_PIPE) srcObjType = "pipe";
|
||||||
|
mesh->meshSourceObjTypeStr = srcObjType;
|
||||||
|
|
||||||
|
mesh->meshSourceObjName = exportPart.sourceObjectName();
|
||||||
|
|
||||||
|
mesh->color = exportPart.color();
|
||||||
|
mesh->opacity = exportPart.opacity();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -241,14 +268,14 @@ bool VdeFileExporter::writeDataPacketToFile(int arrayId, const VdeArrayDataPacke
|
|||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
///
|
///
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
bool VdeFileExporter::writeModelMetaJsonFile(const std::vector<VdeMesh>& meshArr, const std::vector<VdeMeshContentIds>& meshContentIdsArr, QString fileName)
|
bool VdeFileExporter::writeModelMetaJsonFile(const std::vector<VdeMesh>& meshArr, const std::vector<VdeMeshArrayIds>& meshContentIdsArr, QString fileName)
|
||||||
{
|
{
|
||||||
QVariantList jsonMeshMetaList;
|
QVariantList jsonMeshMetaList;
|
||||||
|
|
||||||
for (size_t i = 0; i < meshArr.size(); i++)
|
for (size_t i = 0; i < meshArr.size(); i++)
|
||||||
{
|
{
|
||||||
const VdeMesh& mesh = meshArr[i];
|
const VdeMesh& mesh = meshArr[i];
|
||||||
const VdeMeshContentIds& meshIds = meshContentIdsArr[i];
|
const VdeMeshArrayIds& meshIds = meshContentIdsArr[i];
|
||||||
|
|
||||||
QMap<QString, QVariant> jsonMeshMeta;
|
QMap<QString, QVariant> jsonMeshMeta;
|
||||||
jsonMeshMeta["meshSourceObjType"] = mesh.meshSourceObjTypeStr;
|
jsonMeshMeta["meshSourceObjType"] = mesh.meshSourceObjTypeStr;
|
||||||
@@ -273,7 +300,7 @@ bool VdeFileExporter::writeModelMetaJsonFile(const std::vector<VdeMesh>& meshArr
|
|||||||
jsonMeshMeta["color"] = jsonColor;
|
jsonMeshMeta["color"] = jsonColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
jsonMeshMeta["opacity"] = 1.0;
|
jsonMeshMeta["opacity"] = mesh.opacity;
|
||||||
|
|
||||||
jsonMeshMetaList.push_back(jsonMeshMeta);
|
jsonMeshMetaList.push_back(jsonMeshMeta);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,6 +26,7 @@
|
|||||||
#include <QString>
|
#include <QString>
|
||||||
|
|
||||||
class VdeArrayDataPacket;
|
class VdeArrayDataPacket;
|
||||||
|
class VdeExportPart;
|
||||||
|
|
||||||
class RimGridView;
|
class RimGridView;
|
||||||
|
|
||||||
@@ -47,6 +48,7 @@ struct VdeMesh
|
|||||||
QString meshSourceObjName;
|
QString meshSourceObjName;
|
||||||
|
|
||||||
cvf::Color3f color;
|
cvf::Color3f color;
|
||||||
|
float opacity;
|
||||||
|
|
||||||
int verticesPerPrimitive;
|
int verticesPerPrimitive;
|
||||||
cvf::cref<cvf::Vec3fArray> vertexArr;
|
cvf::cref<cvf::Vec3fArray> vertexArr;
|
||||||
@@ -55,7 +57,9 @@ struct VdeMesh
|
|||||||
cvf::cref<cvf::TextureImage> texImage;
|
cvf::cref<cvf::TextureImage> texImage;
|
||||||
|
|
||||||
VdeMesh()
|
VdeMesh()
|
||||||
: verticesPerPrimitive(-1)
|
: color(1,1,1),
|
||||||
|
opacity(1),
|
||||||
|
verticesPerPrimitive(-1)
|
||||||
{}
|
{}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -65,14 +69,14 @@ struct VdeMesh
|
|||||||
//
|
//
|
||||||
//
|
//
|
||||||
//==================================================================================================
|
//==================================================================================================
|
||||||
struct VdeMeshContentIds
|
struct VdeMeshArrayIds
|
||||||
{
|
{
|
||||||
int vertexArrId;
|
int vertexArrId;
|
||||||
int connArrId;
|
int connArrId;
|
||||||
int texImageArrId;
|
int texImageArrId;
|
||||||
int texCoordsArrId;
|
int texCoordsArrId;
|
||||||
|
|
||||||
VdeMeshContentIds()
|
VdeMeshArrayIds()
|
||||||
: vertexArrId(-1),
|
: vertexArrId(-1),
|
||||||
connArrId(-1),
|
connArrId(-1),
|
||||||
texImageArrId(-1),
|
texImageArrId(-1),
|
||||||
@@ -95,13 +99,13 @@ public:
|
|||||||
bool exportViewContents(const RimGridView& view);
|
bool exportViewContents(const RimGridView& view);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static bool extractMeshFromPart(const RimGridView& view, const cvf::Part& part, VdeMesh* mesh);
|
static bool extractMeshFromExportPart(const VdeExportPart& exportPart, VdeMesh* mesh);
|
||||||
static bool writeModelMetaJsonFile(const std::vector<VdeMesh>& meshArr, const std::vector<VdeMeshContentIds>& meshContentIdsArr, QString fileName);
|
static bool writeModelMetaJsonFile(const std::vector<VdeMesh>& meshArr, const std::vector<VdeMeshArrayIds>& meshContentIdsArr, QString fileName);
|
||||||
static void debugComparePackets(const VdeArrayDataPacket& packetA, const VdeArrayDataPacket& packetB);
|
static void debugComparePackets(const VdeArrayDataPacket& packetA, const VdeArrayDataPacket& packetB);
|
||||||
|
|
||||||
bool writeDataPacketToFile(int arrayId, const VdeArrayDataPacket& packet) const;
|
bool writeDataPacketToFile(int arrayId, const VdeArrayDataPacket& packet) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString m_absOutputFolder;
|
QString m_absOutputFolder;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user