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:
parent
0424202461
commit
9a3dace180
@ -2,13 +2,15 @@
|
|||||||
set (SOURCE_GROUP_HEADER_FILES
|
set (SOURCE_GROUP_HEADER_FILES
|
||||||
${CMAKE_CURRENT_LIST_DIR}/RicImportSurfacesFeature.h
|
${CMAKE_CURRENT_LIST_DIR}/RicImportSurfacesFeature.h
|
||||||
${CMAKE_CURRENT_LIST_DIR}/RicNewGridCaseSurfaceFeature.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
|
set (SOURCE_GROUP_SOURCE_FILES
|
||||||
${CMAKE_CURRENT_LIST_DIR}/RicImportSurfacesFeature.cpp
|
${CMAKE_CURRENT_LIST_DIR}/RicImportSurfacesFeature.cpp
|
||||||
${CMAKE_CURRENT_LIST_DIR}/RicNewGridCaseSurfaceFeature.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
|
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;
|
CAF_CMD_HEADER_INIT;
|
||||||
|
|
||||||
@ -36,10 +36,4 @@ protected:
|
|||||||
bool isCommandEnabled() override;
|
bool isCommandEnabled() override;
|
||||||
void onActionTriggered( bool isChecked ) override;
|
void onActionTriggered( bool isChecked ) override;
|
||||||
void setupActionLook( QAction* actionToSetup ) 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 "RiaApplication.h"
|
||||||
|
|
||||||
|
#include "RifSurfaceExporter.h"
|
||||||
#include "RigSurface.h"
|
#include "RigSurface.h"
|
||||||
#include "RimSurface.h"
|
#include "RimSurface.h"
|
||||||
#include "Riu3DMainWindowTools.h"
|
#include "Riu3DMainWindowTools.h"
|
||||||
@ -30,12 +31,12 @@
|
|||||||
#include <QAction>
|
#include <QAction>
|
||||||
#include <QFileDialog>
|
#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*>();
|
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();
|
RiaApplication* app = RiaApplication::instance();
|
||||||
|
|
||||||
@ -77,75 +78,18 @@ void RicExportSurfaceFeature::onActionTriggered( bool isChecked )
|
|||||||
|
|
||||||
RigSurface* surface = surf->surfaceData();
|
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->setIcon( QIcon( ":/ReservoirSurfaces16x16.png" ) );
|
||||||
actionToSetup->setText( "Export Surface" );
|
actionToSetup->setText( "Export Surface to GOCAD TSurf file" );
|
||||||
}
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
|
||||||
///
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -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;
|
||||||
|
};
|
@ -55,6 +55,8 @@ ${CMAKE_CURRENT_LIST_DIR}/RifRoffReader.h
|
|||||||
${CMAKE_CURRENT_LIST_DIR}/RifColorLegendData.h
|
${CMAKE_CURRENT_LIST_DIR}/RifColorLegendData.h
|
||||||
${CMAKE_CURRENT_LIST_DIR}/RifElasticPropertiesReader.h
|
${CMAKE_CURRENT_LIST_DIR}/RifElasticPropertiesReader.h
|
||||||
${CMAKE_CURRENT_LIST_DIR}/RifFractureModelPlotExporter.h
|
${CMAKE_CURRENT_LIST_DIR}/RifFractureModelPlotExporter.h
|
||||||
|
${CMAKE_CURRENT_LIST_DIR}/RifSurfaceExporter.h
|
||||||
|
|
||||||
|
|
||||||
# HDF5 file reader is directly included in ResInsight main CmakeList.txt
|
# HDF5 file reader is directly included in ResInsight main CmakeList.txt
|
||||||
#${CMAKE_CURRENT_LIST_DIR}/RifHdf5Reader.h
|
#${CMAKE_CURRENT_LIST_DIR}/RifHdf5Reader.h
|
||||||
@ -114,6 +116,7 @@ ${CMAKE_CURRENT_LIST_DIR}/RifRoffReader.cpp
|
|||||||
${CMAKE_CURRENT_LIST_DIR}/RifColorLegendData.cpp
|
${CMAKE_CURRENT_LIST_DIR}/RifColorLegendData.cpp
|
||||||
${CMAKE_CURRENT_LIST_DIR}/RifElasticPropertiesReader.cpp
|
${CMAKE_CURRENT_LIST_DIR}/RifElasticPropertiesReader.cpp
|
||||||
${CMAKE_CURRENT_LIST_DIR}/RifFractureModelPlotExporter.cpp
|
${CMAKE_CURRENT_LIST_DIR}/RifFractureModelPlotExporter.cpp
|
||||||
|
${CMAKE_CURRENT_LIST_DIR}/RifSurfaceExporter.cpp
|
||||||
|
|
||||||
# HDF5 file reader is directly included in ResInsight main CmakeList.txt
|
# HDF5 file reader is directly included in ResInsight main CmakeList.txt
|
||||||
#${CMAKE_CURRENT_LIST_DIR}/RifHdf5Reader.cpp
|
#${CMAKE_CURRENT_LIST_DIR}/RifHdf5Reader.cpp
|
||||||
|
128
ApplicationCode/FileInterface/RifSurfaceExporter.cpp
Normal file
128
ApplicationCode/FileInterface/RifSurfaceExporter.cpp
Normal file
@ -0,0 +1,128 @@
|
|||||||
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// 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 "RifSurfaceExporter.h"
|
||||||
|
|
||||||
|
#include <QFileDialog>
|
||||||
|
#include <QTextStream>
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
bool RifSurfaceExporter::writeGocadTSurfFile( 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 ) ) return false;
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
bool RifSurfaceExporter::writePetrellPtlFile( const QString& fileName,
|
||||||
|
const std::vector<cvf::Vec3d>& vertices,
|
||||||
|
const std::vector<std::pair<unsigned int, unsigned int>>& columnRowIndices )
|
||||||
|
{
|
||||||
|
if ( vertices.size() != columnRowIndices.size() ) return false;
|
||||||
|
|
||||||
|
QFile exportFile( fileName );
|
||||||
|
|
||||||
|
if ( !exportFile.open( QIODevice::WriteOnly | QIODevice::Text ) ) return false;
|
||||||
|
|
||||||
|
QTextStream out( &exportFile );
|
||||||
|
|
||||||
|
out << "#Type: scattered data \n";
|
||||||
|
out << "#Version: 6 \n";
|
||||||
|
out << "#Description: No description \n";
|
||||||
|
out << "#Format: free \n";
|
||||||
|
out << "#Field: 1 x \n";
|
||||||
|
out << "#Field: 2 y \n";
|
||||||
|
out << "#Field: 3 z meters \n";
|
||||||
|
out << "#Field: 4 column \n";
|
||||||
|
out << "#Field: 5 row \n";
|
||||||
|
out << "#Projection: Local Rectangular \n";
|
||||||
|
out << "#Units: meters \n";
|
||||||
|
out << "#End: \n";
|
||||||
|
out << "#Information from grid \n";
|
||||||
|
out << "#Grid_size: Not_avaiable \n";
|
||||||
|
out << "#Grid_space: Not_available \n";
|
||||||
|
out << "#Z_field: z \n";
|
||||||
|
out << "#Vertical_faults: Not_available \n";
|
||||||
|
out << "#History: No history \n";
|
||||||
|
out << "#Z_units: meters \n";
|
||||||
|
|
||||||
|
for ( int i = 0; i < vertices.size(); i++ )
|
||||||
|
{
|
||||||
|
out << vertices[i].x() << " ";
|
||||||
|
out << vertices[i].y() << " ";
|
||||||
|
out << vertices[i].z() << " "; // SIGN? depth or Z, Z needed on PTL?
|
||||||
|
|
||||||
|
out << columnRowIndices[i].first << " ";
|
||||||
|
out << columnRowIndices[i].second;
|
||||||
|
|
||||||
|
out << "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
40
ApplicationCode/FileInterface/RifSurfaceExporter.h
Normal file
40
ApplicationCode/FileInterface/RifSurfaceExporter.h
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// 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 "cvfVector3.h"
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
class QString;
|
||||||
|
|
||||||
|
//==================================================================================================
|
||||||
|
///
|
||||||
|
//==================================================================================================
|
||||||
|
class RifSurfaceExporter
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static bool writeGocadTSurfFile( const QString& fileName,
|
||||||
|
const QString& headerText,
|
||||||
|
const std::vector<cvf::Vec3d>& vertices,
|
||||||
|
const std::vector<unsigned>& triangleIndices );
|
||||||
|
|
||||||
|
static bool writePetrellPtlFile( const QString& fileName,
|
||||||
|
const std::vector<cvf::Vec3d>& vertices,
|
||||||
|
const std::vector<std::pair<unsigned int, unsigned int>>& columnRowIndices );
|
||||||
|
};
|
@ -81,6 +81,7 @@
|
|||||||
#include "RimGeoMechPropertyFilter.h"
|
#include "RimGeoMechPropertyFilter.h"
|
||||||
#include "RimGeoMechPropertyFilterCollection.h"
|
#include "RimGeoMechPropertyFilterCollection.h"
|
||||||
#include "RimGeoMechView.h"
|
#include "RimGeoMechView.h"
|
||||||
|
#include "RimGridCaseSurface.h"
|
||||||
#include "RimGridCollection.h"
|
#include "RimGridCollection.h"
|
||||||
#include "RimGridCrossPlot.h"
|
#include "RimGridCrossPlot.h"
|
||||||
#include "RimGridCrossPlotCollection.h"
|
#include "RimGridCrossPlotCollection.h"
|
||||||
@ -899,7 +900,13 @@ caf::CmdFeatureMenuBuilder RimContextCommandBuilder::commandsFromSelection()
|
|||||||
|
|
||||||
if ( dynamic_cast<RimSurface*>( firstUiItem ) )
|
if ( dynamic_cast<RimSurface*>( firstUiItem ) )
|
||||||
{
|
{
|
||||||
menuBuilder << "RicExportSurfaceFeature";
|
menuBuilder << "RicExportSurfaceToTsurfFeature";
|
||||||
|
// menuBuilder << "RicExportKLayerToPtlFeature";
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( dynamic_cast<RimGridCaseSurface*>( firstUiItem ) )
|
||||||
|
{
|
||||||
|
menuBuilder << "RicExportKLayerToPtlFeature";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if ( dynamic_cast<RimAnnotationCollection*>( firstUiItem ) ||
|
else if ( dynamic_cast<RimAnnotationCollection*>( firstUiItem ) ||
|
||||||
|
@ -201,8 +201,9 @@ void RimGridCaseSurface::extractDataFromGrid()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<unsigned> tringleIndices;
|
std::vector<unsigned> tringleIndices;
|
||||||
std::vector<cvf::Vec3d> vertices;
|
std::vector<cvf::Vec3d> vertices;
|
||||||
|
std::vector<std::pair<unsigned, unsigned>> structGridVertexIndices;
|
||||||
|
|
||||||
for ( size_t i = minI; i < maxI; i++ )
|
for ( size_t i = minI; i < maxI; i++ )
|
||||||
{
|
{
|
||||||
@ -210,6 +211,21 @@ void RimGridCaseSurface::extractDataFromGrid()
|
|||||||
{
|
{
|
||||||
for ( size_t k = minK; k < maxK; k++ )
|
for ( size_t k = minK; k < maxK; k++ )
|
||||||
{
|
{
|
||||||
|
std::pair<unsigned, unsigned> quadIJIndices;
|
||||||
|
|
||||||
|
switch ( faceType )
|
||||||
|
{
|
||||||
|
case cvf::StructGridInterface::NEG_I:
|
||||||
|
quadIJIndices = std::make_pair( j, k );
|
||||||
|
break;
|
||||||
|
case cvf::StructGridInterface::NEG_J:
|
||||||
|
quadIJIndices = std::make_pair( i, k );
|
||||||
|
break;
|
||||||
|
case cvf::StructGridInterface::NEG_K:
|
||||||
|
quadIJIndices = std::make_pair( i, j );
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
size_t cellIndex = grid->cellIndexFromIJK( i, j, k );
|
size_t cellIndex = grid->cellIndexFromIJK( i, j, k );
|
||||||
|
|
||||||
if ( grid->cell( cellIndex ).isInvalid() ) continue;
|
if ( grid->cell( cellIndex ).isInvalid() ) continue;
|
||||||
@ -224,6 +240,12 @@ void RimGridCaseSurface::extractDataFromGrid()
|
|||||||
|
|
||||||
for ( int n = 0; n < 4; n++ )
|
for ( int n = 0; n < 4; n++ )
|
||||||
{
|
{
|
||||||
|
auto localIndexPair = getStructGridIndex( faceType, faceConn[n] );
|
||||||
|
|
||||||
|
structGridVertexIndices.push_back(
|
||||||
|
std::make_pair( quadIJIndices.first + localIndexPair.first,
|
||||||
|
quadIJIndices.second + localIndexPair.second ) );
|
||||||
|
|
||||||
vertices.push_back( cornerVerts[faceConn[n]] );
|
vertices.push_back( cornerVerts[faceConn[n]] );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -238,8 +260,9 @@ void RimGridCaseSurface::extractDataFromGrid()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
m_vertices = vertices;
|
m_vertices = vertices;
|
||||||
m_tringleIndices = tringleIndices;
|
m_tringleIndices = tringleIndices;
|
||||||
|
m_structGridIndices = structGridVertexIndices;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -251,6 +274,36 @@ void RimGridCaseSurface::clearNativeGridData()
|
|||||||
{
|
{
|
||||||
m_vertices.clear();
|
m_vertices.clear();
|
||||||
m_tringleIndices.clear();
|
m_tringleIndices.clear();
|
||||||
|
m_structGridIndices.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
/// Return local column and row number for structured grid based on a given cell face.
|
||||||
|
/// Argument faceType may be superfluous depending on winding and particular NEG_I face may
|
||||||
|
/// need particular handling, see StructGridInterface::cellFaceVertexIndices().
|
||||||
|
//
|
||||||
|
// 7---------6
|
||||||
|
// /| /| |k
|
||||||
|
// / | / | | /j
|
||||||
|
// 4---------5 | |/
|
||||||
|
// | 3------|--2 *---i
|
||||||
|
// | / | /
|
||||||
|
// |/ |/
|
||||||
|
// 0---------1
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
std::pair<cvf::uint, cvf::uint> RimGridCaseSurface::getStructGridIndex( cvf::StructGridInterface::FaceType faceType,
|
||||||
|
cvf::ubyte localVertexIndex )
|
||||||
|
{
|
||||||
|
std::pair<unsigned, unsigned> localIndexPair;
|
||||||
|
|
||||||
|
CVF_TIGHT_ASSERT( localVertexIndex <= 3 );
|
||||||
|
|
||||||
|
if ( localVertexIndex == 0 ) localIndexPair = std::make_pair( 0, 0 );
|
||||||
|
if ( localVertexIndex == 1 ) localIndexPair = std::make_pair( 1, 0 );
|
||||||
|
if ( localVertexIndex == 2 ) localIndexPair = std::make_pair( 1, 1 );
|
||||||
|
if ( localVertexIndex == 3 ) localIndexPair = std::make_pair( 0, 1 );
|
||||||
|
|
||||||
|
return localIndexPair;
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
@ -294,7 +347,7 @@ void RimGridCaseSurface::updateUserDescription()
|
|||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
bool RimGridCaseSurface::updateSurfaceDataFromGridCase()
|
bool RimGridCaseSurface::updateSurfaceDataFromGridCase()
|
||||||
{
|
{
|
||||||
if ( m_vertices.empty() || m_tringleIndices.empty() )
|
if ( m_vertices.empty() || m_tringleIndices.empty() || m_structGridIndices.empty() )
|
||||||
{
|
{
|
||||||
extractDataFromGrid();
|
extractDataFromGrid();
|
||||||
}
|
}
|
||||||
@ -341,3 +394,49 @@ bool RimGridCaseSurface::updateSurfaceDataFromGridCase()
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
bool RimGridCaseSurface::exportStructSurfaceFromGridCase( std::vector<cvf::Vec3d>* vertices,
|
||||||
|
std::vector<std::pair<uint, uint>>* structGridVertexIndices )
|
||||||
|
{
|
||||||
|
if ( m_vertices.empty() || m_tringleIndices.empty() || m_structGridIndices.empty() )
|
||||||
|
{
|
||||||
|
extractDataFromGrid();
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( m_vertices.empty() ) return false;
|
||||||
|
|
||||||
|
*vertices = m_vertices;
|
||||||
|
*structGridVertexIndices = m_structGridIndices;
|
||||||
|
|
||||||
|
if ( !vertices->empty() )
|
||||||
|
{
|
||||||
|
// Permute z-value to avoid numerical issues when surface intersects exactly at cell face
|
||||||
|
|
||||||
|
double delta = 1.0e-5;
|
||||||
|
|
||||||
|
cvf::Vec3d offset = cvf::Vec3d::ZERO;
|
||||||
|
|
||||||
|
if ( m_sliceDirection == RiaDefines::GridCaseAxis::AXIS_I )
|
||||||
|
{
|
||||||
|
offset.x() += delta;
|
||||||
|
}
|
||||||
|
else if ( m_sliceDirection == RiaDefines::GridCaseAxis::AXIS_J )
|
||||||
|
{
|
||||||
|
offset.y() += delta;
|
||||||
|
}
|
||||||
|
else if ( m_sliceDirection == RiaDefines::GridCaseAxis::AXIS_K )
|
||||||
|
{
|
||||||
|
offset.z() += delta;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Include the potential depth offset in the base class
|
||||||
|
offset.z() += depthOffset();
|
||||||
|
|
||||||
|
RimSurface::applyDepthOffset( offset, vertices );
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
@ -24,6 +24,8 @@
|
|||||||
|
|
||||||
#include "cafPdmPtrField.h"
|
#include "cafPdmPtrField.h"
|
||||||
|
|
||||||
|
#include "cvfStructGrid.h"
|
||||||
|
|
||||||
class RimCase;
|
class RimCase;
|
||||||
|
|
||||||
class RimGridCaseSurface : public RimSurface
|
class RimGridCaseSurface : public RimSurface
|
||||||
@ -40,6 +42,9 @@ public:
|
|||||||
bool onLoadData() override;
|
bool onLoadData() override;
|
||||||
void updateUserDescription();
|
void updateUserDescription();
|
||||||
|
|
||||||
|
bool exportStructSurfaceFromGridCase( std::vector<cvf::Vec3d>* vertices,
|
||||||
|
std::vector<std::pair<uint, uint>>* structGridVertexIndices );
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
QList<caf::PdmOptionItemInfo> calculateValueOptions( const caf::PdmFieldHandle* fieldNeedingOptions,
|
QList<caf::PdmOptionItemInfo> calculateValueOptions( const caf::PdmFieldHandle* fieldNeedingOptions,
|
||||||
bool* useOptionsOnly ) override;
|
bool* useOptionsOnly ) override;
|
||||||
@ -50,16 +55,20 @@ protected:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
bool updateSurfaceDataFromGridCase();
|
bool updateSurfaceDataFromGridCase();
|
||||||
|
|
||||||
void fieldChangedByUi( const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue ) override;
|
void fieldChangedByUi( const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue ) override;
|
||||||
|
|
||||||
void extractDataFromGrid();
|
void extractDataFromGrid();
|
||||||
void clearNativeGridData();
|
void clearNativeGridData();
|
||||||
|
|
||||||
|
std::pair<uint, uint> getStructGridIndex( cvf::StructGridInterface::FaceType cellface, cvf::ubyte localVertexIndex );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
caf::PdmPtrField<RimCase*> m_case;
|
caf::PdmPtrField<RimCase*> m_case;
|
||||||
caf::PdmField<caf::AppEnum<RiaDefines::GridCaseAxis>> m_sliceDirection;
|
caf::PdmField<caf::AppEnum<RiaDefines::GridCaseAxis>> m_sliceDirection;
|
||||||
caf::PdmField<int> m_oneBasedSliceIndex;
|
caf::PdmField<int> m_oneBasedSliceIndex;
|
||||||
|
|
||||||
std::vector<unsigned> m_tringleIndices;
|
std::vector<unsigned> m_tringleIndices;
|
||||||
std::vector<cvf::Vec3d> m_vertices;
|
std::vector<cvf::Vec3d> m_vertices;
|
||||||
|
std::vector<std::pair<unsigned, unsigned>> m_structGridIndices;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user