mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
#6495 Fracture Model: add facies properties.
This commit is contained in:
@@ -64,6 +64,7 @@ ${CMAKE_CURRENT_LIST_DIR}/RicReloadWellMeasurementsFeature.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RicWellMeasurementImportTools.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RicImportElasticPropertiesFeature.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RicElasticPropertiesImportTools.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RicFaciesPropertiesImportTools.h
|
||||
|
||||
${CMAKE_CURRENT_LIST_DIR}/RicCloseSourSimDataFeature.h
|
||||
|
||||
@@ -159,6 +160,7 @@ ${CMAKE_CURRENT_LIST_DIR}/RicReloadWellMeasurementsFeature.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RicWellMeasurementImportTools.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RicImportElasticPropertiesFeature.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RicElasticPropertiesImportTools.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RicFaciesPropertiesImportTools.cpp
|
||||
|
||||
${CMAKE_CURRENT_LIST_DIR}/RicCloseSourSimDataFeature.cpp
|
||||
|
||||
|
||||
179
ApplicationCode/Commands/RicFaciesPropertiesImportTools.cpp
Normal file
179
ApplicationCode/Commands/RicFaciesPropertiesImportTools.cpp
Normal file
@@ -0,0 +1,179 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// 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 "RicFaciesPropertiesImportTools.h"
|
||||
|
||||
#include "RiaApplication.h"
|
||||
#include "RiaColorTables.h"
|
||||
#include "RiaFractureDefines.h"
|
||||
#include "RiaLogging.h"
|
||||
#include "RiaStdStringTools.h"
|
||||
|
||||
#include "RimColorLegend.h"
|
||||
#include "RimColorLegendCollection.h"
|
||||
#include "RimColorLegendItem.h"
|
||||
#include "RimFaciesProperties.h"
|
||||
#include "RimFractureModel.h"
|
||||
#include "RimProject.h"
|
||||
|
||||
#include "RifColorLegendData.h"
|
||||
#include "RifRoffReader.h"
|
||||
|
||||
#include "cafColorTable.h"
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RicFaciesPropertiesImportTools::importFaciesPropertiesFromFile( const QString& filePath,
|
||||
RimFractureModel* fractureModel,
|
||||
bool createColorLegend )
|
||||
{
|
||||
if ( filePath.isEmpty() ) return;
|
||||
|
||||
std::map<int, QString> codeNames;
|
||||
try
|
||||
{
|
||||
RifRoffReader::readCodeNames( filePath, codeNames );
|
||||
}
|
||||
catch ( RifRoffReaderException& ex )
|
||||
{
|
||||
RiaLogging::error( QString::fromStdString( ex.message ) );
|
||||
return;
|
||||
}
|
||||
|
||||
RimFaciesProperties* faciesProperties = fractureModel->faciesProperties();
|
||||
if ( !faciesProperties )
|
||||
{
|
||||
faciesProperties = new RimFaciesProperties;
|
||||
}
|
||||
|
||||
for ( auto it : codeNames )
|
||||
{
|
||||
faciesProperties->setFaciesCodeName( it.first, it.second );
|
||||
}
|
||||
|
||||
if ( createColorLegend )
|
||||
{
|
||||
const caf::ColorTable& colorTable = RiaColorTables::contrastCategoryPaletteColors();
|
||||
RimColorLegendCollection* colorLegendCollection = RimProject::current()->colorLegendCollection;
|
||||
RimColorLegend* rockTypeColorLegend = colorLegendCollection->findByName( RiaDefines::rockTypeColorLegendName() );
|
||||
|
||||
RimColorLegend* colorLegend = new RimColorLegend;
|
||||
colorLegend->setColorLegendName( RiaDefines::faciesColorLegendName() );
|
||||
|
||||
for ( auto it : codeNames )
|
||||
{
|
||||
RimColorLegendItem* colorLegendItem = new RimColorLegendItem;
|
||||
|
||||
// Try to find a color from the rock type color legend by fuzzy matching names
|
||||
cvf::Color3f color;
|
||||
if ( !predefinedColorMatch( it.second, rockTypeColorLegend, color ) &&
|
||||
!matchByName( it.second, rockTypeColorLegend, color ) )
|
||||
{
|
||||
// No match use a random color
|
||||
color = colorTable.cycledColor3f( it.first );
|
||||
}
|
||||
|
||||
colorLegendItem->setValues( it.second, it.first, color );
|
||||
colorLegend->appendColorLegendItem( colorLegendItem );
|
||||
}
|
||||
|
||||
colorLegendCollection->appendCustomColorLegend( colorLegend );
|
||||
colorLegendCollection->updateConnectedEditors();
|
||||
}
|
||||
|
||||
faciesProperties->setFilePath( filePath );
|
||||
|
||||
fractureModel->setFaciesProperties( faciesProperties );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RicFaciesPropertiesImportTools::matchByName( const QString& name, RimColorLegend* colorLegend, cvf::Color3f& color )
|
||||
{
|
||||
// No match if color legend does not exist
|
||||
if ( !colorLegend ) return false;
|
||||
|
||||
// Find the best matching name from the legend
|
||||
int bestScore = std::numeric_limits<int>::max();
|
||||
RimColorLegendItem* bestItem = nullptr;
|
||||
for ( RimColorLegendItem* item : colorLegend->colorLegendItems() )
|
||||
{
|
||||
int score = computeEditDistance( name, item->categoryName() );
|
||||
if ( score < bestScore )
|
||||
{
|
||||
bestScore = score;
|
||||
bestItem = item;
|
||||
}
|
||||
}
|
||||
|
||||
// Allow only small difference when determining if something matches
|
||||
const int maximumScoreToMatch = 1;
|
||||
if ( bestScore <= maximumScoreToMatch )
|
||||
{
|
||||
color = bestItem->color();
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
int RicFaciesPropertiesImportTools::computeEditDistance( const QString& a, const QString& b )
|
||||
{
|
||||
// Remove common words from the domain which does not help in the matching
|
||||
std::vector<QString> stopWords = {"rocks", "rock", "stones", "stone"};
|
||||
QString aSimplified = a.toLower();
|
||||
QString bSimplified = b.toLower();
|
||||
for ( auto r : stopWords )
|
||||
{
|
||||
aSimplified.remove( r );
|
||||
bSimplified.remove( r );
|
||||
}
|
||||
|
||||
aSimplified = aSimplified.trimmed();
|
||||
bSimplified = bSimplified.trimmed();
|
||||
|
||||
return RiaStdStringTools::computeEditDistance( aSimplified.toStdString(), bSimplified.toStdString() );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RicFaciesPropertiesImportTools::predefinedColorMatch( const QString& name,
|
||||
RimColorLegend* colorLegend,
|
||||
cvf::Color3f& color )
|
||||
{
|
||||
// Calcite should use limestone color
|
||||
if ( name.toLower().trimmed() == QString( "calcite" ) )
|
||||
{
|
||||
for ( auto i : colorLegend->colorLegendItems() )
|
||||
{
|
||||
if ( i->categoryName() == QString( "Limestone" ) )
|
||||
{
|
||||
color = i->color();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
45
ApplicationCode/Commands/RicFaciesPropertiesImportTools.h
Normal file
45
ApplicationCode/Commands/RicFaciesPropertiesImportTools.h
Normal file
@@ -0,0 +1,45 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#pragma once
|
||||
|
||||
class RimColorLegend;
|
||||
class RimFractureModel;
|
||||
|
||||
namespace cvf
|
||||
{
|
||||
class Color3f;
|
||||
}
|
||||
|
||||
class QString;
|
||||
|
||||
//==================================================================================================
|
||||
///
|
||||
//==================================================================================================
|
||||
class RicFaciesPropertiesImportTools
|
||||
{
|
||||
public:
|
||||
static void importFaciesPropertiesFromFile( const QString& filePath,
|
||||
RimFractureModel* fractureModel,
|
||||
bool createColorLegend = false );
|
||||
|
||||
private:
|
||||
static int computeEditDistance( const QString& a, const QString& b );
|
||||
static bool matchByName( const QString& name, RimColorLegend* colorLegend, cvf::Color3f& color );
|
||||
static bool predefinedColorMatch( const QString& name, RimColorLegend* colorLegend, cvf::Color3f& color );
|
||||
};
|
||||
@@ -19,23 +19,15 @@
|
||||
#include "RicImportFaciesFeature.h"
|
||||
|
||||
#include "RiaApplication.h"
|
||||
#include "RiaColorTables.h"
|
||||
#include "RiaFractureDefines.h"
|
||||
#include "RiaLogging.h"
|
||||
#include "RiaStdStringTools.h"
|
||||
|
||||
#include "RimColorLegend.h"
|
||||
#include "RimColorLegendCollection.h"
|
||||
#include "RimColorLegendItem.h"
|
||||
#include "RimProject.h"
|
||||
|
||||
#include "RifColorLegendData.h"
|
||||
#include "RifRoffReader.h"
|
||||
|
||||
#include "Riu3DMainWindowTools.h"
|
||||
#include "RiuFileDialogTools.h"
|
||||
|
||||
#include "cafColorTable.h"
|
||||
#include "RicFaciesPropertiesImportTools.h"
|
||||
|
||||
#include "RimFractureModel.h"
|
||||
|
||||
#include "cafSelectionManager.h"
|
||||
|
||||
#include <QAction>
|
||||
#include <QFileInfo>
|
||||
@@ -55,6 +47,9 @@ bool RicImportFaciesFeature::isCommandEnabled()
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RicImportFaciesFeature::onActionTriggered( bool isChecked )
|
||||
{
|
||||
RimFractureModel* fractureModel = caf::SelectionManager::instance()->selectedItemAncestorOfType<RimFractureModel>();
|
||||
if ( !fractureModel ) return;
|
||||
|
||||
RiaApplication* app = RiaApplication::instance();
|
||||
QString defaultDir = app->lastUsedDialogDirectoryWithFallbackToProjectFolder( "STIMPLAN_DIR" );
|
||||
|
||||
@@ -70,43 +65,8 @@ void RicImportFaciesFeature::onActionTriggered( bool isChecked )
|
||||
// Remember the path to next time
|
||||
app->setLastUsedDialogDirectory( "STIMPLAN_DIR", QFileInfo( fileName ).absolutePath() );
|
||||
|
||||
std::map<int, QString> codeNames;
|
||||
try
|
||||
{
|
||||
RifRoffReader::readCodeNames( fileName, codeNames );
|
||||
}
|
||||
catch ( RifRoffReaderException& ex )
|
||||
{
|
||||
RiaLogging::error( QString::fromStdString( ex.message ) );
|
||||
return;
|
||||
}
|
||||
|
||||
const caf::ColorTable& colorTable = RiaColorTables::contrastCategoryPaletteColors();
|
||||
RimColorLegendCollection* colorLegendCollection = RimProject::current()->colorLegendCollection;
|
||||
RimColorLegend* rockTypeColorLegend = colorLegendCollection->findByName( RiaDefines::rockTypeColorLegendName() );
|
||||
|
||||
RimColorLegend* colorLegend = new RimColorLegend;
|
||||
colorLegend->setColorLegendName( RiaDefines::faciesColorLegendName() );
|
||||
|
||||
for ( auto it : codeNames )
|
||||
{
|
||||
RimColorLegendItem* colorLegendItem = new RimColorLegendItem;
|
||||
|
||||
// Try to find a color from the rock type color legend by fuzzy matching names
|
||||
cvf::Color3f color;
|
||||
if ( !predefinedColorMatch( it.second, rockTypeColorLegend, color ) &&
|
||||
!matchByName( it.second, rockTypeColorLegend, color ) )
|
||||
{
|
||||
// No match use a random color
|
||||
color = colorTable.cycledColor3f( it.first );
|
||||
}
|
||||
|
||||
colorLegendItem->setValues( it.second, it.first, color );
|
||||
colorLegend->appendColorLegendItem( colorLegendItem );
|
||||
}
|
||||
|
||||
colorLegendCollection->appendCustomColorLegend( colorLegend );
|
||||
colorLegendCollection->updateConnectedEditors();
|
||||
bool createColorLegend = true;
|
||||
RicFaciesPropertiesImportTools::importFaciesPropertiesFromFile( fileName, fractureModel, createColorLegend );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -118,77 +78,3 @@ void RicImportFaciesFeature::setupActionLook( QAction* actionToSetup )
|
||||
// actionToSetup->setIcon( QIcon( ":/Formations16x16.png" ) );
|
||||
actionToSetup->setText( "Import Facies" );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RicImportFaciesFeature::matchByName( const QString& name, RimColorLegend* colorLegend, cvf::Color3f& color )
|
||||
{
|
||||
// No match if color legend does not exist
|
||||
if ( !colorLegend ) return false;
|
||||
|
||||
// Find the best matching name from the legend
|
||||
int bestScore = std::numeric_limits<int>::max();
|
||||
RimColorLegendItem* bestItem = nullptr;
|
||||
for ( RimColorLegendItem* item : colorLegend->colorLegendItems() )
|
||||
{
|
||||
int score = computeEditDistance( name, item->categoryName() );
|
||||
if ( score < bestScore )
|
||||
{
|
||||
bestScore = score;
|
||||
bestItem = item;
|
||||
}
|
||||
}
|
||||
|
||||
// Allow only small difference when determining if something matches
|
||||
const int maximumScoreToMatch = 1;
|
||||
if ( bestScore <= maximumScoreToMatch )
|
||||
{
|
||||
color = bestItem->color();
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
int RicImportFaciesFeature::computeEditDistance( const QString& a, const QString& b )
|
||||
{
|
||||
// Remove common words from the domain which does not help in the matching
|
||||
std::vector<QString> stopWords = {"rocks", "rock", "stones", "stone"};
|
||||
QString aSimplified = a.toLower();
|
||||
QString bSimplified = b.toLower();
|
||||
for ( auto r : stopWords )
|
||||
{
|
||||
aSimplified.remove( r );
|
||||
bSimplified.remove( r );
|
||||
}
|
||||
|
||||
aSimplified = aSimplified.trimmed();
|
||||
bSimplified = bSimplified.trimmed();
|
||||
|
||||
return RiaStdStringTools::computeEditDistance( aSimplified.toStdString(), bSimplified.toStdString() );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RicImportFaciesFeature::predefinedColorMatch( const QString& name, RimColorLegend* colorLegend, cvf::Color3f& color )
|
||||
{
|
||||
// Calcite should use limestone color
|
||||
if ( name.toLower().trimmed() == QString( "calcite" ) )
|
||||
{
|
||||
for ( auto i : colorLegend->colorLegendItems() )
|
||||
{
|
||||
if ( i->categoryName() == QString( "Limestone" ) )
|
||||
{
|
||||
color = i->color();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user