2014-08-11 01:10:07 -05:00
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
2014-09-24 00:14:52 -05:00
|
|
|
// Copyright (C) Statoil ASA
|
|
|
|
// Copyright (C) Ceetron Solutions AS
|
2019-09-06 03:40:57 -05:00
|
|
|
//
|
2014-08-11 01:10:07 -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.
|
2019-09-06 03:40:57 -05:00
|
|
|
//
|
2014-08-11 01:10:07 -05:00
|
|
|
// 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.
|
2019-09-06 03:40:57 -05:00
|
|
|
//
|
|
|
|
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
2014-08-11 01:10:07 -05:00
|
|
|
// for more details.
|
|
|
|
//
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#include "RivTernaryTextureCoordsCreator.h"
|
|
|
|
|
|
|
|
#include "RigCaseCellResultsData.h"
|
2017-01-10 02:51:39 -06:00
|
|
|
#include "RigEclipseCaseData.h"
|
2014-08-11 01:10:07 -05:00
|
|
|
#include "RigPipeInCellEvaluator.h"
|
|
|
|
#include "RigResultAccessorFactory.h"
|
2018-10-16 04:13:56 -05:00
|
|
|
#include "RigTernaryResultAccessor.h"
|
2014-08-11 01:10:07 -05:00
|
|
|
|
2015-05-15 02:16:33 -05:00
|
|
|
#include "RimEclipseCase.h"
|
2019-11-18 09:05:36 -06:00
|
|
|
#include "RimEclipseResultDefinition.h"
|
2017-10-13 07:20:47 -05:00
|
|
|
#include "RimEclipseView.h"
|
|
|
|
#include "RimSimWellInViewCollection.h"
|
2014-08-11 01:10:07 -05:00
|
|
|
#include "RimTernaryLegendConfig.h"
|
|
|
|
|
|
|
|
#include "RivTernaryResultToTextureMapper.h"
|
|
|
|
#include "RivTernaryScalarMapper.h"
|
|
|
|
|
2017-01-09 12:51:15 -06:00
|
|
|
#include "cvfStructGridGeometryGenerator.h"
|
|
|
|
|
2014-08-11 01:10:07 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
///
|
2014-08-11 01:10:07 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-11-20 03:28:35 -06:00
|
|
|
RivTernaryTextureCoordsCreator::RivTernaryTextureCoordsCreator( const RimEclipseResultDefinition* cellResultColors,
|
|
|
|
RimTernaryLegendConfig* ternaryLegendConfig,
|
2019-11-18 09:05:36 -06:00
|
|
|
RimSimWellInViewCollection* simWellInViewCollection,
|
|
|
|
size_t timeStepIndex,
|
|
|
|
size_t gridIndex,
|
2019-09-06 03:40:57 -05:00
|
|
|
const cvf::StructGridQuadToCellFaceMapper* quadMapper )
|
2014-08-11 01:10:07 -05:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
CVF_ASSERT( quadMapper );
|
2014-08-11 01:10:07 -05:00
|
|
|
m_quadMapper = quadMapper;
|
2015-11-23 08:24:03 -06:00
|
|
|
|
2019-11-18 09:05:36 -06:00
|
|
|
RigEclipseCaseData* eclipseCase = cellResultColors->eclipseCase()->eclipseCaseData();
|
2015-11-24 02:59:25 -06:00
|
|
|
|
|
|
|
size_t resTimeStepIdx = timeStepIndex;
|
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( cellResultColors->hasStaticResult() ) resTimeStepIdx = 0;
|
2015-11-24 02:59:25 -06:00
|
|
|
|
2017-08-11 07:05:59 -05:00
|
|
|
RiaDefines::PorosityModelType porosityModel = cellResultColors->porosityModel();
|
2015-11-24 02:59:25 -06:00
|
|
|
|
2020-02-12 04:43:15 -06:00
|
|
|
cvf::ref<RigResultAccessor> soil =
|
|
|
|
RigResultAccessorFactory::createFromResultAddress( eclipseCase,
|
|
|
|
gridIndex,
|
|
|
|
porosityModel,
|
|
|
|
resTimeStepIdx,
|
2022-01-06 01:55:55 -06:00
|
|
|
RigEclipseResultAddress( RiaResultNames::soil() ) );
|
2020-02-12 04:43:15 -06:00
|
|
|
cvf::ref<RigResultAccessor> sgas =
|
|
|
|
RigResultAccessorFactory::createFromResultAddress( eclipseCase,
|
|
|
|
gridIndex,
|
|
|
|
porosityModel,
|
|
|
|
resTimeStepIdx,
|
2022-01-06 01:55:55 -06:00
|
|
|
RigEclipseResultAddress( RiaResultNames::sgas() ) );
|
2020-02-12 04:43:15 -06:00
|
|
|
cvf::ref<RigResultAccessor> swat =
|
|
|
|
RigResultAccessorFactory::createFromResultAddress( eclipseCase,
|
|
|
|
gridIndex,
|
|
|
|
porosityModel,
|
|
|
|
resTimeStepIdx,
|
2022-01-06 01:55:55 -06:00
|
|
|
RigEclipseResultAddress( RiaResultNames::swat() ) );
|
2015-11-24 02:59:25 -06:00
|
|
|
|
|
|
|
m_resultAccessor = new RigTernaryResultAccessor();
|
2019-09-06 03:40:57 -05:00
|
|
|
m_resultAccessor->setTernaryResultAccessors( soil.p(), sgas.p(), swat.p() );
|
2015-11-24 02:59:25 -06:00
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
cvf::ref<RigPipeInCellEvaluator> pipeInCellEval =
|
2019-11-18 09:05:36 -06:00
|
|
|
new RigPipeInCellEvaluator( simWellInViewCollection->resultWellGeometryVisibilities( timeStepIndex ),
|
2019-09-06 03:40:57 -05:00
|
|
|
eclipseCase->gridCellToResultWellIndex( gridIndex ) );
|
2015-11-24 02:59:25 -06:00
|
|
|
|
|
|
|
const RivTernaryScalarMapper* mapper = ternaryLegendConfig->scalarMapper();
|
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
m_texMapper = new RivTernaryResultToTextureMapper( mapper, pipeInCellEval.p() );
|
|
|
|
CVF_ASSERT( m_texMapper.notNull() );
|
2015-11-23 08:24:03 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
///
|
2015-11-23 08:24:03 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-11-20 03:28:35 -06:00
|
|
|
RivTernaryTextureCoordsCreator::RivTernaryTextureCoordsCreator( const RimEclipseResultDefinition* cellResultColors,
|
|
|
|
const RivTernaryScalarMapper* ternaryColorMapper,
|
|
|
|
size_t timeStepIndex )
|
2019-09-06 03:40:57 -05:00
|
|
|
: m_quadMapper( nullptr )
|
2015-11-23 08:24:03 -06:00
|
|
|
{
|
2019-11-18 09:05:36 -06:00
|
|
|
RigEclipseCaseData* eclipseCase = cellResultColors->eclipseCase()->eclipseCaseData();
|
2014-08-11 01:10:07 -05:00
|
|
|
|
|
|
|
size_t resTimeStepIdx = timeStepIndex;
|
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( cellResultColors->hasStaticResult() ) resTimeStepIdx = 0;
|
2014-08-11 01:10:07 -05:00
|
|
|
|
2017-08-11 07:05:59 -05:00
|
|
|
RiaDefines::PorosityModelType porosityModel = cellResultColors->porosityModel();
|
2014-08-11 01:10:07 -05:00
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
size_t gridIndex = 0;
|
2020-02-12 04:43:15 -06:00
|
|
|
cvf::ref<RigResultAccessor> soil =
|
|
|
|
RigResultAccessorFactory::createFromResultAddress( eclipseCase,
|
|
|
|
gridIndex,
|
|
|
|
porosityModel,
|
|
|
|
resTimeStepIdx,
|
2022-01-06 01:55:55 -06:00
|
|
|
RigEclipseResultAddress( RiaResultNames::soil() ) );
|
2020-02-12 04:43:15 -06:00
|
|
|
cvf::ref<RigResultAccessor> sgas =
|
|
|
|
RigResultAccessorFactory::createFromResultAddress( eclipseCase,
|
|
|
|
gridIndex,
|
|
|
|
porosityModel,
|
|
|
|
resTimeStepIdx,
|
2022-01-06 01:55:55 -06:00
|
|
|
RigEclipseResultAddress( RiaResultNames::sgas() ) );
|
2020-02-12 04:43:15 -06:00
|
|
|
cvf::ref<RigResultAccessor> swat =
|
|
|
|
RigResultAccessorFactory::createFromResultAddress( eclipseCase,
|
|
|
|
gridIndex,
|
|
|
|
porosityModel,
|
|
|
|
resTimeStepIdx,
|
2022-01-06 01:55:55 -06:00
|
|
|
RigEclipseResultAddress( RiaResultNames::swat() ) );
|
2015-11-23 08:24:03 -06:00
|
|
|
|
2015-10-23 08:46:25 -05:00
|
|
|
m_resultAccessor = new RigTernaryResultAccessor();
|
2019-09-06 03:40:57 -05:00
|
|
|
m_resultAccessor->setTernaryResultAccessors( soil.p(), sgas.p(), swat.p() );
|
2014-08-11 01:10:07 -05:00
|
|
|
|
2015-11-24 02:59:25 -06:00
|
|
|
// Create a texture mapper without detecting transparency using RigPipeInCellEvaluator
|
2019-09-06 03:40:57 -05:00
|
|
|
m_texMapper = new RivTernaryResultToTextureMapper( ternaryColorMapper, nullptr );
|
|
|
|
CVF_ASSERT( m_texMapper.notNull() );
|
2014-08-11 01:10:07 -05:00
|
|
|
}
|
|
|
|
|
2014-08-11 03:50:31 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
///
|
2014-08-11 03:50:31 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
void RivTernaryTextureCoordsCreator::createTextureCoords( cvf::Vec2fArray* quadTextureCoords )
|
2014-08-11 03:50:31 -05:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
CVF_ASSERT( m_quadMapper.notNull() );
|
|
|
|
createTextureCoords( quadTextureCoords, m_quadMapper.p(), m_resultAccessor.p(), m_texMapper.p() );
|
2014-08-11 03:50:31 -05:00
|
|
|
}
|
|
|
|
|
2015-11-23 08:24:03 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
///
|
2015-11-23 08:24:03 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
void RivTernaryTextureCoordsCreator::createTextureCoords( cvf::Vec2fArray* triTextureCoords,
|
|
|
|
const std::vector<size_t>& triangleToCellIdx )
|
2015-11-23 08:24:03 -06:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
CVF_ASSERT( m_quadMapper.isNull() );
|
2015-11-23 08:24:03 -06:00
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
createTextureCoords( triTextureCoords, triangleToCellIdx, m_resultAccessor.p(), m_texMapper.p() );
|
2015-11-23 08:24:03 -06:00
|
|
|
}
|
|
|
|
|
2014-08-11 01:10:07 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
///
|
2014-08-11 01:10:07 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
void RivTernaryTextureCoordsCreator::createTextureCoords( cvf::Vec2fArray* quadTextureCoords,
|
|
|
|
const cvf::StructGridQuadToCellFaceMapper* quadMapper,
|
|
|
|
const RigTernaryResultAccessor* resultAccessor,
|
|
|
|
const RivTernaryResultToTextureMapper* texMapper )
|
2014-08-11 01:10:07 -05:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
CVF_ASSERT( quadTextureCoords && quadMapper && resultAccessor && texMapper );
|
2014-08-11 01:10:07 -05:00
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
size_t numVertices = quadMapper->quadCount() * 4;
|
|
|
|
quadTextureCoords->resize( numVertices );
|
2014-08-11 01:10:07 -05:00
|
|
|
cvf::Vec2f* rawPtr = quadTextureCoords->ptr();
|
|
|
|
|
2016-08-11 08:30:55 -05:00
|
|
|
#pragma omp parallel for
|
2019-09-06 03:40:57 -05:00
|
|
|
for ( int i = 0; i < static_cast<int>( quadMapper->quadCount() ); i++ )
|
2014-08-11 01:10:07 -05:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
cvf::StructGridInterface::FaceType faceId = quadMapper->cellFace( i );
|
|
|
|
size_t cellIdx = quadMapper->cellIndex( i );
|
2014-08-11 01:10:07 -05:00
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
cvf::Vec2d resultValue = resultAccessor->cellFaceScalar( cellIdx, faceId );
|
|
|
|
cvf::Vec2f texCoord = texMapper->getTexCoord( resultValue.x(), resultValue.y(), cellIdx );
|
2014-08-11 01:10:07 -05:00
|
|
|
|
|
|
|
size_t j;
|
2019-09-06 03:40:57 -05:00
|
|
|
for ( j = 0; j < 4; j++ )
|
|
|
|
{
|
|
|
|
rawPtr[i * 4 + j] = texCoord;
|
2014-08-11 01:10:07 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-11-23 08:24:03 -06:00
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
///
|
2015-11-23 08:24:03 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
void RivTernaryTextureCoordsCreator::createTextureCoords( cvf::Vec2fArray* textureCoords,
|
|
|
|
const std::vector<size_t>& triangleToCellIdx,
|
|
|
|
const RigTernaryResultAccessor* resultAccessor,
|
|
|
|
const RivTernaryResultToTextureMapper* texMapper )
|
2015-11-23 08:24:03 -06:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
CVF_ASSERT( textureCoords && resultAccessor && texMapper );
|
2015-11-23 08:24:03 -06:00
|
|
|
|
|
|
|
size_t numVertices = triangleToCellIdx.size() * 3;
|
2019-09-06 03:40:57 -05:00
|
|
|
textureCoords->resize( numVertices );
|
2015-11-23 08:24:03 -06:00
|
|
|
cvf::Vec2f* rawPtr = textureCoords->ptr();
|
|
|
|
|
2016-08-12 07:48:13 -05:00
|
|
|
#pragma omp parallel for
|
2019-09-06 03:40:57 -05:00
|
|
|
for ( int i = 0; i < static_cast<int>( triangleToCellIdx.size() ); i++ )
|
2015-11-23 08:24:03 -06:00
|
|
|
{
|
|
|
|
size_t cellIdx = triangleToCellIdx[i];
|
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
cvf::Vec2d resultValue = resultAccessor->cellScalarGlobIdx( cellIdx );
|
|
|
|
cvf::Vec2f texCoord = texMapper->getTexCoord( resultValue.x(), resultValue.y(), cellIdx );
|
2015-11-23 08:24:03 -06:00
|
|
|
|
|
|
|
size_t j;
|
2019-09-06 03:40:57 -05:00
|
|
|
for ( j = 0; j < 3; j++ )
|
2015-11-23 08:24:03 -06:00
|
|
|
{
|
|
|
|
rawPtr[i * 3 + j] = texCoord;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|