ResInsight/ApplicationLibCode/ReservoirDataModel/RigSurface.cpp
Magne Sjaastad 2480a782d1
Ensemble Surface improvements
* Performance : Improve surface import
* Performance: Use opm when importing files
* Surface : Use the triangle size as basis for the maximum search distance
* Performance : Resample surfaces in parallell
* Performance: Import file surfaces in parallell
* Ensemble Surface : Create one ensemble per surface
2021-09-16 14:28:19 +02:00

168 lines
6.3 KiB
C++

/////////////////////////////////////////////////////////////////////////////////
//
// 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 "RigSurface.h"
#include "cafAssert.h"
#include "cvfBoundingBox.h"
#include "cvfBoundingBoxTree.h"
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RigSurface::RigSurface() = default;
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RigSurface::~RigSurface() = default;
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
const std::vector<unsigned>& RigSurface::triangleIndices() const
{
return m_triangleIndices;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
const std::vector<cvf::Vec3d>& RigSurface::vertices() const
{
return m_vertices;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RigSurface::setTriangleData( const std::vector<unsigned>& tringleIndices, const std::vector<cvf::Vec3d>& vertices )
{
m_triangleIndices = tringleIndices;
m_vertices = vertices;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RigSurface::addVerticeResult( const QString resultName, const std::vector<float>& resultValues )
{
m_verticeResults[resultName] = resultValues;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::vector<float> RigSurface::propertyValues( const QString& propertyName ) const
{
auto it = m_verticeResults.find( propertyName );
if ( it != m_verticeResults.end() )
{
return it->second;
}
return {};
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::vector<QString> RigSurface::propertyNames() const
{
std::vector<QString> names;
for ( const auto& propertyResult : m_verticeResults )
{
names.push_back( propertyResult.first );
}
return names;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RigSurface::findIntersectingTriangles( const cvf::BoundingBox& inputBB, std::vector<size_t>* triangleStartIndices ) const
{
CAF_ASSERT( m_surfaceBoundingBoxTree.notNull() );
m_surfaceBoundingBoxTree->findIntersections( inputBB, triangleStartIndices );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
double RigSurface::maxExtentTriangleInXDirection() const
{
return m_maxExtentTriangleInXDirection;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
double RigSurface::maxExtentTriangleInYDirection() const
{
return m_maxExtentTriangleInYDirection;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RigSurface::ensureIntersectionSearchTreeIsBuilt()
{
if ( m_surfaceBoundingBoxTree.isNull() )
{
size_t itemCount = triangleCount();
std::vector<cvf::BoundingBox> cellBoundingBoxes;
std::vector<size_t> boundingBoxIds;
cellBoundingBoxes.resize( itemCount );
boundingBoxIds.resize( itemCount );
double maxX = -1.0;
double maxY = -1.0;
for ( size_t triangleIdx = 0; triangleIdx < itemCount; ++triangleIdx )
{
cvf::BoundingBox& cellBB = cellBoundingBoxes[triangleIdx];
cellBB.add( m_vertices[m_triangleIndices[triangleIdx * 3 + 0]] );
cellBB.add( m_vertices[m_triangleIndices[triangleIdx * 3 + 1]] );
cellBB.add( m_vertices[m_triangleIndices[triangleIdx * 3 + 2]] );
boundingBoxIds[triangleIdx] = triangleIdx * 3;
if ( cellBB.extent().x() > maxX ) maxX = cellBB.extent().x();
if ( cellBB.extent().y() > maxY ) maxY = cellBB.extent().y();
}
m_maxExtentTriangleInXDirection = maxX;
m_maxExtentTriangleInYDirection = maxY;
m_surfaceBoundingBoxTree = new cvf::BoundingBoxTree;
m_surfaceBoundingBoxTree->buildTreeFromBoundingBoxes( cellBoundingBoxes, &boundingBoxIds );
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
size_t RigSurface::triangleCount() const
{
return m_triangleIndices.size() / 3;
}