2018-10-25 08:34:21 -05:00
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
2019-01-09 08:21:38 -06:00
|
|
|
// Copyright (C) 2018- Equinor ASA
|
2018-10-25 08:34:21 -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.
|
|
|
|
//
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#include "VdeVizDataExtractor.h"
|
|
|
|
#include "VdeArrayDataPacket.h"
|
2018-12-19 05:31:44 -06:00
|
|
|
#include "VdeCachingHashedIdFactory.h"
|
2019-09-06 03:40:57 -05:00
|
|
|
#include "VdePacketDirectory.h"
|
2018-10-25 08:34:21 -05:00
|
|
|
|
|
|
|
#include "RicHoloLensExportImpl.h"
|
|
|
|
|
|
|
|
#include "RifJsonEncodeDecode.h"
|
|
|
|
|
|
|
|
#include "RiaLogging.h"
|
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
#include "cvfAssert.h"
|
2018-10-25 08:34:21 -05:00
|
|
|
#include "cvfDrawableGeo.h"
|
|
|
|
#include "cvfPrimitiveSet.h"
|
2018-12-19 05:31:44 -06:00
|
|
|
#include "cvfTimer.h"
|
2018-10-25 08:34:21 -05:00
|
|
|
#include "cvfTrace.h"
|
2019-09-06 03:40:57 -05:00
|
|
|
#include "cvfTransform.h"
|
2018-10-25 08:34:21 -05:00
|
|
|
|
|
|
|
//==================================================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//==================================================================================================
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
VdeVizDataExtractor::VdeVizDataExtractor( const RimGridView& view, VdeCachingHashedIdFactory* cachingIdFactory )
|
|
|
|
: m_view( view )
|
|
|
|
, m_cachingIdFactory( cachingIdFactory )
|
2018-10-25 08:34:21 -05:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
CVF_ASSERT( m_cachingIdFactory );
|
2018-10-25 08:34:21 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
void VdeVizDataExtractor::extractViewContents( QString* modelMetaJsonStr,
|
|
|
|
std::vector<int>* allReferencedArrayIds,
|
|
|
|
VdePacketDirectory* packetDirectory )
|
2018-10-25 08:34:21 -05:00
|
|
|
{
|
2018-12-19 05:31:44 -06:00
|
|
|
cvf::Timer tim;
|
|
|
|
|
2018-10-25 08:34:21 -05:00
|
|
|
// First extract the parts (cvfPart + info) to be exported from from the ResInsight view
|
2019-09-06 03:40:57 -05:00
|
|
|
const std::vector<VdeExportPart> exportPartsArr = RicHoloLensExportImpl::partsForExport( m_view );
|
2018-10-25 08:34:21 -05:00
|
|
|
|
|
|
|
// Convert this to an array of export ready meshes
|
2019-09-06 03:40:57 -05:00
|
|
|
const std::vector<std::unique_ptr<VdeMesh>> meshArr = buildMeshArray( exportPartsArr );
|
|
|
|
const int buildMeshes_ms = static_cast<int>( tim.lapTime() * 1000 );
|
2018-10-25 08:34:21 -05:00
|
|
|
|
2018-12-19 05:31:44 -06:00
|
|
|
const size_t meshCount = meshArr.size();
|
2019-09-06 03:40:57 -05:00
|
|
|
cvf::Trace::show( "Analyzing and generating array packet data for %d meshes", meshCount );
|
2018-12-19 05:31:44 -06:00
|
|
|
|
|
|
|
std::vector<VdeMeshArrayIds> allMeshesArrayIdsArr;
|
2019-09-06 03:40:57 -05:00
|
|
|
size_t totNumPrimitives = 0;
|
|
|
|
for ( size_t i = 0; i < meshCount; i++ )
|
2018-10-25 08:34:21 -05:00
|
|
|
{
|
2018-12-19 05:31:44 -06:00
|
|
|
const VdeMesh* mesh = meshArr[i].get();
|
2018-10-25 08:34:21 -05:00
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
const size_t primCount = mesh->connArr.size() / mesh->verticesPerPrimitive;
|
2018-10-25 08:34:21 -05:00
|
|
|
totNumPrimitives += primCount;
|
2019-09-06 03:40:57 -05:00
|
|
|
cvf::Trace::show( " mesh %2d: primCount=%d vertsPerPrim=%d meshSourceObjName='%s' meshSourceObjType='%s'",
|
|
|
|
i,
|
|
|
|
primCount,
|
|
|
|
mesh->verticesPerPrimitive,
|
|
|
|
mesh->meshSourceObjName.toLatin1().constData(),
|
|
|
|
mesh->meshSourceObjTypeStr.toLatin1().constData() );
|
2018-10-25 08:34:21 -05:00
|
|
|
|
2018-12-19 05:31:44 -06:00
|
|
|
VdeMeshArrayIds arrayIdsThisMesh;
|
2018-10-25 08:34:21 -05:00
|
|
|
|
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
const float* floatArr = reinterpret_cast<const float*>( mesh->vertexArr->ptr() );
|
|
|
|
const size_t arrElementCount = 3 * mesh->vertexArr->size();
|
2020-02-12 04:43:15 -06:00
|
|
|
arrayIdsThisMesh.vertexArrId =
|
2023-02-26 03:48:40 -06:00
|
|
|
m_cachingIdFactory->getOrCreateIdForFloatArr( VdeCachingHashedIdFactory::VertexArr, floatArr, arrElementCount );
|
2018-12-19 05:31:44 -06:00
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( !packetDirectory->lookupPacket( arrayIdsThisMesh.vertexArrId ) )
|
2018-12-19 05:31:44 -06:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
cvf::Trace::show( " generating vertices, arrayId=%d", arrayIdsThisMesh.vertexArrId );
|
|
|
|
std::unique_ptr<VdeArrayDataPacket> dataPacket =
|
|
|
|
VdeArrayDataPacket::fromFloat32Arr( arrayIdsThisMesh.vertexArrId, floatArr, arrElementCount );
|
2018-12-19 05:31:44 -06:00
|
|
|
|
|
|
|
// Debug testing of decoding
|
2020-02-12 04:43:15 -06:00
|
|
|
// debugComparePackets(*dataPacket,
|
|
|
|
// VdeArrayDataPacket::fromRawPacketBuffer(dataPacket->fullPacketRawPtr(), dataPacket->fullPacketSize(),
|
|
|
|
// nullptr));
|
2018-12-19 05:31:44 -06:00
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
packetDirectory->addPacket( std::move( dataPacket ) );
|
2018-12-19 05:31:44 -06:00
|
|
|
}
|
2018-10-25 08:34:21 -05:00
|
|
|
}
|
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
const unsigned int* uintArr = mesh->connArr.data();
|
|
|
|
const size_t arrElementCount = mesh->connArr.size();
|
2020-02-12 04:43:15 -06:00
|
|
|
arrayIdsThisMesh.connArrId =
|
|
|
|
m_cachingIdFactory->getOrCreateIdForUint32Arr( VdeCachingHashedIdFactory::ConnArr, uintArr, arrElementCount );
|
2018-12-19 05:31:44 -06:00
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( !packetDirectory->lookupPacket( arrayIdsThisMesh.connArrId ) )
|
2018-12-19 05:31:44 -06:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
cvf::Trace::show( " generating connectivities, arrayId=%d", arrayIdsThisMesh.connArrId );
|
2019-11-04 08:08:09 -06:00
|
|
|
std::unique_ptr<VdeArrayDataPacket> dataPacket =
|
|
|
|
VdeArrayDataPacket::fromUint32Arr( arrayIdsThisMesh.connArrId, uintArr, arrElementCount );
|
2018-12-19 05:31:44 -06:00
|
|
|
|
|
|
|
// Debug testing of decoding
|
2020-02-12 04:43:15 -06:00
|
|
|
// debugComparePackets(*dataPacket,
|
|
|
|
// VdeArrayDataPacket::fromRawPacketBuffer(dataPacket->fullPacketRawPtr(), dataPacket->fullPacketSize(),
|
|
|
|
// nullptr));
|
2018-12-19 05:31:44 -06:00
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
packetDirectory->addPacket( std::move( dataPacket ) );
|
2018-12-19 05:31:44 -06:00
|
|
|
}
|
2018-10-25 08:34:21 -05:00
|
|
|
}
|
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( mesh->texCoordArr.notNull() && mesh->texImage.notNull() )
|
2018-10-25 08:34:21 -05:00
|
|
|
{
|
|
|
|
{
|
2019-11-04 08:08:09 -06:00
|
|
|
const float* floatArr = reinterpret_cast<const float*>( mesh->texCoordArr->ptr() );
|
|
|
|
const size_t arrElementCount = 2 * mesh->texCoordArr->size();
|
|
|
|
arrayIdsThisMesh.texCoordsArrId =
|
2023-02-26 03:48:40 -06:00
|
|
|
m_cachingIdFactory->getOrCreateIdForFloatArr( VdeCachingHashedIdFactory::TexCoordsArr, floatArr, arrElementCount );
|
2019-09-06 03:40:57 -05:00
|
|
|
|
|
|
|
if ( !packetDirectory->lookupPacket( arrayIdsThisMesh.texCoordsArrId ) )
|
2018-12-19 05:31:44 -06:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
cvf::Trace::show( " generating texture coords, arrayId=%d", arrayIdsThisMesh.texCoordsArrId );
|
|
|
|
std::unique_ptr<VdeArrayDataPacket> dataPacket =
|
|
|
|
VdeArrayDataPacket::fromFloat32Arr( arrayIdsThisMesh.texCoordsArrId, floatArr, arrElementCount );
|
2018-12-19 05:31:44 -06:00
|
|
|
|
|
|
|
// Debug testing of decoding
|
2020-02-12 04:43:15 -06:00
|
|
|
// debugComparePackets(*dataPacket,
|
|
|
|
// VdeArrayDataPacket::fromRawPacketBuffer(dataPacket->fullPacketRawPtr(),
|
2019-09-06 03:40:57 -05:00
|
|
|
// dataPacket->fullPacketSize(), nullptr));
|
2018-12-19 05:31:44 -06:00
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
packetDirectory->addPacket( std::move( dataPacket ) );
|
2018-12-19 05:31:44 -06:00
|
|
|
}
|
2018-10-25 08:34:21 -05:00
|
|
|
}
|
|
|
|
{
|
2018-12-19 05:31:44 -06:00
|
|
|
cvf::ref<cvf::UByteArray> byteArr = mesh->texImage->toRgb();
|
2019-11-04 08:08:09 -06:00
|
|
|
arrayIdsThisMesh.texImageArrId =
|
2023-02-26 03:48:40 -06:00
|
|
|
m_cachingIdFactory->getOrCreateIdForUint8Arr( VdeCachingHashedIdFactory::TexImage, byteArr->ptr(), byteArr->size() );
|
2018-10-25 08:34:21 -05:00
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( !packetDirectory->lookupPacket( arrayIdsThisMesh.texImageArrId ) )
|
2018-12-19 05:31:44 -06:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
cvf::Trace::show( " generating texture image, arrayId=%d", arrayIdsThisMesh.texImageArrId );
|
2023-02-26 03:48:40 -06:00
|
|
|
std::unique_ptr<VdeArrayDataPacket> dataPacket = VdeArrayDataPacket::fromUint8ImageRGBArr( arrayIdsThisMesh.texImageArrId,
|
|
|
|
mesh->texImage->width(),
|
|
|
|
mesh->texImage->height(),
|
|
|
|
byteArr->ptr(),
|
|
|
|
byteArr->size() );
|
2018-12-19 05:31:44 -06:00
|
|
|
|
|
|
|
// Debug testing of decoding
|
2020-02-12 04:43:15 -06:00
|
|
|
// debugComparePackets(*dataPacket,
|
|
|
|
// VdeArrayDataPacket::fromRawPacketBuffer(dataPacket->fullPacketRawPtr(),
|
2019-09-06 03:40:57 -05:00
|
|
|
// dataPacket->fullPacketSize(), nullptr));
|
2018-12-19 05:31:44 -06:00
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
packetDirectory->addPacket( std::move( dataPacket ) );
|
2018-12-19 05:31:44 -06:00
|
|
|
}
|
2018-10-25 08:34:21 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
allMeshesArrayIdsArr.push_back( arrayIdsThisMesh );
|
2018-10-25 08:34:21 -05:00
|
|
|
}
|
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
const int fillPacketDir_ms = static_cast<int>( tim.lapTime() * 1000 );
|
2018-10-25 08:34:21 -05:00
|
|
|
|
2019-01-17 02:37:35 -06:00
|
|
|
// Extract any exportable labels present in the view
|
2023-02-26 03:48:40 -06:00
|
|
|
const std::vector<std::pair<cvf::Vec3f, cvf::String>> labelAndPositionsArr = RicHoloLensExportImpl::labelsForExport( m_view );
|
2019-01-17 02:37:35 -06:00
|
|
|
|
|
|
|
// Actually create the JSON containing model meta data
|
2019-09-06 03:40:57 -05:00
|
|
|
*modelMetaJsonStr = createModelMetaJsonString( meshArr, allMeshesArrayIdsArr, labelAndPositionsArr );
|
2018-10-25 08:34:21 -05:00
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
// Find all unique packet array IDs referenced
|
2018-10-25 08:34:21 -05:00
|
|
|
std::set<int> referencedIdsSet;
|
2019-09-06 03:40:57 -05:00
|
|
|
for ( const VdeMeshArrayIds& meshArrayIds : allMeshesArrayIdsArr )
|
2018-10-25 08:34:21 -05:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( meshArrayIds.vertexArrId != -1 ) referencedIdsSet.insert( meshArrayIds.vertexArrId );
|
|
|
|
if ( meshArrayIds.connArrId != -1 ) referencedIdsSet.insert( meshArrayIds.connArrId );
|
|
|
|
if ( meshArrayIds.texImageArrId != -1 ) referencedIdsSet.insert( meshArrayIds.texImageArrId );
|
|
|
|
if ( meshArrayIds.texCoordsArrId != -1 ) referencedIdsSet.insert( meshArrayIds.texCoordsArrId );
|
2018-10-25 08:34:21 -05:00
|
|
|
}
|
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
allReferencedArrayIds->assign( referencedIdsSet.begin(), referencedIdsSet.end() );
|
2018-12-19 05:31:44 -06:00
|
|
|
|
2020-02-12 04:43:15 -06:00
|
|
|
RiaLogging::debug( QString( "HoloLens: Extracted %1 meshes (total of %2 primitives) in %3ms (buildMeshes=%4ms, "
|
|
|
|
"fillPacketDir=%5ms)" )
|
|
|
|
.arg( meshCount )
|
|
|
|
.arg( totNumPrimitives )
|
|
|
|
.arg( static_cast<int>( tim.time() * 1000 ) )
|
|
|
|
.arg( buildMeshes_ms )
|
|
|
|
.arg( fillPacketDir_ms ) );
|
2018-12-19 05:31:44 -06:00
|
|
|
|
2020-02-12 04:43:15 -06:00
|
|
|
// cvf::Trace::show("Total number of primitives extracted: %d in %dms", totNumPrimitives,
|
|
|
|
// static_cast<int>(tim.time()*1000));
|
2018-10-25 08:34:21 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
std::vector<std::unique_ptr<VdeMesh>> VdeVizDataExtractor::buildMeshArray( const std::vector<VdeExportPart>& exportPartsArr )
|
2018-10-25 08:34:21 -05:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
std::vector<std::unique_ptr<VdeMesh>> meshArr;
|
|
|
|
for ( const VdeExportPart& exportPart : exportPartsArr )
|
2018-10-25 08:34:21 -05:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
std::unique_ptr<VdeMesh> mesh = createMeshFromExportPart( exportPart );
|
|
|
|
if ( mesh )
|
2018-10-25 08:34:21 -05:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
meshArr.push_back( std::move( mesh ) );
|
2018-10-25 08:34:21 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return meshArr;
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
std::unique_ptr<VdeMesh> VdeVizDataExtractor::createMeshFromExportPart( const VdeExportPart& exportPart )
|
2018-10-25 08:34:21 -05:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
// cvf::Timer tim;
|
2018-12-19 05:31:44 -06:00
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
const cvf::Part* cvfPart = exportPart.part();
|
|
|
|
const cvf::DrawableGeo* geo = dynamic_cast<const cvf::DrawableGeo*>( cvfPart ? cvfPart->drawable() : nullptr );
|
|
|
|
if ( !geo )
|
2018-10-25 08:34:21 -05:00
|
|
|
{
|
2018-12-19 05:31:44 -06:00
|
|
|
return nullptr;
|
2018-10-25 08:34:21 -05:00
|
|
|
}
|
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( geo->primitiveSetCount() != 1 )
|
2018-10-25 08:34:21 -05:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
RiaLogging::debug( "Only geometries with exactly one primitive set is supported" );
|
2018-12-19 05:31:44 -06:00
|
|
|
return nullptr;
|
2018-10-25 08:34:21 -05:00
|
|
|
}
|
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
const cvf::Vec3fArray* vertexArr = geo->vertexArray();
|
|
|
|
const cvf::PrimitiveSet* primSet = geo->primitiveSet( 0 );
|
|
|
|
if ( !vertexArr || !primSet || primSet->faceCount() == 0 )
|
2018-10-25 08:34:21 -05:00
|
|
|
{
|
2018-12-19 05:31:44 -06:00
|
|
|
return nullptr;
|
2018-10-25 08:34:21 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Support 2 or 3 vertices per primitive
|
|
|
|
const cvf::PrimitiveType primType = primSet->primitiveType();
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( primType != cvf::PT_TRIANGLES && primType != cvf::PT_LINES )
|
2018-10-25 08:34:21 -05:00
|
|
|
{
|
2023-02-26 03:48:40 -06:00
|
|
|
RiaLogging::debug( QString( "Currently only triangle and line primitive sets are supported (saw primitive type: %1)" ).arg( primType ) );
|
2018-12-19 05:31:44 -06:00
|
|
|
return nullptr;
|
2018-10-25 08:34:21 -05:00
|
|
|
}
|
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
const int vertsPerPrimitive = ( primType == cvf::PT_TRIANGLES ) ? 3 : 2;
|
2018-12-19 05:31:44 -06:00
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
std::unique_ptr<VdeMesh> mesh( new VdeMesh );
|
2018-10-25 08:34:21 -05:00
|
|
|
mesh->verticesPerPrimitive = vertsPerPrimitive;
|
|
|
|
|
|
|
|
// Possibly transform the vertices
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( cvfPart->transform() )
|
2018-10-25 08:34:21 -05:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
const cvf::Mat4f m = cvf::Mat4f( cvfPart->transform()->worldTransform() );
|
2018-10-25 08:34:21 -05:00
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
cvf::ref<cvf::Vec3fArray> transVertexArr = new cvf::Vec3fArray( *vertexArr );
|
|
|
|
const size_t vertexCount = transVertexArr->size();
|
|
|
|
for ( size_t i = 0; i < vertexCount; i++ )
|
2018-10-25 08:34:21 -05:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
transVertexArr->ptr( i )->transformPoint( m );
|
2018-10-25 08:34:21 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
mesh->vertexArr = transVertexArr.p();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
mesh->vertexArr = vertexArr;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Fetch connectivities
|
|
|
|
// Using getFaceIndices() allows us to access strips and fans in the same way as triangles
|
|
|
|
// Note that HoloLens visualization wants triangles in clockwise order so we try and fix the winding
|
2018-12-19 05:31:44 -06:00
|
|
|
// This point might be moot if the HoloLens visualization always has to use two-sided lighting to get good results
|
2018-10-25 08:34:21 -05:00
|
|
|
const size_t faceCount = primSet->faceCount();
|
2019-09-06 03:40:57 -05:00
|
|
|
mesh->connArr.reserve( faceCount * vertsPerPrimitive );
|
2018-12-19 05:31:44 -06:00
|
|
|
|
|
|
|
cvf::UIntArray faceConn;
|
2019-09-06 03:40:57 -05:00
|
|
|
for ( size_t iface = 0; iface < faceCount; iface++ )
|
2018-10-25 08:34:21 -05:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
primSet->getFaceIndices( iface, &faceConn );
|
2018-10-25 08:34:21 -05:00
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( vertsPerPrimitive == 3 && exportPart.winding() == VdeExportPart::COUNTERCLOCKWISE )
|
2018-10-25 08:34:21 -05:00
|
|
|
{
|
|
|
|
// Reverse the winding
|
|
|
|
const size_t numConn = faceConn.size();
|
2019-09-06 03:40:57 -05:00
|
|
|
for ( size_t i = 0; i < numConn; i++ )
|
2018-10-25 08:34:21 -05:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
mesh->connArr.push_back( faceConn[numConn - i - 1] );
|
2018-10-25 08:34:21 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
mesh->connArr.insert( mesh->connArr.end(), faceConn.begin(), faceConn.end() );
|
2018-10-25 08:34:21 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( exportPart.textureImage() && geo->textureCoordArray() )
|
2018-10-25 08:34:21 -05:00
|
|
|
{
|
|
|
|
mesh->texCoordArr = geo->textureCoordArray();
|
2019-09-06 03:40:57 -05:00
|
|
|
mesh->texImage = exportPart.textureImage();
|
2018-10-25 08:34:21 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
QString srcObjType = "unknown";
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( exportPart.sourceObjectType() == VdeExportPart::OBJ_TYPE_GRID )
|
|
|
|
srcObjType = "grid";
|
|
|
|
else if ( exportPart.sourceObjectType() == VdeExportPart::OBJ_TYPE_PIPE )
|
|
|
|
srcObjType = "pipe";
|
2018-10-25 08:34:21 -05:00
|
|
|
mesh->meshSourceObjTypeStr = srcObjType;
|
|
|
|
|
|
|
|
mesh->meshSourceObjName = exportPart.sourceObjectName();
|
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
mesh->color = exportPart.color();
|
2018-10-25 08:34:21 -05:00
|
|
|
mesh->opacity = exportPart.opacity();
|
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( exportPart.cullFace() != VdeExportPart::CF_NONE )
|
2019-01-15 08:13:45 -06:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( exportPart.cullFace() == VdeExportPart::CF_FRONT )
|
|
|
|
mesh->cullFaceModeStr = "front";
|
|
|
|
else if ( exportPart.cullFace() == VdeExportPart::CF_BACK )
|
|
|
|
mesh->cullFaceModeStr = "back";
|
|
|
|
else
|
|
|
|
mesh->cullFaceModeStr = "none";
|
2019-01-15 08:13:45 -06:00
|
|
|
}
|
|
|
|
|
2020-02-12 04:43:15 -06:00
|
|
|
// cvf::Trace::show("createMeshFromExportPart(): numFaces=%d, time=%dms", faceCount,
|
|
|
|
// static_cast<int>(tim.time()*1000));
|
2018-12-19 05:31:44 -06:00
|
|
|
|
|
|
|
return mesh;
|
2018-10-25 08:34:21 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2023-02-26 03:48:40 -06:00
|
|
|
QString VdeVizDataExtractor::createModelMetaJsonString( const std::vector<std::unique_ptr<VdeMesh>>& meshArr,
|
|
|
|
const std::vector<VdeMeshArrayIds>& meshContentIdsArr,
|
2020-02-12 04:43:15 -06:00
|
|
|
const std::vector<std::pair<cvf::Vec3f, cvf::String>>& labelAndPositionsArr )
|
2018-10-25 08:34:21 -05:00
|
|
|
{
|
|
|
|
QVariantList jsonMeshMetaList;
|
2019-09-06 03:40:57 -05:00
|
|
|
for ( size_t i = 0; i < meshArr.size(); i++ )
|
2018-10-25 08:34:21 -05:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
const VdeMesh* mesh = meshArr[i].get();
|
2018-10-25 08:34:21 -05:00
|
|
|
const VdeMeshArrayIds& meshIds = meshContentIdsArr[i];
|
|
|
|
|
|
|
|
QMap<QString, QVariant> jsonMeshMeta;
|
2018-12-19 05:31:44 -06:00
|
|
|
jsonMeshMeta["meshSourceObjType"] = mesh->meshSourceObjTypeStr;
|
|
|
|
jsonMeshMeta["meshSourceObjName"] = mesh->meshSourceObjName;
|
2018-10-25 08:34:21 -05:00
|
|
|
|
2018-12-19 05:31:44 -06:00
|
|
|
jsonMeshMeta["verticesPerPrimitive"] = mesh->verticesPerPrimitive;
|
2019-09-06 03:40:57 -05:00
|
|
|
jsonMeshMeta["vertexArrId"] = meshIds.vertexArrId;
|
|
|
|
jsonMeshMeta["connArrId"] = meshIds.connArrId;
|
2018-10-25 08:34:21 -05:00
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( meshIds.texCoordsArrId >= 0 && meshIds.texImageArrId >= 0 )
|
2018-10-25 08:34:21 -05:00
|
|
|
{
|
|
|
|
jsonMeshMeta["texCoordsArrId"] = meshIds.texCoordsArrId;
|
2019-09-06 03:40:57 -05:00
|
|
|
jsonMeshMeta["texImageArrId"] = meshIds.texImageArrId;
|
2018-10-25 08:34:21 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
QMap<QString, QVariant> jsonColor;
|
2018-12-19 05:31:44 -06:00
|
|
|
jsonColor["r"] = mesh->color.r();
|
|
|
|
jsonColor["g"] = mesh->color.g();
|
|
|
|
jsonColor["b"] = mesh->color.b();
|
2018-10-25 08:34:21 -05:00
|
|
|
|
|
|
|
jsonMeshMeta["color"] = jsonColor;
|
|
|
|
}
|
|
|
|
|
2018-12-19 05:31:44 -06:00
|
|
|
jsonMeshMeta["opacity"] = mesh->opacity;
|
2018-10-25 08:34:21 -05:00
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( !mesh->cullFaceModeStr.isEmpty() )
|
2019-01-15 08:13:45 -06:00
|
|
|
{
|
|
|
|
jsonMeshMeta["cullFaceMode"] = mesh->cullFaceModeStr;
|
|
|
|
}
|
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
jsonMeshMetaList.push_back( jsonMeshMeta );
|
2018-10-25 08:34:21 -05:00
|
|
|
}
|
|
|
|
|
2019-01-17 02:37:35 -06:00
|
|
|
QVariantList jsonLabelList;
|
2019-09-06 03:40:57 -05:00
|
|
|
for ( size_t i = 0; i < labelAndPositionsArr.size(); i++ )
|
2019-01-17 02:37:35 -06:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
const cvf::Vec3f& pos = labelAndPositionsArr[i].first;
|
2019-01-17 02:37:35 -06:00
|
|
|
const cvf::String& txt = labelAndPositionsArr[i].second;
|
|
|
|
|
|
|
|
QMap<QString, QVariant> jsonPos;
|
|
|
|
jsonPos["x"] = pos.x();
|
|
|
|
jsonPos["y"] = pos.y();
|
|
|
|
jsonPos["z"] = pos.z();
|
|
|
|
|
|
|
|
QMap<QString, QVariant> jsonLabelEntry;
|
|
|
|
jsonLabelEntry["position"] = jsonPos;
|
2024-09-30 04:21:17 -05:00
|
|
|
jsonLabelEntry["text"] = QString::fromLatin1( txt.toAscii().ptr() );
|
2019-01-17 02:37:35 -06:00
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
jsonLabelList.push_back( jsonLabelEntry );
|
2019-01-17 02:37:35 -06:00
|
|
|
}
|
|
|
|
|
2018-10-25 08:34:21 -05:00
|
|
|
QMap<QString, QVariant> jsonModelMeta;
|
|
|
|
jsonModelMeta["modelName"] = "ResInsightExport";
|
2019-09-06 03:40:57 -05:00
|
|
|
jsonModelMeta["meshArr"] = jsonMeshMetaList;
|
2019-01-17 02:37:35 -06:00
|
|
|
jsonModelMeta["labelsArr"] = jsonLabelList;
|
2018-10-25 08:34:21 -05:00
|
|
|
|
2023-04-17 08:57:39 -05:00
|
|
|
const bool prettifyJson = true;
|
|
|
|
QString jsonStr = ResInsightInternalJson::Json::encode( jsonModelMeta, prettifyJson );
|
2018-10-25 08:34:21 -05:00
|
|
|
return jsonStr;
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
void VdeVizDataExtractor::debugComparePackets( const VdeArrayDataPacket& packetA, const VdeArrayDataPacket& packetB )
|
2018-10-25 08:34:21 -05:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
CVF_ASSERT( packetA.elementCount() == packetB.elementCount() );
|
|
|
|
CVF_ASSERT( packetA.elementSize() == packetB.elementSize() );
|
|
|
|
CVF_ASSERT( packetA.elementType() == packetB.elementType() );
|
2018-10-25 08:34:21 -05:00
|
|
|
|
|
|
|
const char* arrA = packetA.arrayData();
|
|
|
|
const char* arrB = packetB.arrayData();
|
2019-09-06 03:40:57 -05:00
|
|
|
for ( size_t i = 0; i < packetA.elementCount(); i++ )
|
2018-10-25 08:34:21 -05:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
CVF_ASSERT( arrA[i] == arrB[i] );
|
2018-10-25 08:34:21 -05:00
|
|
|
}
|
|
|
|
}
|