diff --git a/ApplicationLibCode/FileInterface/RifVtkSurfaceImporter.cpp b/ApplicationLibCode/FileInterface/RifVtkSurfaceImporter.cpp index 6431828674..d44d5a986c 100644 --- a/ApplicationLibCode/FileInterface/RifVtkSurfaceImporter.cpp +++ b/ApplicationLibCode/FileInterface/RifVtkSurfaceImporter.cpp @@ -39,25 +39,25 @@ bool importFromFile( std::string filename, RigGocadData* gocadData ) return false; } - return importFromXMLDoc( doc, gocadData ); + return importFromXmlDoc( doc, gocadData ); } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -bool importFromPVDFile( const std::string& filename, RigGocadData* gocadData ) +bool importFromPvdFile( const std::string& filename, RigGocadData* gocadData ) { - auto datasets = parsePVDDatasets( filename ); + auto datasets = parsePvdDatasets( filename ); if ( datasets.empty() ) return false; // Sort and import the most recent dataset - std::sort( datasets.begin(), datasets.end(), []( const PVDDataset& a, const PVDDataset& b ) { return a.timestep < b.timestep; } ); + std::sort( datasets.begin(), datasets.end(), []( const PvdDataset& a, const PvdDataset& b ) { return a.timestep < b.timestep; } ); return importDataset( datasets.back(), gocadData ); } -bool importFromXMLDoc( const TiXmlDocument& doc, RigGocadData* gocadData ) +bool importFromXmlDoc( const TiXmlDocument& doc, RigGocadData* gocadData ) { auto* root = doc.FirstChildElement( "VTKFile" ); if ( !root ) return false; @@ -211,9 +211,9 @@ void readProperties( const TiXmlElement* piece, std::vector& proper //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -std::vector parsePVDDatasets( const std::string& filename ) +std::vector parsePvdDatasets( const std::string& filename ) { - std::vector datasets; + std::vector datasets; TiXmlDocument doc; if ( !doc.LoadFile( filename.c_str() ) ) return datasets; @@ -249,7 +249,7 @@ std::vector parsePVDDatasets( const std::stri //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -bool importDataset( const PVDDataset& dataset, RigGocadData* gocadData ) +bool importDataset( const PvdDataset& dataset, RigGocadData* gocadData ) { TiXmlDocument doc; if ( !doc.LoadFile( dataset.filename.c_str() ) ) @@ -257,7 +257,7 @@ bool importDataset( const PVDDataset& dataset, RigGocadData* gocadData ) return false; } - return importFromXMLDoc( doc, gocadData ); + return importFromXmlDoc( doc, gocadData ); } }; // namespace RifVtkSurfaceImporter diff --git a/ApplicationLibCode/ProjectDataModel/Surfaces/CMakeLists_files.cmake b/ApplicationLibCode/ProjectDataModel/Surfaces/CMakeLists_files.cmake index b78f303ac1..c39fc34973 100644 --- a/ApplicationLibCode/ProjectDataModel/Surfaces/CMakeLists_files.cmake +++ b/ApplicationLibCode/ProjectDataModel/Surfaces/CMakeLists_files.cmake @@ -9,6 +9,7 @@ set(SOURCE_GROUP_HEADER_FILES ${CMAKE_CURRENT_LIST_DIR}/RimEnsembleSurface.h ${CMAKE_CURRENT_LIST_DIR}/RimEnsembleStatisticsSurface.h ${CMAKE_CURRENT_LIST_DIR}/RimDepthSurface.h + ${CMAKE_CURRENT_LIST_DIR}/RimFractureSurface.h ) set(SOURCE_GROUP_SOURCE_FILES @@ -22,6 +23,7 @@ set(SOURCE_GROUP_SOURCE_FILES ${CMAKE_CURRENT_LIST_DIR}/RimEnsembleSurface.cpp ${CMAKE_CURRENT_LIST_DIR}/RimEnsembleStatisticsSurface.cpp ${CMAKE_CURRENT_LIST_DIR}/RimDepthSurface.cpp + ${CMAKE_CURRENT_LIST_DIR}/RimFractureSurface.cpp ) list(APPEND CODE_HEADER_FILES ${SOURCE_GROUP_HEADER_FILES}) diff --git a/ApplicationLibCode/ProjectDataModel/Surfaces/RimFractureSurface.cpp b/ApplicationLibCode/ProjectDataModel/Surfaces/RimFractureSurface.cpp new file mode 100644 index 0000000000..735f41fd0d --- /dev/null +++ b/ApplicationLibCode/ProjectDataModel/Surfaces/RimFractureSurface.cpp @@ -0,0 +1,207 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// 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 +// for more details. +// +///////////////////////////////////////////////////////////////////////////////// + +#include "RimFractureSurface.h" + +#include "RiaPreferences.h" + +#include "RimSurfaceCollection.h" + +#include "RifSurfaceImporter.h" +#include "RifVtkSurfaceImporter.h" + +#include "RigGocadData.h" +#include "RigSurface.h" + +#include "cafPdmFieldScriptingCapability.h" +#include "cafPdmObjectScriptingCapability.h" + +#include +#include + +CAF_PDM_SOURCE_INIT( RimFractureSurface, "RimFractureSurface" ); + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RimFractureSurface::RimFractureSurface() +{ + CAF_PDM_InitScriptableObject( "Surface", ":/ReservoirSurface16x16.png" ); + + CAF_PDM_InitFieldNoDefault( &m_surfaceDefinitionFilePath, "SurfaceFilePath", "File" ); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RimFractureSurface::~RimFractureSurface() +{ +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimFractureSurface::setSurfaceFilePath( const QString& filePath ) +{ + m_surfaceDefinitionFilePath = filePath; + + clearCachedNativeData(); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +QString RimFractureSurface::surfaceFilePath() +{ + return m_surfaceDefinitionFilePath().path(); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool RimFractureSurface::onLoadData() +{ + return updateSurfaceData(); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RimSurface* RimFractureSurface::createCopy() +{ + auto newSurface = copyObject(); + if ( !newSurface->onLoadData() ) + { + delete newSurface; + return nullptr; + } + + return newSurface; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimFractureSurface::fieldChangedByUi( const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue ) +{ + RimSurface::fieldChangedByUi( changedField, oldValue, newValue ); + + if ( changedField == &m_surfaceDefinitionFilePath ) + { + clearCachedNativeData(); + updateSurfaceData(); + + auto surfColl = firstAncestorOrThisOfTypeAsserted(); + surfColl->updateViews( { this } ); + } +} + +//-------------------------------------------------------------------------------------------------- +/// Regenerate the surface geometry, using the offset specified. +/// If the surface data hasn't been loaded from file yet, load it. +/// Returns false for fatal failure +//-------------------------------------------------------------------------------------------------- +bool RimFractureSurface::updateSurfaceData() +{ + bool result = true; + /* + if ( m_vertices.empty() ) + { + result = loadDataFromFile(); + } + + std::vector vertices{ m_vertices }; + std::vector tringleIndices{ m_tringleIndices }; + + auto surface = new RigSurface; + if ( !vertices.empty() && !tringleIndices.empty() ) + { + RimSurface::applyDepthOffsetIfNeeded( &vertices ); + + surface->setTriangleData( tringleIndices, vertices ); + } + + if ( m_gocadData ) + { + auto propertyNames = m_gocadData->propertyNames(); + for ( const auto& name : propertyNames ) + { + auto values = m_gocadData->propertyValues( name ); + surface->addVerticeResult( name, values ); + } + } + + setSurfaceData( surface ); + */ + + return result; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimFractureSurface::clearCachedNativeData() +{ + /* + m_vertices.clear(); + m_tringleIndices.clear(); + */ +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool RimFractureSurface::loadDataFromFile() +{ + return false; + + /* + std::pair, std::vector> surface; + + QString filePath = surfaceFilePath(); + if ( filePath.endsWith( "ptl", Qt::CaseInsensitive ) ) + { + surface = RifSurfaceImporter::readPetrelFile( filePath ); + } + else if ( filePath.endsWith( "ts", Qt::CaseInsensitive ) ) + { + m_gocadData = std::make_unique(); + + RifSurfaceImporter::readGocadFile( filePath, m_gocadData.get() ); + + surface = m_gocadData->gocadGeometry(); + } + else if ( filePath.endsWith( "vtu", Qt::CaseInsensitive ) ) + { + m_gocadData = std::make_unique(); + RifVtkSurfaceImporter::importFromFile( filePath.toStdString(), m_gocadData.get() ); + + surface = m_gocadData->gocadGeometry(); + } + else if ( filePath.endsWith( "dat", Qt::CaseInsensitive ) || filePath.endsWith( "xyz", Qt::CaseInsensitive ) ) + { + double resamplingDistance = RiaPreferences::current()->surfaceImportResamplingDistance(); + surface = RifSurfaceImporter::readOpenWorksXyzFile( filePath, resamplingDistance ); + } + + m_vertices = surface.first; + m_tringleIndices = surface.second; + + return !( m_vertices.empty() || m_tringleIndices.empty() ); +*/ +} diff --git a/ApplicationLibCode/ProjectDataModel/Surfaces/RimFractureSurface.h b/ApplicationLibCode/ProjectDataModel/Surfaces/RimFractureSurface.h new file mode 100644 index 0000000000..c79ef7a792 --- /dev/null +++ b/ApplicationLibCode/ProjectDataModel/Surfaces/RimFractureSurface.h @@ -0,0 +1,48 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// 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 +// for more details. +// +///////////////////////////////////////////////////////////////////////////////// + +#pragma once + +#include "RimSurface.h" + +class RimFractureSurface : public RimSurface +{ + CAF_PDM_HEADER_INIT; + +public: + RimFractureSurface(); + ~RimFractureSurface() override; + + void setSurfaceFilePath( const QString& filePath ); + QString surfaceFilePath(); + + bool onLoadData() override; + RimSurface* createCopy() override; + +protected: + bool updateSurfaceData() override; + void clearCachedNativeData() override; + +private: + bool loadDataFromFile(); + +private: + void fieldChangedByUi( const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue ) override; + + caf::PdmField m_surfaceDefinitionFilePath; +};