#5379 Surface : Add depth offset to base surface class

This commit is contained in:
Magne Sjaastad
2020-05-03 11:35:06 +02:00
parent 7bfe631118
commit e0d426df12
11 changed files with 225 additions and 74 deletions

View File

@@ -53,6 +53,8 @@ void RimFileSurface::setSurfaceFilePath( const QString& filePath )
{
setUserDescription( QFileInfo( filePath ).fileName() );
}
clearCachedNativeFileData();
}
//--------------------------------------------------------------------------------------------------
@@ -66,7 +68,7 @@ QString RimFileSurface::surfaceFilePath()
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RimFileSurface::loadData()
bool RimFileSurface::onLoadData()
{
return updateSurfaceDataFromFile();
}
@@ -82,6 +84,7 @@ void RimFileSurface::fieldChangedByUi( const caf::PdmFieldHandle* changedField,
if ( changedField == &m_surfaceDefinitionFilePath )
{
clearCachedNativeFileData();
updateSurfaceDataFromFile();
RimSurfaceCollection* surfColl;
@@ -95,11 +98,46 @@ void RimFileSurface::fieldChangedByUi( const caf::PdmFieldHandle* changedField,
//--------------------------------------------------------------------------------------------------
bool RimFileSurface::updateSurfaceDataFromFile()
{
QString filePath = this->surfaceFilePath();
bool result = true;
if ( m_vertices.empty() )
{
result = loadDataFromFile();
}
std::vector<unsigned> tringleIndices;
std::vector<cvf::Vec3d> vertices{m_vertices};
std::vector<unsigned> tringleIndices{m_tringleIndices};
auto surface = new RigSurface;
if ( !vertices.empty() && !tringleIndices.empty() )
{
RimSurface::applyDepthOffsetIfNeeded( &vertices );
surface->setTriangleData( tringleIndices, vertices );
}
setSurfaceData( surface );
return result;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimFileSurface::clearCachedNativeFileData()
{
m_vertices.clear();
m_tringleIndices.clear();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RimFileSurface::loadDataFromFile()
{
std::vector<cvf::Vec3d> vertices;
std::vector<unsigned> tringleIndices;
QString filePath = this->surfaceFilePath();
if ( filePath.endsWith( "ptl", Qt::CaseInsensitive ) )
{
auto surface = RifSurfaceReader::readPetrelFile( filePath );
@@ -115,15 +153,10 @@ bool RimFileSurface::updateSurfaceDataFromFile()
tringleIndices = surface.second;
}
if ( !vertices.empty() && !tringleIndices.empty() )
{
auto surface = new RigSurface();
surface->setTriangleData( tringleIndices, vertices );
m_vertices = vertices;
m_tringleIndices = tringleIndices;
setSurfaceData( surface );
if ( vertices.empty() || tringleIndices.empty() ) return false;
return true;
}
return false;
return true;
}