2020-01-08 04:56:48 -06:00
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// Copyright (C) 2020- Equinor ASA
|
|
|
|
//
|
|
|
|
// 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 "RivSurfacePartMgr.h"
|
|
|
|
|
2020-01-17 06:23:37 -06:00
|
|
|
#include "RiaApplication.h"
|
|
|
|
#include "RiaPreferences.h"
|
2020-01-08 04:56:48 -06:00
|
|
|
|
|
|
|
#include "RimCase.h"
|
2020-01-09 07:20:10 -06:00
|
|
|
#include "RimEclipseCase.h"
|
|
|
|
#include "RimEclipseCellColors.h"
|
|
|
|
#include "RimEclipseResultDefinition.h"
|
|
|
|
#include "RimEclipseView.h"
|
|
|
|
#include "RimGeoMechCellColors.h"
|
|
|
|
#include "RimGeoMechResultDefinition.h"
|
|
|
|
#include "RimGeoMechView.h"
|
|
|
|
#include "RimRegularLegendConfig.h"
|
2020-01-17 06:23:37 -06:00
|
|
|
#include "RimSurface.h"
|
|
|
|
#include "RimSurfaceInView.h"
|
2020-01-09 07:20:10 -06:00
|
|
|
#include "RimTernaryLegendConfig.h"
|
2020-01-17 06:23:37 -06:00
|
|
|
|
|
|
|
#include "RigHexIntersectionTools.h"
|
|
|
|
#include "RigResultAccessor.h"
|
|
|
|
#include "RigResultAccessorFactory.h"
|
|
|
|
#include "RigSurface.h"
|
|
|
|
|
2020-01-09 07:20:10 -06:00
|
|
|
#include "RivHexGridIntersectionTools.h"
|
2020-01-17 06:23:37 -06:00
|
|
|
#include "RivIntersectionResultsColoringTools.h"
|
|
|
|
#include "RivMeshLinesSourceInfo.h"
|
|
|
|
#include "RivPartPriority.h"
|
|
|
|
#include "RivReservoirSurfaceIntersectionSourceInfo.h"
|
2020-01-09 07:20:10 -06:00
|
|
|
#include "RivScalarMapperUtils.h"
|
2020-01-17 06:23:37 -06:00
|
|
|
#include "RivSurfaceIntersectionGeometryGenerator.h"
|
2020-01-09 07:20:10 -06:00
|
|
|
#include "RivTernaryScalarMapper.h"
|
2020-01-17 06:23:37 -06:00
|
|
|
|
2020-01-08 04:56:48 -06:00
|
|
|
#include "cafEffectGenerator.h"
|
2020-01-17 06:23:37 -06:00
|
|
|
|
2020-01-08 04:56:48 -06:00
|
|
|
#include "cvfDrawableGeo.h"
|
|
|
|
#include "cvfModelBasicList.h"
|
|
|
|
#include "cvfPart.h"
|
|
|
|
#include "cvfPrimitiveSetIndexedUInt.h"
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
RivSurfacePartMgr::RivSurfacePartMgr( RimSurfaceInView* surface )
|
|
|
|
: m_surfaceInView( surface )
|
|
|
|
{
|
2020-01-17 06:23:37 -06:00
|
|
|
CVF_ASSERT( surface );
|
|
|
|
|
|
|
|
m_intersectionFacesTextureCoords = new cvf::Vec2fArray;
|
|
|
|
|
|
|
|
cvf::ref<RivIntersectionHexGridInterface> hexGrid = m_surfaceInView->createHexGridInterface();
|
|
|
|
m_intersectionGenerator = new RivSurfaceIntersectionGeometryGenerator( m_surfaceInView, hexGrid.p() );
|
2020-01-08 04:56:48 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RivSurfacePartMgr::appendNativeGeometryPartsToModel( cvf::ModelBasicList* model, cvf::Transform* scaleTransform )
|
|
|
|
{
|
|
|
|
if ( m_nativeTrianglesPart.isNull() || m_surfaceInView->surface()->surfaceData() != m_usedSurfaceData.p() )
|
|
|
|
{
|
|
|
|
generateNativePartGeometry();
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( m_nativeTrianglesPart.notNull() )
|
|
|
|
{
|
|
|
|
m_nativeTrianglesPart->setTransform( scaleTransform );
|
2020-01-09 07:20:10 -06:00
|
|
|
this->applySingleColor();
|
2020-01-08 04:56:48 -06:00
|
|
|
|
|
|
|
model->addPart( m_nativeTrianglesPart.p() );
|
|
|
|
|
|
|
|
if ( m_nativeMeshLinesPart.notNull() )
|
|
|
|
{
|
|
|
|
m_nativeMeshLinesPart->setTransform( scaleTransform );
|
|
|
|
model->addPart( m_nativeMeshLinesPart.p() );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-09 07:20:10 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RivSurfacePartMgr::updateCellResultColor( size_t timeStepIndex )
|
|
|
|
{
|
2020-01-17 06:23:37 -06:00
|
|
|
if ( m_intersectionFaces.notNull() )
|
2020-01-09 07:20:10 -06:00
|
|
|
{
|
2020-01-17 06:23:37 -06:00
|
|
|
RivIntersectionResultsColoringTools::calculateIntersectionResultColors( timeStepIndex,
|
2020-01-21 08:13:29 -06:00
|
|
|
true,
|
2020-01-17 06:23:37 -06:00
|
|
|
m_surfaceInView,
|
|
|
|
m_intersectionGenerator.p(),
|
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
m_intersectionFaces.p(),
|
|
|
|
m_intersectionFacesTextureCoords.p() );
|
2020-01-09 07:20:10 -06:00
|
|
|
}
|
|
|
|
|
2020-01-24 08:59:18 -06:00
|
|
|
if ( false && m_nativeTrianglesPart.notNull() )
|
2020-01-17 06:23:37 -06:00
|
|
|
{
|
|
|
|
if ( !m_nativeVertexToCellIndexMap.size() )
|
|
|
|
{
|
|
|
|
generateNativeVertexToCellIndexMap();
|
|
|
|
}
|
2020-01-09 07:20:10 -06:00
|
|
|
|
2020-01-17 06:23:37 -06:00
|
|
|
RimGridView* gridView = nullptr;
|
|
|
|
m_surfaceInView->firstAncestorOrThisOfType( gridView );
|
2020-01-09 07:20:10 -06:00
|
|
|
|
2020-01-17 06:23:37 -06:00
|
|
|
if ( !gridView ) return;
|
2020-01-09 07:20:10 -06:00
|
|
|
|
2020-01-17 06:23:37 -06:00
|
|
|
bool isLightingDisabled = gridView->isLightingDisabled();
|
2020-01-09 07:20:10 -06:00
|
|
|
|
2020-01-17 06:23:37 -06:00
|
|
|
RimEclipseResultDefinition* eclipseResDef = nullptr;
|
|
|
|
RimGeoMechResultDefinition* geomResultDef = nullptr;
|
|
|
|
const cvf::ScalarMapper* scalarColorMapper = nullptr;
|
|
|
|
const RivTernaryScalarMapper* ternaryColorMapper = nullptr;
|
2020-01-09 07:20:10 -06:00
|
|
|
|
2020-01-17 06:23:37 -06:00
|
|
|
// Ordinary result
|
2020-01-09 07:20:10 -06:00
|
|
|
|
2020-01-17 06:23:37 -06:00
|
|
|
if ( !eclipseResDef && !geomResultDef )
|
2020-01-09 07:20:10 -06:00
|
|
|
{
|
2020-01-17 06:23:37 -06:00
|
|
|
RimEclipseView* eclipseView = nullptr;
|
|
|
|
m_surfaceInView->firstAncestorOrThisOfType( eclipseView );
|
|
|
|
|
|
|
|
if ( eclipseView )
|
|
|
|
{
|
|
|
|
eclipseResDef = eclipseView->cellResult();
|
|
|
|
if ( !scalarColorMapper ) scalarColorMapper = eclipseView->cellResult()->legendConfig()->scalarMapper();
|
|
|
|
if ( !ternaryColorMapper )
|
|
|
|
ternaryColorMapper = eclipseView->cellResult()->ternaryLegendConfig()->scalarMapper();
|
|
|
|
}
|
|
|
|
|
|
|
|
RimGeoMechView* geoView;
|
|
|
|
m_surfaceInView->firstAncestorOrThisOfType( geoView );
|
|
|
|
|
|
|
|
if ( geoView )
|
|
|
|
{
|
|
|
|
geomResultDef = geoView->cellResult();
|
|
|
|
if ( !scalarColorMapper ) scalarColorMapper = geoView->cellResult()->legendConfig()->scalarMapper();
|
|
|
|
}
|
2020-01-09 07:20:10 -06:00
|
|
|
}
|
|
|
|
|
2020-01-17 06:23:37 -06:00
|
|
|
cvf::ref<cvf::Vec2fArray> nativeFacesTextureCoords = new cvf::Vec2fArray();
|
2020-01-09 07:20:10 -06:00
|
|
|
|
2020-01-17 06:23:37 -06:00
|
|
|
if ( eclipseResDef )
|
2020-01-09 07:20:10 -06:00
|
|
|
{
|
2020-01-17 06:23:37 -06:00
|
|
|
if ( !eclipseResDef->isTernarySaturationSelected() )
|
|
|
|
{
|
|
|
|
RigEclipseCaseData* eclipseCaseData = eclipseResDef->eclipseCase()->eclipseCaseData();
|
|
|
|
|
|
|
|
cvf::ref<RigResultAccessor> resultAccessor;
|
|
|
|
|
|
|
|
if ( !RiaDefines::isPerCellFaceResult( eclipseResDef->resultVariable() ) )
|
|
|
|
|
|
|
|
{
|
|
|
|
resultAccessor = RigResultAccessorFactory::createFromResultDefinition( eclipseCaseData,
|
|
|
|
0,
|
|
|
|
timeStepIndex,
|
|
|
|
eclipseResDef );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( resultAccessor.isNull() )
|
|
|
|
{
|
|
|
|
resultAccessor = new RigHugeValResultAccessor;
|
|
|
|
}
|
|
|
|
|
|
|
|
RivSurfacePartMgr::calculateVertexTextureCoordinates( nativeFacesTextureCoords.p(),
|
|
|
|
m_nativeVertexToCellIndexMap,
|
|
|
|
resultAccessor.p(),
|
|
|
|
scalarColorMapper );
|
|
|
|
|
|
|
|
RivScalarMapperUtils::applyTextureResultsToPart( m_nativeTrianglesPart.p(),
|
|
|
|
nativeFacesTextureCoords.p(),
|
|
|
|
scalarColorMapper,
|
|
|
|
1.0,
|
|
|
|
caf::FC_NONE,
|
|
|
|
isLightingDisabled );
|
|
|
|
}
|
2020-01-09 07:20:10 -06:00
|
|
|
}
|
|
|
|
}
|
2020-01-17 06:23:37 -06:00
|
|
|
}
|
2020-01-09 07:20:10 -06:00
|
|
|
|
2020-01-17 06:23:37 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2020-02-12 04:43:15 -06:00
|
|
|
void RivSurfacePartMgr::appendIntersectionGeometryPartsToModel( cvf::ModelBasicList* model, cvf::Transform* scaleTransform )
|
2020-01-17 06:23:37 -06:00
|
|
|
{
|
|
|
|
if ( m_intersectionFaces.isNull() )
|
2020-01-09 07:20:10 -06:00
|
|
|
{
|
2020-01-17 06:23:37 -06:00
|
|
|
generatePartGeometry();
|
|
|
|
}
|
2020-01-09 07:20:10 -06:00
|
|
|
|
2020-01-17 06:23:37 -06:00
|
|
|
if ( m_intersectionFaces.notNull() )
|
|
|
|
{
|
|
|
|
m_intersectionFaces->setTransform( scaleTransform );
|
|
|
|
model->addPart( m_intersectionFaces.p() );
|
|
|
|
}
|
2020-01-09 07:20:10 -06:00
|
|
|
|
2020-01-17 06:23:37 -06:00
|
|
|
// Mesh Lines
|
2020-01-09 07:20:10 -06:00
|
|
|
|
2020-01-17 06:23:37 -06:00
|
|
|
if ( m_intersectionGridLines.isNull() )
|
|
|
|
{
|
|
|
|
generatePartGeometry();
|
|
|
|
}
|
2020-01-09 07:20:10 -06:00
|
|
|
|
2020-01-17 06:23:37 -06:00
|
|
|
if ( m_intersectionGridLines.notNull() )
|
|
|
|
{
|
|
|
|
m_intersectionGridLines->setTransform( scaleTransform );
|
|
|
|
model->addPart( m_intersectionGridLines.p() );
|
|
|
|
}
|
2020-01-09 07:20:10 -06:00
|
|
|
|
2020-01-17 06:23:37 -06:00
|
|
|
if ( m_intersectionFaultGridLines.notNull() )
|
|
|
|
{
|
|
|
|
m_intersectionFaultGridLines->setTransform( scaleTransform );
|
|
|
|
model->addPart( m_intersectionFaultGridLines.p() );
|
2020-01-09 07:20:10 -06:00
|
|
|
}
|
2020-01-24 08:59:18 -06:00
|
|
|
|
|
|
|
appendNativeGeometryPartsToModel( model, scaleTransform );
|
2020-01-09 07:20:10 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RivSurfacePartMgr::applySingleColor()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
caf::SurfaceEffectGenerator surfaceGen( cvf::Color4f( m_surfaceInView->surface()->color() ), caf::PO_1 );
|
|
|
|
cvf::ref<cvf::Effect> eff = surfaceGen.generateCachedEffect();
|
2020-01-17 06:23:37 -06:00
|
|
|
|
2020-01-30 04:54:30 -06:00
|
|
|
caf::SurfaceEffectGenerator surfaceGenBehind( cvf::Color4f( m_surfaceInView->surface()->color() ),
|
|
|
|
caf::PO_POS_LARGE );
|
2020-01-24 08:59:18 -06:00
|
|
|
cvf::ref<cvf::Effect> effBehind = surfaceGenBehind.generateCachedEffect();
|
|
|
|
|
2020-01-17 06:23:37 -06:00
|
|
|
if ( m_nativeTrianglesPart.notNull() )
|
|
|
|
{
|
2020-01-24 08:59:18 -06:00
|
|
|
m_nativeTrianglesPart->setEffect( effBehind.p() );
|
2020-01-17 06:23:37 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( m_intersectionFaces.notNull() )
|
|
|
|
{
|
|
|
|
m_intersectionFaces->setEffect( eff.p() );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update mesh colors as well, in case of change
|
|
|
|
|
|
|
|
RiaPreferences* prefs = RiaApplication::instance()->preferences();
|
|
|
|
|
|
|
|
if ( m_intersectionGridLines.notNull() )
|
|
|
|
{
|
|
|
|
cvf::ref<cvf::Effect> eff;
|
|
|
|
caf::MeshEffectGenerator CrossSectionEffGen( prefs->defaultGridLineColors() );
|
|
|
|
eff = CrossSectionEffGen.generateCachedEffect();
|
|
|
|
|
|
|
|
m_intersectionGridLines->setEffect( eff.p() );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( m_intersectionFaultGridLines.notNull() )
|
|
|
|
{
|
|
|
|
cvf::ref<cvf::Effect> eff;
|
|
|
|
caf::MeshEffectGenerator CrossSectionEffGen( prefs->defaultFaultGridLineColors() );
|
|
|
|
eff = CrossSectionEffGen.generateCachedEffect();
|
|
|
|
|
|
|
|
m_intersectionFaultGridLines->setEffect( eff.p() );
|
2020-01-09 07:20:10 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-17 06:23:37 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RivSurfacePartMgr::generatePartGeometry()
|
|
|
|
{
|
|
|
|
if ( m_intersectionGenerator.isNull() ) return;
|
|
|
|
|
|
|
|
bool useBufferObjects = true;
|
|
|
|
// Surface geometry
|
|
|
|
{
|
|
|
|
cvf::ref<cvf::DrawableGeo> geo = m_intersectionGenerator->generateSurface();
|
|
|
|
if ( geo.notNull() )
|
|
|
|
{
|
|
|
|
geo->computeNormals();
|
|
|
|
|
|
|
|
if ( useBufferObjects )
|
|
|
|
{
|
|
|
|
geo->setRenderMode( cvf::DrawableGeo::BUFFER_OBJECT );
|
|
|
|
}
|
|
|
|
|
|
|
|
cvf::ref<cvf::Part> part = new cvf::Part;
|
2020-01-30 04:54:30 -06:00
|
|
|
part->setName( "Intersected Reservoir Surface" );
|
2020-01-17 06:23:37 -06:00
|
|
|
part->setDrawable( geo.p() );
|
|
|
|
|
|
|
|
// Set mapping from triangle face index to cell index
|
2020-02-12 04:43:15 -06:00
|
|
|
cvf::ref<RivReservoirSurfaceIntersectionSourceInfo> si =
|
|
|
|
new RivReservoirSurfaceIntersectionSourceInfo( m_intersectionGenerator.p() );
|
2020-01-17 06:23:37 -06:00
|
|
|
part->setSourceInfo( si.p() );
|
|
|
|
|
|
|
|
part->updateBoundingBox();
|
|
|
|
part->setEnableMask( intersectionCellFaceBit );
|
|
|
|
part->setPriority( RivPartPriority::PartType::Intersection );
|
|
|
|
|
|
|
|
m_intersectionFaces = part;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Cell Mesh geometry
|
|
|
|
{
|
|
|
|
cvf::ref<cvf::DrawableGeo> geoMesh = m_intersectionGenerator->createMeshDrawable();
|
|
|
|
if ( geoMesh.notNull() )
|
|
|
|
{
|
|
|
|
if ( useBufferObjects )
|
|
|
|
{
|
|
|
|
geoMesh->setRenderMode( cvf::DrawableGeo::BUFFER_OBJECT );
|
|
|
|
}
|
|
|
|
|
|
|
|
cvf::ref<cvf::Part> part = new cvf::Part;
|
|
|
|
part->setName( "Surface intersection mesh" );
|
|
|
|
part->setDrawable( geoMesh.p() );
|
|
|
|
|
|
|
|
part->updateBoundingBox();
|
|
|
|
part->setEnableMask( intersectionCellMeshBit );
|
|
|
|
part->setPriority( RivPartPriority::PartType::MeshLines );
|
|
|
|
|
|
|
|
part->setSourceInfo( new RivMeshLinesSourceInfo( m_surfaceInView ) );
|
|
|
|
|
|
|
|
m_intersectionGridLines = part;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Fault Mesh geometry
|
|
|
|
{
|
|
|
|
cvf::ref<cvf::DrawableGeo> geoMesh = m_intersectionGenerator->createFaultMeshDrawable();
|
|
|
|
if ( geoMesh.notNull() )
|
|
|
|
{
|
|
|
|
if ( useBufferObjects )
|
|
|
|
{
|
|
|
|
geoMesh->setRenderMode( cvf::DrawableGeo::BUFFER_OBJECT );
|
|
|
|
}
|
|
|
|
|
|
|
|
cvf::ref<cvf::Part> part = new cvf::Part;
|
|
|
|
part->setName( "Surface faultmesh" );
|
|
|
|
part->setDrawable( geoMesh.p() );
|
|
|
|
|
|
|
|
part->updateBoundingBox();
|
|
|
|
part->setEnableMask( intersectionFaultMeshBit );
|
|
|
|
part->setPriority( RivPartPriority::PartType::FaultMeshLines );
|
|
|
|
|
|
|
|
part->setSourceInfo( new RivMeshLinesSourceInfo( m_surfaceInView ) );
|
|
|
|
|
|
|
|
m_intersectionFaultGridLines = part;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
applySingleColor();
|
|
|
|
}
|
|
|
|
|
2020-01-08 04:56:48 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RivSurfacePartMgr::generateNativePartGeometry()
|
|
|
|
{
|
|
|
|
RimCase* ownerCase;
|
|
|
|
m_surfaceInView->firstAncestorOrThisOfTypeAsserted( ownerCase );
|
|
|
|
cvf::Vec3d displayModOffsett = ownerCase->displayModelOffset();
|
|
|
|
|
|
|
|
m_usedSurfaceData = m_surfaceInView->surface()->surfaceData();
|
|
|
|
|
|
|
|
const std::vector<cvf::Vec3d>& vertices = m_usedSurfaceData->vertices();
|
|
|
|
cvf::ref<cvf::Vec3fArray> cvfVertices = new cvf::Vec3fArray( vertices.size() );
|
|
|
|
for ( size_t i = 0; i < vertices.size(); ++i )
|
|
|
|
{
|
|
|
|
( *cvfVertices )[i] = cvf::Vec3f( vertices[i] - displayModOffsett );
|
|
|
|
}
|
|
|
|
|
|
|
|
const std::vector<unsigned>& triangleIndices = m_usedSurfaceData->triangleIndices();
|
|
|
|
cvf::ref<cvf::UIntArray> cvfIndices = new cvf::UIntArray( triangleIndices );
|
|
|
|
cvf::ref<cvf::PrimitiveSetIndexedUInt> indexSet = new cvf::PrimitiveSetIndexedUInt( cvf::PT_TRIANGLES );
|
|
|
|
indexSet->setIndices( cvfIndices.p() );
|
|
|
|
|
|
|
|
cvf::ref<cvf::DrawableGeo> drawGeo = new cvf::DrawableGeo;
|
|
|
|
drawGeo->addPrimitiveSet( indexSet.p() );
|
|
|
|
drawGeo->setVertexArray( cvfVertices.p() );
|
2020-01-09 01:59:11 -06:00
|
|
|
drawGeo->computeNormals();
|
2020-01-08 04:56:48 -06:00
|
|
|
|
2020-01-28 03:21:37 -06:00
|
|
|
cvf::ref<RivObjectSourceInfo> objectSourceInfo = new RivObjectSourceInfo( m_surfaceInView );
|
|
|
|
|
2020-01-08 04:56:48 -06:00
|
|
|
m_nativeTrianglesPart = new cvf::Part();
|
2020-01-17 06:23:37 -06:00
|
|
|
m_nativeTrianglesPart->setName( "Native Reservoir Surface" );
|
2020-01-08 04:56:48 -06:00
|
|
|
m_nativeTrianglesPart->setDrawable( drawGeo.p() );
|
2020-01-28 03:21:37 -06:00
|
|
|
m_nativeTrianglesPart->setSourceInfo( objectSourceInfo.p() );
|
2020-01-09 07:20:10 -06:00
|
|
|
|
2020-01-17 06:23:37 -06:00
|
|
|
m_nativeVertexToCellIndexMap.clear();
|
2020-01-09 07:20:10 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2020-01-17 06:23:37 -06:00
|
|
|
void RivSurfacePartMgr::generateNativeVertexToCellIndexMap()
|
2020-01-09 07:20:10 -06:00
|
|
|
{
|
|
|
|
cvf::ref<RivIntersectionHexGridInterface> hexGrid = m_surfaceInView->createHexGridInterface();
|
|
|
|
|
|
|
|
const std::vector<cvf::Vec3d>& vertices = m_usedSurfaceData->vertices();
|
2020-01-17 06:23:37 -06:00
|
|
|
m_nativeVertexToCellIndexMap.resize( vertices.size(), -1 );
|
2020-01-09 07:20:10 -06:00
|
|
|
|
|
|
|
for ( size_t vxIdx = 0; vxIdx < vertices.size(); ++vxIdx )
|
|
|
|
{
|
|
|
|
cvf::BoundingBox box;
|
|
|
|
box.add( vertices[vxIdx] );
|
|
|
|
std::vector<size_t> cellCandidates;
|
|
|
|
hexGrid->findIntersectingCells( box, &cellCandidates );
|
|
|
|
|
|
|
|
for ( size_t cellIdx : cellCandidates )
|
|
|
|
{
|
|
|
|
cvf::Vec3d cellCorners[8];
|
|
|
|
hexGrid->cellCornerVertices( cellIdx, cellCorners );
|
|
|
|
|
|
|
|
if ( RigHexIntersectionTools::isPointInCell( vertices[vxIdx], cellCorners ) )
|
|
|
|
{
|
2020-01-17 06:23:37 -06:00
|
|
|
m_nativeVertexToCellIndexMap[vxIdx] = cellIdx;
|
2020-01-09 07:20:10 -06:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
/// Calculates the texture coordinates in a "nearly" one dimensional texture.
|
|
|
|
/// Undefined values are coded with a y-texturecoordinate value of 1.0 instead of the normal 0.5
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RivSurfacePartMgr::calculateVertexTextureCoordinates( cvf::Vec2fArray* textureCoords,
|
|
|
|
const std::vector<size_t>& vertexToCellIdxMap,
|
|
|
|
const RigResultAccessor* resultAccessor,
|
|
|
|
const cvf::ScalarMapper* mapper )
|
|
|
|
{
|
|
|
|
if ( !resultAccessor ) return;
|
|
|
|
|
|
|
|
size_t numVertices = vertexToCellIdxMap.size();
|
|
|
|
|
|
|
|
textureCoords->resize( numVertices );
|
|
|
|
cvf::Vec2f* rawPtr = textureCoords->ptr();
|
|
|
|
|
|
|
|
#pragma omp parallel for
|
|
|
|
for ( int vxIdx = 0; vxIdx < numVertices; vxIdx++ )
|
|
|
|
{
|
|
|
|
double cellScalarValue = resultAccessor->cellScalarGlobIdx( vertexToCellIdxMap[vxIdx] );
|
|
|
|
cvf::Vec2f texCoord = mapper->mapToTextureCoord( cellScalarValue );
|
|
|
|
if ( cellScalarValue == HUGE_VAL || cellScalarValue != cellScalarValue ) // a != a is true for NAN's
|
|
|
|
{
|
|
|
|
texCoord[1] = 1.0f;
|
|
|
|
}
|
|
|
|
|
|
|
|
rawPtr[vxIdx] = texCoord;
|
|
|
|
}
|
2020-01-08 04:56:48 -06:00
|
|
|
}
|