mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
WIP: Surface : Add export of surface to PTL file format #5957
- restructured according to issue - but issue indicate export of K-layer only despite RimGridCaseSurface did support I/ slices, too? - if so, test and possibly extend RimGridCaseSurface methods extractDataFromGrid() and getStructGridIndex() - need to check whether all offsets are taken care of
This commit is contained in:
committed by
Magne Sjaastad
parent
0424202461
commit
9a3dace180
@@ -2,13 +2,15 @@
|
||||
set (SOURCE_GROUP_HEADER_FILES
|
||||
${CMAKE_CURRENT_LIST_DIR}/RicImportSurfacesFeature.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RicNewGridCaseSurfaceFeature.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RicExportSurfaceFeature.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RicExportKLayerToPtlFeature.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RicExportSurfaceToTsurfFeature.h
|
||||
)
|
||||
|
||||
set (SOURCE_GROUP_SOURCE_FILES
|
||||
${CMAKE_CURRENT_LIST_DIR}/RicImportSurfacesFeature.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RicNewGridCaseSurfaceFeature.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RicExportSurfaceFeature.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RicExportKLayerToPtlFeature.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RicExportSurfaceToTsurfFeature.cpp
|
||||
)
|
||||
|
||||
list(APPEND CODE_HEADER_FILES
|
||||
|
||||
@@ -0,0 +1,99 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// 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 "RicExportKLayerToPtlFeature.h"
|
||||
|
||||
#include "RiaApplication.h"
|
||||
|
||||
#include "RifSurfaceExporter.h"
|
||||
#include "RigSurface.h"
|
||||
#include "RimGridCaseSurface.h"
|
||||
#include "Riu3DMainWindowTools.h"
|
||||
|
||||
#include "cafSelectionManagerTools.h"
|
||||
#include "cafUtils.h"
|
||||
|
||||
#include <QAction>
|
||||
#include <QFileDialog>
|
||||
|
||||
CAF_CMD_SOURCE_INIT( RicExportKLayerToPtlFeature, "RicExportKLayerToPtlFeature" );
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RicExportKLayerToPtlFeature::isCommandEnabled()
|
||||
{
|
||||
// std::vector<RimGridCaseSurface*> surfaces = caf::selectedObjectsByTypeStrict<RimGridCaseSurface*>();
|
||||
|
||||
std::vector<RimSurface*> surfaces = caf::selectedObjectsByTypeStrict<RimSurface*>();
|
||||
|
||||
return !surfaces.empty();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RicExportKLayerToPtlFeature::onActionTriggered( bool isChecked )
|
||||
{
|
||||
RiaApplication* app = RiaApplication::instance();
|
||||
|
||||
QString defaultDir = app->lastUsedDialogDirectoryWithFallbackToProjectFolder( "EXPORT_SURFACE" );
|
||||
|
||||
QStringList imageFileExtensions;
|
||||
imageFileExtensions << "*.ptl";
|
||||
QString fileExtensionFilter = QString( "Surface (%1)" ).arg( imageFileExtensions.join( " " ) );
|
||||
|
||||
QString defaultExtension = "ptl";
|
||||
QString defaultFileBaseName = "surface";
|
||||
|
||||
QString defaultAbsFileName =
|
||||
caf::Utils::constructFullFileName( defaultDir, defaultFileBaseName, "." + defaultExtension );
|
||||
|
||||
QString selectedExtension;
|
||||
|
||||
std::vector<RimGridCaseSurface*> surfaces = caf::selectedObjectsByTypeStrict<RimGridCaseSurface*>();
|
||||
|
||||
for ( RimGridCaseSurface* surf : surfaces )
|
||||
{
|
||||
QString fileName = QFileDialog::getSaveFileName( nullptr,
|
||||
tr( "Export to File" ),
|
||||
defaultAbsFileName,
|
||||
fileExtensionFilter,
|
||||
&selectedExtension );
|
||||
if ( fileName.isEmpty() ) return;
|
||||
|
||||
app->setLastUsedDialogDirectory( "EXPORT_SURFACE", QFileInfo( fileName ).absolutePath() );
|
||||
|
||||
std::vector<cvf::Vec3d> vertices;
|
||||
std::vector<std::pair<uint, uint>> structGridVertexIndices;
|
||||
|
||||
if ( surf->exportStructSurfaceFromGridCase( &vertices, &structGridVertexIndices ) )
|
||||
{
|
||||
RifSurfaceExporter::writePetrellPtlFile( fileName, vertices, structGridVertexIndices );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RicExportKLayerToPtlFeature::setupActionLook( QAction* actionToSetup )
|
||||
{
|
||||
actionToSetup->setIcon( QIcon( ":/ReservoirSurfaces16x16.png" ) );
|
||||
actionToSetup->setText( "Export Grid Case Surface to Petrell ptl-file" );
|
||||
}
|
||||
@@ -27,7 +27,7 @@
|
||||
//==================================================================================================
|
||||
///
|
||||
//==================================================================================================
|
||||
class RicExportSurfaceFeature : public caf::CmdFeature
|
||||
class RicExportKLayerToPtlFeature : public caf::CmdFeature
|
||||
{
|
||||
CAF_CMD_HEADER_INIT;
|
||||
|
||||
@@ -36,10 +36,4 @@ protected:
|
||||
bool isCommandEnabled() override;
|
||||
void onActionTriggered( bool isChecked ) override;
|
||||
void setupActionLook( QAction* actionToSetup ) override;
|
||||
|
||||
private:
|
||||
static bool writePolygonsToFile( const QString& fileName,
|
||||
const QString& headerText,
|
||||
const std::vector<cvf::Vec3d>& vertices,
|
||||
const std::vector<unsigned>& triangleIndices );
|
||||
};
|
||||
@@ -16,10 +16,11 @@
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "RicExportSurfaceFeature.h"
|
||||
#include "RicExportSurfaceToTsurfFeature.h"
|
||||
|
||||
#include "RiaApplication.h"
|
||||
|
||||
#include "RifSurfaceExporter.h"
|
||||
#include "RigSurface.h"
|
||||
#include "RimSurface.h"
|
||||
#include "Riu3DMainWindowTools.h"
|
||||
@@ -30,12 +31,12 @@
|
||||
#include <QAction>
|
||||
#include <QFileDialog>
|
||||
|
||||
CAF_CMD_SOURCE_INIT( RicExportSurfaceFeature, "RicExportSurfaceFeature" );
|
||||
CAF_CMD_SOURCE_INIT( RicExportSurfaceToTsurfFeature, "RicExportSurfaceToTsurfFeature" );
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RicExportSurfaceFeature::isCommandEnabled()
|
||||
bool RicExportSurfaceToTsurfFeature::isCommandEnabled()
|
||||
{
|
||||
std::vector<RimSurface*> surfaces = caf::selectedObjectsByTypeStrict<RimSurface*>();
|
||||
|
||||
@@ -45,7 +46,7 @@ bool RicExportSurfaceFeature::isCommandEnabled()
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RicExportSurfaceFeature::onActionTriggered( bool isChecked )
|
||||
void RicExportSurfaceToTsurfFeature::onActionTriggered( bool isChecked )
|
||||
{
|
||||
RiaApplication* app = RiaApplication::instance();
|
||||
|
||||
@@ -77,75 +78,18 @@ void RicExportSurfaceFeature::onActionTriggered( bool isChecked )
|
||||
|
||||
RigSurface* surface = surf->surfaceData();
|
||||
|
||||
writePolygonsToFile( fileName, surf->userDescription(), surface->vertices(), surface->triangleIndices() );
|
||||
RifSurfaceExporter::writeGocadTSurfFile( fileName,
|
||||
surf->userDescription(),
|
||||
surface->vertices(),
|
||||
surface->triangleIndices() );
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RicExportSurfaceFeature::setupActionLook( QAction* actionToSetup )
|
||||
void RicExportSurfaceToTsurfFeature::setupActionLook( QAction* actionToSetup )
|
||||
{
|
||||
actionToSetup->setIcon( QIcon( ":/ReservoirSurfaces16x16.png" ) );
|
||||
actionToSetup->setText( "Export Surface" );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RicExportSurfaceFeature::writePolygonsToFile( const QString& fileName,
|
||||
const QString& headerText,
|
||||
const std::vector<cvf::Vec3d>& vertices,
|
||||
const std::vector<unsigned>& triangleIndices )
|
||||
{
|
||||
QFile exportFile( fileName );
|
||||
if ( exportFile.open( QIODevice::WriteOnly | QIODevice::Text ) )
|
||||
{
|
||||
QTextStream out( &exportFile );
|
||||
|
||||
QString headerForExport = headerText;
|
||||
if ( headerText.isEmpty() ) headerForExport = "surface";
|
||||
|
||||
out << "GOCAD TSurf 1 \n";
|
||||
out << "HEADER { \n";
|
||||
out << "name:" + headerText + " \n";
|
||||
out << "} \n";
|
||||
out << "GOCAD_ORIGINAL_COORDINATE_SYSTEM \n";
|
||||
out << "NAME Default \n";
|
||||
out << "AXIS_NAME \"X\" \"Y\" \"Z\" \n";
|
||||
out << "AXIS_UNIT \"m\" \"m\" \"m\" \n";
|
||||
out << "ZPOSITIVE Depth \n";
|
||||
out << "END_ORIGINAL_COORDINATE_SYSTEM \n";
|
||||
|
||||
out << "TFACE \n";
|
||||
|
||||
size_t i = 1;
|
||||
for ( auto v : vertices )
|
||||
{
|
||||
out << "VRTX " << i << " ";
|
||||
out << v.x() << " ";
|
||||
out << v.y() << " ";
|
||||
out << -v.z() << " ";
|
||||
out << "CNXYZ\n";
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
for ( size_t triIndex = 0; triIndex < triangleIndices.size(); triIndex += 3 )
|
||||
{
|
||||
out << "TRGL ";
|
||||
out << " " << 1 + triangleIndices[triIndex + 0];
|
||||
out << " " << 1 + triangleIndices[triIndex + 1];
|
||||
out << " " << 1 + triangleIndices[triIndex + 2];
|
||||
out << " \n";
|
||||
}
|
||||
|
||||
out << "END\n";
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
actionToSetup->setText( "Export Surface to GOCAD TSurf file" );
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// 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
|
||||
|
||||
#include "cafCmdFeature.h"
|
||||
|
||||
#include "cvfVector3.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
//==================================================================================================
|
||||
///
|
||||
//==================================================================================================
|
||||
class RicExportSurfaceToTsurfFeature : public caf::CmdFeature
|
||||
{
|
||||
CAF_CMD_HEADER_INIT;
|
||||
|
||||
protected:
|
||||
// Overrides
|
||||
bool isCommandEnabled() override;
|
||||
void onActionTriggered( bool isChecked ) override;
|
||||
void setupActionLook( QAction* actionToSetup ) override;
|
||||
};
|
||||
Reference in New Issue
Block a user